#!/bin/bash

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


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

source $SCRIPTDIR/../beta_number

SERVICE_URL="$BASE_URL/v5/reports"
echo $SERVICE_URL

REQUEST='<ReportDefinition xmlns="http://api.direct.yandex.com/v5/reports">
            <SelectionCriteria>
                <DateFrom>2018-07-10</DateFrom>
                <DateTo>2018-07-31</DateTo>
            </SelectionCriteria>
            <Goals>2978362</Goals>
            <AttributionModels>LSC</AttributionModels>
            <FieldNames>Date</FieldNames>
            <FieldNames>AvgTimeToConversion</FieldNames>
            <FieldNames>Clicks</FieldNames>
            <FieldNames>Impressions</FieldNames>
            <FieldNames>Conversions</FieldNames>
            <ReportName>bidModifierPerformance_2017-04-25-38</ReportName>
            <ReportType>CUSTOM_REPORT</ReportType>
            <DateRangeType>CUSTOM_DATE</DateRangeType>
            <Format>TSV</Format>
            <IncludeVAT>YES</IncludeVAT>
        </ReportDefinition>'

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

curl \
    -k -v \
    -H 'Authorization: Bearer $oauth_token' \
    -H 'Fake-Login: $client_login' \
    -H 'Accept-Language: ru' \
    -H 'returnMoneyInMicros: false' \
    -d "$REQUEST" \
    "$SERVICE_URL"

echo
