hurley 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Gemfile +8 -0
- data/README.md +3 -0
- data/contributors.yaml +1 -0
- data/hurley.gemspec +0 -4
- data/lib/hurley.rb +9 -5
- data/lib/hurley/client.rb +43 -24
- data/lib/hurley/options.rb +9 -1
- data/lib/hurley/query.rb +1 -0
- data/lib/hurley/url.rb +1 -1
- data/script/test +2 -0
- data/test/query_test.rb +10 -0
- data/test/url_test.rb +10 -2
- metadata +5 -84
- data/Gemfile.lock +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ffa214bf8dbce13368948420d335923d636595a
|
4
|
+
data.tar.gz: 26d36be2f4e2a2701b3de9fa30575e45a51b63c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33fb1096bc78337005394615c78bc62dc9f1f289f0d9c3b6bec0144dcb9566cfa988963481dce6d2beae4e2349ffa68905e038fbba970d3e454e735c51c60ad9
|
7
|
+
data.tar.gz: 37cca53badb8ed4a89b8240443b06219682c2d633e82aa39c1f4667f8cd7a019782e106c5b9d7705ce7a335484753d4cc251a54bc8afeb2afd9c94c0ce816403
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -309,9 +309,12 @@ client.get("/user").body # => {"id": 1}
|
|
309
309
|
## TODO
|
310
310
|
|
311
311
|
* [ ] Backport Faraday adapters as gems
|
312
|
+
* [x] Excon
|
313
|
+
* [ ] Typhoeus
|
312
314
|
* [ ] Integrate into Faraday reliant gems:
|
313
315
|
* [ ] [Sawyer](https://github.com/lostisland/sawyer)
|
314
316
|
* [ ] [Octokit](https://github.com/octokit/octokit.rb)
|
315
317
|
* [ ] [Elastomer](https://github.com/github/elastomer-client)
|
318
|
+
* [ ] Tomdoc all the things
|
316
319
|
* [ ] Fix allll the bugs
|
317
320
|
* [ ] Release v1.0
|
data/contributors.yaml
CHANGED
data/hurley.gemspec
CHANGED
@@ -8,11 +8,7 @@ require "yaml"
|
|
8
8
|
contributors = YAML.load(IO.read(File.expand_path("../contributors.yaml", __FILE__)))
|
9
9
|
|
10
10
|
Gem::Specification.new do |spec|
|
11
|
-
spec.add_development_dependency "addressable", "~> 2.3", ">= 2.3.6"
|
12
11
|
spec.add_development_dependency "bundler", "~> 1.0"
|
13
|
-
spec.add_development_dependency "minitest", "~> 5.5", ">= 5.5.0"
|
14
|
-
spec.add_development_dependency "rake", "~> 10.4.0", ">= 10.4.2"
|
15
|
-
spec.add_development_dependency "sinatra", "~> 1.4", ">= 1.4.5"
|
16
12
|
spec.authors = contributors.keys.compact
|
17
13
|
spec.description = %q{Hurley provides a common interface for working with different HTTP adapters.}
|
18
14
|
spec.email = contributors.values.compact
|
data/lib/hurley.rb
CHANGED
@@ -2,7 +2,7 @@ require "forwardable"
|
|
2
2
|
require "thread"
|
3
3
|
|
4
4
|
module Hurley
|
5
|
-
VERSION = "0.
|
5
|
+
VERSION = "0.2".freeze
|
6
6
|
USER_AGENT = "Hurley v#{VERSION}".freeze
|
7
7
|
LIB_PATH = __FILE__[0...-3]
|
8
8
|
MUTEX = Mutex.new
|
@@ -14,7 +14,9 @@ module Hurley
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.default_client
|
17
|
-
|
17
|
+
mutex do
|
18
|
+
@default_client ||= Client.new
|
19
|
+
end
|
18
20
|
end
|
19
21
|
|
20
22
|
class << self
|
@@ -31,9 +33,11 @@ module Hurley
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def self.default_connection
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
mutex do
|
37
|
+
@default_connection ||= begin
|
38
|
+
Hurley.require_lib "connection"
|
39
|
+
Connection.new
|
40
|
+
end
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
data/lib/hurley/client.rb
CHANGED
@@ -176,40 +176,53 @@ module Hurley
|
|
176
176
|
end
|
177
177
|
|
178
178
|
def prepare!
|
179
|
-
|
180
|
-
header[:authorization] = value
|
181
|
-
end
|
179
|
+
prepare_basic_auth!
|
182
180
|
|
183
181
|
if body
|
184
|
-
|
185
|
-
case body
|
186
|
-
when Query
|
187
|
-
ctype, io = body.to_form
|
188
|
-
self.body = io
|
189
|
-
when Hash
|
190
|
-
ctype, io = options.build_form(body)
|
191
|
-
self.body = io
|
192
|
-
end
|
193
|
-
header[:content_type] ||= ctype || DEFAULT_TYPE
|
182
|
+
prepare_body!
|
194
183
|
else
|
195
184
|
return unless REQUIRED_BODY_VERBS.include?(verb)
|
196
185
|
end
|
197
186
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
187
|
+
prepare_content_length!
|
188
|
+
end
|
189
|
+
|
190
|
+
private
|
191
|
+
|
192
|
+
def prepare_basic_auth!
|
193
|
+
value = !header[:authorization] && url.basic_auth
|
194
|
+
header[:authorization] = value if value
|
195
|
+
end
|
196
|
+
|
197
|
+
def prepare_body!
|
198
|
+
ctype = nil
|
199
|
+
case body
|
200
|
+
when Query
|
201
|
+
ctype, io = body.to_form
|
202
|
+
self.body = io
|
203
|
+
when Hash
|
204
|
+
ctype, io = options.build_form(body)
|
205
|
+
self.body = io
|
206
|
+
end
|
207
|
+
header[:content_type] ||= ctype || DEFAULT_TYPE
|
208
|
+
end
|
209
|
+
|
210
|
+
def prepare_content_length!
|
211
|
+
if header.key?(:content_length) || header[:transfer_encoding] == CHUNKED
|
212
|
+
return
|
213
|
+
end
|
214
|
+
|
215
|
+
if body
|
216
|
+
if sizer = SIZE_METHODS.detect { |method| body.respond_to?(method) }
|
217
|
+
header[:content_length] = body.send(sizer).to_i
|
205
218
|
else
|
206
|
-
header[:
|
219
|
+
header[:transfer_encoding] = CHUNKED
|
207
220
|
end
|
221
|
+
else
|
222
|
+
header[:content_length] = 0
|
208
223
|
end
|
209
224
|
end
|
210
225
|
|
211
|
-
private
|
212
|
-
|
213
226
|
def body_receiver
|
214
227
|
@body_receiver ||= [nil, BodyReceiver.new]
|
215
228
|
end
|
@@ -235,7 +248,13 @@ module Hurley
|
|
235
248
|
@receiver = nil
|
236
249
|
@timing = nil
|
237
250
|
@started_at = Time.now.to_f
|
238
|
-
|
251
|
+
if block_given?
|
252
|
+
yield self
|
253
|
+
complete!
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
def complete!
|
239
258
|
@ended_at = Time.now.to_f
|
240
259
|
if @receiver.respond_to?(:join)
|
241
260
|
@body = @receiver.join
|
data/lib/hurley/options.rb
CHANGED
@@ -20,7 +20,7 @@ module Hurley
|
|
20
20
|
:proxy,
|
21
21
|
|
22
22
|
# Integer limit on the number of redirects that are automatically followed.
|
23
|
-
# Default: 5
|
23
|
+
# Set to < 1 to disable automatic redirections. Default: 5
|
24
24
|
:redirection_limit,
|
25
25
|
|
26
26
|
# Hurley::Query subclass to use for query objects. Defaults to
|
@@ -28,6 +28,14 @@ module Hurley
|
|
28
28
|
:query_class,
|
29
29
|
)
|
30
30
|
|
31
|
+
def timeout_ms
|
32
|
+
self[:timeout].to_i * 1000
|
33
|
+
end
|
34
|
+
|
35
|
+
def open_timeout_ms
|
36
|
+
self[:open_timeout].to_i * 1000
|
37
|
+
end
|
38
|
+
|
31
39
|
def redirection_limit
|
32
40
|
self[:redirection_limit] ||= 5
|
33
41
|
end
|
data/lib/hurley/query.rb
CHANGED
data/lib/hurley/url.rb
CHANGED
@@ -152,7 +152,7 @@ module Hurley
|
|
152
152
|
def basic_auth
|
153
153
|
return unless @user
|
154
154
|
userinfo = @password ? "#{@user}:#{@password}" : @user
|
155
|
-
"Basic #{Base64.encode64(userinfo).
|
155
|
+
"Basic #{Base64.encode64(userinfo).gsub(/\n/, EMPTY)}"
|
156
156
|
end
|
157
157
|
|
158
158
|
def query_class
|
data/script/test
CHANGED
data/test/query_test.rb
CHANGED
@@ -185,5 +185,15 @@ module Hurley
|
|
185
185
|
expected.gsub! /\[|\]/, "[" => "%5B", "]" => "%5D"
|
186
186
|
assert_equal expected, actual
|
187
187
|
end
|
188
|
+
|
189
|
+
def test_parse_double_equal_sign_in_nested_query
|
190
|
+
q = Query::Nested.parse("a[]=1&b[]=2&&c[]=3")
|
191
|
+
assert_equal %w(a b c), q.keys
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_parse_double_equal_sign_in_flat_query
|
195
|
+
q = Query::Flat.parse("a[]=1&b[]=2&&c[]=3")
|
196
|
+
assert_equal %w(a[] b[] c[]), q.keys
|
197
|
+
end
|
188
198
|
end
|
189
199
|
end
|
data/test/url_test.rb
CHANGED
@@ -397,14 +397,22 @@ module Hurley
|
|
397
397
|
u = Url.parse("http://a%20b:1%20%2B%202@foo.com")
|
398
398
|
assert_equal "a b", u.user
|
399
399
|
assert_equal "1 + 2", u.password
|
400
|
-
assert_equal "Basic
|
400
|
+
assert_equal "Basic YSBiOjEgKyAy", u.basic_auth
|
401
|
+
end
|
402
|
+
|
403
|
+
def test_basic_auth_user_with_non_encoded_password
|
404
|
+
u = Url.parse("http://a%20b:MxYut8Rj8tQi6%3DwNf.miTxf%3Eq49%3F%2Cf%40v" \
|
405
|
+
"QX8og3YT%3Fs.%5D8L3h9)@foo.com")
|
406
|
+
assert_equal "a b", u.user
|
407
|
+
assert_equal "MxYut8Rj8tQi6=wNf.miTxf>q49?,f@vQX8og3YT?s.]8L3h9)", u.password
|
408
|
+
assert_equal "Basic YSBiOk14WXV0OFJqOHRRaTY9d05mLm1pVHhmPnE0OT8sZkB2UVg4b2czWVQ/cy5dOEwzaDkp", u.basic_auth
|
401
409
|
end
|
402
410
|
|
403
411
|
def test_basic_auth_user_without_password
|
404
412
|
u = Url.parse("http://a%20b@foo.com")
|
405
413
|
assert_equal "a b", u.user
|
406
414
|
assert_nil u.password
|
407
|
-
assert_equal "Basic
|
415
|
+
assert_equal "Basic YSBi", u.basic_auth
|
408
416
|
end
|
409
417
|
|
410
418
|
def test_join_url_with_auth_url
|
metadata
CHANGED
@@ -1,37 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hurley
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Olson
|
8
8
|
- Wynn Netherland
|
9
9
|
- Ben Maraney
|
10
|
+
- Kevin Kirsche
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date: 2015-
|
14
|
+
date: 2015-09-05 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: addressable
|
17
|
-
requirement: !ruby/object:Gem::Requirement
|
18
|
-
requirements:
|
19
|
-
- - "~>"
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '2.3'
|
22
|
-
- - ">="
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 2.3.6
|
25
|
-
type: :development
|
26
|
-
prerelease: false
|
27
|
-
version_requirements: !ruby/object:Gem::Requirement
|
28
|
-
requirements:
|
29
|
-
- - "~>"
|
30
|
-
- !ruby/object:Gem::Version
|
31
|
-
version: '2.3'
|
32
|
-
- - ">="
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: 2.3.6
|
35
16
|
- !ruby/object:Gem::Dependency
|
36
17
|
name: bundler
|
37
18
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,69 +27,10 @@ dependencies:
|
|
46
27
|
- - "~>"
|
47
28
|
- !ruby/object:Gem::Version
|
48
29
|
version: '1.0'
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: minitest
|
51
|
-
requirement: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - "~>"
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '5.5'
|
56
|
-
- - ">="
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
version: 5.5.0
|
59
|
-
type: :development
|
60
|
-
prerelease: false
|
61
|
-
version_requirements: !ruby/object:Gem::Requirement
|
62
|
-
requirements:
|
63
|
-
- - "~>"
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
version: '5.5'
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 5.5.0
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rake
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 10.4.0
|
76
|
-
- - ">="
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
version: 10.4.2
|
79
|
-
type: :development
|
80
|
-
prerelease: false
|
81
|
-
version_requirements: !ruby/object:Gem::Requirement
|
82
|
-
requirements:
|
83
|
-
- - "~>"
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: 10.4.0
|
86
|
-
- - ">="
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: 10.4.2
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: sinatra
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - "~>"
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: '1.4'
|
96
|
-
- - ">="
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
version: 1.4.5
|
99
|
-
type: :development
|
100
|
-
prerelease: false
|
101
|
-
version_requirements: !ruby/object:Gem::Requirement
|
102
|
-
requirements:
|
103
|
-
- - "~>"
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
version: '1.4'
|
106
|
-
- - ">="
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
version: 1.4.5
|
109
30
|
description: Hurley provides a common interface for working with different HTTP adapters.
|
110
31
|
email:
|
111
32
|
- technoweenie@gmail.com
|
33
|
+
- kev.kirsche@gmail.com
|
112
34
|
executables: []
|
113
35
|
extensions: []
|
114
36
|
extra_rdoc_files: []
|
@@ -116,7 +38,6 @@ files:
|
|
116
38
|
- ".gitignore"
|
117
39
|
- ".travis.yml"
|
118
40
|
- Gemfile
|
119
|
-
- Gemfile.lock
|
120
41
|
- LICENSE.md
|
121
42
|
- README.md
|
122
43
|
- Rakefile
|
@@ -166,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
87
|
version: '0'
|
167
88
|
requirements: []
|
168
89
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.2.
|
90
|
+
rubygems_version: 2.2.3
|
170
91
|
signing_key:
|
171
92
|
specification_version: 4
|
172
93
|
summary: HTTP client wrapper
|
data/Gemfile.lock
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
hurley (0.1)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
addressable (2.3.6)
|
10
|
-
minitest (5.5.0)
|
11
|
-
rack (1.6.0)
|
12
|
-
rack-protection (1.5.3)
|
13
|
-
rack
|
14
|
-
sinatra (1.4.5)
|
15
|
-
rack (~> 1.4)
|
16
|
-
rack-protection (~> 1.4)
|
17
|
-
tilt (~> 1.3, >= 1.3.4)
|
18
|
-
tilt (1.4.1)
|
19
|
-
|
20
|
-
PLATFORMS
|
21
|
-
ruby
|
22
|
-
|
23
|
-
DEPENDENCIES
|
24
|
-
addressable (~> 2.3.6)
|
25
|
-
bundler (~> 1.0)
|
26
|
-
hurley!
|
27
|
-
minitest (~> 5.5.0)
|
28
|
-
sinatra (~> 1.4.5)
|