sucker 1.0.0.beta.3 → 1.0.0.beta.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ Version 1.0.0.beta4
2
+ ========
3
+
4
+ Release date: 2010-10-28
5
+
6
+ Added
7
+ -----
8
+
9
+ * Sucker::Request#get! raises an error if response is not valid.
10
+
11
+ Version 1.0.0.beta3
12
+ ========
13
+
14
+ Release date: 2010-10-25
15
+
16
+ Added
17
+ -----
18
+
19
+ * Sucker::Response#find yields to a block if given one.
20
+
21
+ Deprecated
22
+ ----------
23
+
24
+ * Renamed #node to #find
data/README.md CHANGED
@@ -58,7 +58,7 @@ Stubbing
58
58
 
59
59
  Use [VCR](http://github.com/myronmarston/vcr) to stub your requests.
60
60
 
61
- Caveat: Match URIs on host only and create a new cassette for each stubbed query. [This is how I do it](http://github.com/papercavalier/sucker/blob/master/spec/support/vcr.rb).
61
+ Caveat: Match URIs on host only and create a new cassette for each query. [This is how I do it](http://github.com/papercavalier/sucker/blob/master/spec/support/vcr.rb).
62
62
 
63
63
  Compatibility
64
64
  -------------
data/lib/sucker.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require "active_support/xml_mini/nokogiri"
2
2
  require "curb"
3
- require "digest/md5"
4
3
  require "sucker/request"
5
4
  require "sucker/response"
6
5
  require "uri"
@@ -36,7 +36,7 @@ module Sucker #:nodoc
36
36
  args.each { |k, v| send("#{k}=", v) }
37
37
  end
38
38
 
39
- # A helper method that merges a hash into existing parameters
39
+ # Merges a hash into existing parameters
40
40
  #
41
41
  # worker = Sucker.new
42
42
  # worker << {
@@ -81,6 +81,17 @@ module Sucker #:nodoc
81
81
  Response.new(curl)
82
82
  end
83
83
 
84
+ # Similar to get but raises an error if response is not valid
85
+ def get!
86
+ response = get
87
+
88
+ unless response.valid?
89
+ raise ResponseError, response.inspect
90
+ end
91
+
92
+ response
93
+ end
94
+
84
95
  # Sets the AWS Access Key ID
85
96
  #
86
97
  # worker = Sucker.new
@@ -83,4 +83,6 @@ module Sucker #:nodoc
83
83
  end
84
84
  end
85
85
  end
86
+
87
+ class ResponseError < StandardError; end
86
88
  end
@@ -1,3 +1,3 @@
1
1
  module Sucker #:nodoc
2
- VERSION = "1.0.0.beta.3"
2
+ VERSION = "1.0.0.beta.4"
3
3
  end
@@ -0,0 +1,47 @@
1
+ require "spec_helper"
2
+
3
+ module Sucker
4
+ describe "Kindle" do
5
+ context "Book index" do
6
+ use_vcr_cassette "integration/kindle", :record => :new_episodes
7
+
8
+ let(:items) do
9
+ worker = Sucker.new(
10
+ :locale => "us",
11
+ :key => amazon["key"],
12
+ :secret => amazon["secret"])
13
+ worker << {
14
+ "Operation" => "ItemSearch",
15
+ "SearchIndex" => "Books",
16
+ "Power" => "deleuze binding:kindle",
17
+ "ResponseGroup" => "ItemAttributes" }
18
+ worker.get.find("Item")
19
+ end
20
+
21
+ it "finds Kindle books" do
22
+ items.first["ItemAttributes"]["Title"].should_not be_nil
23
+ end
24
+ end
25
+
26
+ context "Kindle store index" do
27
+ use_vcr_cassette "integration/kindle_2", :record => :new_episodes
28
+
29
+ let(:items) do
30
+ worker = Sucker.new(
31
+ :locale => "us",
32
+ :key => amazon["key"],
33
+ :secret => amazon["secret"])
34
+ worker << {
35
+ "Operation" => "ItemSearch",
36
+ "SearchIndex" => "KindleStore",
37
+ "Keywords" => "deleuze",
38
+ "ResponseGroup" => "ItemAttributes" }
39
+ worker.get.find("Item")
40
+ end
41
+
42
+ it "finds Kindle books" do
43
+ items.first["ItemAttributes"]["Title"].should_not be_nil
44
+ end
45
+ end
46
+ end
47
+ end
@@ -58,8 +58,18 @@ module Sucker
58
58
  end
59
59
 
60
60
  context "#get" do
61
- it "returns a Response object" do
62
- worker.get.class.ancestors.should include Sucker::Response
61
+ it "returns a response" do
62
+ worker.get.class.ancestors.should include Response
63
+ end
64
+ end
65
+
66
+ context "#get!" do
67
+ it "raises if response is not valid" do
68
+ worker << {
69
+ "Operation" => "ItemLookup",
70
+ "IdType" => "ASIN",
71
+ "ItemId" => "0816614024" }
72
+ lambda { worker.get! }.should raise_error ResponseError
63
73
  end
64
74
  end
65
75
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sucker
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196357
4
+ hash: 62196363
5
5
  prerelease: true
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 0
10
10
  - beta
11
- - 3
12
- version: 1.0.0.beta.3
11
+ - 4
12
+ version: 1.0.0.beta.4
13
13
  platform: ruby
14
14
  authors:
15
15
  - Hakan Ensari
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2010-10-25 00:00:00 +01:00
21
+ date: 2010-10-28 00:00:00 +01:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -197,7 +197,7 @@ files:
197
197
  - lib/sucker.rb
198
198
  - LICENSE
199
199
  - README.md
200
- - History.md
200
+ - CHANGELOG.md
201
201
  - spec/fixtures/asins.txt
202
202
  - spec/integration/alternate_versions_spec.rb
203
203
  - spec/integration/errors_spec.rb
@@ -207,6 +207,7 @@ files:
207
207
  - spec/integration/item_search_spec.rb
208
208
  - spec/integration/japan_spec.rb
209
209
  - spec/integration/keyword_search_spec.rb
210
+ - spec/integration/kindle_spec.rb
210
211
  - spec/integration/multiple_locales_spec.rb
211
212
  - spec/integration/power_search_spec.rb
212
213
  - spec/integration/related_items_spec.rb
@@ -266,6 +267,7 @@ test_files:
266
267
  - spec/integration/item_search_spec.rb
267
268
  - spec/integration/japan_spec.rb
268
269
  - spec/integration/keyword_search_spec.rb
270
+ - spec/integration/kindle_spec.rb
269
271
  - spec/integration/multiple_locales_spec.rb
270
272
  - spec/integration/power_search_spec.rb
271
273
  - spec/integration/related_items_spec.rb
data/History.md DELETED
@@ -1,14 +0,0 @@
1
- Version 1.0.0.beta3
2
- ========
3
-
4
- Release date: 2010-10-25
5
-
6
- Added
7
- -----
8
-
9
- * #find yields to a block if given one
10
-
11
- Deprecated
12
- ----------
13
-
14
- * Renamed #node to #find