sucker 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Sucker
2
2
  ======
3
3
 
4
- Sucker is a thin Ruby wrapper to the [Amazon Product Advertising API](https://affiliate-program.amazon.co.uk/gp/advertising/api/detail/main.html). It runs on Curb and Crack and supports __everything__ in the API.
4
+ Sucker is a thin Ruby wrapper to the [Amazon Product Advertising API](https://affiliate-program.amazon.co.uk/gp/advertising/api/detail/main.html). It runs on Curb and XmlSimple and supports __everything__ in the API.
5
5
 
6
6
  ![Sucker](http://upload.wikimedia.org/wikipedia/en/7/71/Vacuum_cleaner_1910.JPG)
7
7
 
@@ -33,7 +33,7 @@ Hit Amazon and do something with the response.
33
33
  p response.time
34
34
  p response.body
35
35
 
36
- response.to_h["ItemLookupResponse"]["Items"]["Item"].each { ... }
36
+ response.to_h["Items"]["Item"].each { ... }
37
37
 
38
38
  Hit Amazon again.
39
39
 
@@ -41,25 +41,27 @@ Hit Amazon again.
41
41
  "ItemId" => 10.more.asins }
42
42
  response = worker.get
43
43
 
44
- For more examples, check the integration specs.
44
+ Check the integration specs for more examples.
45
45
 
46
46
  Testing
47
47
  -------
48
48
 
49
49
  To fake web requests, I do the following:
50
50
 
51
- In a file such as `spec/support/sucker.rb`, I prep things:
51
+ In a file such as `spec/support/sucker.rb`, I prep:
52
52
 
53
53
  require "sucker/stub"
54
54
  Sucker.fixtures_path = File.dirname(__FILE__) + "/../fixtures"
55
55
 
56
- Then, in the spec, I set up a worker and stub the worker:
56
+ In the spec, I set up a worker and then stub it:
57
57
 
58
58
  Sucker.stub(@worker)
59
59
 
60
60
  The first time you run the spec, the worker will perform the actual web request and cache the response. Subsequent requests are then mocked with the cached response.
61
61
 
62
- Specs
62
+ Notes
63
63
  -----
64
64
 
65
- The unit specs should run out of the box after you `bundle install`, but the integration specs require you to create [an amazon.yml file with valid credentials](http://github.com/papercavalier/sucker/blob/master/spec/support/amazon.yml.example) in the spec/support folder.
65
+ * The unit specs should run out of the box after you `bundle install`, but the integration specs require you to create [an amazon.yml file with valid credentials](http://github.com/papercavalier/sucker/blob/master/spec/support/amazon.yml.example) in `spec/support`.
66
+
67
+ * Version 0.5.0 replaces Crack with XmlSimple, which results in a slightly different hash output. Fix up your code accordingly.
data/lib/sucker.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require "cgi"
2
- require "crack/xml"
3
2
  require "curb"
4
3
  require "sucker/request"
5
4
  require "sucker/response"
5
+ require "xmlsimple"
6
6
 
7
7
  # = Sucker
8
8
  # Sucker is a thin Ruby wrapper to the Amazon Product Advertising API.
@@ -64,7 +64,7 @@ module Sucker
64
64
  merge(timestamp).
65
65
  sort.
66
66
  collect do |k, v|
67
- "#{CGI.escape(k)}=" + CGI.escape(v.is_a?(Array) ? v.join(",") : v)
67
+ "#{k}=" + CGI.escape(v.is_a?(Array) ? v.join(",") : v)
68
68
  end.
69
69
  join("&")
70
70
  end
@@ -11,7 +11,7 @@ module Sucker
11
11
  end
12
12
 
13
13
  def to_h
14
- Crack::XML.parse(body)
14
+ XmlSimple.xml_in(body, { "ForceArray" => false })
15
15
  end
16
16
  end
17
17
  end
@@ -23,7 +23,7 @@ module Sucker
23
23
  context "single item" do
24
24
  before do
25
25
  @worker << { "ItemId" => "0816614024" }
26
- @item = @worker.get.to_h["ItemLookupResponse"]["Items"]["Item"]
26
+ @item = @worker.get.to_h["Items"]["Item"]
27
27
  end
28
28
 
29
29
  it "returns an item" do
@@ -43,7 +43,7 @@ module Sucker
43
43
  context "multiple items" do
44
44
  before do
45
45
  @worker << { "ItemId" => ["0816614024", "0143105825"] }
46
- @items = @worker.get.to_h["ItemLookupResponse"]["Items"]["Item"]
46
+ @items = @worker.get.to_h["Items"]["Item"]
47
47
  end
48
48
 
49
49
  it "returns two items" do
@@ -18,10 +18,10 @@ module Sucker
18
18
  context "single item" do
19
19
  before do
20
20
  @worker << { "ItemId" => "0816614024" }
21
- @item = @worker.get.to_h["ItemLookupResponse"]["Items"]["Item"]
21
+ @item = @worker.get.to_h["Items"]["Item"]
22
22
  end
23
23
 
24
- it "returns an item" do
24
+ it "returns an array of items" do
25
25
  @item.should be_an_instance_of Hash
26
26
  end
27
27
  end
@@ -16,7 +16,7 @@ module Sucker
16
16
 
17
17
  Sucker.stub(@worker)
18
18
 
19
- @listings = @worker.get.to_h["SellerListingSearchResponse"]["SellerListings"]
19
+ @listings = @worker.get.to_h["SellerListings"]
20
20
  end
21
21
 
22
22
  it "returns page count" do
@@ -28,7 +28,7 @@ module Sucker
28
28
 
29
29
  Sucker.stub(@worker)
30
30
 
31
- @items = @worker.get.to_h["ItemLookupResponse"]["Items"].map { |items| items["Item"] }.flatten!
31
+ @items = @worker.get.to_h["Items"].map { |items| items["Item"] }.flatten!
32
32
  end
33
33
 
34
34
  it "returns 20 items" do
@@ -5,7 +5,7 @@ module Sucker
5
5
  before do
6
6
  curl = Sucker.new.curl
7
7
  curl.stub(:get).and_return(nil)
8
- curl.stub!(:body_str).and_return("foo")
8
+ curl.stub!(:body_str).and_return("<foo bar='baz' />")
9
9
  curl.stub!(:response_code).and_return(200)
10
10
  curl.stub!(:total_time).and_return(1.0)
11
11
  @response = Response.new(curl)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sucker
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 0.4.0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Hakan Ensari
@@ -16,24 +16,24 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-07-30 00:00:00 +01:00
19
+ date: 2010-07-31 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  prerelease: false
24
24
  type: :runtime
25
- name: crack
25
+ name: xml-simple
26
26
  version_requirements: &id001 !ruby/object:Gem::Requirement
27
27
  none: false
28
28
  requirements:
29
- - - "="
29
+ - - ">="
30
30
  - !ruby/object:Gem::Version
31
- hash: 11
31
+ hash: 15
32
32
  segments:
33
- - 0
34
33
  - 1
35
- - 8
36
- version: 0.1.8
34
+ - 0
35
+ - 12
36
+ version: 1.0.12
37
37
  requirement: *id001
38
38
  - !ruby/object:Gem::Dependency
39
39
  prerelease: false
@@ -42,7 +42,7 @@ dependencies:
42
42
  version_requirements: &id002 !ruby/object:Gem::Requirement
43
43
  none: false
44
44
  requirements:
45
- - - "="
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  hash: 105
48
48
  segments: