asin 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1 @@
1
+ script: "rake travis_ci"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- asin (0.2.0)
4
+ asin (0.3.0)
5
5
  crack (~> 0.1.8)
6
6
  hashie (~> 1.0.0)
7
7
  httpi (~> 0.7.9)
@@ -36,9 +36,6 @@ PLATFORMS
36
36
 
37
37
  DEPENDENCIES
38
38
  asin!
39
- crack (~> 0.1.8)
40
39
  fuubar (~> 0.0.3)
41
- hashie (~> 1.0.0)
42
40
  httpclient (~> 2.1.6.1)
43
- httpi (~> 0.7.9)
44
41
  rspec (~> 2.4.0)
data/README.rdoc CHANGED
@@ -37,8 +37,13 @@ The old configuration syntax is still valid:
37
37
  item.title
38
38
  => Learn Objective-C on the Mac (Learn Series)
39
39
 
40
- # search for any kind of stuff on amazon
41
- items = search 'Learn Objective-C'
40
+ # search for any kind of stuff on amazon with keywords
41
+ items = search_keywords 'Learn', 'Objective-C'
42
+ items.first.title
43
+ => "Learn Objective-C on the Mac (Learn Series)"
44
+
45
+ # search for any kind of stuff on amazon with custom parameters
46
+ search :Keywords => 'Learn Objective-C', :SearchIndex => :Books
42
47
  items.first.title
43
48
  => "Learn Objective-C on the Mac (Learn Series)"
44
49
 
data/lib/asin.rb CHANGED
@@ -24,7 +24,7 @@ require 'asin/configuration'
24
24
  #
25
25
  # The registration process will give you a +secret-key+ and an +access-key+ (AWSAccessKeyId).
26
26
  #
27
- # Both are needed to use ASIN:
27
+ # Both are needed to use ASIN (see Configuration for more details):
28
28
  #
29
29
  # configure :secret => 'your-secret', :key => 'your-key'
30
30
  #
@@ -103,9 +103,9 @@ module ASIN
103
103
 
104
104
  # Performs an +ItemSearch+ REST call against the Amazon API.
105
105
  #
106
- # Expects a search-string which can be an ASIN (Amazon Standard Identification Number) and returns a list of +Items+:
106
+ # Expects a search-string which can be an arbitrary array of strings (ASINs f.e.) and returns a list of +Items+:
107
107
  #
108
- # items = search 'Learn Objective-C'
108
+ # items = search_keywords 'Learn', 'Objective-C'
109
109
  # items.first.title
110
110
  # => "Learn Objective-C on the Mac (Learn Series)"
111
111
  #
@@ -113,15 +113,35 @@ module ASIN
113
113
  #
114
114
  # Additional parameters for the API call like this:
115
115
  #
116
- # search(asin, :SearchIndex => :Music)
116
+ # search_keywords('nirvana', 'never mind', :SearchIndex => :Music)
117
117
  #
118
118
  # Have a look at the different search index values on the Amazon-Documentation[http://docs.amazonwebservices.com/AWSEcommerceService/4-0/]
119
119
  #
120
- def search(search_string, params={:SearchIndex => :Books})
121
- response = call(params.merge(:Operation => :ItemSearch, :Keywords => search_string))
122
- response['ItemSearchResponse']['Items']['Item'].map {|item| Item.new(item)}
120
+ def search_keywords(*keywords)
121
+ params = keywords.last.is_a?(Hash) ? keywords.pop : {:SearchIndex => :Books}
122
+ response = call(params.merge(:Operation => :ItemSearch, :Keywords => keywords.join(' ')))
123
+ (response['ItemSearchResponse']['Items']['Item'] || []).map {|item| Item.new(item)}
123
124
  end
124
-
125
+
126
+ # Performs an +ItemSearch+ REST call against the Amazon API.
127
+ #
128
+ # Expects a Hash of search params where and returns a list of +Items+:
129
+ #
130
+ # items = search :SearchIndex => :Music
131
+ #
132
+ # ==== Options:
133
+ #
134
+ # Additional parameters for the API call like this:
135
+ #
136
+ # search(:Keywords => 'nirvana', :SearchIndex => :Music)
137
+ #
138
+ # Have a look at the different search index values on the Amazon-Documentation[http://docs.amazonwebservices.com/AWSEcommerceService/4-0/]
139
+ #
140
+ def search(params={:SearchIndex => :Books})
141
+ response = call(params.merge(:Operation => :ItemSearch))
142
+ (response['ItemSearchResponse']['Items']['Item'] || []).map {|item| Item.new(item)}
143
+ end
144
+
125
145
  private
126
146
 
127
147
  def credentials_valid?
data/lib/asin/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ASIN
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/rakefile.rb CHANGED
@@ -32,4 +32,11 @@ task :test do
32
32
  t.verbose = true
33
33
  end
34
34
  end
35
- task :default=>:test
35
+ task :default=>:test
36
+
37
+ desc "execute build on travis-ci"
38
+ task :travis_ci do
39
+ puts "WE LOOOOOOOOOOOOVE"
40
+ Rake::Task['spec'].invoke
41
+ puts "TRAVIS CI"
42
+ end
data/spec/asin_spec.rb CHANGED
@@ -1,6 +1,3 @@
1
- ANY_ASIN = '1430218150'
2
- ANY_SEARCH = 'Learn Objective-C'
3
-
4
1
  describe ASIN do
5
2
  before do
6
3
  @helper = ASIN.client
@@ -13,7 +10,7 @@ describe ASIN do
13
10
 
14
11
  context "configuration" do
15
12
  it "should fail without secret and key" do
16
- lambda { @helper.lookup ANY_ASIN }.should raise_error(RuntimeError)
13
+ lambda { @helper.lookup 'bla' }.should raise_error(RuntimeError)
17
14
  end
18
15
 
19
16
  it "should fail with wrong configuration key" do
@@ -43,16 +40,35 @@ describe ASIN do
43
40
  end
44
41
 
45
42
  it "should lookup a book" do
46
- item = @helper.lookup(ANY_ASIN)
43
+ item = @helper.lookup('1430218150')
47
44
  item.title.should =~ /Learn Objective/
48
45
  end
49
46
 
50
- it "should search a book with fulltext" do
51
- items = @helper.search(ANY_SEARCH)
47
+ it "should search_keywords a book with fulltext" do
48
+ items = @helper.search_keywords 'Learn', 'Objective-C'
52
49
  items.should have(10).things
53
50
 
54
51
  items.first.title.should =~ /Learn Objective/
55
52
  end
53
+
54
+ it "should search_keywords never mind music" do
55
+ items = @helper.search_keywords 'nirvana', 'never mind', :SearchIndex => :Music
56
+ items.should have(10).things
57
+
58
+ items.first.title.should =~ /Nevermind/
59
+ end
60
+
61
+ it "should search music" do
62
+ items = @helper.search :SearchIndex => :Music
63
+ items.should have(0).things
64
+ end
65
+
66
+ it "should search never mind music" do
67
+ items = @helper.search :Keywords => 'nirvana', :SearchIndex => :Music
68
+ items.should have(10).things
69
+
70
+ items.first.title.should =~ /Nevermind/
71
+ end
56
72
  end
57
73
  end
58
74
 
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asin
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 2
8
- - 0
9
- version: 0.2.0
4
+ prerelease:
5
+ version: 0.3.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - "Peter Schr\xC3\xB6der"
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-01-30 00:00:00 +01:00
13
+ date: 2011-03-08 00:00:00 +01:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -25,10 +21,6 @@ dependencies:
25
21
  requirements:
26
22
  - - ~>
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- - 1
31
- - 8
32
24
  version: 0.1.8
33
25
  type: :runtime
34
26
  version_requirements: *id001
@@ -40,10 +32,6 @@ dependencies:
40
32
  requirements:
41
33
  - - ~>
42
34
  - !ruby/object:Gem::Version
43
- segments:
44
- - 1
45
- - 0
46
- - 0
47
35
  version: 1.0.0
48
36
  type: :runtime
49
37
  version_requirements: *id002
@@ -55,10 +43,6 @@ dependencies:
55
43
  requirements:
56
44
  - - ~>
57
45
  - !ruby/object:Gem::Version
58
- segments:
59
- - 0
60
- - 7
61
- - 9
62
46
  version: 0.7.9
63
47
  type: :runtime
64
48
  version_requirements: *id003
@@ -70,11 +54,6 @@ dependencies:
70
54
  requirements:
71
55
  - - ~>
72
56
  - !ruby/object:Gem::Version
73
- segments:
74
- - 2
75
- - 1
76
- - 6
77
- - 1
78
57
  version: 2.1.6.1
79
58
  type: :development
80
59
  version_requirements: *id004
@@ -86,10 +65,6 @@ dependencies:
86
65
  requirements:
87
66
  - - ~>
88
67
  - !ruby/object:Gem::Version
89
- segments:
90
- - 2
91
- - 4
92
- - 0
93
68
  version: 2.4.0
94
69
  type: :development
95
70
  version_requirements: *id005
@@ -101,10 +76,6 @@ dependencies:
101
76
  requirements:
102
77
  - - ~>
103
78
  - !ruby/object:Gem::Version
104
- segments:
105
- - 0
106
- - 0
107
- - 3
108
79
  version: 0.0.3
109
80
  type: :development
110
81
  version_requirements: *id006
@@ -121,6 +92,7 @@ files:
121
92
  - .document
122
93
  - .gitignore
123
94
  - .rvmrc
95
+ - .travis.yml
124
96
  - Gemfile
125
97
  - Gemfile.lock
126
98
  - README.rdoc
@@ -146,21 +118,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
118
  requirements:
147
119
  - - ">="
148
120
  - !ruby/object:Gem::Version
149
- segments:
150
- - 0
151
121
  version: "0"
152
122
  required_rubygems_version: !ruby/object:Gem::Requirement
153
123
  none: false
154
124
  requirements:
155
125
  - - ">="
156
126
  - !ruby/object:Gem::Version
157
- segments:
158
- - 0
159
127
  version: "0"
160
128
  requirements: []
161
129
 
162
130
  rubyforge_project: asin
163
- rubygems_version: 1.3.7
131
+ rubygems_version: 1.5.2
164
132
  signing_key:
165
133
  specification_version: 3
166
134
  summary: Simple interface to Amazon Item lookup.