13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/sales/client.rb', line 13
def get_data(ids, start_time = Date.today - 5.day, end_time = Date.today - 1.day)
start_time = start_time.strftime('%Y-%m-%dT%H:%M:%S.000Z')
end_time = end_time.strftime('%Y-%m-%dT%H:%M:%S.000Z')
fail 'ids must be array' unless ids.is_a?(Array)
body = {
"filters":
[
{
"dimension_key":"content",
"option_keys":ids
}
],
"group":"content",
"interval":"day",
"start_date": start_time,
"end_date": end_time,
"sort":"descending",
"limit":100,
"measures":["Royalty_utc", "total_tax_usd_utc", "units_utc"]}
response = request(:post) do |req|
req.url "api/data/timeseries"
req.body = body.to_json
req.['Content-Type'] = 'application/json'
req.['Cookie'] = cookie
req.['Host'] = 'reportingitc2.apple.com'
req.['Origin'] = 'https://reportingitc2.apple.com'
req.['Referer'] = "https://reportingitc2.apple.com/sales.html?startDate=#{start_time}&endDate=#{end_time}&filter_content=#{ids.first}"
end
response.body || []
end
|