Skip to content

Commit

Permalink
Merge pull request #50 from patterninc/INT-3219_AMZN-Normalization-Ph…
Browse files Browse the repository at this point in the history
…ase-1-Create-Product-endpoint

Create Product endpoint
  • Loading branch information
sanjjaymahalingam authored Jun 6, 2023
2 parents 7b556ef + e1b56e8 commit be9eff6
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.0.3 [#](https://github.com/patterninc/muffin_man/pull/50)

- Support for putListingsItem

# 2.0.2 [#49](https://github.com/patterninc/muffin_man/pull/49)

- Better error handling for unauthorized errors when getting LWA tokens
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ As of now, this gem only supports portions of the following APIs with more to co
- `fulfillment_outbound`
- `feeds`
- `notifications`
- `listings`

## Installation

Expand Down
17 changes: 17 additions & 0 deletions lib/muffin_man/listings/v20210801.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ def get_listings_item(seller_id, sku, marketplace_ids, issue_locale: nil, includ
@request_type = "GET"
call_api
end

def put_listings_item(seller_id, sku, marketplace_ids, product_type, attributes, issue_locale: nil,
requirements: nil)
@local_var_path = "/listings/2021-08-01/items/#{seller_id}/#{sku}"
@marketplace_ids = marketplace_ids.is_a?(Array) ? marketplace_ids : [marketplace_ids]
@query_params = {
"marketplaceIds" => @marketplace_ids.join(",")
}
@query_params["issueLocale"] = issue_locale if issue_locale
@request_body = {
"productType" => product_type,
"attributes" => attributes
}
@request_body["requirements"] = requirements if requirements
@request_type = "PUT"
call_api
end
end
end
end
2 changes: 1 addition & 1 deletion lib/muffin_man/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module MuffinMan
VERSION = "2.0.2"
VERSION = "2.0.3"
end
36 changes: 36 additions & 0 deletions spec/muffin_man/listings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,40 @@
expect(JSON.parse(listings_client.get_listings_item(seller_id, sku, amazon_marketplace_id).body).dig("sku")).to eq(sku)
end
end

describe "put_listings_item" do
before { stub_put_listings_item }
let(:product_type) { "LUGGAGE" }
let(:requirements) { "LISTING" }
let(:attributes) do
{
condition_type:
{
value: "new_new",
marketplace_id: "ATVPDKIKX0DER"
},
item_name:
{
value: 'AmazonBasics 16\" Underseat Spinner Carry-On',
language_tag: "en_US",
marketplace_id: "ATVPDKIKX0DER"
}
}
end

let(:put_listing_result) do
{
"sku" => "SD-ABC-12345",
"status" => "ACCEPTED",
"submissionId" => "f1dc2914-75dd-11ea-bc55-0242ac130003",
"issues" => []
}
end

it "makes a request to create a listings item or update an existing listings item" do
response = listings_client.put_listings_item(seller_id, sku, amazon_marketplace_id, product_type, attributes, requirements: requirements)
expect(response.response_code).to eq(200)
expect(JSON.parse(response.body)).to eq(put_listing_result)
end
end
end
6 changes: 6 additions & 0 deletions spec/support/put_listings_item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sku": "SD-ABC-12345",
"status": "ACCEPTED",
"submissionId": "f1dc2914-75dd-11ea-bc55-0242ac130003",
"issues": []
}
5 changes: 5 additions & 0 deletions spec/support/sp_api_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ def stub_get_listings_item
.to_return(status: 200, body: File.read("./spec/support/get_listings_item.json"), headers: {})
end

def stub_put_listings_item
stub_request(:put, "https://#{hostname}/listings/2021-08-01/items/#{seller_id}/#{sku}?marketplaceIds=#{amazon_marketplace_id}")
.to_return(status: 200, body: File.read("./spec/support/put_listings_item.json"), headers: {})
end

def stub_get_prep_instructions
stub_request(:get, "https://#{hostname}/fba/inbound/v0/prepInstructions?ShipToCountryCode=#{country_code}&SellerSKUList=#{sku_list.join(",")}")
.to_return(status: 200, body: File.read("./spec/support/get_prep_instructions.json"), headers: {})
Expand Down

0 comments on commit be9eff6

Please sign in to comment.