forked from xapix-io/amz_sp_api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sp_configuration.rb
39 lines (32 loc) · 1.2 KB
/
sp_configuration.rb
1
2
3
4
5
6
7
8
9
10
11
12
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
require 'configuration'
module AmzSpApi
class SpConfiguration < Configuration
attr_accessor :refresh_token, :client_id, :client_secret, :sandbox, :region,
:save_access_token, :get_access_token # optional lambdas for storing and retrieving token
# from https://github.com/amzn/selling-partner-api-docs/blob/main/guides/developer-guide/SellingPartnerApiDeveloperGuide.md#selling-partner-api-endpoints
AWS_REGION_MAP = {
'na' => 'us-east-1',
'eu' => 'eu-west-1',
'fe' => 'us-west-2'
}.freeze
def aws_region
AWS_REGION_MAP[region]
end
def region=(region)
@region = region
fail ApiError.new("#{region} is not supported or does not exist. Region must be one of the following: #{AWS_REGION_MAP.keys.join(', ')}") unless aws_region
self.host = "#{sandbox ? "sandbox." : ""}sellingpartnerapi-#{region}.amazon.com"
self.base_path = "/" # incorrectly set to full url by codegen
end
def sandbox=(sandbox)
@sandbox = sandbox
self.region = @region
end
def access_token_key
Digest::MD5.hexdigest("#{client_id} #{refresh_token}")
end
def self.default
@@default ||= SpConfiguration.new
end
end
end