rest-client 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rest-client might be problematic. Click here for more details.
- data/Rakefile +1 -1
- data/lib/request_errors.rb +16 -13
- data/lib/rest_client.rb +2 -2
- data/spec/request_errors_spec.rb +10 -0
- metadata +6 -6
data/Rakefile
CHANGED
data/lib/request_errors.rb
CHANGED
@@ -7,6 +7,19 @@ module RestClient
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
+
# Base RestClient exception when there's a response available
|
11
|
+
class ExceptionWithResponse < Exception
|
12
|
+
attr_accessor :response
|
13
|
+
|
14
|
+
def initialize(response=nil)
|
15
|
+
@response = response
|
16
|
+
end
|
17
|
+
|
18
|
+
def http_code
|
19
|
+
@response.code.to_i if @response
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
10
23
|
# A redirect was encountered; caught by execute to retry with the new url.
|
11
24
|
class Redirect < Exception
|
12
25
|
ErrorMessage = "Redirect"
|
@@ -18,12 +31,12 @@ module RestClient
|
|
18
31
|
end
|
19
32
|
|
20
33
|
# Authorization is required to access the resource specified.
|
21
|
-
class Unauthorized <
|
34
|
+
class Unauthorized < ExceptionWithResponse
|
22
35
|
ErrorMessage = 'Unauthorized'
|
23
36
|
end
|
24
37
|
|
25
38
|
# No resource was found at the given URL.
|
26
|
-
class ResourceNotFound <
|
39
|
+
class ResourceNotFound < ExceptionWithResponse
|
27
40
|
ErrorMessage = 'Resource not found'
|
28
41
|
end
|
29
42
|
|
@@ -46,17 +59,7 @@ module RestClient
|
|
46
59
|
# You can get the status code by e.http_code, or see anything about the
|
47
60
|
# response via e.response. For example, the entire result body (which is
|
48
61
|
# probably an HTML error page) is e.response.body.
|
49
|
-
class RequestFailed <
|
50
|
-
attr_accessor :response
|
51
|
-
|
52
|
-
def initialize(response=nil)
|
53
|
-
@response = response
|
54
|
-
end
|
55
|
-
|
56
|
-
def http_code
|
57
|
-
@response.code.to_i if @response
|
58
|
-
end
|
59
|
-
|
62
|
+
class RequestFailed < ExceptionWithResponse
|
60
63
|
def message
|
61
64
|
"HTTP status code #{http_code}"
|
62
65
|
end
|
data/lib/rest_client.rb
CHANGED
@@ -201,9 +201,9 @@ module RestClient
|
|
201
201
|
|
202
202
|
raise Redirect, url
|
203
203
|
elsif res.code == "401"
|
204
|
-
raise Unauthorized
|
204
|
+
raise Unauthorized, res
|
205
205
|
elsif res.code == "404"
|
206
|
-
raise ResourceNotFound
|
206
|
+
raise ResourceNotFound, res
|
207
207
|
else
|
208
208
|
raise RequestFailed, res
|
209
209
|
end
|
data/spec/request_errors_spec.rb
CHANGED
@@ -29,6 +29,16 @@ describe RestClient::RequestFailed do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
describe RestClient::ResourceNotFound do
|
33
|
+
it "also has the http response attached" do
|
34
|
+
begin
|
35
|
+
raise RestClient::ResourceNotFound, :response
|
36
|
+
rescue RestClient::ResourceNotFound => e
|
37
|
+
e.response.should == :response
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
32
42
|
describe "backwards compatibility" do
|
33
43
|
it "alias RestClient::Request::Redirect to RestClient::Redirect" do
|
34
44
|
RestClient::Request::Redirect.should == RestClient::Redirect
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Wiggins
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-03 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -23,13 +23,13 @@ extra_rdoc_files: []
|
|
23
23
|
|
24
24
|
files:
|
25
25
|
- Rakefile
|
26
|
+
- lib/request_errors.rb
|
26
27
|
- lib/resource.rb
|
27
28
|
- lib/rest_client.rb
|
28
|
-
-
|
29
|
-
- spec/resource_spec.rb
|
29
|
+
- spec/base.rb
|
30
30
|
- spec/request_errors_spec.rb
|
31
|
+
- spec/resource_spec.rb
|
31
32
|
- spec/rest_client_spec.rb
|
32
|
-
- spec/base.rb
|
33
33
|
has_rdoc: true
|
34
34
|
homepage: http://rest-client.heroku.com/
|
35
35
|
post_install_message:
|
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
52
|
requirements: []
|
53
53
|
|
54
54
|
rubyforge_project: rest-client
|
55
|
-
rubygems_version: 1.
|
55
|
+
rubygems_version: 1.3.1
|
56
56
|
signing_key:
|
57
57
|
specification_version: 2
|
58
58
|
summary: Simple REST client for Ruby, inspired by microframework syntax for specifying actions.
|