Skip to content
Browse files

Merge branch 'feature/open_search' into develop

  • Loading branch information...
2 parents 4803beb + a661f3f commit 51b506ddaf8711fc1405190cac674bbf4d255e58 @phoet phoet committed Mar 8, 2011
Showing with 69 additions and 23 deletions.
  1. +1 −0 .travis.yml
  2. +1 −4 Gemfile.lock
  3. +7 −2 README.rdoc
  4. +28 −8 lib/asin.rb
  5. +1 −1 lib/asin/version.rb
  6. +8 −1 rakefile.rb
  7. +23 −7 spec/asin_spec.rb
View
1 .travis.yml
@@ -0,0 +1 @@
+script: "rake travis_ci"
View
5 Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- asin (0.2.0)
+ asin (0.3.0)
crack (~> 0.1.8)
hashie (~> 1.0.0)
httpi (~> 0.7.9)
@@ -36,9 +36,6 @@ PLATFORMS
DEPENDENCIES
asin!
- crack (~> 0.1.8)
fuubar (~> 0.0.3)
- hashie (~> 1.0.0)
httpclient (~> 2.1.6.1)
- httpi (~> 0.7.9)
rspec (~> 2.4.0)
View
9 README.rdoc
@@ -37,8 +37,13 @@ The old configuration syntax is still valid:
item.title
=> Learn Objective-C on the Mac (Learn Series)
- # search for any kind of stuff on amazon
- items = search 'Learn Objective-C'
+ # search for any kind of stuff on amazon with keywords
+ items = search_keywords 'Learn', 'Objective-C'
+ items.first.title
+ => "Learn Objective-C on the Mac (Learn Series)"
+
+ # search for any kind of stuff on amazon with custom parameters
+ search :Keywords => 'Learn Objective-C', :SearchIndex => :Books
items.first.title
=> "Learn Objective-C on the Mac (Learn Series)"
View
36 lib/asin.rb
@@ -24,7 +24,7 @@
#
# The registration process will give you a +secret-key+ and an +access-key+ (AWSAccessKeyId).
#
-# Both are needed to use ASIN:
+# Both are needed to use ASIN (see Configuration for more details):
#
# configure :secret => 'your-secret', :key => 'your-key'
#
@@ -103,25 +103,45 @@ def lookup(asin, params={})
# Performs an +ItemSearch+ REST call against the Amazon API.
#
- # Expects a search-string which can be an ASIN (Amazon Standard Identification Number) and returns a list of +Items+:
+ # Expects a search-string which can be an arbitrary array of strings (ASINs f.e.) and returns a list of +Items+:
#
- # items = search 'Learn Objective-C'
+ # items = search_keywords 'Learn', 'Objective-C'
# items.first.title
# => "Learn Objective-C on the Mac (Learn Series)"
#
# ==== Options:
#
# Additional parameters for the API call like this:
#
- # search(asin, :SearchIndex => :Music)
+ # search_keywords('nirvana', 'never mind', :SearchIndex => :Music)
#
# Have a look at the different search index values on the Amazon-Documentation[http://docs.amazonwebservices.com/AWSEcommerceService/4-0/]
#
- def search(search_string, params={:SearchIndex => :Books})
- response = call(params.merge(:Operation => :ItemSearch, :Keywords => search_string))
- response['ItemSearchResponse']['Items']['Item'].map {|item| Item.new(item)}
+ def search_keywords(*keywords)
+ params = keywords.last.is_a?(Hash) ? keywords.pop : {:SearchIndex => :Books}
+ response = call(params.merge(:Operation => :ItemSearch, :Keywords => keywords.join(' ')))
+ (response['ItemSearchResponse']['Items']['Item'] || []).map {|item| Item.new(item)}
end
-
+
+ # Performs an +ItemSearch+ REST call against the Amazon API.
+ #
+ # Expects a Hash of search params where and returns a list of +Items+:
+ #
+ # items = search :SearchIndex => :Music
+ #
+ # ==== Options:
+ #
+ # Additional parameters for the API call like this:
+ #
+ # search(:Keywords => 'nirvana', :SearchIndex => :Music)
+ #
+ # Have a look at the different search index values on the Amazon-Documentation[http://docs.amazonwebservices.com/AWSEcommerceService/4-0/]
+ #
+ def search(params={:SearchIndex => :Books})
+ response = call(params.merge(:Operation => :ItemSearch))
+ (response['ItemSearchResponse']['Items']['Item'] || []).map {|item| Item.new(item)}
+ end
+
private
def credentials_valid?
View
2 lib/asin/version.rb
@@ -1,3 +1,3 @@
module ASIN
- VERSION = "0.2.0"
+ VERSION = "0.3.0"
end
View
9 rakefile.rb
@@ -32,4 +32,11 @@
t.verbose = true
end
end
-task :default=>:test
+task :default=>:test
+
+desc "execute build on travis-ci"
+task :travis_ci do
+ puts "WE LOOOOOOOOOOOOVE"
+ Rake::Task['spec'].invoke
+ puts "TRAVIS CI"
+end
View
30 spec/asin_spec.rb
@@ -1,6 +1,3 @@
-ANY_ASIN = '1430218150'
-ANY_SEARCH = 'Learn Objective-C'
-
describe ASIN do
before do
@helper = ASIN.client
@@ -13,7 +10,7 @@
context "configuration" do
it "should fail without secret and key" do
- lambda { @helper.lookup ANY_ASIN }.should raise_error(RuntimeError)
+ lambda { @helper.lookup 'bla' }.should raise_error(RuntimeError)
end
it "should fail with wrong configuration key" do
@@ -43,16 +40,35 @@
end
it "should lookup a book" do
- item = @helper.lookup(ANY_ASIN)
+ item = @helper.lookup('1430218150')
item.title.should =~ /Learn Objective/
end
- it "should search a book with fulltext" do
- items = @helper.search(ANY_SEARCH)
+ it "should search_keywords a book with fulltext" do
+ items = @helper.search_keywords 'Learn', 'Objective-C'
items.should have(10).things
items.first.title.should =~ /Learn Objective/
end
+
+ it "should search_keywords never mind music" do
+ items = @helper.search_keywords 'nirvana', 'never mind', :SearchIndex => :Music
+ items.should have(10).things
+
+ items.first.title.should =~ /Nevermind/
+ end
+
+ it "should search music" do
+ items = @helper.search :SearchIndex => :Music
+ items.should have(0).things
+ end
+
+ it "should search never mind music" do
+ items = @helper.search :Keywords => 'nirvana', :SearchIndex => :Music
+ items.should have(10).things
+
+ items.first.title.should =~ /Nevermind/
+ end
end
end

0 comments on commit 51b506d

Please sign in to comment.
Something went wrong with that request. Please try again.