Skip to content

Commit

Permalink
Add a Feeds20210630 helper with upload_feed_document
Browse files Browse the repository at this point in the history
This method has previously been mentioned in the README, but was not
defined. This commit defines the method, with a slight change to take
the user requested content-type, which must match due to the signed
headers.
  • Loading branch information
harmonymjb authored and hakanensari committed Oct 31, 2024
1 parent b4eead7 commit daf74be
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ upload_url = response.parse["url"]

# Upload the feed content to the provided URL
feed_content = File.read("inventory_update.xml")
api.upload_feed_document(upload_url, feed_content)
api.upload_feed_document(upload_url, feed_content, "text/xml; charset=UTF-8")

# Create the feed
response = api.create_feed(
Expand Down
4 changes: 4 additions & 0 deletions lib/peddler/api/feeds_2021_06_30.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

require "peddler/api"

require "peddler/helpers/feeds_2021_06_30"

module Peddler
class << self
def feeds_2021_06_30(...)
Expand All @@ -14,6 +16,8 @@ class API
#
# The Selling Partner API for Feeds lets you upload data to Amazon on behalf of a selling partner.
class Feeds20210630 < API
include Peddler::Helpers::Feeds20210630

# Returns feed details for the feeds that match the filters that you specify.
#
# @note This operation can make a static sandbox call.
Expand Down
29 changes: 29 additions & 0 deletions lib/peddler/helpers/feeds_2021_06_30.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

module Peddler
module Helpers
module Feeds20210630
# Uploads feed_content to a signed upload_url previously provided by
# create_feed_document. The upload_url is signed, the Host and content-type
# headers must match the signing.
# @param upload_url [String] The signed url from the `create_feed_document` response.
# @param feed_content [String] The body of the content to upload.
# @param content_type [String] The content type of the upload,
# this must match the content-type requested in `create_feed_document`
# @return [HTTP::Response] The API response
def upload_feed_document(upload_url, feed_content, content_type)
response = HTTP.headers(
"Host" => URI.parse(upload_url).host,
"content-type" => content_type,
).send(:put, upload_url, body: feed_content)

if response.status.client_error?
error = Error.build(response)
raise error if error
end

response
end
end
end
end

0 comments on commit daf74be

Please sign in to comment.