zephyr 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.1.2
@@ -0,0 +1,38 @@
1
+ class Zephyr
2
+ # Raised when a request fails due to either a timeout or when the expected
3
+ # response code does not match the actual response code.
4
+ class FailedRequest < StandardError
5
+ attr_reader :method, :uri, :expected_code, :timeout, :response
6
+
7
+ # The following options are required:
8
+ #
9
+ # method - The HTTP method used for the request.
10
+ # uri - The uri of the request.
11
+ # expected_code - The expected response code for the request.
12
+ # timeout - The timeout (in milliseconds) for the request.
13
+ # response - The response.
14
+ def initialize(options)
15
+ @method = options[:method].to_s.upcase
16
+ @uri = options[:uri]
17
+ @expected_code = options[:expected_code]
18
+ @timeout = options[:timeout]
19
+ @response = options[:response]
20
+
21
+ super "#{@method} #{@uri} - #{error_message}"
22
+ end
23
+
24
+ # Returns whether the request timed out.
25
+ def timed_out?
26
+ @response.timed_out? || @response.code == 0
27
+ end
28
+
29
+ private
30
+ def error_message
31
+ if timed_out?
32
+ "Response exceeded #{@timeout}ms."
33
+ else
34
+ "Expected #{@expected_code} from the server but received #{@response.code}."
35
+ end
36
+ end
37
+ end
38
+ end
data/lib/zephyr.rb CHANGED
@@ -43,6 +43,8 @@ end
43
43
 
44
44
  # A simple front-end for doing HTTP requests quickly and simply.
45
45
  class Zephyr
46
+ autoload :FailedRequest, "zephyr/failed_request"
47
+
46
48
  def initialize(root_uri = '')
47
49
  @root_uri = URI.parse(root_uri.to_s).freeze
48
50
  end
@@ -300,9 +302,12 @@ class Zephyr
300
302
  end
301
303
  result
302
304
  else
303
- response_body = response.timed_out? || response.code == 0 ? "Exceeded #{timeout}ms" : response.body
304
- failed_request = FailedRequest.new(method, expect, response.code, response_headers.to_hash, response_body, response.timed_out?)
305
- Zephyr.logger.error "[zephyr:#{$$}:#{Time.now.to_f}]: #{ failed_request }"
305
+ failed_request = FailedRequest.new(:method => method,
306
+ :uri => uri(path_components),
307
+ :expected_code => expect,
308
+ :timeout => timeout,
309
+ :response => response)
310
+ Zephyr.logger.error "[zephyr:#{$$}:#{Time.now.to_f}]: #{failed_request}"
306
311
  raise failed_request
307
312
  end
308
313
  end
@@ -356,17 +361,3 @@ class Headers
356
361
  add_field(key, value) if key && value
357
362
  end
358
363
  end
359
-
360
- class FailedRequest < StandardError
361
- attr_reader :method
362
- attr_reader :expected
363
- attr_reader :code
364
- attr_reader :headers
365
- attr_reader :body
366
- attr_reader :timed_out
367
-
368
- def initialize(method, expected_code, received_code, headers, body, timed_out)
369
- @method, @expected, @code, @headers, @body, @timed_out = method, expected_code, received_code, headers, body, timed_out
370
- super "Expected #{@expected.inspect} from the server but received #{@code}. #{@body}"
371
- end
372
- 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.1"
8
+ s.version = "1.1.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 = "2012-02-17"
12
+ s.date = "2012-03-16"
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 = [
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "lib/zephyr.rb",
28
+ "lib/zephyr/failed_request.rb",
28
29
  "test/helper.rb",
29
30
  "test/test_zephyr.rb",
30
31
  "zephyr.gemspec"
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.1
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-17 00:00:00.000000000 Z
12
+ date: 2012-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: typhoeus
16
- requirement: &70113484381080 !ruby/object:Gem::Requirement
16
+ requirement: &70159647046820 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.2.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70113484381080
24
+ version_requirements: *70159647046820
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yajl-ruby
27
- requirement: &70113484380360 !ruby/object:Gem::Requirement
27
+ requirement: &70159647045860 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70113484380360
35
+ version_requirements: *70159647045860
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &70113484379780 !ruby/object:Gem::Requirement
38
+ requirement: &70159646995840 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70113484379780
46
+ version_requirements: *70159646995840
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &70113484379100 !ruby/object:Gem::Requirement
49
+ requirement: &70159646993360 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70113484379100
57
+ version_requirements: *70159646993360
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: shoulda
60
- requirement: &70113484378520 !ruby/object:Gem::Requirement
60
+ requirement: &70159646992740 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 2.11.3
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70113484378520
68
+ version_requirements: *70159646992740
69
69
  description: Simple HTTP client using Typheous, derived from the Riak client
70
70
  email: matt.knopp@gmail.com
71
71
  executables: []
@@ -82,6 +82,7 @@ files:
82
82
  - Rakefile
83
83
  - VERSION
84
84
  - lib/zephyr.rb
85
+ - lib/zephyr/failed_request.rb
85
86
  - test/helper.rb
86
87
  - test/test_zephyr.rb
87
88
  - zephyr.gemspec
@@ -100,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
101
  version: '0'
101
102
  segments:
102
103
  - 0
103
- hash: 13337105164833368
104
+ hash: 2863491660694697364
104
105
  required_rubygems_version: !ruby/object:Gem::Requirement
105
106
  none: false
106
107
  requirements: