Class: Spaceship::SalesClient

Inherits:
Client
  • Object
show all
Defined in:
lib/sales/client.rb

Overview

This class is used to upload Digital files (Images, Videos, JSON files) onto the du-itc service. Its implementation is tied to the tunes module (in particular using AppVersion instances)

Init and Login collapse

Class Method Details

.hostnameObject



9
10
11
# File 'lib/sales/client.rb', line 9

def self.hostname
  "https://reportingitc2.apple.com/"
end

Instance Method Details

#get_data(ids, start_time = Date.today - 5.day, end_time = Date.today - 1.day) ⇒ Object



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.headers['Content-Type'] = 'application/json'
    req.headers['Cookie']         = cookie
    req.headers['Host']           = 'reportingitc2.apple.com'
    req.headers['Origin']         = 'https://reportingitc2.apple.com'
    req.headers['Referer']        = "https://reportingitc2.apple.com/sales.html?startDate=#{start_time}&endDate=#{end_time}&filter_content=#{ids.first}"
  end

  response.body || []
end

#send_login_request(user, password) ⇒ Object



48
49
50
# File 'lib/sales/client.rb', line 48

def (user, password)
  (user, password)
end