zephyr 1.1.3 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/Gemfile.lock +4 -0
- data/VERSION +1 -1
- data/lib/ext/typhoeus_ext.rb +16 -0
- data/lib/zephyr.rb +28 -17
- data/test/helper.rb +1 -1
- data/test/test_zephyr.rb +48 -37
- data/zephyr.gemspec +4 -2
- metadata +20 -3
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -6,7 +6,10 @@ GEM
|
|
6
6
|
bundler (~> 1.0)
|
7
7
|
git (>= 1.2.5)
|
8
8
|
rake
|
9
|
+
metaclass (0.0.1)
|
9
10
|
mime-types (1.16)
|
11
|
+
mocha (0.12.0)
|
12
|
+
metaclass (~> 0.0.1)
|
10
13
|
rake (0.9.2)
|
11
14
|
shoulda (2.11.3)
|
12
15
|
typhoeus (0.2.4)
|
@@ -20,6 +23,7 @@ PLATFORMS
|
|
20
23
|
DEPENDENCIES
|
21
24
|
bundler (~> 1.0.0)
|
22
25
|
jeweler (~> 1.6.4)
|
26
|
+
mocha (~> 0.12.0)
|
23
27
|
shoulda (~> 2.11.3)
|
24
28
|
typhoeus (>= 0.2.4)
|
25
29
|
yajl-ruby
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.5
|
data/lib/zephyr.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require 'net/http'
|
3
3
|
require 'typhoeus'
|
4
|
+
require 'ext/typhoeus_ext'
|
4
5
|
require 'yajl'
|
5
6
|
|
6
7
|
# Stolen with a fair bit of modification from the riak-client gem, which is
|
@@ -58,7 +59,7 @@ class Zephyr
|
|
58
59
|
|
59
60
|
class << self
|
60
61
|
@debug_mode = false
|
61
|
-
|
62
|
+
|
62
63
|
def logger
|
63
64
|
@@logger
|
64
65
|
end
|
@@ -74,6 +75,30 @@ class Zephyr
|
|
74
75
|
def debug_mode=(mode)
|
75
76
|
@debug_mode = mode
|
76
77
|
end
|
78
|
+
|
79
|
+
def percent_encode(value)
|
80
|
+
typhoeus_easy.send(:easy_escape, value.to_s, value.to_s.bytesize)
|
81
|
+
end
|
82
|
+
|
83
|
+
def build_query_string(params)
|
84
|
+
params.map do |k, v|
|
85
|
+
if v.kind_of? Array
|
86
|
+
build_query_string(v.map { |x| [k, x] })
|
87
|
+
else
|
88
|
+
"#{percent_encode(k)}=#{percent_encode(v)}"
|
89
|
+
end
|
90
|
+
end.sort.join '&'
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
# NOTE: This is here only because it provides a binding to
|
96
|
+
# Curb's 'easy_escape' function, which does what we want.
|
97
|
+
# Don't use it to perform requests. Ever.
|
98
|
+
#
|
99
|
+
def typhoeus_easy
|
100
|
+
@_typhoeus_easy ||= Typhoeus::Easy.new.freeze
|
101
|
+
end
|
77
102
|
end
|
78
103
|
|
79
104
|
@@logger = Logger.new(STDOUT)
|
@@ -218,20 +243,6 @@ class Zephyr
|
|
218
243
|
Typheous::Hydra.hydra.cleanup
|
219
244
|
end
|
220
245
|
|
221
|
-
def percent_encode(value)
|
222
|
-
typhoeus_easy.send(:easy_escape, value.to_s, value.to_s.bytesize)
|
223
|
-
end
|
224
|
-
|
225
|
-
private
|
226
|
-
|
227
|
-
# NOTE: This is here only because it provides a binding to
|
228
|
-
# Curb's 'easy_escape' function, which does what we want.
|
229
|
-
# Don't use it to perform requests. Ever.
|
230
|
-
#
|
231
|
-
def typhoeus_easy
|
232
|
-
@_typhoeus_easy ||= Typhoeus::Easy.new.freeze
|
233
|
-
end
|
234
|
-
|
235
246
|
def verify_path_and_entity!(path_components, entity)
|
236
247
|
begin
|
237
248
|
verify_path!(path_components)
|
@@ -280,7 +291,7 @@ class Zephyr
|
|
280
291
|
http_end = Time.now.to_f
|
281
292
|
|
282
293
|
Zephyr.logger.info "[zephyr:#{$$}:#{Time.now.to_f}] \"%s %s\" %s %0.4f" % [
|
283
|
-
method.to_s.upcase,
|
294
|
+
method.to_s.upcase, response.request.url, response.code, (http_end - http_start)
|
284
295
|
]
|
285
296
|
|
286
297
|
# be consistent with what came before
|
@@ -298,7 +309,7 @@ class Zephyr
|
|
298
309
|
result
|
299
310
|
else
|
300
311
|
failed_request = FailedRequest.new(:method => method,
|
301
|
-
:uri =>
|
312
|
+
:uri => response.request.url,
|
302
313
|
:expected_code => expect,
|
303
314
|
:timeout => timeout,
|
304
315
|
:response => response)
|
data/test/helper.rb
CHANGED
@@ -8,8 +8,8 @@ rescue Bundler::BundlerError => e
|
|
8
8
|
exit e.status_code
|
9
9
|
end
|
10
10
|
require 'test/unit'
|
11
|
+
require 'mocha'
|
11
12
|
require 'shoulda'
|
12
|
-
require 'typhoeus'
|
13
13
|
|
14
14
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
15
15
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
data/test/test_zephyr.rb
CHANGED
@@ -11,59 +11,56 @@ class TestZephyr < Test::Unit::TestCase
|
|
11
11
|
end
|
12
12
|
|
13
13
|
context "query string parameters" do
|
14
|
-
should "be sorted" do
|
15
|
-
zephyr = Zephyr.new
|
14
|
+
should "be sorted" do
|
16
15
|
duples = ('a'..'z').zip('A'..'Z') # [ [ 'a', 'A' ], [ 'b', 'B' ], ... ]
|
17
16
|
expected = duples.map { |l,u| '%s=%s' % [ l, u ] }.sort.join('&')
|
18
17
|
|
19
|
-
assert_equal expected,
|
18
|
+
assert_equal expected, Zephyr.build_query_string(Hash[duples.shuffle])
|
20
19
|
end
|
21
20
|
|
22
21
|
should "be constructed for arrays" do
|
23
22
|
zephyr = Zephyr.new
|
24
|
-
assert_equal 'a=1&a=2',
|
23
|
+
assert_equal 'a=1&a=2', Zephyr.build_query_string(:a => [ 2, 1 ])
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
28
27
|
context "percent encoding" do
|
29
28
|
should "be correct" do
|
30
|
-
zephyr = Zephyr.new
|
31
|
-
|
32
29
|
# RFC 3986 Reserved Characters
|
33
|
-
assert_equal '%21',
|
34
|
-
assert_equal '%2A',
|
35
|
-
assert_equal '%27',
|
36
|
-
assert_equal '%28',
|
37
|
-
assert_equal '%29',
|
38
|
-
assert_equal '%3B',
|
39
|
-
assert_equal '%3A',
|
40
|
-
assert_equal '%40',
|
41
|
-
assert_equal '%26',
|
42
|
-
assert_equal '%3D',
|
43
|
-
assert_equal '%2B',
|
44
|
-
assert_equal '%24',
|
45
|
-
assert_equal '%2C',
|
46
|
-
assert_equal '%2F',
|
47
|
-
assert_equal '%3F',
|
48
|
-
assert_equal '%23',
|
49
|
-
assert_equal '%5B',
|
50
|
-
assert_equal '%5D',
|
30
|
+
assert_equal '%21', Zephyr.percent_encode('!')
|
31
|
+
assert_equal '%2A', Zephyr.percent_encode('*')
|
32
|
+
assert_equal '%27', Zephyr.percent_encode("'")
|
33
|
+
assert_equal '%28', Zephyr.percent_encode('(')
|
34
|
+
assert_equal '%29', Zephyr.percent_encode(')')
|
35
|
+
assert_equal '%3B', Zephyr.percent_encode(';')
|
36
|
+
assert_equal '%3A', Zephyr.percent_encode(':')
|
37
|
+
assert_equal '%40', Zephyr.percent_encode('@')
|
38
|
+
assert_equal '%26', Zephyr.percent_encode('&')
|
39
|
+
assert_equal '%3D', Zephyr.percent_encode('=')
|
40
|
+
assert_equal '%2B', Zephyr.percent_encode('+')
|
41
|
+
assert_equal '%24', Zephyr.percent_encode('$')
|
42
|
+
assert_equal '%2C', Zephyr.percent_encode(',')
|
43
|
+
assert_equal '%2F', Zephyr.percent_encode('/')
|
44
|
+
assert_equal '%3F', Zephyr.percent_encode('?')
|
45
|
+
assert_equal '%23', Zephyr.percent_encode('#')
|
46
|
+
assert_equal '%5B', Zephyr.percent_encode('[')
|
47
|
+
assert_equal '%5D', Zephyr.percent_encode(']')
|
51
48
|
|
52
49
|
# Common Percent Encodings
|
53
|
-
assert_equal '%3C',
|
54
|
-
assert_equal '%3E',
|
55
|
-
assert_equal '%22',
|
56
|
-
assert_equal '%7B',
|
57
|
-
assert_equal '%7D',
|
58
|
-
assert_equal '%7C',
|
59
|
-
assert_equal '%5C',
|
60
|
-
assert_equal '%60',
|
61
|
-
assert_equal '%5E',
|
62
|
-
assert_equal '%25',
|
63
|
-
assert_equal '%20',
|
50
|
+
assert_equal '%3C', Zephyr.percent_encode('<')
|
51
|
+
assert_equal '%3E', Zephyr.percent_encode('>')
|
52
|
+
assert_equal '%22', Zephyr.percent_encode('"')
|
53
|
+
assert_equal '%7B', Zephyr.percent_encode('{')
|
54
|
+
assert_equal '%7D', Zephyr.percent_encode('}')
|
55
|
+
assert_equal '%7C', Zephyr.percent_encode('|')
|
56
|
+
assert_equal '%5C', Zephyr.percent_encode('\\')
|
57
|
+
assert_equal '%60', Zephyr.percent_encode('`')
|
58
|
+
assert_equal '%5E', Zephyr.percent_encode('^')
|
59
|
+
assert_equal '%25', Zephyr.percent_encode('%')
|
60
|
+
assert_equal '%20', Zephyr.percent_encode(' ')
|
64
61
|
|
65
62
|
# Should test for \n as %0A or %0D or %0D%0A
|
66
|
-
assert_contains ['%0A', '%0D', '%0D%0A'],
|
63
|
+
assert_contains ['%0A', '%0D', '%0D%0A'], Zephyr.percent_encode("\n")
|
67
64
|
|
68
65
|
# Should figure out why the will not be percent encoded by libcurl
|
69
66
|
#assert_equal '%2E', zephyr.percent_encode('.')
|
@@ -72,7 +69,21 @@ class TestZephyr < Test::Unit::TestCase
|
|
72
69
|
#assert_equal '%7E', zephyr.percent_encode('~')
|
73
70
|
|
74
71
|
# Fancy
|
75
|
-
assert_equal '%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8',
|
72
|
+
assert_equal '%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8', Zephyr.percent_encode('まつもと')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "using Typhoeus extensions" do
|
77
|
+
should "use Zephyr for escaping" do
|
78
|
+
z = Zephyr.new("http://www.google.com")
|
79
|
+
Zephyr.expects(:percent_encode).times(4)
|
80
|
+
z.get(200, 1000, [{:query => ["test string", "again"]}])
|
81
|
+
end
|
82
|
+
|
83
|
+
should "use Zephyr for building query string" do
|
84
|
+
z = Zephyr.new("http://www.google.com")
|
85
|
+
Zephyr.expects(:build_query_string).times(1)
|
86
|
+
z.get(200, 1000, [{:query => ["test string", "again"]}])
|
76
87
|
end
|
77
88
|
end
|
78
89
|
end
|
data/zephyr.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "zephyr"
|
8
|
-
s.version = "1.1.
|
8
|
+
s.version = "1.1.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Matt Knopp"]
|
12
|
-
s.date = "2012-07-
|
12
|
+
s.date = "2012-07-06"
|
13
13
|
s.description = "Simple HTTP client using Typheous, derived from the Riak client"
|
14
14
|
s.email = "matt.knopp@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"VERSION",
|
27
27
|
"lib/zephyr.rb",
|
28
28
|
"lib/zephyr/failed_request.rb",
|
29
|
+
"lib/ext/typhoeus_ext.rb",
|
29
30
|
"test/helper.rb",
|
30
31
|
"test/test_zephyr.rb",
|
31
32
|
"zephyr.gemspec"
|
@@ -45,6 +46,7 @@ Gem::Specification.new do |s|
|
|
45
46
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
46
47
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
47
48
|
s.add_development_dependency(%q<shoulda>, ["~> 2.11.3"])
|
49
|
+
s.add_development_dependency(%q<mocha>, ["~> 0.12.0"])
|
48
50
|
else
|
49
51
|
s.add_dependency(%q<typhoeus>, [">= 0.2.4"])
|
50
52
|
s.add_dependency(%q<yajl-ruby>, [">= 0"])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zephyr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
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-07-
|
12
|
+
date: 2012-07-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: typhoeus
|
@@ -91,6 +91,22 @@ dependencies:
|
|
91
91
|
- - ~>
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: 2.11.3
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: mocha
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.12.0
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.12.0
|
94
110
|
description: Simple HTTP client using Typheous, derived from the Riak client
|
95
111
|
email: matt.knopp@gmail.com
|
96
112
|
executables: []
|
@@ -108,6 +124,7 @@ files:
|
|
108
124
|
- VERSION
|
109
125
|
- lib/zephyr.rb
|
110
126
|
- lib/zephyr/failed_request.rb
|
127
|
+
- lib/ext/typhoeus_ext.rb
|
111
128
|
- test/helper.rb
|
112
129
|
- test/test_zephyr.rb
|
113
130
|
- zephyr.gemspec
|
@@ -132,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
149
|
version: '0'
|
133
150
|
requirements: []
|
134
151
|
rubyforge_project:
|
135
|
-
rubygems_version: 1.8.
|
152
|
+
rubygems_version: 1.8.24
|
136
153
|
signing_key:
|
137
154
|
specification_version: 3
|
138
155
|
summary: Simple HTTP client using Typheous, derived from the Riak client
|