zephyr 1.1.7 → 1.1.8

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.
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gem "yajl-ruby"
5
5
 
6
6
 
7
7
  group :development do
8
- gem "bundler", "~> 1.0.0"
8
+ gem "bundler", "~> 1.0.21"
9
9
  gem "jeweler", "~> 1.6.4"
10
10
  gem "shoulda", "~> 2.11.3"
11
11
  gem "mocha", "~> 0.12.0", :require => false
data/Gemfile.lock CHANGED
@@ -10,7 +10,7 @@ GEM
10
10
  mime-types (1.16)
11
11
  mocha (0.12.0)
12
12
  metaclass (~> 0.0.1)
13
- rake (0.9.2)
13
+ rake (0.9.2.2)
14
14
  shoulda (2.11.3)
15
15
  typhoeus (0.2.4)
16
16
  mime-types
@@ -21,7 +21,7 @@ PLATFORMS
21
21
  ruby
22
22
 
23
23
  DEPENDENCIES
24
- bundler (~> 1.0.0)
24
+ bundler (~> 1.0.21)
25
25
  jeweler (~> 1.6.4)
26
26
  mocha (~> 0.12.0)
27
27
  shoulda (~> 2.11.3)
data/Rakefile CHANGED
@@ -17,8 +17,8 @@ Jeweler::Tasks.new do |gem|
17
17
  gem.name = "zephyr"
18
18
  gem.homepage = "http://github.com/mhat/zephyr"
19
19
  gem.license = "MIT"
20
- gem.summary = %Q{Simple HTTP client using Typheous, derived from the Riak client}
21
- gem.description = %Q{Simple HTTP client using Typheous, derived from the Riak client}
20
+ gem.summary = %Q{Battle-tested HTTP client using Typhoeus, derived from the Riak client}
21
+ gem.description = %Q{Battle-tested HTTP client using Typhoeus, derived from the Riak client}
22
22
  gem.email = "matt.knopp@gmail.com"
23
23
  gem.authors = ["Matt Knopp"]
24
24
  # dependencies defined in Gemfile
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.7
1
+ 1.1.8
data/lib/zephyr.rb CHANGED
@@ -218,6 +218,22 @@ class Zephyr
218
218
  perform(:delete, path_components, headers, expected_statuses, timeout)
219
219
  end
220
220
 
221
+ # Performs a custom HTTP method request to the specified resource.
222
+ #
223
+ # A PURGE request to /users/#{@user.id} which is expecting a 200 OK within 666ms
224
+ #
225
+ # http.custom(:purge, 200, 666, ["users", @user.id])
226
+ #
227
+ # This returns a hash with three keys:
228
+ # :status The numeric HTTP status code
229
+ # :body The body of the response entity, if any
230
+ # :headers A hash of header values
231
+ def custom(method, expected_statuses, timeout, path_components, headers={})
232
+ headers = default_headers.merge(headers)
233
+ verify_path!(path_components)
234
+ perform(method, path_components, headers, expected_statuses, timeout)
235
+ end
236
+
221
237
  # Creates a URI object, combining the root_uri passed on initialization
222
238
  # with the given parts.
223
239
  #
@@ -272,6 +288,7 @@ class Zephyr
272
288
  params[:timeout] = timeout
273
289
  params[:follow_location] = false
274
290
  params[:params] = path_components.pop if path_components.last.is_a?(Hash)
291
+ params[:method] = method
275
292
 
276
293
  # seriously, why is this on by default
277
294
  Typhoeus::Hydra.hydra.disable_memoization
@@ -285,9 +302,8 @@ class Zephyr
285
302
  params[:body] = data if data != ''
286
303
  end
287
304
 
288
- # request has class methods for :delete, :get, :head, :put, and :post
289
305
  http_start = Time.now.to_f
290
- response = Typhoeus::Request.send(method, uri(path_components).to_s, params)
306
+ response = Typhoeus::Request.run(uri(path_components).to_s, params)
291
307
  http_end = Time.now.to_f
292
308
 
293
309
  Zephyr.logger.info "[zephyr:#{$$}:#{Time.now.to_f}] \"%s %s\" %s %0.4f" % [
data/test/test_zephyr.rb CHANGED
@@ -1,6 +1,15 @@
1
+ # encoding: utf-8
1
2
  require 'helper'
2
3
 
3
4
  class TestZephyr < Test::Unit::TestCase
5
+ PARAMS = { :method => :get, :timeout => 1000,
6
+ :params => [{:query => ["test string", "again"]}] }
7
+
8
+ TYPHOEUS_RESPONSE = Typhoeus::Response.new(
9
+ :code => 200,
10
+ :body => '',
11
+ :request => Typhoeus::Request.new("http://www.example.com")
12
+ )
4
13
 
5
14
  context "urls" do
6
15
  should "be canonicalized" do
@@ -79,15 +88,71 @@ class TestZephyr < Test::Unit::TestCase
79
88
  end
80
89
 
81
90
  should "use Zephyr for escaping" do
82
- z = Zephyr.new("http://www.google.com")
83
- Zephyr.expects(:percent_encode).times(4)
84
- z.get(200, 1000, [{:query => ["test string", "まつもと"]}])
91
+ r = Typhoeus::Request.new("http://www.google.com", PARAMS)
92
+ Zephyr.expects(:percent_encode).times(2)
93
+ r.params_string
85
94
  end
86
95
 
87
96
  should "use Zephyr for building query string" do
88
- z = Zephyr.new("http://www.google.com")
97
+ r = Typhoeus::Request.new("http://www.google.com", PARAMS)
89
98
  Zephyr.expects(:build_query_string).times(1)
90
- z.get(200, 1000, [{:query => ["test string", "again"]}])
99
+ r.params_string
91
100
  end
92
101
  end
102
+
103
+ should "support HTTP GET" do
104
+ z = Zephyr.new("http://www.example.com")
105
+ Typhoeus::Request.expects(:run).with do |uri, params|
106
+ params[:method] == :get && uri == 'http://www.example.com/images/1'
107
+ end.returns(TYPHOEUS_RESPONSE)
108
+ z.get(200, 1, ["images", "1"])
109
+ end
110
+
111
+ should "support HTTP POST" do
112
+ post_response = Typhoeus::Response.new(
113
+ :code => 201,
114
+ :body => '',
115
+ :request => Typhoeus::Request.new("http://www.example.com")
116
+ )
117
+
118
+ z = Zephyr.new("http://www.example.com")
119
+ Typhoeus::Request.expects(:run).with do |uri, params|
120
+ params[:method] == :post &&
121
+ params[:params] == {:name => 'Test User'} &&
122
+ uri == 'http://www.example.com/users'
123
+ end.returns(post_response)
124
+ z.post(201, 1, ["users", {:name => 'Test User'}], '')
125
+ end
126
+
127
+ should "support HTTP PUT" do
128
+ z = Zephyr.new("http://www.example.com")
129
+ Typhoeus::Request.expects(:run).with do |uri, params|
130
+ params[:method] == :put &&
131
+ params[:params] == {:name => 'Test User'} &&
132
+ uri == 'http://www.example.com/users/1'
133
+ end.returns(TYPHOEUS_RESPONSE)
134
+ z.put(200, 1, ["users", 1, {:name => 'Test User'}], '')
135
+ end
136
+
137
+ should "support HTTP DELETE" do
138
+ delete_response = Typhoeus::Response.new(
139
+ :code => 204,
140
+ :body => '',
141
+ :request => Typhoeus::Request.new("http://www.example.com")
142
+ )
143
+
144
+ z = Zephyr.new("http://www.example.com")
145
+ Typhoeus::Request.expects(:run).with do |uri, params|
146
+ params[:method] == :delete && uri == 'http://www.example.com/users/1'
147
+ end.returns(delete_response)
148
+ z.delete(204, 1, ["users", 1])
149
+ end
150
+
151
+ should "support custom HTTP methods" do
152
+ z = Zephyr.new("http://www.example.com")
153
+ Typhoeus::Request.expects(:run).with do |uri, params|
154
+ params[:method] == :purge
155
+ end.returns(TYPHOEUS_RESPONSE)
156
+ z.custom(:purge, 200, 1, ["images", "4271e4c1594adc92651cf431029429d8"])
157
+ end
93
158
  end
data/zephyr.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "zephyr"
8
- s.version = "1.1.7"
8
+ s.version = "1.1.8"
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
12
  s.date = "2012-07-27"
13
- s.description = "Simple HTTP client using Typhoeus, derived from the Riak client"
13
+ s.description = "Battle-tested HTTP client using Typhoeus, derived from the Riak client"
14
14
  s.email = "matt.knopp@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
35
35
  s.licenses = ["MIT"]
36
36
  s.require_paths = ["lib"]
37
37
  s.rubygems_version = "1.8.11"
38
- s.summary = "Simple HTTP client using Typhoeus, derived from the Riak client"
38
+ s.summary = "Battle-tested HTTP client using Typhoeus, derived from the Riak client"
39
39
 
40
40
  if s.respond_to? :specification_version then
41
41
  s.specification_version = 3
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.7
4
+ version: 1.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -107,7 +107,7 @@ dependencies:
107
107
  - - ~>
108
108
  - !ruby/object:Gem::Version
109
109
  version: 0.12.0
110
- description: Simple HTTP client using Typhoeus, derived from the Riak client
110
+ description: Battle-tested HTTP client using Typhoeus, derived from the Riak client
111
111
  email: matt.knopp@gmail.com
112
112
  executables: []
113
113
  extensions: []
@@ -152,5 +152,5 @@ rubyforge_project:
152
152
  rubygems_version: 1.8.24
153
153
  signing_key:
154
154
  specification_version: 3
155
- summary: Simple HTTP client using Typhoeus, derived from the Riak client
155
+ summary: Battle-tested HTTP client using Typhoeus, derived from the Riak client
156
156
  test_files: []