#!/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/json/v5/reports"

REQUEST='{
    "params" : {
        "SelectionCriteria" : {
            "DateFrom": "2018-01-01",
            "DateTo": "2018-03-01"
        },
        "Goals" : [2978362,4248286],
        "AttributionModels" : ["LSC"],
        "FieldNames" : ["Date", "Clicks", "Impressions", "Conversions", "CostPerConversion", "GoalsRoi", "Revenue", "ConversionRate"],
        "Page" : { "Limit" : 20 },
        "ReportName" : "testReport 20170220-2",
        "ReportType" : "CUSTOM_REPORT",
        "DateRangeType" : "CUSTOM_DATE",
        "Format" : "TSV",
        "IncludeVAT" : "YES",
    }
}'

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

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

echo
