Class: MuffinMan::Reports::V20210630

Inherits:
SpApiClient show all
Defined in:
lib/muffin_man/reports/v20210630.rb

Constant Summary collapse

SANDBOX_REPORT_TYPES =
"FEE_DISCOUNTS_REPORT,GET_AFN_INVENTORY_DATA".freeze
SANDBOX_PROCESSING_STATUSES =
"IN_QUEUE,IN_PROGRESS".freeze
SANDBOX_REPORT_TYPE =
"GET_MERCHANT_LISTINGS_ALL_DATA".freeze
SANDBOX_START_TIME =
"2019-12-10T20:11:24.000Z".freeze
SANDBOX_CANCEL_REPORT_ID =
"ID".freeze
SANDBOX_MARKETPLACE_IDS =
%w[
  A1PA6795UKMFR9
  ATVPDKIKX0DER
].freeze
SANDBOX_REPORT_ID =
"ID323".freeze
SANDBOX_REPORT_DOCUMENT_ID =
"0356cf79-b8b0-4226-b4b9-0ee058ea5760".freeze
GET_REPORTS_PARAMS =
%w[
  reportTypes
  processingStatuses
  marketplaceIds
  pageSize
  createdSince
  createdUntil
  nextToken
].freeze

Constants inherited from SpApiClient

SpApiClient::ACCESS_TOKEN_URL, SpApiClient::AWS_REGION_MAP, SpApiClient::SERVICE_NAME

Instance Attribute Summary

Attributes inherited from SpApiClient

#access_token_cache_key, #aws_access_key_id, #aws_secret_access_key, #client_id, #client_secret, #config, #credentials, #local_var_path, #pii_data_elements, #query_params, #refresh_token, #region, #request_body, #request_type, #sandbox, #scope, #sts_iam_role_arn

Instance Method Summary collapse

Methods inherited from SpApiClient

#initialize

Constructor Details

This class inherits a constructor from MuffinMan::SpApiClient

Instance Method Details

#cancel_report(report_id) ⇒ Object



63
64
65
66
67
68
# File 'lib/muffin_man/reports/v20210630.rb', line 63

def cancel_report(report_id)
  report_id = sandbox ? SANDBOX_CANCEL_REPORT_ID : report_id
  @local_var_path = "/reports/2021-06-30/reports/#{report_id}"
  @request_type = "DELETE"
  call_api
end

#create_report(report_type, marketplace_ids, start_time = nil, end_time = nil, report_options = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/muffin_man/reports/v20210630.rb', line 39

def create_report(report_type, marketplace_ids, start_time = nil, end_time = nil, report_options = {})
  report_type = sandbox ? SANDBOX_REPORT_TYPE : report_type
  marketplace_ids = sandbox ? SANDBOX_MARKETPLACE_IDS : marketplace_ids
  start_time = sandbox ? SANDBOX_START_TIME : start_time

  @local_var_path = "/reports/2021-06-30/reports"
  @request_body = {
    "reportType" => report_type,
    "marketplaceIds" => marketplace_ids
  }
  @request_body["dataStartTime"] = start_time unless start_time.nil?
  @request_body["dataEndTime"] = end_time unless end_time.nil?
  @request_body["reportOptions"] = report_options unless report_options.empty?
  @request_type = "POST"
  call_api
end

#get_report(report_id) ⇒ Object



56
57
58
59
60
61
# File 'lib/muffin_man/reports/v20210630.rb', line 56

def get_report(report_id)
  report_id = sandbox ? SANDBOX_REPORT_ID : report_id
  @local_var_path = "/reports/2021-06-30/reports/#{report_id}"
  @request_type = "GET"
  call_api
end

#get_report_document(report_document_id) ⇒ Object



70
71
72
73
74
75
# File 'lib/muffin_man/reports/v20210630.rb', line 70

def get_report_document(report_document_id)
  report_document_id = sandbox ? SANDBOX_REPORT_DOCUMENT_ID : report_document_id
  @local_var_path = "/reports/2021-06-30/documents/#{report_document_id}"
  @request_type = "GET"
  call_api
end

#get_report_document_body(report_document_id) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/muffin_man/reports/v20210630.rb', line 77

def get_report_document_body(report_document_id)
  response = get_report_document(report_document_id)
  parsed_response=JSON.parse(response.body)
  report=Net::HTTP.get(URI.parse(parsed_response['url']))
  unless (parsed_response['compressionAlgorithm']).nil?
    input = StringIO.new(report)
    report = Zlib::GzipReader.new(input).read
  end
  report
end

#get_reports(params = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/muffin_man/reports/v20210630.rb', line 26

def get_reports(params = {})
  @local_var_path = "/reports/2021-06-30/reports"
  if sandbox
    params = {
      "reportTypes" => SANDBOX_REPORT_TYPES,
      "processingStatuses" => SANDBOX_PROCESSING_STATUSES
    }
  end
  @query_params = params.slice(*GET_REPORTS_PARAMS)
  @request_type = "GET"
  call_api
end