hurley 0.1 → 0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70bb285608ba9cef1503ea1acf003fbdc48c0648
4
- data.tar.gz: 0b9e00c2e5880c432c41865ed996cffdb9174d46
3
+ metadata.gz: 6ffa214bf8dbce13368948420d335923d636595a
4
+ data.tar.gz: 26d36be2f4e2a2701b3de9fa30575e45a51b63c8
5
5
  SHA512:
6
- metadata.gz: a9d694cf97f96c3099171fa5479b6c2ad5e3037ec02fa53776945a1b1166e45084e13508c660d5948e2c4b4445fa29020eae28e2187f1474629e28c05509b324
7
- data.tar.gz: f48211a98ac3616638afbdd58c5b95dca7e6e486cf2eec6503147321ea628c2f6bbe082840568cff4923e865f9842247aadf5d3c3a352fe2b69a0b887660317a
6
+ metadata.gz: 33fb1096bc78337005394615c78bc62dc9f1f289f0d9c3b6bec0144dcb9566cfa988963481dce6d2beae4e2349ffa68905e038fbba970d3e454e735c51c60ad9
7
+ data.tar.gz: 37cca53badb8ed4a89b8240443b06219682c2d633e82aa39c1f4667f8cd7a019782e106c5b9d7705ce7a335484753d4cc251a54bc8afeb2afd9c94c0ce816403
data/.gitignore CHANGED
@@ -1,4 +1,4 @@
1
1
  log
2
2
  tmp
3
3
  pkg
4
-
4
+ Gemfile.lock
data/Gemfile CHANGED
@@ -1,2 +1,10 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
+
4
+ gem "addressable", "~> 2.3", ">= 2.3.6"
5
+ gem "rake", "~> 10.4.0", ">= 10.4.2"
6
+
7
+ group :test do
8
+ gem "minitest", "~> 5.6"
9
+ gem "sinatra", "~> 1.4", ">= 1.4.5"
10
+ end
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
@@ -6,3 +6,4 @@
6
6
  Rick Olson: technoweenie@gmail.com
7
7
  Wynn Netherland:
8
8
  Ben Maraney:
9
+ Kevin Kirsche: kev.kirsche@gmail.com
@@ -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
@@ -2,7 +2,7 @@ require "forwardable"
2
2
  require "thread"
3
3
 
4
4
  module Hurley
5
- VERSION = "0.1".freeze
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
- @default_client ||= mutex { Client.new }
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
- @default_connection ||= mutex do
35
- Hurley.require_lib "connection"
36
- Connection.new
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
 
@@ -176,40 +176,53 @@ module Hurley
176
176
  end
177
177
 
178
178
  def prepare!
179
- if value = !header[:authorization] && url.basic_auth
180
- header[:authorization] = value
181
- end
179
+ prepare_basic_auth!
182
180
 
183
181
  if body
184
- ctype = nil
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
- if !header.key?(:content_length) && header[:transfer_encoding] != CHUNKED
199
- if body
200
- if sizer = SIZE_METHODS.detect { |method| body.respond_to?(method) }
201
- header[:content_length] = body.send(sizer).to_i
202
- else
203
- header[:transfer_encoding] = CHUNKED
204
- end
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[:content_length] = 0
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
- yield self if block_given?
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
@@ -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
@@ -42,6 +42,7 @@ module Hurley
42
42
 
43
43
  def parse_query(raw_query)
44
44
  raw_query.to_s.split(AMP).each do |pair|
45
+ next if pair.empty?
45
46
  escaped_key, escaped_value = pair.split(EQ, 2)
46
47
  key = CGI.unescape(escaped_key)
47
48
  value = escaped_value ? CGI.unescape(escaped_value) : nil
@@ -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).rstrip}"
155
+ "Basic #{Base64.encode64(userinfo).gsub(/\n/, EMPTY)}"
156
156
  end
157
157
 
158
158
  def query_class
@@ -17,6 +17,8 @@
17
17
  #
18
18
  # # Run against multiple rbenv versions
19
19
  # $ RBENV_VERSIONS="1.9.3-p194 ree-1.8.7-2012.02" script/test
20
+ # # Run tests with Addressable::URI
21
+ # $ HURLEY_ADDRESSABLE=1 script/test
20
22
  set -e
21
23
 
22
24
  port=3999
@@ -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
@@ -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 #{Base64.encode64("a b:1 + 2").rstrip}", u.basic_auth
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 #{Base64.encode64("a b").rstrip}", u.basic_auth
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.1'
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-01-07 00:00:00.000000000 Z
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.2
90
+ rubygems_version: 2.2.3
170
91
  signing_key:
171
92
  specification_version: 4
172
93
  summary: HTTP client wrapper
@@ -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)