#!/bin/bash

tokens_file='/etc/direct-tokens/api_test_tokens'
client_login='at-direct-api-test'
operator_login='at-direct-super'
oauth_token=$(grep "^$operator_login " $tokens_file |awk '{print $2}')


SCRIPTPATH=`readlink -f $0`
SCRIPTDIR=`dirname $SCRIPTPATH`

source $SCRIPTDIR/beta_number

SERVICE_URL="$JSON_URL/campaigns"
#echo $SERVICE_URL

[ -z "$cid" ] && cid=31090857

#PriorityGoals='null'
PriorityGoals='{"Items": [ {"GoalId": 12, "Value": 88000000, "Operation": "SET"} ]}'

REQUEST='
  {
    "method":"update",
    "params": {
        "Campaigns": [
          {
            "TextCampaign": {
              "PriorityGoals": '$PriorityGoals'
            },
            "Id": '$cid'
          }
        ]
    }
  }';

case "$1" in
    *-r*)
        echo "$REQUEST"
        exit
        ;;
esac

curl \
    -s -k \
    -H "Authorization: Bearer $oauth_token"\
    -H "Client-Login: $client_login" \
    -d "$REQUEST" \
    "$SERVICE_URL"

echo
