sucker 1.2.0 → 1.3.0.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +1 -1
- data/README.md +45 -20
- data/lib/sucker/parameters.rb +11 -7
- data/lib/sucker/parameters.rbc +723 -0
- data/lib/sucker/request.rb +52 -154
- data/lib/sucker/request.rbc +2719 -0
- data/lib/sucker/response.rb +14 -36
- data/lib/sucker/response.rbc +1307 -0
- data/lib/sucker/version.rb +3 -1
- data/lib/sucker/version.rbc +130 -0
- data/lib/sucker.rb +4 -2
- data/lib/sucker.rbc +286 -0
- data/spec/fixtures/cassette_library/0394751221.yml +26 -0
- data/spec/fixtures/cassette_library/0415246334.yml +26 -0
- data/spec/fixtures/cassette_library/0679753354.yml +26 -0
- data/spec/fixtures/cassette_library/0816614024-0007218095.yml +26 -0
- data/spec/fixtures/cassette_library/0816614024-0143105825.yml +26 -0
- data/spec/fixtures/cassette_library/0816614024.yml +26 -0
- data/spec/fixtures/cassette_library/482224816x.yml +26 -0
- data/spec/fixtures/cassette_library/816614024.yml +151 -0
- data/spec/fixtures/cassette_library/a2h6nh4sqyfz4m.yml +26 -0
- data/spec/fixtures/cassette_library/a2jyso6w6kep83.yml +26 -0
- data/spec/fixtures/cassette_library/author-lacan-or-deleuze-and-not-fiction.yml +26 -0
- data/spec/fixtures/cassette_library/b000aspues.yml +26 -0
- data/spec/fixtures/cassette_library/deleuze-binding-kindle.yml +26 -0
- data/spec/fixtures/cassette_library/deleuze.yml +26 -0
- data/spec/fixtures/cassette_library/george-orwell.yml +26 -0
- data/spec/fixtures/cassette_library/spec/sucker/request.yml +4 -4
- data/spec/fixtures/cassette_library/spec/sucker/response.yml +3 -3
- data/spec/spec_helper.rbc +230 -0
- data/spec/sucker/parameters_spec.rbc +1476 -0
- data/spec/sucker/request_spec.rb +34 -217
- data/spec/sucker/request_spec.rbc +2473 -0
- data/spec/sucker/response_spec.rb +46 -95
- data/spec/sucker/response_spec.rbc +2854 -0
- data/spec/sucker_spec.rbc +287 -0
- data/spec/support/amazon_credentials.rbc +154 -0
- data/spec/support/asins.rbc +335 -0
- data/spec/support/vcr.rbc +356 -0
- metadata +72 -96
- data/CHANGELOG.md +0 -47
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,59 +1,84 @@
|
|
1
1
|
Sucker
|
2
2
|
======
|
3
3
|
|
4
|
-
Sucker is a [
|
4
|
+
Sucker is a [Nokogiri-](http://github.com/rails/rails/blob/master/activesupport/lib/active_support/xml_mini/nokogiri.rb)based Ruby wrapper to the [Amazon Product Advertising API](https://affiliate-program.amazon.co.uk/gp/advertising/api/detail/main.html).
|
5
5
|
|
6
6
|
It's fast and supports __the entire API__.
|
7
7
|
|
8
8
|

|
9
9
|
|
10
|
+
|
11
|
+
1.3.0.pre
|
12
|
+
---------
|
13
|
+
This release has major changes under the hood.
|
14
|
+
|
15
|
+
I replaced curb with Net::HTTP to make the library JRuby compatible and edited out some nonessential code. Check [here](http://rdoc.info/github/papercavalier/sucker/master/frames) to see what's left.
|
16
|
+
|
10
17
|
Usage
|
11
18
|
-----
|
12
19
|
|
13
|
-
|
20
|
+
Set up.
|
14
21
|
|
15
22
|
worker = Sucker.new(
|
16
23
|
:locale => :us,
|
17
|
-
:key =>
|
18
|
-
:secret =>
|
24
|
+
:key => 'API KEY',
|
25
|
+
:secret => 'API SECRET')
|
19
26
|
|
20
|
-
Build a
|
27
|
+
Build a request.
|
21
28
|
|
22
29
|
worker << {
|
23
|
-
"Operation" =>
|
24
|
-
"IdType" =>
|
25
|
-
"ItemId" =>
|
26
|
-
"ResponseGroup" =>
|
30
|
+
"Operation" => 'ItemLookup',
|
31
|
+
"IdType" => 'ASIN',
|
32
|
+
"ItemId" => '0816614024',
|
33
|
+
"ResponseGroup" => 'ItemAttributes' }
|
27
34
|
|
28
35
|
Get a response.
|
29
36
|
|
30
37
|
response = worker.get
|
31
38
|
|
32
|
-
|
39
|
+
Consume.
|
33
40
|
|
34
|
-
|
35
|
-
# parse
|
36
|
-
end
|
41
|
+
items = response.find('Item') if response.valid?
|
37
42
|
|
38
43
|
Repeat ad infinitum.
|
39
44
|
|
40
|
-
[Check the features](http://relishapp.com/papercavalier/sucker)
|
45
|
+
[Check the features](http://relishapp.com/papercavalier/sucker).
|
46
|
+
|
47
|
+
[Read the API.](https://affiliate-program.amazon.co.uk/gp/advertising/api/detail/main.html)
|
48
|
+
|
49
|
+
|
50
|
+
Multiple local IPs
|
51
|
+
------------------
|
41
52
|
|
42
|
-
|
53
|
+
Amazon limits calls to a venue to one per second per IP. If you have
|
54
|
+
multiple interfaces set up and want to use all to query Amazon, just do:
|
55
|
+
|
56
|
+
worker.local_ip = '75.80.85.90'
|
57
|
+
worker.get # This request will route through the above IP
|
58
|
+
|
59
|
+
More concise syntax
|
60
|
+
-------------------
|
61
|
+
|
62
|
+
If you are on Ruby 1.9, try:
|
63
|
+
|
64
|
+
worker << {
|
65
|
+
operation: 'ItemLookup',
|
66
|
+
id_type: 'ASIN',
|
67
|
+
item_id: '0816614024' }
|
43
68
|
|
44
69
|
Stubbing
|
45
70
|
--------
|
46
71
|
|
47
|
-
Use [VCR](http://github.com/myronmarston/vcr)
|
72
|
+
Use [VCR](http://github.com/myronmarston/vcr).
|
48
73
|
|
49
|
-
|
74
|
+
Check out [this](http://github.com/papercavalier/sucker/blob/master/spec/support/vcr.rb) and [this](https://github.com/papercavalier/sucker/blob/master/features/step_definitions/sucker_steps.rb).
|
50
75
|
|
51
76
|
Compatibility
|
52
77
|
-------------
|
53
78
|
|
54
|
-
Specs pass against Ruby 1.8.7
|
79
|
+
Specs pass against Ruby 1.8.7, Ruby 1.9.2, JRuby 1.5.6, and Rubinius 1.2.1.
|
55
80
|
|
56
|
-
|
57
|
-
|
81
|
+
Morale of the story
|
82
|
+
-------------------
|
58
83
|
|
59
84
|
Don't overabstract a spaghetti API.
|
data/lib/sucker/parameters.rb
CHANGED
@@ -1,21 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'active_support/inflector'
|
2
4
|
|
3
|
-
module Sucker
|
4
|
-
|
5
|
+
module Sucker #:nodoc:
|
6
|
+
|
7
|
+
class Parameters < Hash #:nodoc:
|
5
8
|
API_VERSION = '2010-11-01'
|
6
9
|
SERVICE = 'AWSECommerceService'
|
7
10
|
|
8
|
-
def initialize
|
11
|
+
def initialize
|
9
12
|
self.store 'Service', SERVICE
|
10
13
|
self.store 'Version', API_VERSION
|
11
14
|
self.store 'Timestamp', timestamp
|
12
15
|
end
|
13
16
|
|
14
17
|
def normalize
|
15
|
-
inject({}) do |
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
inject({}) do |hash, key_value|
|
19
|
+
key, value = key_value
|
20
|
+
value = value.is_a?(Array) ? value.join(',') : value.to_s
|
21
|
+
hash[key.to_s.camelize] = value
|
22
|
+
hash
|
19
23
|
end
|
20
24
|
end
|
21
25
|
|