nestful 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd97aa5fb848801d10cc36bfcc8a1f1d3997393e
4
- data.tar.gz: a7f428dd9f1d1f363e8834f5180511d2eeec7036
3
+ metadata.gz: 5b7d6e5baffbf7d32a64d374b1e6b37dcb54417a
4
+ data.tar.gz: 45d87dc4273b826411fcf2f0c06d7e8a263dd175
5
5
  SHA512:
6
- metadata.gz: 28b12558ec65700945a6a594a42710174114e3f87c56350aca183265d3be2a1e41ffb24db9468a81dbe17618982733d401395e65c0ce65710c7578c1182d6244
7
- data.tar.gz: 2e10eec7723fbfb4cb5f291b7a904c1ce0e1f81927a5705a8332e41d7f5d171bfe6af8007f23b7fcf6574059679b5fb79f76fa8be43117d3824f60a25e26bb21
6
+ metadata.gz: f21c61bf0ab954f6974b93a13b669f95d023256410609c1522fd43ab7cb6f1be2b646083581acd66c63fe12a058faec8ecc32fc6a08f040e139296eec04c5077
7
+ data.tar.gz: b50d117f9b93444b8312bcfe141a85fb905f029f7f28b7ccd740bfc00f225e7b87b20448dc91504d078c1b054bacf1710bc7432082386148ff1b59c4e86dad4d
@@ -44,12 +44,20 @@ module Nestful
44
44
  request(:put, path, body, headers, &block)
45
45
  end
46
46
 
47
+ def patch(path, body = '', headers = {}, &block)
48
+ request(:patch, path, body, headers, &block)
49
+ end
50
+
47
51
  def post(path, body = '', headers = {}, &block)
48
52
  request(:post, path, body, headers, &block)
49
53
  end
50
54
 
51
55
  protected
52
56
 
57
+ def request=(request)
58
+ @request = request
59
+ end
60
+
53
61
  # Makes a request to the remote service.
54
62
  def request(method, path, *arguments)
55
63
  response = http.send(method, path, *arguments)
@@ -58,9 +66,9 @@ module Nestful
58
66
  handle_response(response)
59
67
 
60
68
  rescue Timeout::Error, Net::OpenTimeout => e
61
- raise TimeoutError.new(e.message)
69
+ raise TimeoutError.new(@request, e.message)
62
70
  rescue OpenSSL::SSL::SSLError => e
63
- raise SSLError.new(e.message)
71
+ raise SSLError.new(@request, e.message)
64
72
  rescue SocketError,
65
73
  EOFError,
66
74
  Net::HTTPBadResponse,
@@ -75,10 +83,10 @@ module Nestful
75
83
  Errno::EHOSTUNREACH,
76
84
  Errno::EINVAL,
77
85
  Errno::ENOPROTOOPT => e
78
- raise ErrnoError.new(e.message)
86
+ raise ErrnoError.new(@request, e.message)
79
87
  rescue Zlib::DataError,
80
88
  Zlib::BufError => e
81
- raise ZlibError.new(e.message)
89
+ raise ZlibError.new(@request, e.message)
82
90
  end
83
91
 
84
92
  # Handles response and error codes from the remote service.
@@ -87,30 +95,30 @@ module Nestful
87
95
  when 200...299
88
96
  response
89
97
  when 300..399
90
- raise Redirection.new(response)
98
+ raise Redirection.new(@request, response)
91
99
  when 400
92
- raise BadRequest.new(response)
100
+ raise BadRequest.new(@request, response)
93
101
  when 401
94
- raise UnauthorizedAccess.new(response)
102
+ raise UnauthorizedAccess.new(@request, response)
95
103
  when 403
96
- raise ForbiddenAccess.new(response)
104
+ raise ForbiddenAccess.new(@request, response)
97
105
  when 404
98
- raise ResourceNotFound.new(response)
106
+ raise ResourceNotFound.new(@request, response)
99
107
  when 405
100
- raise MethodNotAllowed.new(response)
108
+ raise MethodNotAllowed.new(@request, response)
101
109
  when 409
102
- raise ResourceConflict.new(response)
110
+ raise ResourceConflict.new(@request, response)
103
111
  when 410
104
- raise ResourceGone.new(response)
112
+ raise ResourceGone.new(@request, response)
105
113
  when 422
106
- raise ResourceInvalid.new(response)
114
+ raise ResourceInvalid.new(@request, response)
107
115
  when 401...500
108
- raise ClientError.new(response)
116
+ raise ClientError.new(@request, response)
109
117
  when 500...600
110
- raise ServerError.new(response)
118
+ raise ServerError.new(@request, response)
111
119
  else
112
120
  raise ResponseError.new(
113
- response, "Unknown response code: #{response.code}"
121
+ @request, response, "Unknown response code: #{response.code}"
114
122
  )
115
123
  end
116
124
  end
@@ -1,23 +1,22 @@
1
1
  module Nestful
2
- class Error < StandardError; end
3
- ConnectionError = Error
4
-
5
- class RequestError < Error
6
- def initialize(message)
7
- @message = message
8
- end
2
+ class Error < StandardError
3
+ attr_reader :request
9
4
 
10
- def to_s
11
- @message
5
+ def initialize(request = nil, message = nil)
6
+ super(message)
7
+ @request = request
12
8
  end
13
9
  end
14
10
 
11
+ ConnectionError = Error
12
+ RequestError = Error
13
+
15
14
  class ResponseError < Error
16
15
  attr_reader :response
17
16
 
18
- def initialize(response, message = nil)
17
+ def initialize(request, response, message = nil)
18
+ super(request, message)
19
19
  @response = response
20
- @message = message
21
20
  end
22
21
 
23
22
  def to_s
@@ -100,7 +100,7 @@ module Nestful
100
100
  attempts += 1
101
101
 
102
102
  raise error unless error.response['Location']
103
- raise RedirectionLoop.new(error.response) if attempts > max_attempts
103
+ raise RedirectionLoop.new(self, error.response) if attempts > max_attempts
104
104
 
105
105
  location = error.response['Location'].scrub
106
106
  location = URI.parse(location)
@@ -119,7 +119,8 @@ module Nestful
119
119
  Connection.new(uri,
120
120
  :proxy => proxy,
121
121
  :timeout => timeout,
122
- :ssl_options => ssl_options
122
+ :ssl_options => ssl_options,
123
+ :request => self
123
124
  )
124
125
  end
125
126
 
@@ -1,3 +1,3 @@
1
1
  module Nestful
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -29,6 +29,12 @@ class TestRequest < MiniTest::Unit::TestCase
29
29
  assert_requested(:put, 'http://example.com/v1/tokens')
30
30
  end
31
31
 
32
+ def test_patch
33
+ stub_request(:any, 'http://example.com/v1/tokens')
34
+ Nestful::Request.new('http://example.com/v1/tokens', :method => :patch).execute
35
+ assert_requested(:patch, 'http://example.com/v1/tokens')
36
+ end
37
+
32
38
  def test_head
33
39
  stub_request(:any, 'http://example.com/v1/tokens')
34
40
  Nestful::Request.new('http://example.com/v1/tokens', :method => :head).execute
@@ -35,6 +35,16 @@ class TestResponse < MiniTest::Unit::TestCase
35
35
  assert_equal 201, response.status
36
36
  end
37
37
 
38
+ def test_errors_include_request
39
+ stub_request(:any, 'http://example.com/v1/charges').to_return(:status => 404)
40
+
41
+ begin
42
+ Nestful.get('http://example.com/v1/charges')
43
+ rescue Nestful::ResourceNotFound => e
44
+ assert_equal 'http://example.com/v1/charges', e.request.url
45
+ end
46
+ end
47
+
38
48
  def test_raises_404
39
49
  stub_request(:any, 'http://example.com/v1/charges').to_return(:status => 404)
40
50
 
@@ -58,4 +68,4 @@ class TestResponse < MiniTest::Unit::TestCase
58
68
  assert response.respond_to?(:fetch)
59
69
  assert response.fetch('result')
60
70
  end
61
- end
71
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nestful
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex MacCaw
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-09 00:00:00.000000000 Z
11
+ date: 2015-08-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -72,4 +72,3 @@ test_files:
72
72
  - test/nestful/test_request.rb
73
73
  - test/nestful/test_resource.rb
74
74
  - test/nestful/test_response.rb
75
- has_rdoc: