Skip to content

Commit be9eff6

Browse files
Merge pull request #50 from patterninc/INT-3219_AMZN-Normalization-Phase-1-Create-Product-endpoint
Create Product endpoint
2 parents 7b556ef + e1b56e8 commit be9eff6

File tree

7 files changed

+70
-1
lines changed

7 files changed

+70
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 2.0.3 [#](https://github.com/patterninc/muffin_man/pull/50)
2+
3+
- Support for putListingsItem
4+
15
# 2.0.2 [#49](https://github.com/patterninc/muffin_man/pull/49)
26

37
- Better error handling for unauthorized errors when getting LWA tokens

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ As of now, this gem only supports portions of the following APIs with more to co
1515
- `fulfillment_outbound`
1616
- `feeds`
1717
- `notifications`
18+
- `listings`
1819

1920
## Installation
2021

lib/muffin_man/listings/v20210801.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ def get_listings_item(seller_id, sku, marketplace_ids, issue_locale: nil, includ
1919
@request_type = "GET"
2020
call_api
2121
end
22+
23+
def put_listings_item(seller_id, sku, marketplace_ids, product_type, attributes, issue_locale: nil,
24+
requirements: nil)
25+
@local_var_path = "/listings/2021-08-01/items/#{seller_id}/#{sku}"
26+
@marketplace_ids = marketplace_ids.is_a?(Array) ? marketplace_ids : [marketplace_ids]
27+
@query_params = {
28+
"marketplaceIds" => @marketplace_ids.join(",")
29+
}
30+
@query_params["issueLocale"] = issue_locale if issue_locale
31+
@request_body = {
32+
"productType" => product_type,
33+
"attributes" => attributes
34+
}
35+
@request_body["requirements"] = requirements if requirements
36+
@request_type = "PUT"
37+
call_api
38+
end
2239
end
2340
end
2441
end

lib/muffin_man/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module MuffinMan
4-
VERSION = "2.0.2"
4+
VERSION = "2.0.3"
55
end

spec/muffin_man/listings_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,40 @@
1616
expect(JSON.parse(listings_client.get_listings_item(seller_id, sku, amazon_marketplace_id).body).dig("sku")).to eq(sku)
1717
end
1818
end
19+
20+
describe "put_listings_item" do
21+
before { stub_put_listings_item }
22+
let(:product_type) { "LUGGAGE" }
23+
let(:requirements) { "LISTING" }
24+
let(:attributes) do
25+
{
26+
condition_type:
27+
{
28+
value: "new_new",
29+
marketplace_id: "ATVPDKIKX0DER"
30+
},
31+
item_name:
32+
{
33+
value: 'AmazonBasics 16\" Underseat Spinner Carry-On',
34+
language_tag: "en_US",
35+
marketplace_id: "ATVPDKIKX0DER"
36+
}
37+
}
38+
end
39+
40+
let(:put_listing_result) do
41+
{
42+
"sku" => "SD-ABC-12345",
43+
"status" => "ACCEPTED",
44+
"submissionId" => "f1dc2914-75dd-11ea-bc55-0242ac130003",
45+
"issues" => []
46+
}
47+
end
48+
49+
it "makes a request to create a listings item or update an existing listings item" do
50+
response = listings_client.put_listings_item(seller_id, sku, amazon_marketplace_id, product_type, attributes, requirements: requirements)
51+
expect(response.response_code).to eq(200)
52+
expect(JSON.parse(response.body)).to eq(put_listing_result)
53+
end
54+
end
1955
end

spec/support/put_listings_item.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sku": "SD-ABC-12345",
3+
"status": "ACCEPTED",
4+
"submissionId": "f1dc2914-75dd-11ea-bc55-0242ac130003",
5+
"issues": []
6+
}

spec/support/sp_api_helpers.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ def stub_get_listings_item
192192
.to_return(status: 200, body: File.read("./spec/support/get_listings_item.json"), headers: {})
193193
end
194194

195+
def stub_put_listings_item
196+
stub_request(:put, "https://#{hostname}/listings/2021-08-01/items/#{seller_id}/#{sku}?marketplaceIds=#{amazon_marketplace_id}")
197+
.to_return(status: 200, body: File.read("./spec/support/put_listings_item.json"), headers: {})
198+
end
199+
195200
def stub_get_prep_instructions
196201
stub_request(:get, "https://#{hostname}/fba/inbound/v0/prepInstructions?ShipToCountryCode=#{country_code}&SellerSKUList=#{sku_list.join(",")}")
197202
.to_return(status: 200, body: File.read("./spec/support/get_prep_instructions.json"), headers: {})

0 commit comments

Comments
 (0)