#!/bin/bash

tokens_file='/etc/direct-tokens/api_test_tokens'
client_login='andy-ilyin-client'
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="$URL/campaigns"
#echo $SERVICE_URL

REQUEST='<?xml version="1.0" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:general="http://api.direct.yandex.com/v5/general"
    xmlns:campaigns="http://api.direct.yandex.com/v5/campaigns"
>
    <soapenv:Body>
        <campaigns:GetRequest>
            <SelectionCriteria>
                <Ids>7412867</Ids>
            </SelectionCriteria>
            <FieldNames>Id</FieldNames>
            <FieldNames>Name</FieldNames>
            <FieldNames>ExcludedSites</FieldNames>
            <TextCampaignFieldNames>Settings</TextCampaignFieldNames>
        </campaigns:GetRequest>
    </soapenv:Body>
</soapenv:Envelope>';

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

curl \
     -k \
    -H "Authorization: Bearer $oauth_token" \
    -H "SOAPAction: 'http://api.direct.yandex.com/v5/campaigns/get'" \
    -H "Client-Login: $client_login" \
    -d "$REQUEST" \
    "$SERVICE_URL"

echo
