sucker 2.0.0.pre.1 → 2.0.0.pre.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -15,57 +15,87 @@ Check out [these examples](http://relishapp.com/papercavalier/sucker) if in a hu
15
15
 
16
16
  Set up.
17
17
 
18
- request = Sucker.new(
19
- :locale => :us,
20
- :key => amazon_key,
21
- :secret => amazon_secret)
18
+ ```ruby
19
+ request = Sucker.new(
20
+ :locale => :us,
21
+ :key => amazon_key,
22
+ :secret => amazon_secret)
23
+ ```
22
24
 
23
25
  Build a request.
24
26
 
25
- request << {
26
- 'Operation' => 'ItemLookup',
27
- 'IdType' => 'ASIN',
28
- 'ItemId' => 10.asins,
29
- 'ResponseGroup' => 'ItemAttributes' }
27
+ ```ruby
28
+ request << {
29
+ 'Operation' => 'ItemLookup',
30
+ 'IdType' => 'ASIN',
31
+ 'ItemId' => 10.asins,
32
+ 'ResponseGroup' => 'ItemAttributes' }
33
+ ```
30
34
 
31
35
  Get a response.
32
36
 
33
- response = request.get
37
+ ```ruby
38
+ response = request.get
39
+ ```
34
40
 
35
41
  Fulfill a business value.
36
42
 
37
- if response.valid?
38
- response.each('Item') do |item|
39
- consume(item)
40
- end
41
- end
43
+ ```ruby
44
+ if response.valid?
45
+ response.each('Item') do |item|
46
+ consume(item)
47
+ end
48
+ end
49
+ ```
42
50
 
43
51
  Repeat ad infinitum.
44
52
 
45
53
  The following are all valid ways to query a response:
46
54
 
47
- items = response.find('Item')
48
- items = response['Item']
49
- items = response.map('Item') { |item| ... }
50
- response.each('Item') { |item| ... }
55
+ ```ruby
56
+ items = response.find('Item')
57
+ items = response['Item']
58
+ items = response.map('Item') { |item| ... }
59
+ response.each('Item') { |item| ... }
60
+ ```
51
61
 
52
62
  To dig further into the response object:
53
63
 
54
- p response.valid?,
55
- response.body,
56
- response.code,
57
- response.errors,
58
- response.has_errors?,
59
- response.to_hash,
60
- response.xml
64
+ ```ruby
65
+ p response.valid?,
66
+ response.body,
67
+ response.code,
68
+ response.errors,
69
+ response.has_errors?,
70
+ response.to_hash,
71
+ response.xml
72
+ ```
61
73
 
62
74
  To use multiple local IPs on your server, configure the request adapter:
63
75
 
64
- adapter = request.adapter
65
- adapter.socket_local.host = '10.0.0.2'
76
+ ```ruby
77
+ adapter = request.adapter
78
+ adapter.socket_local.host = '10.0.0.2'
79
+ ```
66
80
 
67
81
  [Browse the public interface of Sucker.](http://rdoc.info/github/papercavalier/sucker/master/frames)
68
82
 
83
+ Evented Requests
84
+ ----------------
85
+
86
+ I am including a simple synchrony driver in the 2.0 major version release.
87
+
88
+ ```ruby
89
+ require 'sucker/synchrony'
90
+
91
+ EM.synchrony do
92
+ # set up request
93
+ response = request.get
94
+ # do something with the response
95
+ EM.stop
96
+ end
97
+ ```
98
+
69
99
  Stubbing Tests
70
100
  --------------
71
101
 
@@ -0,0 +1,23 @@
1
+ require 'sucker'
2
+ require 'em-synchrony'
3
+ require 'em-synchrony/em-http'
4
+
5
+ module Sucker
6
+ class Request
7
+ def adapter
8
+ @adapter ||= EM::HttpRequest
9
+ end
10
+
11
+ def get
12
+ http = EM::HttpRequest.new(url).get
13
+ Response.new(http)
14
+ end
15
+ end
16
+
17
+ class Response
18
+ def initialize(http)
19
+ self.body = http.response
20
+ self.code = http.response_header.status
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Sucker
2
- VERSION = '2.0.0.pre.1'
2
+ VERSION = '2.0.0.pre.2'
3
3
  end
@@ -5,7 +5,7 @@ module Sucker
5
5
  use_vcr_cassette 'spec/sucker/request', :record => :new_episodes
6
6
 
7
7
  let(:request) do
8
- Sucker.new(
8
+ Request.new(
9
9
  :locale => :us,
10
10
  :key => 'key',
11
11
  :secret => 'secret')
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ require 'sucker/synchrony'
3
+
4
+ module Sucker
5
+ describe Request do
6
+ let(:request) do
7
+ Request.new(
8
+ :locale => :us,
9
+ :key => 'key',
10
+ :secret => 'secret')
11
+ end
12
+
13
+ it "uses an evented adapter" do
14
+ request.adapter.should eql ::EM::HttpRequest
15
+ end
16
+
17
+ describe "#get" do
18
+ it "returns a response" do
19
+ EM.synchrony do
20
+ response = request.get
21
+ EM.stop
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 0
9
9
  - pre
10
- - 1
11
- version: 2.0.0.pre.1
10
+ - 2
11
+ version: 2.0.0.pre.2
12
12
  platform: ruby
13
13
  authors:
14
14
  - Paper Cavalier
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-06-02 00:00:00 +01:00
19
+ date: 2011-06-20 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -30,9 +30,7 @@ dependencies:
30
30
  segments:
31
31
  - 2
32
32
  - 2
33
- - 0
34
- - 2
35
- version: 2.2.0.2
33
+ version: "2.2"
36
34
  type: :runtime
37
35
  version_requirements: *id001
38
36
  - !ruby/object:Gem::Dependency
@@ -46,8 +44,7 @@ dependencies:
46
44
  segments:
47
45
  - 1
48
46
  - 4
49
- - 0
50
- version: 1.4.0
47
+ version: "1.4"
51
48
  type: :runtime
52
49
  version_requirements: *id002
53
50
  - !ruby/object:Gem::Dependency
@@ -61,8 +58,7 @@ dependencies:
61
58
  segments:
62
59
  - 1
63
60
  - 0
64
- - 0
65
- version: 1.0.0
61
+ version: "1.0"
66
62
  type: :development
67
63
  version_requirements: *id003
68
64
  - !ruby/object:Gem::Dependency
@@ -76,8 +72,7 @@ dependencies:
76
72
  segments:
77
73
  - 0
78
74
  - 10
79
- - 0
80
- version: 0.10.0
75
+ version: "0.10"
81
76
  type: :development
82
77
  version_requirements: *id004
83
78
  - !ruby/object:Gem::Dependency
@@ -89,14 +84,16 @@ dependencies:
89
84
  - - ~>
90
85
  - !ruby/object:Gem::Version
91
86
  segments:
87
+ - 1
92
88
  - 0
93
- - 3
94
89
  - 0
95
- version: 0.3.0
90
+ - beta
91
+ - 4
92
+ version: 1.0.0.beta.4
96
93
  type: :development
97
94
  version_requirements: *id005
98
95
  - !ruby/object:Gem::Dependency
99
- name: rake
96
+ name: em-synchrony
100
97
  prerelease: false
101
98
  requirement: &id006 !ruby/object:Gem::Requirement
102
99
  none: false
@@ -105,9 +102,11 @@ dependencies:
105
102
  - !ruby/object:Gem::Version
106
103
  segments:
107
104
  - 0
108
- - 8
109
- - 7
110
- version: 0.8.7
105
+ - 3
106
+ - 0
107
+ - beta
108
+ - 1
109
+ version: 0.3.0.beta.1
111
110
  type: :development
112
111
  version_requirements: *id006
113
112
  - !ruby/object:Gem::Dependency
@@ -120,9 +119,8 @@ dependencies:
120
119
  - !ruby/object:Gem::Version
121
120
  segments:
122
121
  - 0
123
- - 3
124
- - 0
125
- version: 0.3.0
122
+ - 4
123
+ version: "0.4"
126
124
  type: :development
127
125
  version_requirements: *id007
128
126
  - !ruby/object:Gem::Dependency
@@ -136,8 +134,7 @@ dependencies:
136
134
  segments:
137
135
  - 2
138
136
  - 6
139
- - 0
140
- version: 2.6.0
137
+ version: "2.6"
141
138
  type: :development
142
139
  version_requirements: *id008
143
140
  - !ruby/object:Gem::Dependency
@@ -151,8 +148,7 @@ dependencies:
151
148
  segments:
152
149
  - 1
153
150
  - 10
154
- - 0
155
- version: 1.10.0
151
+ version: "1.10"
156
152
  type: :development
157
153
  version_requirements: *id009
158
154
  - !ruby/object:Gem::Dependency
@@ -166,8 +162,7 @@ dependencies:
166
162
  segments:
167
163
  - 1
168
164
  - 6
169
- - 4
170
- version: 1.6.4
165
+ version: "1.6"
171
166
  type: :development
172
167
  version_requirements: *id010
173
168
  description: A Ruby wrapper to the Amazon Product Advertising API
@@ -184,6 +179,7 @@ files:
184
179
  - lib/sucker/parameters.rb
185
180
  - lib/sucker/request.rb
186
181
  - lib/sucker/response.rb
182
+ - lib/sucker/synchrony.rb
187
183
  - lib/sucker/version.rb
188
184
  - lib/sucker.rb
189
185
  - LICENSE
@@ -211,6 +207,7 @@ files:
211
207
  - spec/sucker/parameters_spec.rb
212
208
  - spec/sucker/request_spec.rb
213
209
  - spec/sucker/response_spec.rb
210
+ - spec/sucker/synchrony_spec.rb
214
211
  - spec/sucker_spec.rb
215
212
  - spec/support/amazon_credentials.rb
216
213
  - spec/support/asins.rb
@@ -273,6 +270,7 @@ test_files:
273
270
  - spec/sucker/parameters_spec.rb
274
271
  - spec/sucker/request_spec.rb
275
272
  - spec/sucker/response_spec.rb
273
+ - spec/sucker/synchrony_spec.rb
276
274
  - spec/sucker_spec.rb
277
275
  - spec/support/amazon_credentials.rb
278
276
  - spec/support/asins.rb