Skip to content

Instantly share code, notes, and snippets.

@gregawoods
Last active November 1, 2022 12:22
Show Gist options
  • Save gregawoods/91152da26231f4c2ef2fd10297f8e0ac to your computer and use it in GitHub Desktop.
Save gregawoods/91152da26231f4c2ef2fd10297f8e0ac to your computer and use it in GitHub Desktop.
Recursively download XSD documents for use with Amazon MWS.

Recursively download XSD documents for use with Amazon MWS. These can be used to validate XML documents before posting them to the Amazon Feeds API.

You could schedule this to run occasionally via cron in order to keep your XSD files up to date.

See also:

Usage

Files are downloaded to lib/xsd. Modify download_xsd_file to store somewhere else.

rake amazon:xsd
require 'nokogiri'
namespace :amazon do
desc 'Download XSD files recursively'
task xsd: :environment do
dest = download_xsd_file(
'amzn-envelope.xsd',
'https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_1_9/'
)
# Validate schema
Nokogiri::XML::Schema(File.open(dest))
puts 'Done!'
end
def download_xsd_file(file_name, base_url, downloads: [])
return if downloads.include?(file_name)
puts "- downloading #{file_name}..."
downloads << file_name
destination = Rails.root.join('lib', 'xsd', file_name)
File.open(destination, 'w') do |f|
IO.copy_stream(open(base_url + file_name), f)
end
raw_xml = Nokogiri::XML(File.open(destination))
raw_xml.xpath('//xsd:include').each do |tag|
file_name = tag.attribute('schemaLocation').value
download_xsd_file(file_name, base_url, downloads: downloads)
end
destination
end
end
@MST1122
Copy link

MST1122 commented Jun 30, 2021

@iamsr can you share the link for the new API for product type and listing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment