dustbag 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +92 -0
  4. data/lib/dustbag.rb +47 -0
  5. data/lib/dustbag/accessories.rb +7 -0
  6. data/lib/dustbag/accessory.rb +6 -0
  7. data/lib/dustbag/arguments.rb +8 -0
  8. data/lib/dustbag/availability_attributes.rb +9 -0
  9. data/lib/dustbag/browse_node.rb +15 -0
  10. data/lib/dustbag/browse_nodes.rb +7 -0
  11. data/lib/dustbag/common.rb +7 -0
  12. data/lib/dustbag/customer_reviews.rb +11 -0
  13. data/lib/dustbag/dimension.rb +13 -0
  14. data/lib/dustbag/dimensions.rb +10 -0
  15. data/lib/dustbag/editorial_review.rb +11 -0
  16. data/lib/dustbag/editorial_reviews.rb +7 -0
  17. data/lib/dustbag/http_headers.rb +8 -0
  18. data/lib/dustbag/image.rb +5 -0
  19. data/lib/dustbag/image_set.rb +9 -0
  20. data/lib/dustbag/image_sets.rb +7 -0
  21. data/lib/dustbag/item.rb +21 -0
  22. data/lib/dustbag/item_attributes.rb +79 -0
  23. data/lib/dustbag/item_link.rb +9 -0
  24. data/lib/dustbag/item_links.rb +7 -0
  25. data/lib/dustbag/item_search_request.rb +7 -0
  26. data/lib/dustbag/item_search_response.rb +8 -0
  27. data/lib/dustbag/items.rb +14 -0
  28. data/lib/dustbag/language.rb +7 -0
  29. data/lib/dustbag/languages.rb +7 -0
  30. data/lib/dustbag/offer.rb +52 -0
  31. data/lib/dustbag/offer_summary.rb +12 -0
  32. data/lib/dustbag/offers.rb +7 -0
  33. data/lib/dustbag/operation_request.rb +13 -0
  34. data/lib/dustbag/parser.rb +26 -0
  35. data/lib/dustbag/parser/collection_node.rb +37 -0
  36. data/lib/dustbag/parser/map_collection_node.rb +19 -0
  37. data/lib/dustbag/parser/node.rb +112 -0
  38. data/lib/dustbag/price.rb +13 -0
  39. data/lib/dustbag/request.rb +11 -0
  40. data/lib/dustbag/similar_product.rb +6 -0
  41. data/lib/dustbag/similar_products.rb +7 -0
  42. data/lib/dustbag/simple_product.rb +9 -0
  43. data/lib/dustbag/variation_attribute.rb +7 -0
  44. data/lib/dustbag/variation_attributes.rb +7 -0
  45. data/lib/dustbag/variation_summary.rb +13 -0
  46. data/lib/dustbag/variations.rb +18 -0
  47. data/lib/dustbag/version.rb +3 -0
  48. data/spec/dustbag/accessories_spec.rb +9 -0
  49. data/spec/dustbag/accessory_spec.rb +10 -0
  50. data/spec/dustbag/arguments_spec.rb +9 -0
  51. data/spec/dustbag/availability_attributes_spec.rb +21 -0
  52. data/spec/dustbag/browse_node_spec.rb +33 -0
  53. data/spec/dustbag/browse_nodes_spec.rb +9 -0
  54. data/spec/dustbag/customer_reviews_spec.rb +17 -0
  55. data/spec/dustbag/dimension_spec.rb +17 -0
  56. data/spec/dustbag/dimensions_spec.rb +29 -0
  57. data/spec/dustbag/editorial_review_spec.rb +21 -0
  58. data/spec/dustbag/editorial_reviews_spec.rb +9 -0
  59. data/spec/dustbag/http_headers_spec.rb +11 -0
  60. data/spec/dustbag/image_set_spec.rb +13 -0
  61. data/spec/dustbag/image_sets_spec.rb +9 -0
  62. data/spec/dustbag/image_spec.rb +9 -0
  63. data/spec/dustbag/item_attributes_spec.rb +188 -0
  64. data/spec/dustbag/item_link_spec.rb +17 -0
  65. data/spec/dustbag/item_links_spec.rb +9 -0
  66. data/spec/dustbag/item_search_request_spec.rb +21 -0
  67. data/spec/dustbag/item_search_response_spec.rb +13 -0
  68. data/spec/dustbag/item_spec.rb +110 -0
  69. data/spec/dustbag/items_spec.rb +25 -0
  70. data/spec/dustbag/language_spec.rb +17 -0
  71. data/spec/dustbag/languages_spec.rb +9 -0
  72. data/spec/dustbag/offer_spec.rb +43 -0
  73. data/spec/dustbag/offer_summary_spec.rb +30 -0
  74. data/spec/dustbag/offers_spec.rb +9 -0
  75. data/spec/dustbag/operation_request_spec.rb +27 -0
  76. data/spec/dustbag/parser_spec.rb +23 -0
  77. data/spec/dustbag/price_spec.rb +18 -0
  78. data/spec/dustbag/request_spec.rb +25 -0
  79. data/spec/dustbag/similar_product_spec.rb +18 -0
  80. data/spec/dustbag/similar_products_spec.rb +9 -0
  81. data/spec/dustbag/variation_attribute_spec.rb +17 -0
  82. data/spec/dustbag/variation_attributes_spec.rb +9 -0
  83. data/spec/dustbag/variation_summary_spec.rb +19 -0
  84. data/spec/dustbag/variations_spec.rb +22 -0
  85. data/spec/fixtures/accessories.xml +23 -0
  86. data/spec/fixtures/accessory.xml +4 -0
  87. data/spec/fixtures/arguments.xml +11 -0
  88. data/spec/fixtures/availability_attributes.xml +5 -0
  89. data/spec/fixtures/book_item_attributes.xml +61 -0
  90. data/spec/fixtures/browse_node.xml +23 -0
  91. data/spec/fixtures/browse_nodes.xml +25 -0
  92. data/spec/fixtures/customer_reviews.xml +5 -0
  93. data/spec/fixtures/dimension.xml +1 -0
  94. data/spec/fixtures/dimensions.xml +6 -0
  95. data/spec/fixtures/editorial_review.xml +5 -0
  96. data/spec/fixtures/editorial_reviews.xml +7 -0
  97. data/spec/fixtures/http_headers.xml +3 -0
  98. data/spec/fixtures/image.xml +5 -0
  99. data/spec/fixtures/image_set.xml +32 -0
  100. data/spec/fixtures/image_sets.xml +34 -0
  101. data/spec/fixtures/invalid_request.xml +8 -0
  102. data/spec/fixtures/item.xml +40 -0
  103. data/spec/fixtures/item_attributes.xml +58 -0
  104. data/spec/fixtures/item_large.xml +500 -0
  105. data/spec/fixtures/item_link.xml +4 -0
  106. data/spec/fixtures/item_links.xml +30 -0
  107. data/spec/fixtures/item_medium.xml +123 -0
  108. data/spec/fixtures/item_search_request.xml +5 -0
  109. data/spec/fixtures/item_search_response.xml +433 -0
  110. data/spec/fixtures/item_small.xml +40 -0
  111. data/spec/fixtures/item_with_accessories.xml +122 -0
  112. data/spec/fixtures/item_with_variation_attributes.xml +264 -0
  113. data/spec/fixtures/item_with_variations.xml +1016 -0
  114. data/spec/fixtures/items.xml +411 -0
  115. data/spec/fixtures/language.xml +4 -0
  116. data/spec/fixtures/languages.xml +6 -0
  117. data/spec/fixtures/movie_item_attributes.xml +30 -0
  118. data/spec/fixtures/offer.xml +26 -0
  119. data/spec/fixtures/offer_summary.xml +11 -0
  120. data/spec/fixtures/offers.xml +31 -0
  121. data/spec/fixtures/operation_request.xml +18 -0
  122. data/spec/fixtures/price.xml +5 -0
  123. data/spec/fixtures/request.xml +8 -0
  124. data/spec/fixtures/root_browse_node.xml +11 -0
  125. data/spec/fixtures/similar_product.xml +4 -0
  126. data/spec/fixtures/similar_products.xml +18 -0
  127. data/spec/fixtures/variation_attribute.xml +4 -0
  128. data/spec/fixtures/variation_attributes.xml +6 -0
  129. data/spec/fixtures/variation_summary.xml +12 -0
  130. data/spec/fixtures/variations.xml +1000 -0
  131. data/spec/shared_examples/collection_node.rb +15 -0
  132. data/spec/shared_examples/common_response.rb +7 -0
  133. data/spec/shared_examples/map_collection_node.rb +13 -0
  134. data/spec/shared_examples/node.rb +9 -0
  135. data/spec/shared_examples/node_context.rb +6 -0
  136. data/spec/shared_examples/simple_product.rb +4 -0
  137. data/spec/spec_helper.rb +16 -0
  138. metadata +356 -0
@@ -0,0 +1,18 @@
1
+ module Dustbag
2
+ class Variations
3
+ include Parser::Node
4
+ include Parser::CollectionNode
5
+
6
+ member_name 'Item'
7
+
8
+ numeric_attributes total: 'TotalVariations',
9
+ total_pages: 'TotalVariationPages'
10
+
11
+ def dimensions
12
+ dimensions = subnode('VariationDimensions')
13
+ dimensions && dimensions.locate('VariationDimension').map do |dimension|
14
+ dimension.text
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Dustbag
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ module Dustbag
4
+ describe Accessories do
5
+ include_context 'load xml from fixture'
6
+
7
+ it_behaves_like 'a collection node of', Accessory
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ module Dustbag
4
+ describe Accessory do
5
+ include_context 'load xml from fixture'
6
+
7
+ it_behaves_like 'a node'
8
+ it_behaves_like 'a simple product'
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ module Dustbag
4
+ describe Arguments do
5
+ include_context 'load xml from fixture'
6
+
7
+ it_behaves_like 'a map collection node'
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module Dustbag
4
+ describe AvailabilityAttributes do
5
+ include_context 'load xml from fixture'
6
+
7
+ it_behaves_like 'a node'
8
+
9
+ describe '#type' do
10
+ it { expect(subject.type).to eq 'now' }
11
+ end
12
+
13
+ describe '#maximum_hours' do
14
+ it { expect(subject.maximum_hours).to eq 0 }
15
+ end
16
+
17
+ describe '#minimum_hours' do
18
+ it { expect(subject.minimum_hours).to eq 0 }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ module Dustbag
4
+ describe BrowseNode do
5
+ include_context 'load xml from fixture'
6
+
7
+ it_behaves_like 'a node'
8
+
9
+ describe '#id' do
10
+ it { expect(subject.id).to eq 2407749011 }
11
+ end
12
+
13
+ describe '#name' do
14
+ it { expect(subject.name).to eq 'Unlocked Cell Phones' }
15
+ end
16
+
17
+ describe '#ancestors' do
18
+ it { expect(subject.ancestors).to be_a_kind_of BrowseNodes }
19
+ end
20
+
21
+ describe '#category_root?' do
22
+ context 'when category root' do
23
+ include_context 'load xml from fixture', 'root_browse_node'
24
+
25
+ it { expect(subject.category_root?).to be_truthy }
26
+ end
27
+
28
+ context 'when not category root' do
29
+ it { expect(subject.category_root?).to be_falsy }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ module Dustbag
4
+ describe BrowseNodes do
5
+ include_context 'load xml from fixture'
6
+
7
+ it_behaves_like 'a collection node of', BrowseNode
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ module Dustbag
4
+ describe CustomerReviews do
5
+ include_context 'load xml from fixture'
6
+
7
+ it_behaves_like 'a node'
8
+
9
+ describe '#iframe_url' do
10
+ it { expect(subject.iframe_url).to eq 'http://www.amazon.com/reviews/iframe?akid=AKIAIHNK3TBF4L5EDREQ&alinkCode=xm2&asin=B00ZQVSKSM&atag=magmalabs-20&exp=2015-11-06T18%3A09%3A07Z&v=2&sig=LVQAhPoL48XLrPTdDEa%2FjC4h8r81FFEVqO2OmhIosT8%3D' }
11
+ end
12
+
13
+ describe '#any?' do
14
+ it { expect(subject.any?).to be_truthy }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ module Dustbag
4
+ describe Dimension do
5
+ include_context 'load xml from fixture'
6
+
7
+ it_behaves_like 'a node'
8
+
9
+ describe '#value' do
10
+ it { expect(subject.value).to eq 559 }
11
+ end
12
+
13
+ describe '#units' do
14
+ it { expect(subject.units).to eq 'hundredths-inches' }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ module Dustbag
4
+ describe Dimensions do
5
+ include_context 'load xml from fixture'
6
+
7
+ it_behaves_like 'a node'
8
+
9
+ describe '#height' do
10
+ it { expect(subject.height.value).to eq 559 }
11
+ it { expect(subject.height.units).to eq 'hundredths-inches' }
12
+ end
13
+
14
+ describe '#length' do
15
+ it { expect(subject.length.value).to eq 263 }
16
+ it { expect(subject.length.units).to eq 'hundredths-inches' }
17
+ end
18
+
19
+ describe '#weight' do
20
+ it { expect(subject.weight.value).to eq 34 }
21
+ it { expect(subject.weight.units).to eq 'hundredths-pounds' }
22
+ end
23
+
24
+ describe '#width' do
25
+ it { expect(subject.width.value).to eq 285 }
26
+ it { expect(subject.width.units).to eq 'hundredths-inches'}
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module Dustbag
4
+ describe EditorialReview do
5
+ include_context 'load xml from fixture'
6
+
7
+ it_behaves_like 'a node'
8
+
9
+ describe '#source' do
10
+ it { expect(subject.source).to eq 'Product Description' }
11
+ end
12
+
13
+ describe '#content' do
14
+ it { expect(subject.content).to eq 'Quad core processing power in a great value product. 4.5" display. 5MP rear camera with a VGA front facing camera. Great 24hr battery performance with a 2390mAh battery. Personalize with colored bands.' }
15
+ end
16
+
17
+ describe '#link_suppressed?' do
18
+ it { expect(subject.link_suppressed?).to be_falsy }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ module Dustbag
4
+ describe EditorialReviews do
5
+ include_context 'load xml from fixture'
6
+
7
+ it_behaves_like 'a collection node of', EditorialReview
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ module Dustbag
4
+ describe HttpHeaders do
5
+ include_context 'load xml from fixture'
6
+
7
+ it_behaves_like 'a map collection node'
8
+
9
+ it { expect(subject['UserAgent']).to_not be_nil }
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ module Dustbag
4
+ describe ImageSet do
5
+ include_context 'load xml from fixture'
6
+
7
+ it_behaves_like 'a node'
8
+
9
+ describe '#category' do
10
+ it { expect(subject.category).to eq 'primary' }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ module Dustbag
4
+ describe ImageSets do
5
+ include_context 'load xml from fixture'
6
+
7
+ it_behaves_like 'a collection node of', ImageSet
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ module Dustbag
4
+ describe Image do
5
+ include_context 'load xml from fixture'
6
+
7
+ it_behaves_like 'a node'
8
+ end
9
+ end
@@ -0,0 +1,188 @@
1
+ require 'spec_helper'
2
+
3
+ module Dustbag
4
+ describe ItemAttributes do
5
+ include_context 'load xml from fixture'
6
+
7
+ it_behaves_like 'a node'
8
+
9
+ describe '#manufacturer' do
10
+ it { expect(subject.manufacturer).to eq 'Motorola' }
11
+ end
12
+
13
+ describe '#product_group' do
14
+ it { expect(subject.product_group).to eq 'Wireless' }
15
+ end
16
+
17
+ describe '#title' do
18
+ it { expect(subject.title).to eq 'Motorola Moto G (3rd Generation) - Black - 8 GB - Global GSM Unlocked Phone' }
19
+ end
20
+
21
+ describe '#binding' do
22
+ it { expect(subject.binding).to eq 'Unlocked Phone' }
23
+ end
24
+
25
+ describe '#brand' do
26
+ it { expect(subject.brand).to eq 'Motorola' }
27
+ end
28
+
29
+ describe '#color' do
30
+ it { expect(subject.color).to eq 'Black' }
31
+ end
32
+
33
+ describe '#ean' do
34
+ it { expect(subject.ean).to eq '0701799787331' }
35
+ end
36
+
37
+ describe '#ean_list' do
38
+ it { expect(subject.ean_list).to_not be_empty }
39
+ it { expect(subject.ean_list).to include('0701799787331') }
40
+ it { expect(subject.ean_list).to include('0723755007703') }
41
+ end
42
+
43
+ describe '#features' do
44
+ it { expect(subject.features).to_not be_empty }
45
+ it { expect(subject.features.first).to eq 'Advanced water resistance'}
46
+ it { expect(subject.features.last).to eq '4G LTE Speed; Browse, stream music, watch video, and play games at blazing speed.'}
47
+ end
48
+
49
+ describe '#eligible_for_trade_in?' do
50
+ context 'when eligible'
51
+ context 'when not eligible'
52
+ end
53
+
54
+ describe '#item_dimensions' do
55
+ it { expect(subject.item_dimensions).to be_a_kind_of Dimensions }
56
+ end
57
+
58
+ describe '#labels' do
59
+ it { expect(subject.labels).to_not be_empty }
60
+ it { expect(subject.labels.first).to eq 'Motorola' }
61
+ end
62
+
63
+ describe '#list_price' do
64
+ it { expect(subject.list_price).to be_a_kind_of Money }
65
+ end
66
+
67
+ describe '#model' do
68
+ it { expect(subject.model).to eq 'XT1540' }
69
+ end
70
+
71
+ describe '#mpn' do
72
+ it { expect(subject.mpn).to eq '00770NARTL' }
73
+ end
74
+
75
+ describe '#package_dimensions' do
76
+ it { expect(subject.package_dimensions).to be_a_kind_of Dimensions }
77
+ end
78
+
79
+ describe '#package_quantity' do
80
+ it { expect(subject.package_quantity).to eq 1 }
81
+ end
82
+
83
+ describe '#part_number' do
84
+ it { expect(subject.part_number).to eq '00770NARTL' }
85
+ end
86
+
87
+ describe '#product_type_name' do
88
+ it { expect(subject.product_type_name).to eq 'WIRELESS_ACCESSORY' }
89
+ end
90
+
91
+ describe '#publisher' do
92
+ it { expect(subject.publisher).to eq 'Motorola' }
93
+ end
94
+
95
+ describe '#size' do
96
+ it { expect(subject.size).to eq '8 GB' }
97
+ end
98
+
99
+ describe '#studio' do
100
+ it { expect(subject.studio).to eq 'Motorola' }
101
+ end
102
+
103
+ describe '#trade_in_value' do
104
+ it { expect(subject.trade_in_value).to be_a_kind_of Money }
105
+ end
106
+
107
+ describe '#upc' do
108
+ it { expect(subject.upc).to eq '723755007703' }
109
+ end
110
+
111
+ describe '#upc_list' do
112
+ it { expect(subject.upc_list).to_not be_empty }
113
+ it { expect(subject.upc_list).to include('723755007703') }
114
+ it { expect(subject.upc_list).to include('701799787331') }
115
+ end
116
+
117
+ context 'when a movie' do
118
+ include_context 'load xml from fixture', 'movie_item_attributes'
119
+
120
+ describe '#actors' do
121
+ it { expect(subject.actors).to eq ['Robert Downey Jr.', 'Chris Hemsworth', 'Mark Ruffalo', 'Chris Evans', 'Scarlett Johansson'] }
122
+ end
123
+
124
+ describe '#creators' do
125
+ it { expect(subject.creators).to eq({ 'Producer' => 'Kevin Feige', 'Writer' => 'Joss Whedon' }) }
126
+ end
127
+
128
+ describe '#director' do
129
+ it { expect(subject.director).to eq 'Joss Whedon' }
130
+ end
131
+
132
+ describe '#audience_rating' do
133
+ it { expect(subject.audience_rating).to eq 'PG-13 (Parental Guidance Suggested)' }
134
+ end
135
+
136
+ describe '#genre' do
137
+ it { expect(subject.genre).to eq 'Action' }
138
+ end
139
+
140
+ describe '#languages' do
141
+ it { expect(subject.languages).to be_a_kind_of Languages }
142
+ it { expect(subject.languages.first).to be_a_kind_of Language }
143
+ end
144
+
145
+ describe '#release_date' do
146
+ it { expect(subject.release_date).to eq Date.parse('2015-10-02') }
147
+ end
148
+
149
+ describe '#running_time' do
150
+ it { expect(subject.running_time).to be_a_kind_of Dimension }
151
+ it { expect(subject.running_time.value).to eq 189 }
152
+ it { expect(subject.running_time.units).to eq 'minutes'}
153
+ end
154
+
155
+ describe '#adult_product?' do
156
+ it { expect(subject.adult_product?).to be_falsy }
157
+ end
158
+ end
159
+
160
+ context 'when a book' do
161
+ include_context 'load xml from fixture', 'book_item_attributes'
162
+
163
+ describe '#authors' do
164
+ it { expect(subject.authors).to eq ['Ryan Bigg', 'Yehuda Katz', 'Steve Klabnik', 'Rebecca Skinner'] }
165
+ end
166
+
167
+ describe '#isbn' do
168
+ it { expect(subject.isbn).to eq '1617291099' }
169
+ end
170
+
171
+ describe '#number_of_items' do
172
+ it { expect(subject.number_of_items).to eq 1 }
173
+ end
174
+
175
+ describe '#number_of_pages' do
176
+ it { expect(subject.number_of_pages).to eq 576 }
177
+ end
178
+
179
+ describe '#package_quantity' do
180
+ it { expect(subject.package_quantity).to eq 1 }
181
+ end
182
+
183
+ describe '#publication_date' do
184
+ it { expect(subject.publication_date).to eq Date.parse('2015-09-19') }
185
+ end
186
+ end
187
+ end
188
+ end