Class: MuffinMan::DataKiosk::V20231115

Inherits:
SpApiClient show all
Defined in:
lib/muffin_man/data_kiosk/v20231115.rb

Constant Summary collapse

SANDBOX_PAGE_SIZE =
1
SANDBOX_PROCESSING_STATUSES =
"DONE, IN_PROGRESS"
SANDBOX_QUERY =
<<-QUERY
query {
  sampleQuery(
    startDate: "2023-03-01"
    endDate: "2023-03-31"
    marketplaceIds: ["ATVPDKIKX0DER"]
  ) {
    sales {
      date
      averageSellingPrice {
        amount
        currencyCode
      }
    }
  }
}
QUERY
SANDBOX_QUERY_ID =
"QueryId1"
SANDBOX_DOCUMENT_ID =
"DocumentId1"
GET_QUERIES_PARAMS =
%w[
  processingStatuses
  pageSize
  createdSince
  createdUntil
  paginationToken
].freeze

Constants inherited from SpApiClient

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

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_query(query_id) ⇒ Object



67
68
69
70
71
72
# File 'lib/muffin_man/data_kiosk/v20231115.rb', line 67

def cancel_query(query_id)
  query_id = SANDBOX_QUERY_ID if sandbox
  @local_var_path = "/dataKiosk/2023-11-15/queries/#{query_id}"
  @request_type = "DELETE"
  call_api
end

#create_query(query, pagination_token = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/muffin_man/data_kiosk/v20231115.rb', line 49

def create_query(query, pagination_token = nil)
  @local_var_path = "/dataKiosk/2023-11-15/queries"
  query = SANDBOX_QUERY if sandbox
  @request_body = {
    "query" => query
  }
  @request_body["paginationToken"] = pagination_token unless pagination_token.nil?
  @request_type = "POST"
  call_api
end

#get_document(document_id) ⇒ Object



74
75
76
77
78
79
# File 'lib/muffin_man/data_kiosk/v20231115.rb', line 74

def get_document(document_id)
  document_id = SANDBOX_DOCUMENT_ID if sandbox
  @local_var_path = "/dataKiosk/2023-11-15/documents/#{document_id}"
  @request_type = "GET"
  call_api
end

#get_queries(params = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/muffin_man/data_kiosk/v20231115.rb', line 36

def get_queries(params = {})
  @local_var_path = "/dataKiosk/2023-11-15/queries"
  if sandbox
    params = {
      "pageSize" => SANDBOX_PAGE_SIZE,
      "processingStatuses" => SANDBOX_PROCESSING_STATUSES
    }
  end
  @query_params = params.slice(*GET_QUERIES_PARAMS)
  @request_type = "GET"
  call_api
end

#get_query(query_id) ⇒ Object



60
61
62
63
64
65
# File 'lib/muffin_man/data_kiosk/v20231115.rb', line 60

def get_query(query_id)
  query_id = SANDBOX_QUERY_ID if sandbox
  @local_var_path = "/dataKiosk/2023-11-15/queries/#{query_id}"
  @request_type = "GET"
  call_api
end

#retrieve_document_content(document_id) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/muffin_man/data_kiosk/v20231115.rb', line 81

def retrieve_document_content(document_id)
  response = get_document(document_id)
  if response.success?
    Typhoeus.get(JSON.parse(response.body)["documentUrl"], accept_encoding: "")
  else
    response
  end
end