dustbag 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +92 -0
- data/lib/dustbag.rb +47 -0
- data/lib/dustbag/accessories.rb +7 -0
- data/lib/dustbag/accessory.rb +6 -0
- data/lib/dustbag/arguments.rb +8 -0
- data/lib/dustbag/availability_attributes.rb +9 -0
- data/lib/dustbag/browse_node.rb +15 -0
- data/lib/dustbag/browse_nodes.rb +7 -0
- data/lib/dustbag/common.rb +7 -0
- data/lib/dustbag/customer_reviews.rb +11 -0
- data/lib/dustbag/dimension.rb +13 -0
- data/lib/dustbag/dimensions.rb +10 -0
- data/lib/dustbag/editorial_review.rb +11 -0
- data/lib/dustbag/editorial_reviews.rb +7 -0
- data/lib/dustbag/http_headers.rb +8 -0
- data/lib/dustbag/image.rb +5 -0
- data/lib/dustbag/image_set.rb +9 -0
- data/lib/dustbag/image_sets.rb +7 -0
- data/lib/dustbag/item.rb +21 -0
- data/lib/dustbag/item_attributes.rb +79 -0
- data/lib/dustbag/item_link.rb +9 -0
- data/lib/dustbag/item_links.rb +7 -0
- data/lib/dustbag/item_search_request.rb +7 -0
- data/lib/dustbag/item_search_response.rb +8 -0
- data/lib/dustbag/items.rb +14 -0
- data/lib/dustbag/language.rb +7 -0
- data/lib/dustbag/languages.rb +7 -0
- data/lib/dustbag/offer.rb +52 -0
- data/lib/dustbag/offer_summary.rb +12 -0
- data/lib/dustbag/offers.rb +7 -0
- data/lib/dustbag/operation_request.rb +13 -0
- data/lib/dustbag/parser.rb +26 -0
- data/lib/dustbag/parser/collection_node.rb +37 -0
- data/lib/dustbag/parser/map_collection_node.rb +19 -0
- data/lib/dustbag/parser/node.rb +112 -0
- data/lib/dustbag/price.rb +13 -0
- data/lib/dustbag/request.rb +11 -0
- data/lib/dustbag/similar_product.rb +6 -0
- data/lib/dustbag/similar_products.rb +7 -0
- data/lib/dustbag/simple_product.rb +9 -0
- data/lib/dustbag/variation_attribute.rb +7 -0
- data/lib/dustbag/variation_attributes.rb +7 -0
- data/lib/dustbag/variation_summary.rb +13 -0
- data/lib/dustbag/variations.rb +18 -0
- data/lib/dustbag/version.rb +3 -0
- data/spec/dustbag/accessories_spec.rb +9 -0
- data/spec/dustbag/accessory_spec.rb +10 -0
- data/spec/dustbag/arguments_spec.rb +9 -0
- data/spec/dustbag/availability_attributes_spec.rb +21 -0
- data/spec/dustbag/browse_node_spec.rb +33 -0
- data/spec/dustbag/browse_nodes_spec.rb +9 -0
- data/spec/dustbag/customer_reviews_spec.rb +17 -0
- data/spec/dustbag/dimension_spec.rb +17 -0
- data/spec/dustbag/dimensions_spec.rb +29 -0
- data/spec/dustbag/editorial_review_spec.rb +21 -0
- data/spec/dustbag/editorial_reviews_spec.rb +9 -0
- data/spec/dustbag/http_headers_spec.rb +11 -0
- data/spec/dustbag/image_set_spec.rb +13 -0
- data/spec/dustbag/image_sets_spec.rb +9 -0
- data/spec/dustbag/image_spec.rb +9 -0
- data/spec/dustbag/item_attributes_spec.rb +188 -0
- data/spec/dustbag/item_link_spec.rb +17 -0
- data/spec/dustbag/item_links_spec.rb +9 -0
- data/spec/dustbag/item_search_request_spec.rb +21 -0
- data/spec/dustbag/item_search_response_spec.rb +13 -0
- data/spec/dustbag/item_spec.rb +110 -0
- data/spec/dustbag/items_spec.rb +25 -0
- data/spec/dustbag/language_spec.rb +17 -0
- data/spec/dustbag/languages_spec.rb +9 -0
- data/spec/dustbag/offer_spec.rb +43 -0
- data/spec/dustbag/offer_summary_spec.rb +30 -0
- data/spec/dustbag/offers_spec.rb +9 -0
- data/spec/dustbag/operation_request_spec.rb +27 -0
- data/spec/dustbag/parser_spec.rb +23 -0
- data/spec/dustbag/price_spec.rb +18 -0
- data/spec/dustbag/request_spec.rb +25 -0
- data/spec/dustbag/similar_product_spec.rb +18 -0
- data/spec/dustbag/similar_products_spec.rb +9 -0
- data/spec/dustbag/variation_attribute_spec.rb +17 -0
- data/spec/dustbag/variation_attributes_spec.rb +9 -0
- data/spec/dustbag/variation_summary_spec.rb +19 -0
- data/spec/dustbag/variations_spec.rb +22 -0
- data/spec/fixtures/accessories.xml +23 -0
- data/spec/fixtures/accessory.xml +4 -0
- data/spec/fixtures/arguments.xml +11 -0
- data/spec/fixtures/availability_attributes.xml +5 -0
- data/spec/fixtures/book_item_attributes.xml +61 -0
- data/spec/fixtures/browse_node.xml +23 -0
- data/spec/fixtures/browse_nodes.xml +25 -0
- data/spec/fixtures/customer_reviews.xml +5 -0
- data/spec/fixtures/dimension.xml +1 -0
- data/spec/fixtures/dimensions.xml +6 -0
- data/spec/fixtures/editorial_review.xml +5 -0
- data/spec/fixtures/editorial_reviews.xml +7 -0
- data/spec/fixtures/http_headers.xml +3 -0
- data/spec/fixtures/image.xml +5 -0
- data/spec/fixtures/image_set.xml +32 -0
- data/spec/fixtures/image_sets.xml +34 -0
- data/spec/fixtures/invalid_request.xml +8 -0
- data/spec/fixtures/item.xml +40 -0
- data/spec/fixtures/item_attributes.xml +58 -0
- data/spec/fixtures/item_large.xml +500 -0
- data/spec/fixtures/item_link.xml +4 -0
- data/spec/fixtures/item_links.xml +30 -0
- data/spec/fixtures/item_medium.xml +123 -0
- data/spec/fixtures/item_search_request.xml +5 -0
- data/spec/fixtures/item_search_response.xml +433 -0
- data/spec/fixtures/item_small.xml +40 -0
- data/spec/fixtures/item_with_accessories.xml +122 -0
- data/spec/fixtures/item_with_variation_attributes.xml +264 -0
- data/spec/fixtures/item_with_variations.xml +1016 -0
- data/spec/fixtures/items.xml +411 -0
- data/spec/fixtures/language.xml +4 -0
- data/spec/fixtures/languages.xml +6 -0
- data/spec/fixtures/movie_item_attributes.xml +30 -0
- data/spec/fixtures/offer.xml +26 -0
- data/spec/fixtures/offer_summary.xml +11 -0
- data/spec/fixtures/offers.xml +31 -0
- data/spec/fixtures/operation_request.xml +18 -0
- data/spec/fixtures/price.xml +5 -0
- data/spec/fixtures/request.xml +8 -0
- data/spec/fixtures/root_browse_node.xml +11 -0
- data/spec/fixtures/similar_product.xml +4 -0
- data/spec/fixtures/similar_products.xml +18 -0
- data/spec/fixtures/variation_attribute.xml +4 -0
- data/spec/fixtures/variation_attributes.xml +6 -0
- data/spec/fixtures/variation_summary.xml +12 -0
- data/spec/fixtures/variations.xml +1000 -0
- data/spec/shared_examples/collection_node.rb +15 -0
- data/spec/shared_examples/common_response.rb +7 -0
- data/spec/shared_examples/map_collection_node.rb +13 -0
- data/spec/shared_examples/node.rb +9 -0
- data/spec/shared_examples/node_context.rb +6 -0
- data/spec/shared_examples/simple_product.rb +4 -0
- data/spec/spec_helper.rb +16 -0
- metadata +356 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0a0b547e89a4dbcbb9fe7e467fbcf2b442f0d045
|
4
|
+
data.tar.gz: 701d443ae47bd1fb8e30e7bb77a5c71108737970
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 17753ceb38260a57ae4ef5d557014a26ce76382eb968a47ded76618c53e31d01cf2240451513d199b9c7712736b4cb4744b6952cee6097ecd26c9d4610086d87
|
7
|
+
data.tar.gz: b7993fd441f38f07f4c8f12ea16dd8c7e57f3d341ce71b60864884839c6386ff5a11169a35134ecc1612343b77e7840f92d6923b83a64c768b991d77736dfd60
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) [2015] [Herman Eleazar Moreno Valle]
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# Dustbag
|
2
|
+
[![Build Status](https://snap-ci.com/supherman/dustbag/branch/master/build_image)](https://snap-ci.com/supherman/dustbag/branch/master)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/supherman/dustbag/badges/gpa.svg)](https://codeclimate.com/github/supherman/dustbag)
|
4
|
+
[![Test Coverage](https://codeclimate.com/github/supherman/dustbag/badges/coverage.svg)](https://codeclimate.com/github/supherman/dustbag/coverage)
|
5
|
+
|
6
|
+
**Dustbag** is a set of response parsers for [Vacumm](https://github.com/hakanensari/vacuum) (a Ruby wrapper of the [Amazon Product Advertising API](https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html)
|
7
|
+
|
8
|
+
|
9
|
+
![](https://sightsandsoundsinc.files.wordpress.com/2010/06/dust-image.jpg)
|
10
|
+
|
11
|
+
Vacuum is an excellent client for the Amazon Product Advertising API, it handles all the possible interactons with the API, but unfortunately you're required to implement your own response parse mechanisms. So Vacuum just give us a ton of dust (in form of xml), which is not bad, because that's not its job, dustbag's job is to handle all that dust and give it a meaningful use.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application’s Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'dustbag'
|
19
|
+
```
|
20
|
+
|
21
|
+
## Prerequisite
|
22
|
+
|
23
|
+
You'll need credentials to access to the Amazon Product Advertising API, also an affiliate tag, you can get them following [this instructions](https://affiliate-program.amazon.com/gp/advertising/api/detail/your-account.html?ie=UTF8&pf_rd_i=assoc-api-thank-you-0&pf_rd_m=ATVPDKIKX0DER&pf_rd_p=&pf_rd_r=&pf_rd_s=assoc-center-1&pf_rd_t=501&ref_=amb_link_83957991_1&rw_useCurrentProtocol=1)
|
24
|
+
|
25
|
+
Once you get your credentials, you'll need to configure Vacuum to use your credentials, you have two options, you can set the following env vars:
|
26
|
+
|
27
|
+
```zsh
|
28
|
+
export AWS_ACCESS_KEY_ID=key
|
29
|
+
export AWS_SECRET_ACCESS_KEY=secret
|
30
|
+
```
|
31
|
+
|
32
|
+
Or, you can explicitly say to vacuum to use your credentials:
|
33
|
+
|
34
|
+
```Ruby
|
35
|
+
request.configure(
|
36
|
+
aws_access_key_id: 'key',
|
37
|
+
aws_secret_access_key: 'secret',
|
38
|
+
associate_tag: 'tag'
|
39
|
+
)
|
40
|
+
```
|
41
|
+
|
42
|
+
One more thing, this gem makes use of the [Money](https://github.com/RubyMoney/money) gem, money makes use of i18n to format money strings, by default this behaviour is disabled, if you want to enable i18n with money, you can enable it by setting the next env var:
|
43
|
+
|
44
|
+
```
|
45
|
+
export USE_I18N_FOR_MONEY=true
|
46
|
+
```
|
47
|
+
|
48
|
+
|
49
|
+
## Usage
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
require 'vacuum'
|
53
|
+
require 'dustbag'
|
54
|
+
|
55
|
+
request = Vacuum.new
|
56
|
+
request.associate_tag = 'tag'
|
57
|
+
|
58
|
+
response = request.item_search(
|
59
|
+
query: {
|
60
|
+
'Keywords' => 'Architecture',
|
61
|
+
'SearchIndex' => 'Books'
|
62
|
+
}
|
63
|
+
)
|
64
|
+
|
65
|
+
response.parser = Dustbag::Parser
|
66
|
+
|
67
|
+
response.parse
|
68
|
+
|
69
|
+
```
|
70
|
+
|
71
|
+
You'll get an ```ItemSearchReponse``` object, this object has an 'items' method which is a collection of the Items matchig your search, if you want to see what can you do with these itmes, look at the source code of the [```Item``` class](https://github.com/supherman/dustbag/blob/master/lib/dustbag/item.rb)
|
72
|
+
|
73
|
+
## Project status
|
74
|
+
|
75
|
+
Right now, there is only one response parser implemented (ItemSearchResponse), the remaining work is to implement the following responses:
|
76
|
+
|
77
|
+
- [BrowseNodeLookup](http://docs.aws.amazon.com/AWSECommerceService/latest/DG/BrowseNodeLookup.html)
|
78
|
+
- [ItemLookup](http://docs.aws.amazon.com/AWSECommerceService/latest/DG/ItemLookup.html)
|
79
|
+
- [SimilarityLookup](http://docs.aws.amazon.com/AWSECommerceService/latest/DG/SimilarityLookup.html)
|
80
|
+
- [CartAdd](http://docs.aws.amazon.com/AWSECommerceService/latest/DG/CartAdd.html)
|
81
|
+
- [CartClear](http://docs.aws.amazon.com/AWSECommerceService/latest/DG/CartClear.html)
|
82
|
+
- [CartCreate](http://docs.aws.amazon.com/AWSECommerceService/latest/DG/CartCreate.html)
|
83
|
+
- [CartGet](http://docs.aws.amazon.com/AWSECommerceService/latest/DG/CartGet.html)
|
84
|
+
- [CartModify](http://docs.aws.amazon.com/AWSECommerceService/latest/DG/CartModify.html)
|
85
|
+
|
86
|
+
## Contributing
|
87
|
+
|
88
|
+
1. Fork it
|
89
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
90
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
91
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
92
|
+
5. Create new Pull Request
|
data/lib/dustbag.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'money'
|
2
|
+
require 'ox'
|
3
|
+
require 'dustbag/version'
|
4
|
+
|
5
|
+
Money.use_i18n = ENV['USE_I18N_FOR_MONEY'] || false
|
6
|
+
|
7
|
+
module Dustbag
|
8
|
+
autoload :Accessories, 'dustbag/accessories'
|
9
|
+
autoload :Accessory, 'dustbag/accessory'
|
10
|
+
autoload :Arguments, 'dustbag/arguments'
|
11
|
+
autoload :AvailabilityAttributes, 'dustbag/availability_attributes'
|
12
|
+
autoload :BrowseNode, 'dustbag/browse_node'
|
13
|
+
autoload :BrowseNodes, 'dustbag/browse_nodes'
|
14
|
+
autoload :Common, 'dustbag/common'
|
15
|
+
autoload :CustomerReviews, 'dustbag/customer_reviews'
|
16
|
+
autoload :Dimension, 'dustbag/dimension'
|
17
|
+
autoload :Dimensions, 'dustbag/dimensions'
|
18
|
+
autoload :EditorialReview, 'dustbag/editorial_review'
|
19
|
+
autoload :EditorialReviews, 'dustbag/editorial_reviews'
|
20
|
+
autoload :HttpHeaders, 'dustbag/http_headers'
|
21
|
+
autoload :Image, 'dustbag/image'
|
22
|
+
autoload :ImageSet, 'dustbag/image_set'
|
23
|
+
autoload :ImageSets, 'dustbag/image_sets'
|
24
|
+
autoload :Item, 'dustbag/item'
|
25
|
+
autoload :ItemAttributes, 'dustbag/item_attributes'
|
26
|
+
autoload :ItemLink, 'dustbag/item_link'
|
27
|
+
autoload :ItemLinks, 'dustbag/item_links'
|
28
|
+
autoload :ItemSearchRequest, 'dustbag/item_search_request'
|
29
|
+
autoload :ItemSearchResponse, 'dustbag/item_search_response'
|
30
|
+
autoload :Items, 'dustbag/items'
|
31
|
+
autoload :Language, 'dustbag/language'
|
32
|
+
autoload :Languages, 'dustbag/languages'
|
33
|
+
autoload :Offer, 'dustbag/offer'
|
34
|
+
autoload :OfferSummary, 'dustbag/offer_summary'
|
35
|
+
autoload :Offers, 'dustbag/offers'
|
36
|
+
autoload :OperationRequest, 'dustbag/operation_request'
|
37
|
+
autoload :Parser, 'dustbag/parser'
|
38
|
+
autoload :Price, 'dustbag/price'
|
39
|
+
autoload :Request, 'dustbag/request'
|
40
|
+
autoload :SimilarProduct, 'dustbag/similar_product'
|
41
|
+
autoload :SimilarProducts, 'dustbag/similar_products'
|
42
|
+
autoload :SimpleProduct, 'dustbag/simple_product'
|
43
|
+
autoload :VariationAttribute, 'dustbag/variation_attribute'
|
44
|
+
autoload :VariationAttributes, 'dustbag/variation_attributes'
|
45
|
+
autoload :VariationSummary, 'dustbag/variation_summary'
|
46
|
+
autoload :Variations, 'dustbag/variations'
|
47
|
+
end
|
data/lib/dustbag/item.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Dustbag
|
2
|
+
class Item
|
3
|
+
include Parser::Node
|
4
|
+
|
5
|
+
text_attributes asin: 'ASIN',
|
6
|
+
parent_asin: 'ParentASIN',
|
7
|
+
detail_page_url: 'DetailPageURL'
|
8
|
+
|
9
|
+
numeric_attributes :sales_rank
|
10
|
+
|
11
|
+
children :item_links, :item_attributes, :image_sets, :offer_summary,
|
12
|
+
:offers, :customer_reviews, :editorial_reviews, :similar_products,
|
13
|
+
:browse_nodes, :accessories, :variation_summary, :variations,
|
14
|
+
:variation_attributes
|
15
|
+
|
16
|
+
children small_image: Image,
|
17
|
+
medium_image: Image,
|
18
|
+
large_image: Image
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Dustbag
|
2
|
+
class ItemAttributes
|
3
|
+
include Parser::Node
|
4
|
+
|
5
|
+
text_attributes :manufacturer, :product_group, :title, :director, :binding,
|
6
|
+
:brand, :color, :model, :part_number, :product_type_name,
|
7
|
+
:publisher, :studio, :size, :audience_rating, :genre
|
8
|
+
|
9
|
+
numeric_attributes :number_of_items, :number_of_pages, :package_quantity
|
10
|
+
|
11
|
+
text_attributes ean: 'EAN',
|
12
|
+
mpn: 'MPN',
|
13
|
+
upc: 'UPC',
|
14
|
+
isbn: 'ISBN'
|
15
|
+
|
16
|
+
children item_dimensions: Dimensions,
|
17
|
+
package_dimensions: Dimensions,
|
18
|
+
running_time: Dimension
|
19
|
+
|
20
|
+
children :languages
|
21
|
+
|
22
|
+
def actors
|
23
|
+
repeated_subnodes_text('Actor')
|
24
|
+
end
|
25
|
+
|
26
|
+
def creators
|
27
|
+
repeated_subnodes('Creator').inject({}) do |acc, val|
|
28
|
+
acc[val['Role']] = val.text
|
29
|
+
acc
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def authors
|
34
|
+
repeated_subnodes_text('Author')
|
35
|
+
end
|
36
|
+
|
37
|
+
def ean_list
|
38
|
+
list = subnode('EANList')
|
39
|
+
list && list.locate('EANListElement').map do |element|
|
40
|
+
element.text
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def features
|
45
|
+
repeated_subnodes_text('Feature')
|
46
|
+
end
|
47
|
+
|
48
|
+
def labels
|
49
|
+
repeated_subnodes_text('Label')
|
50
|
+
end
|
51
|
+
|
52
|
+
def trade_in_value
|
53
|
+
Price.parse(subnode('TradeInValue'))
|
54
|
+
end
|
55
|
+
|
56
|
+
def upc_list
|
57
|
+
list = subnode('UPCList')
|
58
|
+
list && list.locate('UPCListElement').map do |element|
|
59
|
+
element.text
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def list_price
|
64
|
+
Price.parse(subnode('ListPrice'))
|
65
|
+
end
|
66
|
+
|
67
|
+
def release_date
|
68
|
+
Date.parse(subnode_text('ReleaseDate')) rescue nil
|
69
|
+
end
|
70
|
+
|
71
|
+
def publication_date
|
72
|
+
Date.parse(subnode_text('PublicationDate')) rescue nil
|
73
|
+
end
|
74
|
+
|
75
|
+
def adult_product?
|
76
|
+
subnode_text('IsAdultProduct') == '1'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|