asin 1.1.2 → 2.0.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.irbrc +12 -0
- data/.rspec +1 -0
- data/.travis.yml +2 -3
- data/CHANGELOG.md +8 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +72 -17
- data/README.md +33 -38
- data/asin.gemspec +1 -1
- data/lib/asin.rb +4 -7
- data/lib/asin/adapter.rb +222 -0
- data/lib/asin/client.rb +21 -135
- data/lib/asin/configuration.rb +1 -7
- data/lib/asin/version.rb +1 -1
- data/spec/cassettes/asin/lookup_and_search_should_have_metadata.yml +1 -1
- data/spec/lib/browse_node_spec.rb +3 -3
- data/spec/lib/cart_spec.rb +13 -106
- data/spec/lib/config_spec.rb +11 -11
- data/spec/lib/search_spec.rb +53 -42
- data/spec/lib/similarity_spec.rb +4 -4
- data/spec/spec_helper.rb +5 -1
- metadata +20 -21
- data/lib/asin/simple_cart.rb +0 -54
- data/lib/asin/simple_item.rb +0 -44
- data/lib/asin/simple_node.rb +0 -44
data/spec/lib/config_spec.rb
CHANGED
@@ -8,31 +8,31 @@ module ASIN
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should fail with wrong configuration key" do
|
11
|
-
lambda { @helper.configure :wrong => 'key' }.
|
11
|
+
expect(lambda { @helper.configure :wrong => 'key' }).to raise_error(ArgumentError)
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should not override the configuration" do
|
15
15
|
config = @helper.configure :key => 'wont get overridden'
|
16
|
-
config.key.
|
16
|
+
expect(config.key).to_not be_nil
|
17
17
|
|
18
18
|
config = @helper.configure :secret => 'is also set'
|
19
|
-
config.key.
|
20
|
-
config.secret.
|
19
|
+
expect(config.key).to_not be_nil
|
20
|
+
expect(config.secret).to_not be_nil
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should work with a configuration block" do
|
24
24
|
conf = ASIN::Configuration.configure do |config|
|
25
25
|
config.key = 'bla'
|
26
26
|
end
|
27
|
-
conf.key.
|
27
|
+
expect(conf.key).to eql('bla')
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should read configuration from yml" do
|
31
31
|
config = ASIN::Configuration.configure :yaml => 'spec/asin.yml'
|
32
|
-
config.secret.
|
33
|
-
config.key.
|
34
|
-
config.host.
|
35
|
-
config.logger.
|
32
|
+
expect(config.secret).to eql('secret_yml')
|
33
|
+
expect(config.key).to eql('key_yml')
|
34
|
+
expect(config.host).to eql('host_yml')
|
35
|
+
expect(config.logger).to eql('logger_yml')
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should read configuration from yml with block" do
|
@@ -40,8 +40,8 @@ module ASIN
|
|
40
40
|
config.secret = nil
|
41
41
|
config.key = yml['secret']
|
42
42
|
end
|
43
|
-
conf.secret.
|
44
|
-
conf.key.
|
43
|
+
expect(conf.secret).to be_nil
|
44
|
+
expect(conf.key).to eql('secret_yml')
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
data/spec/lib/search_spec.rb
CHANGED
@@ -10,84 +10,95 @@ module ASIN
|
|
10
10
|
|
11
11
|
it "should lookup a book", :vcr do
|
12
12
|
items = @helper.lookup(ANY_ASIN)
|
13
|
-
items.first.title.
|
13
|
+
expect(items.first.title).to match(/Learn Objective/)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should have metadata", :vcr do
|
17
17
|
items = @helper.lookup(ANY_ASIN, :ResponseGroup => :Medium)
|
18
18
|
item = items.first
|
19
|
-
item.asin.
|
20
|
-
item.title.
|
21
|
-
item.
|
22
|
-
item.
|
23
|
-
item.
|
24
|
-
item.
|
19
|
+
expect(item.asin).to eql(ANY_ASIN)
|
20
|
+
expect(item.title).to match(/Learn Objective/)
|
21
|
+
expect(item.sales_rank).to eql('209840')
|
22
|
+
expect(item.amount).to eql(3999)
|
23
|
+
expect(item.details_url).to eql("http://www.amazon.com/Learn-Objective-C-Mac-Series/dp/1430218150%3FSubscriptionId%3DAKIAIBNLWSCV5OXMPD6A%26tag%3Dphoet-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D1430218150")
|
24
|
+
expect(item.image_url).to eql("http://ecx.images-amazon.com/images/I/41kq5bDvnUL.jpg")
|
25
|
+
expect(item.review).to match(/Take your coding skills to the next level/)
|
26
|
+
|
27
|
+
# <ItemAttributes>
|
28
|
+
expect(item.item_height).to eql("925")
|
29
|
+
expect(item.item_length).to eql("752")
|
30
|
+
expect(item.item_width).to eql("71")
|
31
|
+
expect(item.item_weight).to eql("137")
|
32
|
+
expect(item.package_height).to eql("102")
|
33
|
+
expect(item.package_length).to eql("921")
|
34
|
+
expect(item.package_width).to eql("701")
|
35
|
+
expect(item.package_weight).to eql("123")
|
36
|
+
expect(item.author.count).to eql(2)
|
37
|
+
expect(item.author.first).to eql("Scott Knaster")
|
38
|
+
expect(item.binding).to eql("Paperback")
|
39
|
+
expect(item.brand).to eql("Apress")
|
40
|
+
expect(item.ean).to eql("9781430218159")
|
41
|
+
expect(item.edition).to eql("1")
|
42
|
+
expect(item.isbn).to eql("1430218150")
|
43
|
+
expect(item.label).to eql("Apress")
|
44
|
+
expect(item.language).to eql("English")
|
45
|
+
expect(item.formatted_price).to eql("$39.99")
|
46
|
+
expect(item.manufacturer).to eql("Apress")
|
47
|
+
expect(item.mpn).to eql("978-1-4302-1815-9")
|
48
|
+
expect(item.page_count).to eql("360")
|
49
|
+
expect(item.part_number).to eql("978-1-4302-1815-9")
|
50
|
+
expect(item.product_group).to eql("Book")
|
51
|
+
expect(item.publication_date).to eql("2009-01-07")
|
52
|
+
expect(item.publisher).to eql("Apress")
|
53
|
+
expect(item.sku).to eql("mon0001920250")
|
54
|
+
expect(item.studio).to eql("Apress")
|
55
|
+
|
56
|
+
# <OfferSummary>
|
57
|
+
expect(item.total_new).to eql("56")
|
58
|
+
expect(item.total_used).to eql("62")
|
25
59
|
end
|
26
60
|
|
27
61
|
it "should lookup multiple response groups", :vcr do
|
28
62
|
items = @helper.lookup(ANY_ASIN, :ResponseGroup => [:Small, :AlternateVersions])
|
29
63
|
|
30
64
|
item = items.first
|
31
|
-
item.asin.
|
32
|
-
item.title.
|
65
|
+
expect(item.asin).to eql(ANY_ASIN)
|
66
|
+
expect(item.title).to match(/Learn Objective/)
|
33
67
|
end
|
34
68
|
|
35
69
|
it "should lookup multiple books", :vcr do
|
36
70
|
items = @helper.lookup(ANY_ASIN, ANY_OTHER_ASIN)
|
37
71
|
|
38
|
-
items.last.title.
|
39
|
-
items.first.title.
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should return a custom item class", :vcr do
|
43
|
-
module TEST
|
44
|
-
class TestItem
|
45
|
-
attr_accessor :testo
|
46
|
-
def initialize(hash)
|
47
|
-
@testo = hash
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
@helper.configure :item_type => TEST::TestItem
|
52
|
-
@helper.lookup(ANY_ASIN).first.testo.should_not be_nil
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should return a raw value", :vcr do
|
56
|
-
@helper.configure :item_type => :raw
|
57
|
-
@helper.lookup(ANY_ASIN).first['ItemAttributes']['Title'].should_not be_nil
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should return a mash value", :vcr do
|
61
|
-
@helper.configure :item_type => :mash
|
62
|
-
@helper.lookup(ANY_ASIN).first.ItemAttributes.Title.should_not be_nil
|
72
|
+
expect(items.last.title).to match(/Beginning iPhone Development/)
|
73
|
+
expect(items.first.title).to match(/Learn Objective-C/)
|
63
74
|
end
|
64
75
|
|
65
76
|
it "should search_keywords and handle a single result", :vcr do
|
66
77
|
items = @helper.search_keywords('0471317519')
|
67
|
-
items.first.title.
|
78
|
+
expect(items.first.title).to match(/A Self-Teaching Guide/)
|
68
79
|
end
|
69
80
|
|
70
81
|
it "should search_keywords a book with fulltext", :vcr do
|
71
82
|
items = @helper.search_keywords 'Learn', 'Objective-C'
|
72
|
-
items.
|
73
|
-
items.first.title.
|
83
|
+
expect(items).to have(10).things
|
84
|
+
expect(items.first.title).to match(/Learn Objective-C /)
|
74
85
|
end
|
75
86
|
|
76
87
|
it "should search_keywords never mind music", :vcr do
|
77
88
|
items = @helper.search_keywords 'nirvana', 'never mind', :SearchIndex => :Music
|
78
|
-
items.
|
79
|
-
items.map(&:title).join.
|
89
|
+
expect(items).to have(10).things
|
90
|
+
expect(items.map(&:title).join).to match(/Nevermind/)
|
80
91
|
end
|
81
92
|
|
82
93
|
it "should search music", :vcr do
|
83
94
|
items = @helper.search :SearchIndex => :Music
|
84
|
-
items.
|
95
|
+
expect(items).to have(0).things
|
85
96
|
end
|
86
97
|
|
87
98
|
it "should search never mind music", :vcr do
|
88
99
|
items = @helper.search :Keywords => 'nirvana', :SearchIndex => :Music
|
89
|
-
items.
|
90
|
-
items.map(&:title).join.
|
100
|
+
expect(items).to have(10).things
|
101
|
+
expect(items.map(&:title).join).to match(/Nevermind/)
|
91
102
|
end
|
92
103
|
end
|
93
104
|
end
|
data/spec/lib/similarity_spec.rb
CHANGED
@@ -10,14 +10,14 @@ module ASIN
|
|
10
10
|
|
11
11
|
it "should find similar items", :vcr do
|
12
12
|
items = @helper.similar(ANY_ASIN)
|
13
|
-
items.
|
14
|
-
items.first.title.
|
13
|
+
expect(items).to have(10).elements
|
14
|
+
expect(items.first.title).to match(/Programming in Objective-C/)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should find similar items for multiple asins and different config", :vcr do
|
18
18
|
items = @helper.similar(ANY_ASIN, ANY_OTHER_ASIN, :SimilarityType => :Intersection, :ResponseGroup => :Small)
|
19
|
-
items.
|
20
|
-
items.first.title.
|
19
|
+
expect(items).to have(4).elements
|
20
|
+
expect(items.first.title).to match(/Beginning iOS 5 Development/)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,10 +5,14 @@ unless Net.const_defined? :HTTPSession
|
|
5
5
|
class Net::HTTPSession < Net::HTTP::HTTPSession; end
|
6
6
|
end
|
7
7
|
|
8
|
+
require 'coveralls'
|
9
|
+
Coveralls.wear!
|
10
|
+
|
11
|
+
require 'pry' unless defined? JRUBY_VERSION
|
8
12
|
require 'rspec'
|
9
13
|
require 'asin'
|
10
14
|
require 'asin/client' # is somehow needed for jruby
|
11
|
-
require '
|
15
|
+
require 'asin/adapter'
|
12
16
|
require 'httpclient'
|
13
17
|
require 'vcr'
|
14
18
|
require 'httpi'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Schröder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: crack
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rash
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.4'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.4'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: httpi
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,20 +150,6 @@ dependencies:
|
|
136
150
|
- - ~>
|
137
151
|
- !ruby/object:Gem::Version
|
138
152
|
version: 2.11.0
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: pry
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ~>
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: 0.9.9
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ~>
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: 0.9.9
|
153
153
|
description: Amazon Simple INterface - Support for ItemLookup, SimilarityLookup, Search,
|
154
154
|
BrowseNode and Cart Operations.
|
155
155
|
email:
|
@@ -160,7 +160,8 @@ extra_rdoc_files: []
|
|
160
160
|
files:
|
161
161
|
- .document
|
162
162
|
- .gitignore
|
163
|
-
- .
|
163
|
+
- .irbrc
|
164
|
+
- .rspec
|
164
165
|
- .travis.yml
|
165
166
|
- CHANGELOG.md
|
166
167
|
- Gemfile
|
@@ -168,11 +169,9 @@ files:
|
|
168
169
|
- README.md
|
169
170
|
- asin.gemspec
|
170
171
|
- lib/asin.rb
|
172
|
+
- lib/asin/adapter.rb
|
171
173
|
- lib/asin/client.rb
|
172
174
|
- lib/asin/configuration.rb
|
173
|
-
- lib/asin/simple_cart.rb
|
174
|
-
- lib/asin/simple_item.rb
|
175
|
-
- lib/asin/simple_node.rb
|
176
175
|
- lib/asin/version.rb
|
177
176
|
- rakefile.rb
|
178
177
|
- spec/asin.yml
|
@@ -221,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
221
220
|
version: '0'
|
222
221
|
requirements: []
|
223
222
|
rubyforge_project: asin
|
224
|
-
rubygems_version: 2.0.
|
223
|
+
rubygems_version: 2.0.3
|
225
224
|
signing_key:
|
226
225
|
specification_version: 4
|
227
226
|
summary: Amazon Simple INterface - Support for ItemLookup, SimilarityLookup, Search,
|
data/lib/asin/simple_cart.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'hashie'
|
2
|
-
|
3
|
-
module ASIN
|
4
|
-
|
5
|
-
# = SimpleCart
|
6
|
-
#
|
7
|
-
# The +SimpleCart+ class is a wrapper for the Amazon XML-REST-Response.
|
8
|
-
#
|
9
|
-
# A Hashie::Mash is used for the internal data representation and can be accessed over the +raw+ attribute.
|
10
|
-
#
|
11
|
-
class SimpleCart
|
12
|
-
|
13
|
-
attr_reader :raw
|
14
|
-
|
15
|
-
def initialize(hash)
|
16
|
-
@raw = Hashie::Mash.new(hash)
|
17
|
-
end
|
18
|
-
|
19
|
-
def cart_id
|
20
|
-
@raw.CartId
|
21
|
-
end
|
22
|
-
|
23
|
-
def hmac
|
24
|
-
@raw.HMAC
|
25
|
-
end
|
26
|
-
|
27
|
-
def url
|
28
|
-
@raw.PurchaseURL
|
29
|
-
end
|
30
|
-
|
31
|
-
def price
|
32
|
-
@raw.SubTotal.FormattedPrice
|
33
|
-
end
|
34
|
-
|
35
|
-
def items
|
36
|
-
return [] unless @raw.CartItems
|
37
|
-
@raw.CartItems.CartItem.is_a?(Array) ? @raw.CartItems.CartItem : [@raw.CartItems.CartItem]
|
38
|
-
end
|
39
|
-
|
40
|
-
def saved_items
|
41
|
-
return [] unless @raw.SavedForLaterItems
|
42
|
-
@raw.SavedForLaterItems.SavedForLaterItem.is_a?(Array) ? @raw.SavedForLaterItems.SavedForLaterItem : [@raw.SavedForLaterItems.SavedForLaterItem]
|
43
|
-
end
|
44
|
-
|
45
|
-
def valid?
|
46
|
-
@raw.Request.IsValid == 'True'
|
47
|
-
end
|
48
|
-
|
49
|
-
def empty?
|
50
|
-
@raw.CartItems.nil?
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
data/lib/asin/simple_item.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'hashie'
|
2
|
-
|
3
|
-
module ASIN
|
4
|
-
|
5
|
-
# =SimpleItem
|
6
|
-
#
|
7
|
-
# The +SimpleItem+ class is a wrapper for the Amazon XML-REST-Response.
|
8
|
-
#
|
9
|
-
# A Hashie::Mash is used for the internal data representation and can be accessed over the +raw+ attribute.
|
10
|
-
#
|
11
|
-
class SimpleItem
|
12
|
-
|
13
|
-
attr_reader :raw
|
14
|
-
|
15
|
-
def initialize(hash)
|
16
|
-
@raw = Hashie::Mash.new(hash)
|
17
|
-
end
|
18
|
-
|
19
|
-
def asin
|
20
|
-
@raw.ASIN
|
21
|
-
end
|
22
|
-
|
23
|
-
def title
|
24
|
-
@raw.ItemAttributes!.Title
|
25
|
-
end
|
26
|
-
|
27
|
-
def amount
|
28
|
-
@raw.ItemAttributes!.ListPrice!.Amount.to_i
|
29
|
-
end
|
30
|
-
|
31
|
-
def details_url
|
32
|
-
@raw.DetailPageURL
|
33
|
-
end
|
34
|
-
|
35
|
-
def review
|
36
|
-
@raw.EditorialReviews!.EditorialReview!.Content
|
37
|
-
end
|
38
|
-
|
39
|
-
def image_url
|
40
|
-
@raw.LargeImage!.URL
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
data/lib/asin/simple_node.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'hashie'
|
2
|
-
|
3
|
-
module ASIN
|
4
|
-
|
5
|
-
# =SimpleNode
|
6
|
-
#
|
7
|
-
# The +SimpleNode+ class is a wrapper for the Amazon XML-REST-Response.
|
8
|
-
#
|
9
|
-
# A Hashie::Mash is used for the internal data representation and can be accessed over the +raw+ attribute.
|
10
|
-
#
|
11
|
-
class SimpleNode
|
12
|
-
|
13
|
-
attr_reader :raw
|
14
|
-
|
15
|
-
def initialize(hash)
|
16
|
-
@raw = Hashie::Mash.new(hash)
|
17
|
-
end
|
18
|
-
|
19
|
-
def name
|
20
|
-
@raw.Name
|
21
|
-
end
|
22
|
-
|
23
|
-
def node_id
|
24
|
-
@raw.BrowseNodeId
|
25
|
-
end
|
26
|
-
|
27
|
-
def children
|
28
|
-
return [] unless @raw.Children
|
29
|
-
@raw.Children.BrowseNode.is_a?(Array) ? @raw.Children.BrowseNode : [@raw.Children.BrowseNode]
|
30
|
-
end
|
31
|
-
|
32
|
-
def ancestors
|
33
|
-
return [] unless @raw.Ancestors
|
34
|
-
@raw.Ancestors.BrowseNode.is_a?(Array) ? @raw.Ancestors.BrowseNode : [@raw.Ancestors.BrowseNode]
|
35
|
-
end
|
36
|
-
|
37
|
-
def top_item_set
|
38
|
-
return [] unless @raw.TopItemSet
|
39
|
-
@raw.TopItemSet.TopItem.is_a?(Array) ? @raw.TopItemSet.TopItem : [@raw.TopItemSet.TopItem]
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|