zephyr 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -0
- data/Rakefile +0 -9
- data/VERSION +1 -1
- data/lib/zephyr.rb +15 -23
- data/test/helper.rb +1 -0
- data/test/test_zephyr.rb +73 -2
- data/zephyr.gemspec +5 -2
- metadata +20 -4
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -42,12 +42,3 @@ end
|
|
42
42
|
|
43
43
|
task :default => :test
|
44
44
|
|
45
|
-
require 'rake/rdoctask'
|
46
|
-
Rake::RDocTask.new do |rdoc|
|
47
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
-
|
49
|
-
rdoc.rdoc_dir = 'rdoc'
|
50
|
-
rdoc.title = "zephyr #{version}"
|
51
|
-
rdoc.rdoc_files.include('README*')
|
52
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
-
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.2
|
data/lib/zephyr.rb
CHANGED
@@ -15,20 +15,22 @@
|
|
15
15
|
|
16
16
|
# Splits headers into < 8KB chunks
|
17
17
|
# @private
|
18
|
-
module Net
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
18
|
+
module Net
|
19
|
+
module HTTPHeader
|
20
|
+
def each_capitalized
|
21
|
+
# 1.9 check
|
22
|
+
respond_to?(:enum_for) and (block_given? or return enum_for(__method__))
|
23
|
+
@header.each do |k,v|
|
24
|
+
base_length = "#{k}: \r\n".length
|
25
|
+
values = v.map { |i| i.to_s.split(', ') }.flatten
|
26
|
+
while !values.empty?
|
27
|
+
current_line = ""
|
28
|
+
while values.first && current_line.length + base_length + values.first.length + 2 < 8192
|
29
|
+
val = values.shift.strip
|
30
|
+
current_line += current_line.empty? ? val : ", #{val}"
|
31
|
+
end
|
32
|
+
yield capitalize(k), current_line
|
30
33
|
end
|
31
|
-
yield capitalize(k), current_line
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -64,8 +66,6 @@ class Zephyr
|
|
64
66
|
perform(:head, path_components, headers, expected_statuses, timeout)
|
65
67
|
end
|
66
68
|
|
67
|
-
Workfeed::Timer.time_method self, :head, 'http_head'
|
68
|
-
|
69
69
|
# Performs a GET request to the specified resource.
|
70
70
|
#
|
71
71
|
# A request to /users/#{@user.id}/things?q=woof with an Accept header of
|
@@ -83,8 +83,6 @@ class Zephyr
|
|
83
83
|
perform(:get, path_components, headers, expected_statuses, timeout)
|
84
84
|
end
|
85
85
|
|
86
|
-
Workfeed::Timer.time_method self, :get, 'http_get'
|
87
|
-
|
88
86
|
# The same thing as #get, but decodes the response entity as JSON (if it's
|
89
87
|
# application/json) and adds it under the :json key in the returned hash.
|
90
88
|
def get_json(expected_statuses, timeout, path_components, headers={}, yajl_opts={})
|
@@ -118,8 +116,6 @@ class Zephyr
|
|
118
116
|
perform(:put, path_components, headers, expected_statuses, timeout, entity)
|
119
117
|
end
|
120
118
|
|
121
|
-
Workfeed::Timer.time_method self, :put, 'http_put'
|
122
|
-
|
123
119
|
# The same thing as #put, but encodes the entity as JSON and specifies
|
124
120
|
# "application/json" as the request entity content type.
|
125
121
|
def put_json(expected_statuses, timeout, path_components, entity, headers={})
|
@@ -144,8 +140,6 @@ class Zephyr
|
|
144
140
|
perform(:post, path_components, headers, expected_statuses, timeout, entity)
|
145
141
|
end
|
146
142
|
|
147
|
-
Workfeed::Timer.time_method self, :post, 'http_post'
|
148
|
-
|
149
143
|
# The same thing as #post, but encodes the entity as JSON and specifies
|
150
144
|
# "application/json" as the request entity content type.
|
151
145
|
def post_json(expected_statuses, timeout, path_components, entity, headers={})
|
@@ -175,8 +169,6 @@ class Zephyr
|
|
175
169
|
perform(:delete, path_components, headers, expected_statuses, timeout)
|
176
170
|
end
|
177
171
|
|
178
|
-
Workfeed::Timer.time_method self, :delete, 'http_delete'
|
179
|
-
|
180
172
|
# Creates a URI object, combining the root_uri passed on initialization
|
181
173
|
# with the given parts.
|
182
174
|
#
|
data/test/helper.rb
CHANGED
data/test/test_zephyr.rb
CHANGED
@@ -1,7 +1,78 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestZephyr < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
context "urls" do
|
6
|
+
should "be canonicalized" do
|
7
|
+
assert_equal 'http://example.com/', Zephyr.new('http://example.com').uri.to_s
|
8
|
+
assert_equal 'http://example.com/', Zephyr.new('http://example.com/').uri.to_s
|
9
|
+
assert_equal 'http://example.com/', Zephyr.new('http://example.com//').uri.to_s
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "query string parameters" do
|
14
|
+
should "be sorted" do
|
15
|
+
zephyr = Zephyr.new
|
16
|
+
duples = ('a'..'z').zip('A'..'Z') # [ [ 'a', 'A' ], [ 'b', 'B' ], ... ]
|
17
|
+
expected = duples.map { |l,u| '%s=%s' % [ l, u ] }.sort.join('&')
|
18
|
+
|
19
|
+
assert_equal expected, zephyr.build_query_string(Hash[duples.shuffle])
|
20
|
+
end
|
21
|
+
|
22
|
+
should "be constructed for arrays" do
|
23
|
+
zephyr = Zephyr.new
|
24
|
+
assert_equal 'a=1&a=2', zephyr.build_query_string(:a => [ 2, 1 ])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "percent encoding" do
|
29
|
+
should "be correct" do
|
30
|
+
zephyr = Zephyr.new
|
31
|
+
|
32
|
+
# RFC 3986 Reserved Characters
|
33
|
+
assert_equal '%21', zephyr.percent_encode('!')
|
34
|
+
assert_equal '%2A', zephyr.percent_encode('*')
|
35
|
+
assert_equal '%27', zephyr.percent_encode("'")
|
36
|
+
assert_equal '%28', zephyr.percent_encode('(')
|
37
|
+
assert_equal '%29', zephyr.percent_encode(')')
|
38
|
+
assert_equal '%3B', zephyr.percent_encode(';')
|
39
|
+
assert_equal '%3A', zephyr.percent_encode(':')
|
40
|
+
assert_equal '%40', zephyr.percent_encode('@')
|
41
|
+
assert_equal '%26', zephyr.percent_encode('&')
|
42
|
+
assert_equal '%3D', zephyr.percent_encode('=')
|
43
|
+
assert_equal '%2B', zephyr.percent_encode('+')
|
44
|
+
assert_equal '%24', zephyr.percent_encode('$')
|
45
|
+
assert_equal '%2C', zephyr.percent_encode(',')
|
46
|
+
assert_equal '%2F', zephyr.percent_encode('/')
|
47
|
+
assert_equal '%3F', zephyr.percent_encode('?')
|
48
|
+
assert_equal '%23', zephyr.percent_encode('#')
|
49
|
+
assert_equal '%5B', zephyr.percent_encode('[')
|
50
|
+
assert_equal '%5D', zephyr.percent_encode(']')
|
51
|
+
|
52
|
+
# Common Percent Encodings
|
53
|
+
assert_equal '%3C', zephyr.percent_encode('<')
|
54
|
+
assert_equal '%3E', zephyr.percent_encode('>')
|
55
|
+
assert_equal '%22', zephyr.percent_encode('"')
|
56
|
+
assert_equal '%7B', zephyr.percent_encode('{')
|
57
|
+
assert_equal '%7D', zephyr.percent_encode('}')
|
58
|
+
assert_equal '%7C', zephyr.percent_encode('|')
|
59
|
+
assert_equal '%5C', zephyr.percent_encode('\\')
|
60
|
+
assert_equal '%60', zephyr.percent_encode('`')
|
61
|
+
assert_equal '%5E', zephyr.percent_encode('^')
|
62
|
+
assert_equal '%25', zephyr.percent_encode('%')
|
63
|
+
assert_equal '%20', zephyr.percent_encode(' ')
|
64
|
+
|
65
|
+
# Should test for \n as %0A or %0D or %0D%0A
|
66
|
+
assert_contains ['%0A', '%0D', '%0D%0A'], zephyr.percent_encode("\n")
|
67
|
+
|
68
|
+
# Should figure out why the will not be percent encoded by libcurl
|
69
|
+
#assert_equal '%2E', zephyr.percent_encode('.')
|
70
|
+
#assert_equal '%2D', zephyr.percent_encode('-')
|
71
|
+
#assert_equal '%5F', zephyr.percent_encode('_')
|
72
|
+
#assert_equal '%7E', zephyr.percent_encode('~')
|
73
|
+
|
74
|
+
# Fancy
|
75
|
+
assert_equal '%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8', zephyr.percent_encode('まつもと')
|
76
|
+
end
|
6
77
|
end
|
7
78
|
end
|
data/zephyr.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{zephyr}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.2"
|
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 = %q{2011-
|
12
|
+
s.date = %q{2011-10-03}
|
13
13
|
s.description = %q{Simple HTTP client using Typheous, derived from the Riak client}
|
14
14
|
s.email = %q{matt.knopp@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -42,15 +42,18 @@ Gem::Specification.new do |s|
|
|
42
42
|
s.add_runtime_dependency(%q<typhoeus>, [">= 0.2.4"])
|
43
43
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
44
44
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
45
|
+
s.add_development_dependency(%q<shoulda>, ["~> 2.11.3"])
|
45
46
|
else
|
46
47
|
s.add_dependency(%q<typhoeus>, [">= 0.2.4"])
|
47
48
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
48
49
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
50
|
+
s.add_dependency(%q<shoulda>, ["~> 2.11.3"])
|
49
51
|
end
|
50
52
|
else
|
51
53
|
s.add_dependency(%q<typhoeus>, [">= 0.2.4"])
|
52
54
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
53
55
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
56
|
+
s.add_dependency(%q<shoulda>, ["~> 2.11.3"])
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zephyr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt Knopp
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-03 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -66,6 +66,22 @@ dependencies:
|
|
66
66
|
prerelease: false
|
67
67
|
type: :development
|
68
68
|
requirement: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: shoulda
|
71
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 37
|
77
|
+
segments:
|
78
|
+
- 2
|
79
|
+
- 11
|
80
|
+
- 3
|
81
|
+
version: 2.11.3
|
82
|
+
prerelease: false
|
83
|
+
type: :development
|
84
|
+
requirement: *id004
|
69
85
|
description: Simple HTTP client using Typheous, derived from the Riak client
|
70
86
|
email: matt.knopp@gmail.com
|
71
87
|
executables: []
|