muffin_man 1.5.1 → 1.5.3
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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +4 -0
- data/.rubocop.yml +31 -0
- data/.rubocop_todo.yml +482 -0
- data/CHANGELOG.md +13 -1
- data/Gemfile +4 -0
- data/README.md +3 -0
- data/lib/muffin_man/fba_inventory/v1.rb +30 -0
- data/lib/muffin_man/feeds/v20210630.rb +45 -0
- data/lib/muffin_man/fulfillment_outbound/v20200701.rb +56 -0
- data/lib/muffin_man/notifications/v1.rb +85 -0
- data/lib/muffin_man/request_helpers/base.rb +3 -0
- data/lib/muffin_man/request_helpers/outbound_fulfillment/address.rb +92 -0
- data/lib/muffin_man/request_helpers/outbound_fulfillment/fulfillment_order_request.rb +104 -0
- data/lib/muffin_man/request_helpers/outbound_fulfillment/fulfillment_preview_request.rb +64 -0
- data/lib/muffin_man/request_helpers/outbound_fulfillment/item.rb +69 -0
- data/lib/muffin_man/request_helpers/outbound_fulfillment/v20200701.rb +41 -0
- data/lib/muffin_man/request_helpers.rb +1 -0
- data/lib/muffin_man/sp_api_client.rb +11 -1
- data/lib/muffin_man/version.rb +1 -1
- data/lib/muffin_man.rb +5 -1
- data/lib/sp_api_helpers.rb +1 -0
- data/muffin_man.gemspec +1 -0
- metadata +26 -2
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MuffinMan
|
4
|
+
module FulfillmentOutbound
|
5
|
+
class V20200701 < SpApiClient
|
6
|
+
# @param [MuffinMan::RequestHelpers::OutboundFulFillment::FulfillmentPreviewRequest] fulfillment_preview_request
|
7
|
+
# in the form of object
|
8
|
+
def get_fulfillment_preview(fulfillment_preview_request)
|
9
|
+
return unprocessable_entity(fulfillment_preview_request&.errors) unless fulfillment_preview_request&.valid?
|
10
|
+
|
11
|
+
@local_var_path = "/fba/outbound/2020-07-01/fulfillmentOrders/preview"
|
12
|
+
@request_body = fulfillment_preview_request.to_camelize
|
13
|
+
@request_type = "POST"
|
14
|
+
call_api
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param [MuffinMan::RequestHelpers::OutboundFulFillment::FulfillmentOrderRequest] fulfillment_order_request
|
18
|
+
# in the form of object
|
19
|
+
def create_fulfillment_order(fulfillment_order_request)
|
20
|
+
return unprocessable_entity(fulfillment_order_request&.errors) unless fulfillment_order_request&.valid?
|
21
|
+
|
22
|
+
@local_var_path = "/fba/outbound/2020-07-01/fulfillmentOrders"
|
23
|
+
@request_body = fulfillment_order_request.to_camelize
|
24
|
+
@request_type = "POST"
|
25
|
+
call_api
|
26
|
+
end
|
27
|
+
|
28
|
+
# @param [String] query_start_date optional
|
29
|
+
# @param [String] next_token optional
|
30
|
+
def list_all_fulfillment_orders(query_start_date: nil, next_token: nil)
|
31
|
+
@local_var_path = "/fba/outbound/2020-07-01/fulfillmentOrders"
|
32
|
+
|
33
|
+
@query_params = {} unless query_start_date.nil? && next_token.nil?
|
34
|
+
|
35
|
+
@query_params[:queryStartDate] = query_start_date unless query_start_date.nil?
|
36
|
+
@query_params[:nextToken] = next_token unless next_token.nil?
|
37
|
+
@request_type = "GET"
|
38
|
+
call_api
|
39
|
+
end
|
40
|
+
|
41
|
+
# @param [String] seller_fulfillment_order_id
|
42
|
+
def get_fulfillment_order(seller_fulfillment_order_id)
|
43
|
+
@local_var_path = "/fba/outbound/2020-07-01/fulfillmentOrders/#{seller_fulfillment_order_id}"
|
44
|
+
@request_type = "GET"
|
45
|
+
call_api
|
46
|
+
end
|
47
|
+
|
48
|
+
# @param [String] seller_fulfillment_order_id
|
49
|
+
def cancel_fulfillment_order(seller_fulfillment_order_id)
|
50
|
+
@local_var_path = "/fba/outbound/2020-07-01/fulfillmentOrders/#{seller_fulfillment_order_id}/cancel"
|
51
|
+
@request_type = "PUT"
|
52
|
+
call_api
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MuffinMan
|
4
|
+
module Notifications
|
5
|
+
require "json"
|
6
|
+
require "sp_api_helpers"
|
7
|
+
class V1 < SpApiClient
|
8
|
+
NOTIFICATION_PATH = "/notifications/v1"
|
9
|
+
NOTIFICATION_SCOPE = "sellingpartnerapi::notifications"
|
10
|
+
PROCESSING_DIRECTIVE_SUPPORTED_NOTIFICATIONS = ["ANY_OFFER_CHANGED"].freeze
|
11
|
+
|
12
|
+
def create_destination(arn, name, params = {})
|
13
|
+
@local_var_path = "#{NOTIFICATION_PATH}/destinations"
|
14
|
+
params = params.transform_keys(&:to_s)
|
15
|
+
@scope = NOTIFICATION_SCOPE
|
16
|
+
destination_params = { "resourceSpecification" => { "sqs" => { "arn" => arn } }, "name" => name }
|
17
|
+
unless params["region"].nil? || params["account_id"].nil?
|
18
|
+
destination_params["resourceSpecification"].merge!("eventBridge" => { "region" => params["region"],
|
19
|
+
"accountId" => params["account_id"] })
|
20
|
+
end
|
21
|
+
@request_body = destination_params
|
22
|
+
@request_type = "POST"
|
23
|
+
call_api
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_destinations(params = {})
|
27
|
+
@local_var_path = "#{NOTIFICATION_PATH}/destinations"
|
28
|
+
@scope = NOTIFICATION_SCOPE
|
29
|
+
@query_params = sp_api_params(params)
|
30
|
+
@request_type = "GET"
|
31
|
+
call_api
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_destination(destination_id)
|
35
|
+
@local_var_path = "#{NOTIFICATION_PATH}/destinations/#{destination_id}"
|
36
|
+
@scope = NOTIFICATION_SCOPE
|
37
|
+
@request_type = "GET"
|
38
|
+
call_api
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_subscription(notification_type, params = {})
|
42
|
+
@local_var_path = "#{NOTIFICATION_PATH}/subscriptions/#{notification_type}"
|
43
|
+
params = params.transform_keys(&:to_s)
|
44
|
+
subscription_params = { "destinationId" => params["destination_id"] }
|
45
|
+
# currently SP-API's `processingDirective` only supports ANY_OFFER_CHANGED notification type.
|
46
|
+
if PROCESSING_DIRECTIVE_SUPPORTED_NOTIFICATIONS.include? notification_type
|
47
|
+
subscription_params["processingDirective"] =
|
48
|
+
{ "eventFilter" => { "eventFilterType" => notification_type,
|
49
|
+
"marketplaceIds" => params["marketplace_ids"] } }
|
50
|
+
unless params["aggregation_time_period"].nil?
|
51
|
+
subscription_params["processingDirective"]["eventFilter"]
|
52
|
+
.merge!("aggregationSettings" => {
|
53
|
+
"aggregationTimePeriod" => params["aggregation_time_period"]
|
54
|
+
})
|
55
|
+
end
|
56
|
+
end
|
57
|
+
subscription_params.merge!("payloadVersion" => params["payload_version"]) unless params["payload_version"].nil?
|
58
|
+
@request_body = subscription_params
|
59
|
+
@request_type = "POST"
|
60
|
+
call_api
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_subscription(notification_type, params = {})
|
64
|
+
@local_var_path = "#{NOTIFICATION_PATH}/subscriptions/#{notification_type}"
|
65
|
+
@query_params = sp_api_params(params)
|
66
|
+
@request_type = "GET"
|
67
|
+
call_api
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_subscription_by_id(notification_type, subscription_id)
|
71
|
+
@local_var_path = "#{NOTIFICATION_PATH}/subscriptions/#{notification_type}/#{subscription_id}"
|
72
|
+
@scope = NOTIFICATION_SCOPE
|
73
|
+
@request_type = "GET"
|
74
|
+
call_api
|
75
|
+
end
|
76
|
+
|
77
|
+
def delete_subscription_by_id(notification_type, subscription_id)
|
78
|
+
@local_var_path = "#{NOTIFICATION_PATH}/subscriptions/#{notification_type}/#{subscription_id}"
|
79
|
+
@scope = NOTIFICATION_SCOPE
|
80
|
+
@request_type = "DELETE"
|
81
|
+
call_api
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MuffinMan
|
4
|
+
module RequestHelpers
|
5
|
+
module OutboundFulfillment
|
6
|
+
class Address < MuffinMan::RequestHelpers::Base
|
7
|
+
attr_accessor :name, :address_line1, :address_line2, :address_line3, :city,
|
8
|
+
:district_or_county, :state_or_region, :country_code, :postal_code, :phone
|
9
|
+
|
10
|
+
# Initializes the object
|
11
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
12
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
13
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
14
|
+
def initialize(attributes = {})
|
15
|
+
super
|
16
|
+
return unless attributes.is_a?(Hash)
|
17
|
+
|
18
|
+
attributes = attributes.with_indifferent_access
|
19
|
+
|
20
|
+
self.name = attributes["name"] if attributes.key?("name")
|
21
|
+
|
22
|
+
if attributes.key?("address_line1") || attributes.key?("line1")
|
23
|
+
self.address_line1 = attributes["address_line1"] || attributes["line1"]
|
24
|
+
end
|
25
|
+
|
26
|
+
if attributes.key?("address_line2") || attributes.key?("line2")
|
27
|
+
self.address_line2 = attributes["address_line2"] || attributes["line2"]
|
28
|
+
end
|
29
|
+
|
30
|
+
if attributes.key?("address_line3") || attributes.key?("line3")
|
31
|
+
self.address_line3 = attributes["address_line3"] || attributes("line3")
|
32
|
+
end
|
33
|
+
|
34
|
+
self.city = attributes["city"] if attributes.key?("city")
|
35
|
+
|
36
|
+
self.district_or_county = attributes["district_or_county"] if attributes.key?("district_or_county")
|
37
|
+
|
38
|
+
if attributes.key?("state_or_region") || attributes.key?("state_or_province_code")
|
39
|
+
self.state_or_region = attributes["state_or_region"] || attributes["state_or_province_code"]
|
40
|
+
end
|
41
|
+
|
42
|
+
self.postal_code = attributes["postal_code"] if attributes.key?("postal_code")
|
43
|
+
|
44
|
+
self.country_code = attributes["country_code"] if attributes.key?("country_code")
|
45
|
+
|
46
|
+
self.phone = attributes["phone"] if attributes.key?("phone")
|
47
|
+
end
|
48
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
49
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
50
|
+
|
51
|
+
# return true if the model is valid
|
52
|
+
def valid?
|
53
|
+
return false if name.blank?
|
54
|
+
return false if address_line1.blank?
|
55
|
+
return false if state_or_region.blank?
|
56
|
+
return false if country_code.blank?
|
57
|
+
|
58
|
+
true
|
59
|
+
end
|
60
|
+
|
61
|
+
# Show invalid properties with the reasons.
|
62
|
+
# return Array for invalid properties with the reasons
|
63
|
+
def errors
|
64
|
+
errors = []
|
65
|
+
errors.push('"name" cannot be nil.') if name.blank?
|
66
|
+
errors.push('"address_line1" cannot be nil.') if address_line1.blank?
|
67
|
+
errors.push('"state_or_region" cannot be nil.') if state_or_region.blank?
|
68
|
+
errors.push('"country_code" cannot be nil.') if country_code.blank?
|
69
|
+
|
70
|
+
errors
|
71
|
+
end
|
72
|
+
|
73
|
+
# Format request object in sp-api request format
|
74
|
+
# @return hash for sp-api request format
|
75
|
+
def to_camelize
|
76
|
+
{
|
77
|
+
"name" => name,
|
78
|
+
"addressLine1" => address_line1,
|
79
|
+
"addressLine2" => address_line2,
|
80
|
+
"addressLine3" => address_line3,
|
81
|
+
"city" => city,
|
82
|
+
"districtOrCounty" => district_or_county,
|
83
|
+
"stateOrRegion" => state_or_region,
|
84
|
+
"countryCode" => country_code,
|
85
|
+
"postalCode" => postal_code,
|
86
|
+
"phone" => phone
|
87
|
+
}
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MuffinMan
|
4
|
+
module RequestHelpers
|
5
|
+
module OutboundFulfillment
|
6
|
+
class FulfillmentOrderRequest < MuffinMan::RequestHelpers::Base
|
7
|
+
attr_accessor :seller_fulfillment_order_id, :displayable_order_id, :displayable_order_date_time,
|
8
|
+
:displayable_order_comment, :shipping_speed_category, :destination_address, :items,
|
9
|
+
:optional_params
|
10
|
+
|
11
|
+
OPTIONAL_CREATE_FULFILLMENT_ORDER_PARAMS = %w[
|
12
|
+
marketplaceId
|
13
|
+
deliveryWindow
|
14
|
+
fulfillmentAction
|
15
|
+
fulfillmentPolicy
|
16
|
+
codSettings
|
17
|
+
shipFromCountryCode
|
18
|
+
notificationEmails
|
19
|
+
featureConstraints
|
20
|
+
].freeze
|
21
|
+
|
22
|
+
# Initializes the object
|
23
|
+
# @param [String] seller_fulfillment_order_id
|
24
|
+
# @param [String] displayable_order_id
|
25
|
+
# @param [String] displayable_order_date_time
|
26
|
+
# @param [String] displayable_order_comment
|
27
|
+
# @param [String] shipping_speed_category
|
28
|
+
# @param [MuffinMan::RequestHelpers::OutboundFulfillment::Address] destination_address in form of object
|
29
|
+
# @param [MuffinMan::RequestHelpers::OutboundFulfillment::Item] items in the form of list of items objects
|
30
|
+
# @param [Hash] optional_params optional sp-api attributes in the form of hash
|
31
|
+
# rubocop:disable Metrics/ParameterLists
|
32
|
+
def initialize(seller_fulfillment_order_id, displayable_order_id, displayable_order_date_time,
|
33
|
+
displayable_order_comment, shipping_speed_category, destination_address, items,
|
34
|
+
optional_params = {})
|
35
|
+
super
|
36
|
+
@seller_fulfillment_order_id = seller_fulfillment_order_id
|
37
|
+
@displayable_order_id = displayable_order_id
|
38
|
+
@displayable_order_date_time = displayable_order_date_time
|
39
|
+
@displayable_order_comment = displayable_order_comment
|
40
|
+
@shipping_speed_category = shipping_speed_category
|
41
|
+
@destination_address = destination_address
|
42
|
+
@items = items
|
43
|
+
@optional_params = optional_params
|
44
|
+
end
|
45
|
+
# rubocop:enable Metrics/ParameterLists
|
46
|
+
|
47
|
+
# Check to see if the all the properties in the model are valid
|
48
|
+
# @return true if the model is valid
|
49
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
50
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
51
|
+
def valid?
|
52
|
+
return false if seller_fulfillment_order_id.blank?
|
53
|
+
return false if displayable_order_id.blank?
|
54
|
+
return false if displayable_order_date_time.blank?
|
55
|
+
return false if displayable_order_comment.blank?
|
56
|
+
return false if shipping_speed_category.blank?
|
57
|
+
return false if destination_address.blank?
|
58
|
+
return false if items.blank?
|
59
|
+
return false if destination_address.present? && !destination_address.valid?
|
60
|
+
return false if items.present? && items.map(&:valid?).include?(false)
|
61
|
+
|
62
|
+
true
|
63
|
+
end
|
64
|
+
|
65
|
+
# Show invalid properties with the reasons.
|
66
|
+
# @return Array for invalid properties with the
|
67
|
+
def errors
|
68
|
+
errors = []
|
69
|
+
errors.push('"seller_fulfillment_order_id" cannot be nil.') if seller_fulfillment_order_id.blank?
|
70
|
+
errors.push('"displayable_order_id" cannot be nil.') if displayable_order_id.blank?
|
71
|
+
errors.push('"displayable_order_date_time" cannot be nil.') if displayable_order_date_time.blank?
|
72
|
+
errors.push('"displayable_order_comment" cannot be nil.') if displayable_order_comment.blank?
|
73
|
+
errors.push('"shipping_speed_category" cannot be nil.') if shipping_speed_category.blank?
|
74
|
+
errors.push('"destination_address" cannot be nil.') if destination_address.blank?
|
75
|
+
errors.push('"items" cannot be nil.') if items.blank?
|
76
|
+
|
77
|
+
if !destination_address.nil? && !destination_address.valid?
|
78
|
+
errors.push("invalid value for \"destination_address\", #{destination_address.errors}")
|
79
|
+
end
|
80
|
+
|
81
|
+
errors.push('invalid value for "items"') if !items.nil? && items.map(&:valid?).include?(false)
|
82
|
+
|
83
|
+
errors
|
84
|
+
end
|
85
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
86
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
87
|
+
|
88
|
+
# Format request object in sp-api request format
|
89
|
+
# @return hash for sp-api request format
|
90
|
+
def to_camelize
|
91
|
+
{
|
92
|
+
"sellerFulfillmentOrderId" => seller_fulfillment_order_id,
|
93
|
+
"displayableOrderId" => displayable_order_id,
|
94
|
+
"displayableOrderDate" => displayable_order_date_time,
|
95
|
+
"displayableOrderComment" => displayable_order_comment,
|
96
|
+
"shippingSpeedCategory" => shipping_speed_category,
|
97
|
+
"destinationAddress" => destination_address,
|
98
|
+
"items" => items.map(&:to_camelize)
|
99
|
+
}.merge!(optional_params.slice(*OPTIONAL_CREATE_FULFILLMENT_ORDER_PARAMS))
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MuffinMan
|
4
|
+
module RequestHelpers
|
5
|
+
module OutboundFulfillment
|
6
|
+
class FulfillmentPreviewRequest < MuffinMan::RequestHelpers::Base
|
7
|
+
attr_accessor :address, :items, :optional_params
|
8
|
+
|
9
|
+
OPTIONAL_FULFILLMENT_PREVIEW_PARAMS = %w[
|
10
|
+
marketplaceId
|
11
|
+
shippingSpeedCategories
|
12
|
+
includeCODFulfillmentPreview
|
13
|
+
includeDeliveryWindows
|
14
|
+
featureConstraints
|
15
|
+
].freeze
|
16
|
+
|
17
|
+
# Initializes the object
|
18
|
+
# @param [MuffinMan::RequestHelpers::OutboundFulfillment::Address] address in the form of object
|
19
|
+
# @param[MuffinMan::RequestHelpers::OutboundFulfillment::Item] items in the form of list of items objects
|
20
|
+
# @param [Hash] optional_params optional sp-api attributes in the form of hash
|
21
|
+
def initialize(address, items, optional_params = {})
|
22
|
+
super
|
23
|
+
@address = address
|
24
|
+
@items = items
|
25
|
+
@optional_params = optional_params
|
26
|
+
end
|
27
|
+
|
28
|
+
# Check to see if the all the properties in the model are valid
|
29
|
+
# @return true if the model is valid
|
30
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
31
|
+
def valid?
|
32
|
+
return false if address.blank? || !address.is_a?(MuffinMan::RequestHelpers::OutboundFulfillment::Address)
|
33
|
+
return false if items.blank? || !items.is_a?(Array)
|
34
|
+
|
35
|
+
return false if !address.valid? || items.map(&:valid?).include?(false)
|
36
|
+
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
# Show invalid properties with the reasons.
|
41
|
+
# @return Array for invalid properties with the reasons
|
42
|
+
def errors
|
43
|
+
errors = []
|
44
|
+
errors.push('"address" cannot be nil.') if address.blank?
|
45
|
+
errors.push('"items" cannot be nil.') if items.blank?
|
46
|
+
errors.push("invalid value for \"address\",#{address.errors}") if address.present? && !address.valid?
|
47
|
+
errors.push('invalid value for "items"') if items.present? && items.map(&:valid?).include?(false)
|
48
|
+
|
49
|
+
errors
|
50
|
+
end
|
51
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
52
|
+
|
53
|
+
# Format request object in sp-api request format
|
54
|
+
# @return hash for sp-api request format
|
55
|
+
def to_camelize
|
56
|
+
{
|
57
|
+
"address" => address.to_camelize,
|
58
|
+
"items" => items.map(&:to_camelize)
|
59
|
+
}.merge!(optional_params.slice(*OPTIONAL_FULFILLMENT_PREVIEW_PARAMS))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MuffinMan
|
4
|
+
module RequestHelpers
|
5
|
+
module OutboundFulfillment
|
6
|
+
class Item < MuffinMan::RequestHelpers::Base
|
7
|
+
attr_accessor :seller_sku, :seller_fulfillment_order_item_id, :quantity, :optional_params
|
8
|
+
|
9
|
+
OPTIONAL_ITEM_PARAMS = %w[
|
10
|
+
perUnitDeclaredValue
|
11
|
+
giftMessage
|
12
|
+
displayableComment
|
13
|
+
fulfillmentNetworkSku
|
14
|
+
perUnitDeclaredValue
|
15
|
+
perUnitPrice
|
16
|
+
perUnitTax
|
17
|
+
].freeze
|
18
|
+
|
19
|
+
# Initializes the object
|
20
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
21
|
+
def initialize(attributes = {})
|
22
|
+
super
|
23
|
+
return unless attributes.is_a?(Hash)
|
24
|
+
|
25
|
+
attributes = attributes.with_indifferent_access
|
26
|
+
|
27
|
+
@seller_sku = attributes["seller_sku"] if attributes.key?("seller_sku")
|
28
|
+
|
29
|
+
if attributes.key?("seller_fulfillment_order_item_id")
|
30
|
+
@seller_fulfillment_order_item_id = attributes["seller_fulfillment_order_item_id"]
|
31
|
+
end
|
32
|
+
|
33
|
+
@quantity = attributes["quantity"] if attributes.key?("quantity")
|
34
|
+
|
35
|
+
@optional_params = attributes.slice(*OPTIONAL_ITEM_PARAMS)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Check to see if the all the properties in the model are valid
|
39
|
+
# @return true if the model is valid
|
40
|
+
def valid?
|
41
|
+
return false if seller_sku.blank?
|
42
|
+
return false if seller_fulfillment_order_item_id.blank?
|
43
|
+
return false if quantity.blank?
|
44
|
+
|
45
|
+
true
|
46
|
+
end
|
47
|
+
|
48
|
+
# Show invalid properties with the reasons.
|
49
|
+
# @return Array for invalid properties with the reasons
|
50
|
+
def errors
|
51
|
+
errors = []
|
52
|
+
errors.push('"seller_sku" cannot be nil.') if seller_sku.blank?
|
53
|
+
errors.push('"seller_fulfillment_order_item_id" cannot be nil.') if seller_fulfillment_order_item_id.blank?
|
54
|
+
errors.push('"quantity" cannot be nil.') if quantity.blank?
|
55
|
+
|
56
|
+
errors
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_camelize
|
60
|
+
{
|
61
|
+
"sellerSku" => seller_sku,
|
62
|
+
"sellerFulfillmentOrderItemId" => seller_fulfillment_order_item_id,
|
63
|
+
"quantity" => quantity
|
64
|
+
}.merge!(optional_params.slice(*OPTIONAL_ITEM_PARAMS))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MuffinMan
|
4
|
+
module RequestHelpers
|
5
|
+
module OutboundFulfillment
|
6
|
+
class V20200701
|
7
|
+
def self.address_request(name, address_line1, state_or_region, country_code, optional_params = {})
|
8
|
+
Address.new({
|
9
|
+
"name" => name,
|
10
|
+
"address_line1" => address_line1,
|
11
|
+
"state_or_region" => state_or_region,
|
12
|
+
"country_code" => country_code
|
13
|
+
}.merge(optional_params))
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.item_request(seller_sku, seller_fulfillment_order_item_id, quantity, optional_params = {})
|
17
|
+
Item.new({
|
18
|
+
"seller_sku" => seller_sku,
|
19
|
+
"seller_fulfillment_order_item_id" => seller_fulfillment_order_item_id,
|
20
|
+
"quantity" => quantity
|
21
|
+
}.merge(optional_params))
|
22
|
+
end
|
23
|
+
|
24
|
+
# rubocop:disable Metrics/ParameterLists
|
25
|
+
def self.fulfillment_order_request(seller_fulfillment_order_id, displayable_order_id,
|
26
|
+
displayable_order_date_time,
|
27
|
+
displayable_order_comment, shipping_speed_category,
|
28
|
+
destination_address, items, optional_params = {})
|
29
|
+
FulfillmentOrderRequest.new(seller_fulfillment_order_id, displayable_order_id, displayable_order_date_time,
|
30
|
+
displayable_order_comment, shipping_speed_category, destination_address,
|
31
|
+
items, optional_params)
|
32
|
+
end
|
33
|
+
# rubocop:enable Metrics/ParameterLists
|
34
|
+
|
35
|
+
def self.fulfillment_preview_request(address, items, optional_params = {})
|
36
|
+
FulfillmentPreviewRequest.new(address, items, optional_params)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -20,6 +20,8 @@ module MuffinMan
|
|
20
20
|
"fe" => "us-west-2"
|
21
21
|
}.freeze
|
22
22
|
|
23
|
+
UNPROCESSABLE_ENTITY_STATUS_CODE = 422
|
24
|
+
|
23
25
|
def initialize(credentials, sandbox = false)
|
24
26
|
@refresh_token = credentials[:refresh_token]
|
25
27
|
@client_id = credentials[:client_id]
|
@@ -127,7 +129,7 @@ module MuffinMan
|
|
127
129
|
client = Aws::STS::Client.new(
|
128
130
|
region: derive_aws_region,
|
129
131
|
credentials: Aws::Credentials.new(aws_access_key_id, aws_secret_access_key),
|
130
|
-
http_wire_trace: (ENV
|
132
|
+
http_wire_trace: (ENV.fetch("AWS_DEBUG", nil) == "true" || false)
|
131
133
|
)
|
132
134
|
client.assume_role(role_arn: sts_iam_role_arn, role_session_name: SecureRandom.uuid)
|
133
135
|
end
|
@@ -182,5 +184,13 @@ module MuffinMan
|
|
182
184
|
|
183
185
|
@aws_region
|
184
186
|
end
|
187
|
+
|
188
|
+
def unprocessable_entity(errors)
|
189
|
+
Typhoeus::Response.new(code: UNPROCESSABLE_ENTITY_STATUS_CODE, body: { errors: errors.to_s }.to_json)
|
190
|
+
end
|
191
|
+
|
192
|
+
def sp_api_params(params)
|
193
|
+
params.to_h.transform_keys { |key| key.to_s.split("_").map.with_index { |x, i| i.positive? ? x.capitalize : x }.join }
|
194
|
+
end
|
185
195
|
end
|
186
196
|
end
|
data/lib/muffin_man/version.rb
CHANGED
data/lib/muffin_man.rb
CHANGED
@@ -14,7 +14,11 @@ require "muffin_man/product_pricing/v0"
|
|
14
14
|
require "muffin_man/listings/v20210801"
|
15
15
|
require "muffin_man/fulfillment_inbound/v0"
|
16
16
|
require "muffin_man/fulfillment_inbound/v1"
|
17
|
-
|
17
|
+
require "muffin_man/fulfillment_outbound/v20200701"
|
18
|
+
require "muffin_man/fba_inventory/v1"
|
19
|
+
require "muffin_man/request_helpers"
|
20
|
+
require "muffin_man/feeds/v20210630"
|
21
|
+
require "muffin_man/notifications/v1"
|
18
22
|
|
19
23
|
module MuffinMan
|
20
24
|
class Error < StandardError; end
|
data/lib/sp_api_helpers.rb
CHANGED
data/muffin_man.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: muffin_man
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-11-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -116,6 +116,20 @@ dependencies:
|
|
116
116
|
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: 2.4.4
|
119
|
+
- !ruby/object:Gem::Dependency
|
120
|
+
name: activesupport
|
121
|
+
requirement: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
type: :runtime
|
127
|
+
prerelease: false
|
128
|
+
version_requirements: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
119
133
|
description:
|
120
134
|
email:
|
121
135
|
- gavin@pattern.com
|
@@ -129,6 +143,7 @@ files:
|
|
129
143
|
- ".gitignore"
|
130
144
|
- ".rspec"
|
131
145
|
- ".rubocop.yml"
|
146
|
+
- ".rubocop_todo.yml"
|
132
147
|
- CHANGELOG.md
|
133
148
|
- CODE_OF_CONDUCT.md
|
134
149
|
- Gemfile
|
@@ -142,11 +157,15 @@ files:
|
|
142
157
|
- lib/muffin_man/catalog_items/base_api.rb
|
143
158
|
- lib/muffin_man/catalog_items/v20201201.rb
|
144
159
|
- lib/muffin_man/catalog_items/v20220401.rb
|
160
|
+
- lib/muffin_man/fba_inventory/v1.rb
|
161
|
+
- lib/muffin_man/feeds/v20210630.rb
|
145
162
|
- lib/muffin_man/finances/v0.rb
|
146
163
|
- lib/muffin_man/fulfillment_inbound/v0.rb
|
147
164
|
- lib/muffin_man/fulfillment_inbound/v1.rb
|
165
|
+
- lib/muffin_man/fulfillment_outbound/v20200701.rb
|
148
166
|
- lib/muffin_man/listings/v20210801.rb
|
149
167
|
- lib/muffin_man/lwa/auth_helper.rb
|
168
|
+
- lib/muffin_man/notifications/v1.rb
|
150
169
|
- lib/muffin_man/orders/v0.rb
|
151
170
|
- lib/muffin_man/product_fees/v0.rb
|
152
171
|
- lib/muffin_man/product_pricing/v0.rb
|
@@ -154,6 +173,11 @@ files:
|
|
154
173
|
- lib/muffin_man/request_helpers.rb
|
155
174
|
- lib/muffin_man/request_helpers/base.rb
|
156
175
|
- lib/muffin_man/request_helpers/inbound_shipment_plan_request_item.rb
|
176
|
+
- lib/muffin_man/request_helpers/outbound_fulfillment/address.rb
|
177
|
+
- lib/muffin_man/request_helpers/outbound_fulfillment/fulfillment_order_request.rb
|
178
|
+
- lib/muffin_man/request_helpers/outbound_fulfillment/fulfillment_preview_request.rb
|
179
|
+
- lib/muffin_man/request_helpers/outbound_fulfillment/item.rb
|
180
|
+
- lib/muffin_man/request_helpers/outbound_fulfillment/v20200701.rb
|
157
181
|
- lib/muffin_man/solicitations/v1.rb
|
158
182
|
- lib/muffin_man/sp_api_client.rb
|
159
183
|
- lib/muffin_man/tokens/v20210301.rb
|