amazon_feed_validator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +13 -0
  5. data/.travis.yml +5 -0
  6. data/Amazon.xsd +92 -0
  7. data/CHANGELOG.md +6 -0
  8. data/Gemfile +6 -0
  9. data/Gemfile.lock +72 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +43 -0
  12. data/Rakefile +27 -0
  13. data/amazon_feed_validator.gemspec +31 -0
  14. data/bin/console +14 -0
  15. data/bin/setup +8 -0
  16. data/lib/amazon_feed_validator.rb +10 -0
  17. data/lib/amazon_feed_validator/constructor_methods.rb +12 -0
  18. data/lib/amazon_feed_validator/feed_validator.rb +37 -0
  19. data/lib/amazon_feed_validator/version.rb +3 -0
  20. data/lib/rake_tasks.rb +2 -0
  21. data/lib/tasks/amazon.rake +46 -0
  22. data/lib/xsd/AdditionalProductInformation.xsd +23 -0
  23. data/lib/xsd/Amazon.xsd +92 -0
  24. data/lib/xsd/Arts.xsd +144 -0
  25. data/lib/xsd/AutoAccessory.xsd +2103 -0
  26. data/lib/xsd/Baby.xsd +234 -0
  27. data/lib/xsd/Beauty.xsd +1107 -0
  28. data/lib/xsd/Books.xsd +210 -0
  29. data/lib/xsd/CE.xsd +2935 -0
  30. data/lib/xsd/CameraPhoto.xsd +2719 -0
  31. data/lib/xsd/ClothingAccessories.xsd +128 -0
  32. data/lib/xsd/Coins.xsd +129 -0
  33. data/lib/xsd/Collectibles.xsd +83 -0
  34. data/lib/xsd/Computers.xsd +2414 -0
  35. data/lib/xsd/EUCompliance.xsd +24 -0
  36. data/lib/xsd/EducationSupplies.xsd +215 -0
  37. data/lib/xsd/EntertainmentCollectibles.xsd +106 -0
  38. data/lib/xsd/FBA.xsd +28 -0
  39. data/lib/xsd/FoodAndBeverages.xsd +1397 -0
  40. data/lib/xsd/FoodServiceAndJanSan.xsd +216 -0
  41. data/lib/xsd/FulfillmentCenter.xsd +57 -0
  42. data/lib/xsd/Furniture.xsd +98 -0
  43. data/lib/xsd/GiftCards.xsd +102 -0
  44. data/lib/xsd/Gourmet.xsd +100 -0
  45. data/lib/xsd/Health.xsd +1232 -0
  46. data/lib/xsd/Home.xsd +5642 -0
  47. data/lib/xsd/HomeImprovement.xsd +1234 -0
  48. data/lib/xsd/Industrial.xsd +962 -0
  49. data/lib/xsd/Inventory.xsd +49 -0
  50. data/lib/xsd/Jewelry.xsd +1123 -0
  51. data/lib/xsd/LabSupplies.xsd +411 -0
  52. data/lib/xsd/LargeAppliances.xsd +650 -0
  53. data/lib/xsd/Lighting.xsd +278 -0
  54. data/lib/xsd/Listings.xsd +32 -0
  55. data/lib/xsd/Luggage.xsd +121 -0
  56. data/lib/xsd/LuxuryBeauty.xsd +108 -0
  57. data/lib/xsd/MaterialHandling.xsd +112 -0
  58. data/lib/xsd/MechanicalFasteners.xsd +174 -0
  59. data/lib/xsd/Miscellaneous.xsd +157 -0
  60. data/lib/xsd/Motorcycles.xsd +351 -0
  61. data/lib/xsd/Music.xsd +255 -0
  62. data/lib/xsd/MusicalInstruments.xsd +974 -0
  63. data/lib/xsd/Office.xsd +1142 -0
  64. data/lib/xsd/OrderAcknowledgement.xsd +55 -0
  65. data/lib/xsd/OrderAdjustment.xsd +175 -0
  66. data/lib/xsd/OrderFulfillment.xsd +65 -0
  67. data/lib/xsd/Outdoors.xsd +1041 -0
  68. data/lib/xsd/Override.xsd +48 -0
  69. data/lib/xsd/PetSupplies.xsd +216 -0
  70. data/lib/xsd/PowerTransmission.xsd +87 -0
  71. data/lib/xsd/Price.xsd +227 -0
  72. data/lib/xsd/ProcessingReport.xsd +87 -0
  73. data/lib/xsd/Product.xsd +1332 -0
  74. data/lib/xsd/ProductClothing.xsd +334 -0
  75. data/lib/xsd/ProductImage.xsd +57 -0
  76. data/lib/xsd/ProfessionalHealthCare.xsd +135 -0
  77. data/lib/xsd/RawMaterials.xsd +125 -0
  78. data/lib/xsd/Relationship.xsd +47 -0
  79. data/lib/xsd/SWVG.xsd +358 -0
  80. data/lib/xsd/SettlementReport.xsd +258 -0
  81. data/lib/xsd/Shoes.xsd +240 -0
  82. data/lib/xsd/Sports.xsd +790 -0
  83. data/lib/xsd/SportsMemorabilia.xsd +66 -0
  84. data/lib/xsd/ThreeDPrinting.xsd +105 -0
  85. data/lib/xsd/TiresAndWheels.xsd +358 -0
  86. data/lib/xsd/Tools.xsd +84 -0
  87. data/lib/xsd/Toys.xsd +632 -0
  88. data/lib/xsd/ToysBaby.xsd +337 -0
  89. data/lib/xsd/Video.xsd +406 -0
  90. data/lib/xsd/WineAndAlcohol.xsd +197 -0
  91. data/lib/xsd/Wireless.xsd +134 -0
  92. data/lib/xsd/amzn-base.xsd +4845 -0
  93. data/lib/xsd/amzn-envelope.xsd +98 -0
  94. data/lib/xsd/amzn-header.xsd +45 -0
  95. metadata +235 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e65d748831183d31838b0643bba6c9d754a61e081eb795af60d97dbabeb8cc93
4
+ data.tar.gz: 7dfd2f7f363cac1c9de9cec3a829f00788bb55e5e4ebdc8e52db2a9ae3a14952
5
+ SHA512:
6
+ metadata.gz: 50ca85f80b98618a32e98cb9529be2d52b114472dec4d971aaa4bcb0fab33387945d776049736193c1d83867f7d98675da9074fac70487b54a122c3ad0dabba9
7
+ data.tar.gz: f04365c4acb03579b19ccad8675c9e001519f738822ade5fb4b156b825fc66fb6d8690e30b86f5e6eee912363e4b14c13eb9cac2a73f78c479c3bcd277460d86
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'spec/**/*'
4
+ - 'bin/**/*'
5
+
6
+ Style/Documentation:
7
+ Enabled: false
8
+
9
+ Layout/IndentationConsistency:
10
+ EnforcedStyle: rails
11
+
12
+ Layout/MultilineMethodCallIndentation:
13
+ EnforcedStyle: indented
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,92 @@
1
+ <?xml version="1.0"?>
2
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
3
+ <xsd:annotation>
4
+ <xsd:documentation>
5
+ $Date: 2004/11/18 $
6
+ AMAZON.COM CONFIDENTIAL.This document and the information contained in it are
7
+ confidential and proprietary information of Amazon.com and may not be reproduced,distributed or used, in whole or in part, for any purpose other than as necessary to list products for sale on the www.amazon.com web site pursuant to an agreement with Amazon.com.
8
+ </xsd:documentation>
9
+ </xsd:annotation>
10
+ <xsd:include schemaLocation="amzn-base.xsd"/>
11
+
12
+ <xsd:element name="Amazon-Vendor-Only">
13
+ <xsd:complexType>
14
+ <xsd:sequence>
15
+ <xsd:element name="Cost" type="CurrencyAmount"/>
16
+ </xsd:sequence>
17
+ </xsd:complexType>
18
+ </xsd:element>
19
+ <xsd:annotation>
20
+ <xsd:documentation>
21
+ If you are using the Amazon-Only structure, please also include and populate the Amazon-Vendor-Only structure.
22
+ </xsd:documentation>
23
+ </xsd:annotation>
24
+
25
+ <xsd:element name="Amazon-Only">
26
+ <xsd:complexType>
27
+ <xsd:sequence>
28
+ <xsd:element name="Tier" type="xsd:positiveInteger"/>
29
+ <xsd:element name="PurchasingCategory" type="StringNotNull"/>
30
+ <xsd:element name="PurchasingSubCategory" type="StringNotNull"/>
31
+ <xsd:element name="PackagingType" type="StringNotNull"/>
32
+ <xsd:element name="UnderlyingAvailability">
33
+ <xsd:simpleType>
34
+ <xsd:restriction base="xsd:string">
35
+ <xsd:enumeration value="backordered"/>
36
+ <xsd:enumeration value="manufacturer-out-of-stock"/>
37
+ <xsd:enumeration value="pre-ordered"/>
38
+ <xsd:enumeration value="2-3-days"/>
39
+ <xsd:enumeration value="1-2-weeks"/>
40
+ <xsd:enumeration value="4-6-weeks"/>
41
+ </xsd:restriction>
42
+ </xsd:simpleType>
43
+ </xsd:element>
44
+ <xsd:element name="ReplenishmentCategory">
45
+ <xsd:simpleType>
46
+ <xsd:restriction base="xsd:string">
47
+ <xsd:enumeration value="basic-replenishment"/>
48
+ <xsd:enumeration value="limited-replenishment"/>
49
+ <xsd:enumeration value="manufacturer-out-of-stock"/>
50
+ <xsd:enumeration value="new-product"/>
51
+ <xsd:enumeration value="non-replenishable"/>
52
+ <xsd:enumeration value="non-stockupable"/>
53
+ <xsd:enumeration value="obsolete"/>
54
+ <xsd:enumeration value="planned-replenishment"/>
55
+ </xsd:restriction>
56
+ </xsd:simpleType>
57
+ </xsd:element>
58
+ <xsd:element name="DropShipStatus">
59
+ <xsd:simpleType>
60
+ <xsd:restriction base="xsd:string">
61
+ <xsd:enumeration value="drop-ship-disabled"/>
62
+ <xsd:enumeration value="drop-ship-disabled-by-buyer"/>
63
+ <xsd:enumeration value="drop-ship-enabled"/>
64
+ <xsd:enumeration value="drop-ship-enabled-no-auto-pricing"/>
65
+ <xsd:enumeration value="drop-ship-only"/>
66
+ </xsd:restriction>
67
+ </xsd:simpleType>
68
+ </xsd:element>
69
+ <xsd:element name="OutOfStockWebsiteMessage">
70
+ <xsd:simpleType>
71
+ <xsd:restriction base="xsd:string">
72
+ <xsd:enumeration value="email-me-when-available"/>
73
+ <xsd:enumeration value="out-of-stock"/>
74
+ <xsd:enumeration value="pre-order-ute"/>
75
+ <xsd:enumeration value="underlying-availability"/>
76
+ </xsd:restriction>
77
+ </xsd:simpleType>
78
+ </xsd:element>
79
+ </xsd:sequence>
80
+ </xsd:complexType>
81
+ </xsd:element>
82
+ </xsd:schema>
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ # 0.1.0
4
+
5
+ * Validate product message
6
+ * Validate fragance message
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in amazon_feed_validator.gemspec
6
+ gemspec
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ amazon_feed_validator (0.1.0)
5
+ activesupport (~> 5.2)
6
+ hashie (~> 3.6)
7
+ nokogiri (~> 1.8)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (5.2.1)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ ast (2.4.0)
18
+ concurrent-ruby (1.0.5)
19
+ diff-lcs (1.3)
20
+ hashie (3.6.0)
21
+ i18n (1.1.0)
22
+ concurrent-ruby (~> 1.0)
23
+ jaro_winkler (1.5.1)
24
+ mini_portile2 (2.3.0)
25
+ minitest (5.11.3)
26
+ nokogiri (1.8.4)
27
+ mini_portile2 (~> 2.3.0)
28
+ parallel (1.12.1)
29
+ parser (2.5.1.2)
30
+ ast (~> 2.4.0)
31
+ powerpack (0.1.2)
32
+ rainbow (3.0.0)
33
+ rake (10.5.0)
34
+ rspec (3.8.0)
35
+ rspec-core (~> 3.8.0)
36
+ rspec-expectations (~> 3.8.0)
37
+ rspec-mocks (~> 3.8.0)
38
+ rspec-core (3.8.0)
39
+ rspec-support (~> 3.8.0)
40
+ rspec-expectations (3.8.1)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.8.0)
43
+ rspec-mocks (3.8.0)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.8.0)
46
+ rspec-support (3.8.0)
47
+ rubocop (0.59.0)
48
+ jaro_winkler (~> 1.5.1)
49
+ parallel (~> 1.10)
50
+ parser (>= 2.5, != 2.5.1.1)
51
+ powerpack (~> 0.1)
52
+ rainbow (>= 2.2.2, < 4.0)
53
+ ruby-progressbar (~> 1.7)
54
+ unicode-display_width (~> 1.0, >= 1.0.1)
55
+ ruby-progressbar (1.10.0)
56
+ thread_safe (0.3.6)
57
+ tzinfo (1.2.5)
58
+ thread_safe (~> 0.1)
59
+ unicode-display_width (1.4.0)
60
+
61
+ PLATFORMS
62
+ ruby
63
+
64
+ DEPENDENCIES
65
+ amazon_feed_validator!
66
+ bundler (~> 1.16)
67
+ rake (~> 10.0)
68
+ rspec (~> 3.0)
69
+ rubocop (~> 0.59)
70
+
71
+ BUNDLED WITH
72
+ 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Emil Kampp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # AmazonFeedValidator
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'amazon_feed_validator'
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ To validate a single feed item based on Amazons feed type enumeration:
14
+
15
+ ```ruby
16
+ validator = AmazonFeedValidator.new(feed, name: 'Product')
17
+ validator.validate # => true or false
18
+ validator.errors # => ["Some error description"]
19
+ ```
20
+
21
+ To validate a whole feed file:
22
+
23
+ ```ruby
24
+ validator = AmazonFeedValidator.new(feed, name: 'amzn-envelope')
25
+ validator.validate # => true or false
26
+ validator.errors # => ["Some error description"]
27
+ ```
28
+
29
+ ## Development
30
+
31
+ To update xsd files run:
32
+
33
+ ```bash
34
+ bundle exec rake amazon:xsd
35
+ ```
36
+
37
+ ## Testing
38
+
39
+ To run all tests:
40
+
41
+ ```bash
42
+ bundle exec rake
43
+ ```
@@ -0,0 +1,27 @@
1
+ # rubocop:disable Lint/HandleExceptions
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ import './lib/tasks/amazon.rake'
7
+
8
+ begin
9
+ require 'rubocop/rake_task'
10
+
11
+ RuboCop::RakeTask.new(:rubocop) do |t|
12
+ t.options = ['--display-cop-names']
13
+ end
14
+ rescue LoadError
15
+ # noop
16
+ end
17
+
18
+ RSpec::Core::RakeTask.new(:spec)
19
+
20
+ task default: %i[spec rubocop]
21
+
22
+ desc 'Load the environment'
23
+ task :environment do
24
+ require_relative './lib/amazon_feed_validator'
25
+ end
26
+
27
+ # rubocop:enable Lint/HandleExceptions
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'amazon_feed_validator/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'amazon_feed_validator'
7
+ spec.version = AmazonFeedValidator::VERSION
8
+ spec.authors = ['Emil Kampp']
9
+ spec.email = ['emil@kampp.me']
10
+
11
+ spec.summary = 'Validate your Amazon feed files'
12
+ spec.description = 'Validates your Amazon XML feed files'
13
+ spec.homepage = 'https://amazon.com'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.16'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
+ spec.add_development_dependency 'rubocop', '~> 0.59'
27
+
28
+ spec.add_runtime_dependency 'activesupport', '~> 5.2'
29
+ spec.add_runtime_dependency 'hashie', '~> 3.6'
30
+ spec.add_runtime_dependency 'nokogiri', '~> 1.8'
31
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'amazon_feed_validator'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ require 'active_support/all'
2
+ require 'hashie/mash'
3
+ require 'nokogiri'
4
+
5
+ require 'amazon_feed_validator/version'
6
+ require 'amazon_feed_validator/constructor_methods'
7
+
8
+ module AmazonFeedValidator
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,12 @@
1
+ # rubocop:disable Style/AccessModifierDeclarations
2
+
3
+ require 'amazon_feed_validator/feed_validator'
4
+
5
+ module AmazonFeedValidator
6
+ def new(*args)
7
+ AmazonFeedValidator::FeedValidator.new(*args)
8
+ end
9
+ module_function :new
10
+ end
11
+
12
+ # rubocop:enable Style/AccessModifierDeclarations
@@ -0,0 +1,37 @@
1
+ module AmazonFeedValidator
2
+ class FeedValidator
3
+ XSDDIR = File.expand_path('../xsd', __dir__)
4
+
5
+ attr_reader :feed, :options, :errors
6
+
7
+ def initialize(feed, **options)
8
+ @feed = Nokogiri::XML feed
9
+ @options = Hashie::Mash.new options
10
+ end
11
+
12
+ def validate
13
+ @errors = Nokogiri::XML::Schema(xsd_file(options.name))
14
+ .validate(feed)
15
+ .map(&:to_s)
16
+ errors.empty?
17
+ end
18
+
19
+ private
20
+
21
+ def xsd_file(name)
22
+ file = File.read File.expand_path sanitize_name(name), XSDDIR
23
+
24
+ # Replace schema location references with ones pointing to local xsd
25
+ # files
26
+ file.gsub! \
27
+ 'schemaLocation="',
28
+ "schemaLocation=\"#{XSDDIR}/"
29
+ end
30
+
31
+ def sanitize_name(name)
32
+ name ||= 'Product.xsd'
33
+ name = "#{name}.xsd" unless name.include? '.xsd'
34
+ name
35
+ end
36
+ end
37
+ end