sp_api_clients 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +161 -0
  3. data/LICENSE +21 -0
  4. data/README.md +284 -0
  5. data/lib/amazon_sp_clients/adapter_loader.rb +28 -0
  6. data/lib/amazon_sp_clients/api_client.rb +309 -0
  7. data/lib/amazon_sp_clients/api_error.rb +37 -0
  8. data/lib/amazon_sp_clients/api_response.rb +54 -0
  9. data/lib/amazon_sp_clients/configuration.rb +144 -0
  10. data/lib/amazon_sp_clients/marketplaces.rb +63 -0
  11. data/lib/amazon_sp_clients/middlewares/raise_error.rb +166 -0
  12. data/lib/amazon_sp_clients/session.rb +124 -0
  13. data/lib/amazon_sp_clients/sp_fba_inventory.rb +8 -0
  14. data/lib/amazon_sp_clients/sp_feeds_2021.rb +8 -0
  15. data/lib/amazon_sp_clients/sp_fulfillment_outbound_2020.rb +8 -0
  16. data/lib/amazon_sp_clients/sp_listings_items_2021.rb +8 -0
  17. data/lib/amazon_sp_clients/sp_orders_v0.rb +8 -0
  18. data/lib/amazon_sp_clients/sp_reports_2021.rb +8 -0
  19. data/lib/amazon_sp_clients/sp_tokens_2021.rb +8 -0
  20. data/lib/amazon_sp_clients/sp_vdf_inventory_v1.rb +8 -0
  21. data/lib/amazon_sp_clients/sp_vdf_orders_v1.rb +8 -0
  22. data/lib/amazon_sp_clients/sp_vdf_shipping_v1.rb +8 -0
  23. data/lib/amazon_sp_clients/sp_vendor_invoices.rb +8 -0
  24. data/lib/amazon_sp_clients/sp_vendor_orders.rb +8 -0
  25. data/lib/amazon_sp_clients/sp_vendor_transaction_status.rb +8 -0
  26. data/lib/amazon_sp_clients/sp_vendors_shipments.rb +8 -0
  27. data/lib/amazon_sp_clients/token_exchange_auth.rb +82 -0
  28. data/lib/amazon_sp_clients/uploader.rb +77 -0
  29. data/lib/amazon_sp_clients/v2/api.rb +43 -0
  30. data/lib/amazon_sp_clients/v2/apis/fba_inventory.rb +80 -0
  31. data/lib/amazon_sp_clients/v2/apis/feeds_2021.rb +86 -0
  32. data/lib/amazon_sp_clients/v2/apis/fulfillment_outbound_2020.rb +184 -0
  33. data/lib/amazon_sp_clients/v2/apis/listings_items_2021.rb +144 -0
  34. data/lib/amazon_sp_clients/v2/apis/orders_v0.rb +165 -0
  35. data/lib/amazon_sp_clients/v2/apis/reports_2021.rb +117 -0
  36. data/lib/amazon_sp_clients/v2/apis/tokens_2021.rb +25 -0
  37. data/lib/amazon_sp_clients/v2/apis/vdf_inventory_v1.rb +26 -0
  38. data/lib/amazon_sp_clients/v2/apis/vdf_orders_v1.rb +61 -0
  39. data/lib/amazon_sp_clients/v2/apis/vdf_shipping_v1.rb +139 -0
  40. data/lib/amazon_sp_clients/v2/apis/vendor_invoices.rb +25 -0
  41. data/lib/amazon_sp_clients/v2/apis/vendor_orders.rb +106 -0
  42. data/lib/amazon_sp_clients/v2/apis/vendor_transaction_status.rb +25 -0
  43. data/lib/amazon_sp_clients/v2/apis/vendors_shipments.rb +120 -0
  44. data/lib/amazon_sp_clients/v2/apis.rb +82 -0
  45. data/lib/amazon_sp_clients/v2/client.rb +198 -0
  46. data/lib/amazon_sp_clients/v2/config.rb +85 -0
  47. data/lib/amazon_sp_clients/v2/credentials.rb +91 -0
  48. data/lib/amazon_sp_clients/v2/documents.rb +115 -0
  49. data/lib/amazon_sp_clients/v2/error_mapper.rb +235 -0
  50. data/lib/amazon_sp_clients/v2/errors.rb +117 -0
  51. data/lib/amazon_sp_clients/v2/lwa.rb +100 -0
  52. data/lib/amazon_sp_clients/v2/rdt.rb +104 -0
  53. data/lib/amazon_sp_clients/v2/token.rb +39 -0
  54. data/lib/amazon_sp_clients/v2.rb +33 -0
  55. data/lib/amazon_sp_clients/version.rb +3 -0
  56. data/lib/amazon_sp_clients.rb +69 -0
  57. data/lib/sp_api_clients.rb +6 -0
  58. data/sp_api_clients.gemspec +53 -0
  59. data/vendor/fba_inventory/lib/sp_fba_inventory/api/fba_inventory_api.rb +289 -0
  60. data/vendor/fba_inventory/lib/sp_fba_inventory.rb +12 -0
  61. data/vendor/feeds_2021/lib/sp_feeds_2021/api/feeds_api.rb +367 -0
  62. data/vendor/feeds_2021/lib/sp_feeds_2021.rb +12 -0
  63. data/vendor/fulfillment_outbound_2020/lib/sp_fulfillment_outbound_2020/api/fba_outbound_api.rb +845 -0
  64. data/vendor/fulfillment_outbound_2020/lib/sp_fulfillment_outbound_2020.rb +12 -0
  65. data/vendor/listings_items_2021/lib/sp_listings_items_2021/api/listings_api.rb +480 -0
  66. data/vendor/listings_items_2021/lib/sp_listings_items_2021.rb +12 -0
  67. data/vendor/orders_v0/lib/sp_orders_v0/api/orders_v0_api.rb +593 -0
  68. data/vendor/orders_v0/lib/sp_orders_v0/api/shipment_api.rb +83 -0
  69. data/vendor/orders_v0/lib/sp_orders_v0.rb +13 -0
  70. data/vendor/reports_2021/lib/sp_reports_2021/api/reports_api.rb +530 -0
  71. data/vendor/reports_2021/lib/sp_reports_2021.rb +12 -0
  72. data/vendor/tokens_2021/lib/sp_tokens_2021/api/tokens_api.rb +77 -0
  73. data/vendor/tokens_2021/lib/sp_tokens_2021.rb +12 -0
  74. data/vendor/vdf_inventory_v1/lib/sp_vdf_inventory_v1/api/update_inventory_api.rb +83 -0
  75. data/vendor/vdf_inventory_v1/lib/sp_vdf_inventory_v1.rb +12 -0
  76. data/vendor/vdf_orders_v1/lib/sp_vdf_orders_v1/api/vendor_orders_api.rb +217 -0
  77. data/vendor/vdf_orders_v1/lib/sp_vdf_orders_v1.rb +12 -0
  78. data/vendor/vdf_shipping_v1/lib/sp_vdf_shipping_v1/api/customer_invoices_api.rb +152 -0
  79. data/vendor/vdf_shipping_v1/lib/sp_vdf_shipping_v1/api/vendor_shipping_api.rb +264 -0
  80. data/vendor/vdf_shipping_v1/lib/sp_vdf_shipping_v1/api/vendor_shipping_labels_api.rb +208 -0
  81. data/vendor/vdf_shipping_v1/lib/sp_vdf_shipping_v1.rb +14 -0
  82. data/vendor/vendor_invoices/lib/sp_vendor_invoices/api/vendor_payments_api.rb +77 -0
  83. data/vendor/vendor_invoices/lib/sp_vendor_invoices.rb +12 -0
  84. data/vendor/vendor_orders/lib/sp_vendor_orders/api/vendor_orders_api.rb +323 -0
  85. data/vendor/vendor_orders/lib/sp_vendor_orders.rb +12 -0
  86. data/vendor/vendor_transaction_status/lib/sp_vendor_transaction_status/api/vendor_transaction_api.rb +75 -0
  87. data/vendor/vendor_transaction_status/lib/sp_vendor_transaction_status.rb +12 -0
  88. data/vendor/vendors_shipments/lib/sp_vendors_shipments/api/vendor_shipping_api.rb +337 -0
  89. data/vendor/vendors_shipments/lib/sp_vendors_shipments.rb +12 -0
  90. metadata +321 -0
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'amazon_sp_clients/v2/token'
4
+
5
+ module AmazonSpClients
6
+ module V2
7
+ # Restricted data tokens (RDT). The Tokens API issues a short-lived
8
+ # token for named restricted resources; a call that returns PII sends
9
+ # that token instead of the normal access token.
10
+ #
11
+ # client.orders_v0.get_orders(ids, rdt: RDT::ORDERS_AND_ITEMS)
12
+ # client.reports_2021.get_report_document(id, rdt: RDT.report_document(id))
13
+ module RDT
14
+ # One restricted resource: HTTP method, path template and the PII
15
+ # data elements wanted. A value object, so equal resources make
16
+ # equal cache keys.
17
+ Resource = Data.define(:http_method, :path, :data_elements)
18
+
19
+ class Resource
20
+ # @return [Hash] the shape the Tokens API expects
21
+ def to_request
22
+ { method: http_method, path: path, dataElements: data_elements }.compact
23
+ end
24
+ end
25
+
26
+ # Orders with buyer info and shipping address (v1's :orders).
27
+ ORDERS = [
28
+ Resource.new(http_method: 'GET', path: '/orders/v0/orders',
29
+ data_elements: %w[buyerInfo shippingAddress].freeze)
30
+ ].freeze
31
+
32
+ # ORDERS plus order items with buyer info (v1's :orders_and_items).
33
+ ORDERS_AND_ITEMS = [
34
+ *ORDERS,
35
+ Resource.new(http_method: 'GET', path: '/orders/v0/orders/{orderId}/orderItems',
36
+ data_elements: %w[buyerInfo].freeze)
37
+ ].freeze
38
+
39
+ # @param http_method [String] e.g. 'GET'
40
+ # @param path [String] path template, e.g. '/orders/v0/orders/{orderId}'
41
+ # @param data_elements [Array<String>, nil] PII fields wanted
42
+ # @return [Resource]
43
+ def self.resource(http_method, path, data_elements = nil)
44
+ Resource.new(http_method: http_method, path: path, data_elements: data_elements)
45
+ end
46
+
47
+ # Path prefix of getReportDocument in reports_2021. A token is only
48
+ # good for the exact path it names, document id included.
49
+ REPORT_DOCUMENTS_PATH = '/reports/2021-06-30/documents'
50
+
51
+ # The resource list for a restricted report document (PII report
52
+ # types such as order and returns reports).
53
+ #
54
+ # @param document_id [String] the reportDocumentId
55
+ # @return [Array<Resource>]
56
+ def self.report_document(document_id)
57
+ [resource('GET', "#{REPORT_DOCUMENTS_PATH}/#{document_id}")].freeze
58
+ end
59
+
60
+ # Restricted tokens per resource list, with expiry. One lock, held
61
+ # while a missing token is fetched, so concurrent callers for the
62
+ # same resources cause one Tokens API call. The fetch block runs
63
+ # inside the lock and must not come back to this cache.
64
+ class Cache
65
+ def initialize
66
+ @entries = {}
67
+ @mutex = Mutex.new
68
+ end
69
+
70
+ # @param resources [Array<Resource>]
71
+ # @yieldreturn [Token] a fresh restricted token, asked for on a miss
72
+ # @return [String] the restricted data token
73
+ def fetch(resources)
74
+ key = cache_key(resources)
75
+
76
+ @mutex.synchronize do
77
+ entry = @entries[key]
78
+ return entry.access_token if entry && !entry.expired?
79
+
80
+ sweep
81
+ token = yield
82
+ @entries[key] = token
83
+ token.access_token
84
+ end
85
+ end
86
+
87
+ # @return [Integer] cached tokens, expired ones included until the next miss
88
+ def size = @mutex.synchronize { @entries.size }
89
+
90
+ private
91
+
92
+ # A frozen copy, so the caller's own array is left alone.
93
+ def cache_key(resources)
94
+ list = Array(resources)
95
+ list.frozen? ? list : list.dup.freeze
96
+ end
97
+
98
+ def sweep
99
+ @entries.delete_if { |_, token| token.expired? }
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'amazon_sp_clients/v2/errors'
4
+
5
+ module AmazonSpClients
6
+ module V2
7
+ # An access token with its expiry, as returned by LWA or by the
8
+ # Tokens API (restricted data tokens). Frozen: a refresh swaps the
9
+ # whole object, so a reader never sees a token paired with another
10
+ # exchange's expiry.
11
+ Token = Data.define(:access_token, :token_type, :expires_in, :expires_at, :refresh_token)
12
+
13
+ class Token
14
+ # Seconds before the real expiry at which the token counts as
15
+ # expired, so a request started just before it never carries a
16
+ # dead token.
17
+ EXPIRY_SKEW = 60
18
+
19
+ # @param now [Time]
20
+ # @return [Boolean] true within EXPIRY_SKEW of expiry, or when
21
+ # the token has no expiry at all
22
+ def expired?(now = Time.now.utc)
23
+ return true if expires_at.nil?
24
+
25
+ now >= expires_at - EXPIRY_SKEW
26
+ end
27
+
28
+ # Token values stay out of consoles and error trackers.
29
+ #
30
+ # @return [String]
31
+ def inspect
32
+ fields = to_h.merge(access_token: access_token && FILTERED,
33
+ refresh_token: refresh_token && FILTERED)
34
+
35
+ "#<#{self.class.name} #{fields.map { |k, v| "#{k}=#{v.inspect}" }.join(' ')}>"
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'amazon_sp_clients/version'
4
+ require 'amazon_sp_clients/marketplaces'
5
+ require 'amazon_sp_clients/api_error'
6
+ require 'amazon_sp_clients/api_response'
7
+
8
+ require 'amazon_sp_clients/v2/errors'
9
+ require 'amazon_sp_clients/v2/config'
10
+ require 'amazon_sp_clients/v2/token'
11
+ require 'amazon_sp_clients/v2/error_mapper'
12
+ require 'amazon_sp_clients/v2/lwa'
13
+ require 'amazon_sp_clients/v2/credentials'
14
+ require 'amazon_sp_clients/v2/rdt'
15
+ require 'amazon_sp_clients/v2/documents'
16
+ require 'amazon_sp_clients/v2/api'
17
+ require 'amazon_sp_clients/v2/client'
18
+ require 'amazon_sp_clients/v2/apis'
19
+
20
+ # Ruby clients for the Amazon Selling Partner API.
21
+ module AmazonSpClients
22
+ # The second-generation client: explicit per-client configuration, a
23
+ # thread-safe token source, first-class restricted data tokens and
24
+ # typed errors. Loads without the v1 code.
25
+ #
26
+ # require 'amazon_sp_clients/v2'
27
+ #
28
+ # config = AmazonSpClients::V2::Config.new(endpoint: 'na')
29
+ # client = AmazonSpClients::V2::Client.new(config) { current_access_token }
30
+ # client.orders_v0.get_orders(marketplace_ids, created_after: since)
31
+ module V2
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module AmazonSpClients
2
+ VERSION = '2.0.0'.freeze
3
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'amazon_sp_clients/version'
4
+ require 'amazon_sp_clients/marketplaces'
5
+
6
+ require 'amazon_sp_clients/middlewares/raise_error'
7
+
8
+ require 'amazon_sp_clients/token_exchange_auth'
9
+ require 'amazon_sp_clients/session'
10
+
11
+ require 'amazon_sp_clients/api_client'
12
+ require 'amazon_sp_clients/api_error'
13
+ require 'amazon_sp_clients/configuration'
14
+ require 'amazon_sp_clients/api_response'
15
+
16
+ require 'amazon_sp_clients/uploader'
17
+
18
+ require 'faraday'
19
+ require 'httpclient'
20
+
21
+ module AmazonSpClients
22
+ # Normal calls
23
+ def self.new_session(refresh_token)
24
+ AmazonSpClients::Session.new.authenticate(refresh_token)
25
+ end
26
+
27
+ # Grantless calls
28
+ def self.new_migration_session
29
+ scope = 'sellingpartnerapi::migration'
30
+ AmazonSpClients::Session.new.authenticate_grantless(scope)
31
+ end
32
+
33
+ def self.new_callback_session(&)
34
+ AmazonSpClients::Session.new.with_callback(&)
35
+ end
36
+
37
+ def self.upload_feed_data(
38
+ feed_document_response,
39
+ document_content_type,
40
+ payload
41
+ )
42
+ uploader = AmazonSpClients::Uploader.new
43
+ uploader.upload(feed_document_response, document_content_type, payload)
44
+
45
+ uploader.response
46
+ end
47
+
48
+ def self.download_feed_report(feed_processing_report)
49
+ AmazonSpClients::Downloader.new(feed_processing_report).download
50
+ end
51
+
52
+ def self.download_report_document(doc_params)
53
+ url = doc_params.fetch(:url)
54
+ conn =
55
+ Faraday.new(request: { timeout: configure.timeout }) do |c|
56
+ c.use AmazonSpClients::Middlewares::RaiseError, { service: :uploads }
57
+ end
58
+
59
+ conn.get(url)&.body
60
+ end
61
+
62
+ def self.configure
63
+ if block_given?
64
+ yield(Configuration.default)
65
+ else
66
+ Configuration.default
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The gem is sp_api_clients; the code keeps its AmazonSpClients name.
4
+ # Bundler requires a gem by its name, so this file points it at the
5
+ # real entry point. `require 'amazon_sp_clients/v2'` loads V2 alone.
6
+ require 'amazon_sp_clients'
@@ -0,0 +1,53 @@
1
+ require_relative 'lib/amazon_sp_clients/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'sp_api_clients'
5
+ spec.version = AmazonSpClients::VERSION
6
+ spec.authors = ['Dropstream']
7
+ spec.email = ['351015+nina-saule@users.noreply.github.com']
8
+
9
+ spec.summary = 'Experimental Ruby clients for the Amazon Selling Partner API'
10
+ spec.description = 'Ruby clients for the Amazon Selling Partner API (SP-API), generated from ' \
11
+ "Amazon's models. Experimental; consider peddler for production use. " \
12
+ 'Not affiliated with Amazon.'
13
+ spec.homepage = 'https://github.com/dropstream/amazon_sp_clients'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 3.3')
16
+
17
+ # Releases go to rubygems.org through the tag workflow, never from a laptop.
18
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
19
+
20
+ spec.metadata['homepage_uri'] = spec.homepage
21
+ spec.metadata['source_code_uri'] = spec.homepage
22
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
23
+ spec.metadata['rubygems_mfa_required'] = 'true'
24
+
25
+ # Only lib/, vendor/, the gemspec and the top-level docs ship. Tests,
26
+ # the generator, CI config, dotfiles and the dev tooling stay behind.
27
+ dev_files = %r{
28
+ ^(test|spec|features|amzn-models|gemfiles|bin)/ |
29
+ ^lib/generator |
30
+ ^\. |
31
+ ^(Gemfile(\.lock)?|Rakefile|CLAUDE\.md|codegen-config\.yml|selling-partner-api-models\.sha)$
32
+ }x
33
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
34
+ `git ls-files -z`.split("\x0").reject { |f| f.match(dev_files) }
35
+ end
36
+ spec.bindir = 'exe'
37
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
+ spec.require_paths = ['lib']
39
+
40
+ spec.add_dependency 'faraday', '>= 1.10', '< 3'
41
+ spec.add_dependency 'faraday-httpclient', '>= 1.0', '< 3'
42
+ spec.add_dependency 'faraday-retry', '>= 1.0', '< 3'
43
+ spec.add_dependency 'httpclient'
44
+ spec.add_dependency 'multi_xml'
45
+
46
+ spec.add_development_dependency 'dotenv'
47
+ spec.add_development_dependency 'rake'
48
+ spec.add_development_dependency 'rspec'
49
+ spec.add_development_dependency 'rubocop', '~> 1.86'
50
+ spec.add_development_dependency 'timecop'
51
+ spec.add_development_dependency 'webmock'
52
+ spec.add_development_dependency 'yard'
53
+ end
@@ -0,0 +1,289 @@
1
+ =begin
2
+ #Selling Partner API for FBA Inventory
3
+
4
+ #The Selling Partner API for FBA Inventory lets you programmatically retrieve information about inventory in Amazon's fulfillment network.
5
+
6
+ OpenAPI spec version: v1
7
+
8
+ Generated by: lib/generator (bundle exec rake generate)
9
+ =end
10
+
11
+ module AmazonSpClients
12
+ module SpFbaInventory
13
+ class FbaInventoryApi
14
+ attr_accessor :api_client
15
+
16
+ def initialize(session)
17
+ @api_client = AmazonSpClients::ApiClient.new(session)
18
+ end
19
+ # Requests that Amazon add items to the Sandbox Inventory with desired amount of quantity in the sandbox environment. This is a sandbox-only operation and must be directed to a sandbox endpoint. Refer to [Selling Partner API sandbox](https://developer-docs.amazon.com/sp-api/docs/the-selling-partner-api-sandbox) for more information.
20
+ # @param body List of items to add to Sandbox inventory.
21
+ # @param x_amzn_idempotency_token A unique token/requestId provided with each call to ensure idempotency.
22
+ # @param [Hash] opts the optional parameters
23
+ # @return [AddInventoryResponse]
24
+ def add_inventory(body, x_amzn_idempotency_token, opts = {})
25
+ data = add_inventory_with_http_info(body, x_amzn_idempotency_token, opts)
26
+ return data
27
+ end
28
+
29
+ # Requests that Amazon add items to the Sandbox Inventory with desired amount of quantity in the sandbox environment. This is a sandbox-only operation and must be directed to a sandbox endpoint. Refer to [Selling Partner API sandbox](https://developer-docs.amazon.com/sp-api/docs/the-selling-partner-api-sandbox) for more information.
30
+ # @param body List of items to add to Sandbox inventory.
31
+ # @param x_amzn_idempotency_token A unique token/requestId provided with each call to ensure idempotency.
32
+ # @param [Hash] opts the optional parameters
33
+ # @return [Array<(AddInventoryResponse)>] AddInventoryResponse data, response status code and response headers
34
+ def add_inventory_with_http_info(body, x_amzn_idempotency_token, opts = {})
35
+ if @api_client.config.debugging
36
+ @api_client.config.logger.debug 'Calling API: FbaInventoryApi.add_inventory ...'
37
+ end
38
+ # verify the required parameter 'body' is set
39
+ if @api_client.config.client_side_validation && body.nil?
40
+ fail ArgumentError, "Missing the required parameter 'body' when calling FbaInventoryApi.add_inventory"
41
+ end
42
+ # verify the required parameter 'x_amzn_idempotency_token' is set
43
+ if @api_client.config.client_side_validation && x_amzn_idempotency_token.nil?
44
+ fail ArgumentError, "Missing the required parameter 'x_amzn_idempotency_token' when calling FbaInventoryApi.add_inventory"
45
+ end
46
+ # resource path
47
+ local_var_path = '/fba/inventory/v1/items/inventory'
48
+
49
+ # query parameters
50
+ query_params = opts[:query_params] || {}
51
+
52
+ # header parameters
53
+ header_params = opts[:header_params] || {}
54
+ # HTTP header 'Accept' (if needed)
55
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
56
+ # HTTP header 'Content-Type'
57
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
58
+ header_params[:'x-amzn-idempotency-token'] = x_amzn_idempotency_token
59
+
60
+ # form parameters
61
+ form_params = opts[:form_params] || {}
62
+
63
+ # http body (model)
64
+ post_body = opts[:body] || @api_client.object_to_http_body(body)
65
+
66
+ return_type = opts[:return_type] || 'AmazonSpClients::ApiResponse'
67
+
68
+ auth_names = opts[:auth_names] || []
69
+ data = @api_client.call_api(:POST, local_var_path,
70
+ :header_params => header_params,
71
+ :query_params => query_params,
72
+ :form_params => form_params,
73
+ :body => post_body,
74
+ :auth_names => auth_names,
75
+ :return_type => return_type)
76
+
77
+ if @api_client.config.debugging
78
+ @api_client.config.logger.debug "API called: FbaInventoryApi#add_inventory\nData: #{data.inspect}"
79
+ end
80
+ return data
81
+ end
82
+ # Requests that Amazon create product-details in the Sandbox Inventory in the sandbox environment. This is a sandbox-only operation and must be directed to a sandbox endpoint. Refer to [Selling Partner API sandbox](https://developer-docs.amazon.com/sp-api/docs/the-selling-partner-api-sandbox) for more information.
83
+ # @param body CreateInventoryItem Request Body Parameter.
84
+ # @param [Hash] opts the optional parameters
85
+ # @return [CreateInventoryItemResponse]
86
+ def create_inventory_item(body, opts = {})
87
+ data = create_inventory_item_with_http_info(body, opts)
88
+ return data
89
+ end
90
+
91
+ # Requests that Amazon create product-details in the Sandbox Inventory in the sandbox environment. This is a sandbox-only operation and must be directed to a sandbox endpoint. Refer to [Selling Partner API sandbox](https://developer-docs.amazon.com/sp-api/docs/the-selling-partner-api-sandbox) for more information.
92
+ # @param body CreateInventoryItem Request Body Parameter.
93
+ # @param [Hash] opts the optional parameters
94
+ # @return [Array<(CreateInventoryItemResponse)>] CreateInventoryItemResponse data, response status code and response headers
95
+ def create_inventory_item_with_http_info(body, opts = {})
96
+ if @api_client.config.debugging
97
+ @api_client.config.logger.debug 'Calling API: FbaInventoryApi.create_inventory_item ...'
98
+ end
99
+ # verify the required parameter 'body' is set
100
+ if @api_client.config.client_side_validation && body.nil?
101
+ fail ArgumentError, "Missing the required parameter 'body' when calling FbaInventoryApi.create_inventory_item"
102
+ end
103
+ # resource path
104
+ local_var_path = '/fba/inventory/v1/items'
105
+
106
+ # query parameters
107
+ query_params = opts[:query_params] || {}
108
+
109
+ # header parameters
110
+ header_params = opts[:header_params] || {}
111
+ # HTTP header 'Accept' (if needed)
112
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
113
+ # HTTP header 'Content-Type'
114
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
115
+
116
+ # form parameters
117
+ form_params = opts[:form_params] || {}
118
+
119
+ # http body (model)
120
+ post_body = opts[:body] || @api_client.object_to_http_body(body)
121
+
122
+ return_type = opts[:return_type] || 'AmazonSpClients::ApiResponse'
123
+
124
+ auth_names = opts[:auth_names] || []
125
+ data = @api_client.call_api(:POST, local_var_path,
126
+ :header_params => header_params,
127
+ :query_params => query_params,
128
+ :form_params => form_params,
129
+ :body => post_body,
130
+ :auth_names => auth_names,
131
+ :return_type => return_type)
132
+
133
+ if @api_client.config.debugging
134
+ @api_client.config.logger.debug "API called: FbaInventoryApi#create_inventory_item\nData: #{data.inspect}"
135
+ end
136
+ return data
137
+ end
138
+ # Requests that Amazon Deletes an item from the Sandbox Inventory in the sandbox environment. This is a sandbox-only operation and must be directed to a sandbox endpoint. Refer to [Selling Partner API sandbox](https://developer-docs.amazon.com/sp-api/docs/the-selling-partner-api-sandbox) for more information.
139
+ # @param seller_sku A single seller SKU used for querying the specified seller SKU inventory summaries.
140
+ # @param marketplace_id The marketplace ID for the marketplace for which the sellerSku is to be deleted.
141
+ # @param [Hash] opts the optional parameters
142
+ # @return [DeleteInventoryItemResponse]
143
+ def delete_inventory_item(seller_sku, marketplace_id, opts = {})
144
+ data = delete_inventory_item_with_http_info(seller_sku, marketplace_id, opts)
145
+ return data
146
+ end
147
+
148
+ # Requests that Amazon Deletes an item from the Sandbox Inventory in the sandbox environment. This is a sandbox-only operation and must be directed to a sandbox endpoint. Refer to [Selling Partner API sandbox](https://developer-docs.amazon.com/sp-api/docs/the-selling-partner-api-sandbox) for more information.
149
+ # @param seller_sku A single seller SKU used for querying the specified seller SKU inventory summaries.
150
+ # @param marketplace_id The marketplace ID for the marketplace for which the sellerSku is to be deleted.
151
+ # @param [Hash] opts the optional parameters
152
+ # @return [Array<(DeleteInventoryItemResponse)>] DeleteInventoryItemResponse data, response status code and response headers
153
+ def delete_inventory_item_with_http_info(seller_sku, marketplace_id, opts = {})
154
+ if @api_client.config.debugging
155
+ @api_client.config.logger.debug 'Calling API: FbaInventoryApi.delete_inventory_item ...'
156
+ end
157
+ # verify the required parameter 'seller_sku' is set
158
+ if @api_client.config.client_side_validation && seller_sku.nil?
159
+ fail ArgumentError, "Missing the required parameter 'seller_sku' when calling FbaInventoryApi.delete_inventory_item"
160
+ end
161
+ # verify the required parameter 'marketplace_id' is set
162
+ if @api_client.config.client_side_validation && marketplace_id.nil?
163
+ fail ArgumentError, "Missing the required parameter 'marketplace_id' when calling FbaInventoryApi.delete_inventory_item"
164
+ end
165
+ # resource path
166
+ local_var_path = '/fba/inventory/v1/items/{sellerSku}'.sub('{' + 'sellerSku' + '}', seller_sku.to_s)
167
+
168
+ # query parameters
169
+ query_params = opts[:query_params] || {}
170
+ query_params[:'marketplaceId'] = marketplace_id
171
+
172
+ # header parameters
173
+ header_params = opts[:header_params] || {}
174
+ # HTTP header 'Accept' (if needed)
175
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
176
+
177
+ # form parameters
178
+ form_params = opts[:form_params] || {}
179
+
180
+ # http body (model)
181
+ post_body = opts[:body]
182
+
183
+ return_type = opts[:return_type] || 'AmazonSpClients::ApiResponse'
184
+
185
+ auth_names = opts[:auth_names] || []
186
+ data = @api_client.call_api(:DELETE, local_var_path,
187
+ :header_params => header_params,
188
+ :query_params => query_params,
189
+ :form_params => form_params,
190
+ :body => post_body,
191
+ :auth_names => auth_names,
192
+ :return_type => return_type)
193
+
194
+ if @api_client.config.debugging
195
+ @api_client.config.logger.debug "API called: FbaInventoryApi#delete_inventory_item\nData: #{data.inspect}"
196
+ end
197
+ return data
198
+ end
199
+ # Returns a list of inventory summaries. The summaries returned depend on the presence or absence of the startDateTime, sellerSkus and sellerSku parameters: - All inventory summaries with available details are returned when the startDateTime, sellerSkus and sellerSku parameters are omitted. - When startDateTime is provided, the operation returns inventory summaries that have had changes after the date and time specified. The sellerSkus and sellerSku parameters are ignored. Important: To avoid errors, use both startDateTime and nextToken to get the next page of inventory summaries that have changed after the date and time specified. - When the sellerSkus parameter is provided, the operation returns inventory summaries for only the specified sellerSkus. The sellerSku parameter is ignored. - When the sellerSku parameter is provided, the operation returns inventory summaries for only the specified sellerSku. Note: The parameters associated with this operation may contain special characters that must be encoded to successfully call the API. To avoid errors with SKUs when encoding URLs, refer to [URL Encoding](https://developer-docs.amazon.com/sp-api/docs/url-encoding). Usage Plan: | Rate (requests per second) | Burst | | ---- | ---- | | 2 | 2 | The x-amzn-RateLimit-Limit response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits).
200
+ # @param granularity_type The granularity type for the inventory aggregation level.
201
+ # @param granularity_id The granularity ID for the inventory aggregation level.
202
+ # @param marketplace_ids The marketplace ID for the marketplace for which to return inventory summaries.
203
+ # @param [Hash] opts the optional parameters
204
+ # @option opts [BOOLEAN] :details true to return inventory summaries with additional summarized inventory details and quantities. Otherwise, returns inventory summaries only (default value). (default to false)
205
+ # @option opts [DateTime] :start_date_time A start date and time in ISO8601 format. If specified, all inventory summaries that have changed since then are returned. You must specify a date and time that is no earlier than 18 months prior to the date and time when you call the API. Note: Changes in inboundWorkingQuantity, inboundShippedQuantity and inboundReceivingQuantity are not detected.
206
+ # @option opts [Array<String>] :seller_skus A list of seller SKUs for which to return inventory summaries. You may specify up to 50 SKUs.
207
+ # @option opts [String] :seller_sku A single seller SKU used for querying the specified seller SKU inventory summaries.
208
+ # @option opts [String] :next_token String token returned in the response of your previous request. The string token will expire 30 seconds after being created.
209
+ # @return [GetInventorySummariesResponse]
210
+ def get_inventory_summaries(granularity_type, granularity_id, marketplace_ids, opts = {})
211
+ data = get_inventory_summaries_with_http_info(granularity_type, granularity_id, marketplace_ids, opts)
212
+ return data
213
+ end
214
+
215
+ # Returns a list of inventory summaries. The summaries returned depend on the presence or absence of the startDateTime, sellerSkus and sellerSku parameters: - All inventory summaries with available details are returned when the startDateTime, sellerSkus and sellerSku parameters are omitted. - When startDateTime is provided, the operation returns inventory summaries that have had changes after the date and time specified. The sellerSkus and sellerSku parameters are ignored. Important: To avoid errors, use both startDateTime and nextToken to get the next page of inventory summaries that have changed after the date and time specified. - When the sellerSkus parameter is provided, the operation returns inventory summaries for only the specified sellerSkus. The sellerSku parameter is ignored. - When the sellerSku parameter is provided, the operation returns inventory summaries for only the specified sellerSku. Note: The parameters associated with this operation may contain special characters that must be encoded to successfully call the API. To avoid errors with SKUs when encoding URLs, refer to [URL Encoding](https://developer-docs.amazon.com/sp-api/docs/url-encoding). Usage Plan: | Rate (requests per second) | Burst | | ---- | ---- | | 2 | 2 | The x-amzn-RateLimit-Limit response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits).
216
+ # @param granularity_type The granularity type for the inventory aggregation level.
217
+ # @param granularity_id The granularity ID for the inventory aggregation level.
218
+ # @param marketplace_ids The marketplace ID for the marketplace for which to return inventory summaries.
219
+ # @param [Hash] opts the optional parameters
220
+ # @option opts [BOOLEAN] :details true to return inventory summaries with additional summarized inventory details and quantities. Otherwise, returns inventory summaries only (default value).
221
+ # @option opts [DateTime] :start_date_time A start date and time in ISO8601 format. If specified, all inventory summaries that have changed since then are returned. You must specify a date and time that is no earlier than 18 months prior to the date and time when you call the API. Note: Changes in inboundWorkingQuantity, inboundShippedQuantity and inboundReceivingQuantity are not detected.
222
+ # @option opts [Array<String>] :seller_skus A list of seller SKUs for which to return inventory summaries. You may specify up to 50 SKUs.
223
+ # @option opts [String] :seller_sku A single seller SKU used for querying the specified seller SKU inventory summaries.
224
+ # @option opts [String] :next_token String token returned in the response of your previous request. The string token will expire 30 seconds after being created.
225
+ # @return [Array<(GetInventorySummariesResponse)>] GetInventorySummariesResponse data, response status code and response headers
226
+ def get_inventory_summaries_with_http_info(granularity_type, granularity_id, marketplace_ids, opts = {})
227
+ if @api_client.config.debugging
228
+ @api_client.config.logger.debug 'Calling API: FbaInventoryApi.get_inventory_summaries ...'
229
+ end
230
+ # verify the required parameter 'granularity_type' is set
231
+ if @api_client.config.client_side_validation && granularity_type.nil?
232
+ fail ArgumentError, "Missing the required parameter 'granularity_type' when calling FbaInventoryApi.get_inventory_summaries"
233
+ end
234
+ # verify enum value
235
+ if @api_client.config.client_side_validation && !['Marketplace'].include?(granularity_type)
236
+ fail ArgumentError, "invalid value for 'granularity_type', must be one of Marketplace"
237
+ end
238
+ # verify the required parameter 'granularity_id' is set
239
+ if @api_client.config.client_side_validation && granularity_id.nil?
240
+ fail ArgumentError, "Missing the required parameter 'granularity_id' when calling FbaInventoryApi.get_inventory_summaries"
241
+ end
242
+ # verify the required parameter 'marketplace_ids' is set
243
+ if @api_client.config.client_side_validation && marketplace_ids.nil?
244
+ fail ArgumentError, "Missing the required parameter 'marketplace_ids' when calling FbaInventoryApi.get_inventory_summaries"
245
+ end
246
+ # resource path
247
+ local_var_path = '/fba/inventory/v1/summaries'
248
+
249
+ # query parameters
250
+ query_params = opts[:query_params] || {}
251
+ query_params[:'granularityType'] = granularity_type
252
+ query_params[:'granularityId'] = granularity_id
253
+ query_params[:'marketplaceIds'] = @api_client.build_collection_param(marketplace_ids, :csv)
254
+ query_params[:'details'] = opts[:'details'] if !opts[:'details'].nil?
255
+ query_params[:'startDateTime'] = opts[:'start_date_time'] if !opts[:'start_date_time'].nil?
256
+ query_params[:'sellerSkus'] = @api_client.build_collection_param(opts[:'seller_skus'], :csv) if !opts[:'seller_skus'].nil?
257
+ query_params[:'sellerSku'] = opts[:'seller_sku'] if !opts[:'seller_sku'].nil?
258
+ query_params[:'nextToken'] = opts[:'next_token'] if !opts[:'next_token'].nil?
259
+
260
+ # header parameters
261
+ header_params = opts[:header_params] || {}
262
+ # HTTP header 'Accept' (if needed)
263
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
264
+
265
+ # form parameters
266
+ form_params = opts[:form_params] || {}
267
+
268
+ # http body (model)
269
+ post_body = opts[:body]
270
+
271
+ return_type = opts[:return_type] || 'AmazonSpClients::ApiResponse'
272
+
273
+ auth_names = opts[:auth_names] || []
274
+ data = @api_client.call_api(:GET, local_var_path,
275
+ :header_params => header_params,
276
+ :query_params => query_params,
277
+ :form_params => form_params,
278
+ :body => post_body,
279
+ :auth_names => auth_names,
280
+ :return_type => return_type)
281
+
282
+ if @api_client.config.debugging
283
+ @api_client.config.logger.debug "API called: FbaInventoryApi#get_inventory_summaries\nData: #{data.inspect}"
284
+ end
285
+ return data
286
+ end
287
+ end
288
+ end
289
+ end
@@ -0,0 +1,12 @@
1
+ =begin
2
+ #Selling Partner API for FBA Inventory
3
+
4
+ #The Selling Partner API for FBA Inventory lets you programmatically retrieve information about inventory in Amazon's fulfillment network.
5
+
6
+ OpenAPI spec version: v1
7
+
8
+ Generated by: lib/generator (bundle exec rake generate)
9
+ =end
10
+
11
+ # APIs
12
+ require_relative './sp_fba_inventory/api/fba_inventory_api'