sucker 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,45 @@
1
1
  h1. Sucker
2
2
 
3
- Sucker is a thin Ruby wrapper to the Amazon Product Advertising API. It's built on Curb, which is great for querying Amazon on multiple network ports.
3
+ Sucker is a thin Ruby wrapper to the Amazon Product Advertising API. It's built on Curb and Crack.
4
4
 
5
- @sucker = Sucker.new(
6
- :locale => "us",
7
- :key => "key",
8
- :secret => "secret")
5
+ I wrote this because ruby_aaws feels somewhat bloated and we are too lazy to conjure a straightforward way to run the latter through multiple network interfaces.
9
6
 
10
- @sucker.curl { |curl| curl.interface = "eth2" }
7
+ h2. Examples
11
8
 
12
- @sucker.parameters.merge!({
13
- "Operation" => "ItemLookup",
14
- "IdType" => "ASIN",
15
- "ItemId" => "0816614024" })
16
- @sucker.fetch
17
- p @sucker.to_h # Now, do something with that hash!
9
+ Woo a worker.
18
10
 
19
- !http://upload.wikimedia.org/wikipedia/commons/a/af/Vacuum_cleaner.jpg!
11
+ bc. @worker = Sucker.new(
12
+ :locale => "us",
13
+ :key => "API KEY",
14
+ :secret => "API SECRET")
15
+
16
+ Fiddle with curl.
17
+
18
+ bc. @worker.curl { |c| c.interface = "eth1" }
19
+
20
+ Set up a request.
21
+
22
+ bc. @worker << {
23
+ "Operation" => "ItemLookup",
24
+ "IdType" => "ASIN",
25
+ "ItemId" => ["0816614024", "0143105825"] }
26
+
27
+ Hit the Amazon API.
28
+
29
+ bc. @worker.fetch
30
+
31
+ Do something with the response.
32
+
33
+ bc. pp @worker.to_h
34
+
35
+ Hit the Amazon API again.
36
+
37
+ bc. @worker << {
38
+ "ItemId" => ["0393329259", "0393317757"] }
39
+ @worker.fetch
40
+
41
+ Check the integration tests in the spec folder for some more examples.
42
+
43
+ h2. Tangential Endnote
44
+
45
+ !http://upload.wikimedia.org/wikipedia/en/7/71/Vacuum_cleaner_1910.JPG!
@@ -29,6 +29,11 @@ module Sucker
29
29
  args.each { |k, v| send("#{k}=", v) }
30
30
  end
31
31
 
32
+ # A helper method that merges a hash into the parameters
33
+ def <<(hash)
34
+ self.parameters.merge!(hash)
35
+ end
36
+
32
37
  # A reusable, configurable cURL object
33
38
  def curl
34
39
  @curl ||= Curl::Easy.new
@@ -99,7 +104,6 @@ module Sucker
99
104
  :query => sign_query)
100
105
  end
101
106
 
102
- # Timestamps the parameters
103
107
  def timestamp_parameters
104
108
  self.parameters["Timestamp"] = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
105
109
  end
@@ -10,15 +10,14 @@ module Sucker
10
10
 
11
11
  # @sucker.curl { |curl| curl.verbose = true }
12
12
 
13
- @sucker.parameters.merge!({
14
- "Operation" => "ItemLookup",
15
- "IdType" => "ASIN"})
13
+ @sucker << {
14
+ "Operation" => "ItemLookup",
15
+ "IdType" => "ASIN" }
16
16
  end
17
17
 
18
18
  context "single item" do
19
19
  before do
20
- @sucker.parameters.merge!({
21
- "ItemId" => "0816614024" })
20
+ @sucker << { "ItemId" => "0816614024" }
22
21
  @sucker.fetch
23
22
  @item = @sucker.to_h["ItemLookupResponse"]["Items"]["Item"]
24
23
  end
@@ -38,8 +37,7 @@ module Sucker
38
37
 
39
38
  context "multiple items" do
40
39
  before do
41
- @sucker.parameters.merge!({
42
- "ItemId" => ["0816614024", "0143105825"] })
40
+ @sucker << { "ItemId" => ["0816614024", "0143105825"] }
43
41
  @sucker.fetch
44
42
  @items = @sucker.to_h["ItemLookupResponse"]["Items"]["Item"]
45
43
  end
@@ -10,9 +10,9 @@ module Sucker
10
10
 
11
11
  # @sucker.curl { |curl| curl.verbose = true }
12
12
 
13
- @sucker.parameters.merge!({
14
- "Operation" => "SellerListingSearch",
15
- "SellerId" => "A31N271NVIORU3"})
13
+ @sucker << {
14
+ "Operation" => "SellerListingSearch",
15
+ "SellerId" => "A31N271NVIORU3" }
16
16
  @sucker.fetch
17
17
  @listings = @sucker.to_h["SellerListingSearchResponse"]["SellerListings"]
18
18
  end
@@ -1,6 +1,5 @@
1
1
  require "rubygems"
2
- require "bundler"
3
- Bundler.require(:default)
2
+ require "bundler/setup"
4
3
 
5
4
  require File.expand_path("../../lib/sucker", __FILE__)
6
5
 
@@ -16,6 +16,13 @@ module Sucker
16
16
  end
17
17
  end
18
18
 
19
+ context "#<<" do
20
+ it "merges a hash into the paramters" do
21
+ @sucker << { "foo" => "bar" }
22
+ @sucker.parameters["foo"].should eql "bar"
23
+ end
24
+ end
25
+
19
26
  context "#curl" do
20
27
  it "returns a cURL object" do
21
28
  @sucker.curl.should be_an_instance_of Curl::Easy
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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Hakan Ensari
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-07-21 00:00:00 +01:00
19
+ date: 2010-07-22 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency