weary 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- weary (1.0.1)
4
+ weary (1.1.1)
5
5
  addressable (~> 2.3.2)
6
6
  multi_json (~> 1.3.0)
7
7
  promise (~> 0.3.0)
@@ -207,10 +207,17 @@ module Weary
207
207
  parameters = parameters.first || {}
208
208
  @defaults ||= {}
209
209
  request = resource.request(@defaults.merge(parameters), &block)
210
+ self.pass_values_onto_requestable(request)
210
211
  request
211
212
  end
212
213
  end
213
214
  end
214
215
 
216
+ include Weary::Requestable
217
+
218
+ def initialize
219
+ yield self if block_given?
220
+ end
221
+
215
222
  end
216
223
  end
@@ -20,11 +20,27 @@ module Weary
20
20
 
21
21
  def sign(env)
22
22
  req = Rack::Request.new(env)
23
+ post_body = req.body.read
24
+ req.body.rewind
23
25
  SimpleOAuth::Header.new req.request_method,
24
26
  req.url,
25
- req.params,
27
+ request_body_to_hash(post_body),
26
28
  @oauth
27
29
  end
30
+
31
+ # Stolen from Rack::Utils
32
+ def request_body_to_hash(qs, d = nil)
33
+ params = Rack::Utils::KeySpaceConstrainedParams.new
34
+ default_sep = /[&;] */n
35
+
36
+ (qs || '').split(d ? /[#{d}] */n : default_sep).each do |p|
37
+ k, v = p.split('=', 2).map { |s| Rack::Utils.unescape(s, defined?(::Encoding) ? Encoding::BINARY : nil) }
38
+
39
+ Rack::Utils.normalize_params(params, k, v)
40
+ end
41
+
42
+ return params.to_params_hash
43
+ end
28
44
  end
29
45
  end
30
46
  end
@@ -70,7 +70,7 @@ module Weary
70
70
  if !parameters.nil?
71
71
  if ["POST", "PUT"].include? method
72
72
  @body = query_params_from_hash(parameters)
73
- body stringio_encode(@body)
73
+ body StringIO.new(@body)
74
74
  use Weary::Middleware::ContentType
75
75
  else
76
76
  uri.query_values = parameters
@@ -123,10 +123,21 @@ module Weary
123
123
 
124
124
  private
125
125
 
126
- def query_params_from_hash(hash)
127
- tmp_uri = Addressable::URI.new
128
- tmp_uri.query_values = hash
129
- tmp_uri.query
126
+ # Stolen from Faraday
127
+ def query_params_from_hash(value, prefix = nil)
128
+ case value
129
+ when Array
130
+ value.map { |v| query_params_from_hash(v, "#{prefix}%5B%5D") }.join("&")
131
+ when Hash
132
+ value.map { |k, v|
133
+ query_params_from_hash(v, prefix ? "#{prefix}%5B#{Rack::Utils.escape_path(k)}%5D" : Rack::Utils.escape_path(k))
134
+ }.join("&")
135
+ when NilClass
136
+ prefix
137
+ else
138
+ raise ArgumentError, "value must be a Hash" if prefix.nil?
139
+ "#{prefix}=#{Rack::Utils.escape_path(value)}"
140
+ end
130
141
  end
131
142
 
132
143
  def rack_env_defaults
@@ -57,8 +57,8 @@ module Weary
57
57
  #
58
58
  # Returns the Requestable object.
59
59
  def pass_values_onto_requestable(requestable)
60
- requestable.headers self.headers
61
- requestable.adapter self.adapter
60
+ requestable.headers self.headers unless @headers.nil?
61
+ requestable.adapter self.adapter unless @connection.nil?
62
62
  if has_middleware?
63
63
  @middlewares.each {|middleware| requestable.use *middleware }
64
64
  end
@@ -1,3 +1,3 @@
1
1
  module Weary
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -257,6 +257,27 @@ describe Weary::Client do
257
257
  client.instance_variable_set :@defaults, :user => "mwunsch", :repo => "weary"
258
258
  expect { client.send(action) }.to_not raise_error
259
259
  end
260
+
261
+ it "forwards requestables on to the requests" do
262
+ action = :show
263
+ url = "http://github.com/api/v2/json/repos/show/{user}/{repo}"
264
+ @klass.get action, url
265
+ adapter = Class.new { include Weary::Adapter }
266
+ client = @klass.new
267
+ client.adapter adapter
268
+ client.send(action, :user => "mwunsch", :repo => "weary").adapter.should eql adapter
269
+ end
270
+
271
+ it "accepts a block to further add requestables" do
272
+ action = :show
273
+ url = "http://github.com/api/v2/json/repos/show/{user}/{repo}"
274
+ @klass.get action, url
275
+ adapter = Class.new { include Weary::Adapter }
276
+ client = @klass.new do |c|
277
+ c.adapter adapter
278
+ end
279
+ client.send(action, :user => "mwunsch", :repo => "weary").adapter.should eql adapter
280
+ end
260
281
  end
261
282
 
262
283
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weary
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-18 00:00:00.000000000 Z
12
+ date: 2012-10-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -160,12 +160,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
160
  - - ! '>='
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0'
163
+ segments:
164
+ - 0
165
+ hash: -2981531106124675018
163
166
  required_rubygems_version: !ruby/object:Gem::Requirement
164
167
  none: false
165
168
  requirements:
166
169
  - - ! '>='
167
170
  - !ruby/object:Gem::Version
168
171
  version: '0'
172
+ segments:
173
+ - 0
174
+ hash: -2981531106124675018
169
175
  requirements: []
170
176
  rubyforge_project: weary
171
177
  rubygems_version: 1.8.23