api-client 0.3.0 → 0.4.0
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/lib/api_client.rb +3 -0
- data/lib/api_client/exceptions.rb +3 -0
- data/lib/api_client/exceptions/bad_gateway.rb +5 -0
- data/lib/api_client/exceptions/internal_server_error.rb +5 -0
- data/lib/api_client/exceptions/service_unavailable.rb +5 -0
- data/lib/api_client/version.rb +1 -1
- data/spec/api_client_spec.rb +60 -0
- metadata +7 -4
data/lib/api_client.rb
CHANGED
|
@@ -21,6 +21,9 @@ module ApiClient
|
|
|
21
21
|
when '401' then raise ApiClient::Exceptions::Unauthorized
|
|
22
22
|
when '403' then raise ApiClient::Exceptions::Forbidden
|
|
23
23
|
when '404' then raise ApiClient::Exceptions::NotFound
|
|
24
|
+
when '500' then raise ApiClient::Exceptions::InternalServerError
|
|
25
|
+
when '502' then raise ApiClient::Exceptions::BadGateway
|
|
26
|
+
when '503' then raise ApiClient::Exceptions::ServiceUnavailable
|
|
24
27
|
end
|
|
25
28
|
end
|
|
26
29
|
end
|
|
@@ -3,4 +3,7 @@ module ApiClient::Exceptions
|
|
|
3
3
|
autoload :NotFound, 'api_client/exceptions/not_found'
|
|
4
4
|
autoload :Unauthorized, 'api_client/exceptions/unauthorized'
|
|
5
5
|
autoload :Forbidden, 'api_client/exceptions/forbidden'
|
|
6
|
+
autoload :InternalServerError, 'api_client/exceptions/internal_server_error'
|
|
7
|
+
autoload :BadGateway, 'api_client/exceptions/bad_gateway'
|
|
8
|
+
autoload :ServiceUnavailable, 'api_client/exceptions/service_unavailable'
|
|
6
9
|
end
|
data/lib/api_client/version.rb
CHANGED
data/spec/api_client_spec.rb
CHANGED
|
@@ -32,6 +32,36 @@ describe ApiClient do
|
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
+
context "when response code is 500" do
|
|
36
|
+
before :each do
|
|
37
|
+
FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "500")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should return a InternalServerError exception" do
|
|
41
|
+
lambda { ApiClient.get('http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::InternalServerError)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context "when response code is 502" do
|
|
46
|
+
before :each do
|
|
47
|
+
FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "502")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should return a BadGateway exception" do
|
|
51
|
+
lambda { ApiClient.get('http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::BadGateway)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context "when response code is 503" do
|
|
56
|
+
before :each do
|
|
57
|
+
FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "503")
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "should return a ServiceUnavailable exception" do
|
|
61
|
+
lambda { ApiClient.get('http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::ServiceUnavailable)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
35
65
|
context "when response code is 2xx" do
|
|
36
66
|
before :each do
|
|
37
67
|
FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "201", :body => "User#3333")
|
|
@@ -74,6 +104,36 @@ describe ApiClient do
|
|
|
74
104
|
end
|
|
75
105
|
end
|
|
76
106
|
|
|
107
|
+
context "when response code is 500" do
|
|
108
|
+
before :each do
|
|
109
|
+
FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "500")
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "should return a InternalServerError exception" do
|
|
113
|
+
lambda { ApiClient.post('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::InternalServerError)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
context "when response code is 502" do
|
|
118
|
+
before :each do
|
|
119
|
+
FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "502")
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "should return a BadGateway exception" do
|
|
123
|
+
lambda { ApiClient.post('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::BadGateway)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
context "when response code is 503" do
|
|
128
|
+
before :each do
|
|
129
|
+
FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "503")
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it "should return a ServiceUnavailable exception" do
|
|
133
|
+
lambda { ApiClient.post('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::ServiceUnavailable)
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
77
137
|
context "when response code is 2xx" do
|
|
78
138
|
before :each do
|
|
79
139
|
FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "201", :body => "User#3333")
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: api-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-
|
|
12
|
+
date: 2012-06-01 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rake
|
|
@@ -76,9 +76,12 @@ files:
|
|
|
76
76
|
- api_client.gemspec
|
|
77
77
|
- lib/api_client.rb
|
|
78
78
|
- lib/api_client/exceptions.rb
|
|
79
|
+
- lib/api_client/exceptions/bad_gateway.rb
|
|
79
80
|
- lib/api_client/exceptions/forbidden.rb
|
|
80
81
|
- lib/api_client/exceptions/generic.rb
|
|
82
|
+
- lib/api_client/exceptions/internal_server_error.rb
|
|
81
83
|
- lib/api_client/exceptions/not_found.rb
|
|
84
|
+
- lib/api_client/exceptions/service_unavailable.rb
|
|
82
85
|
- lib/api_client/exceptions/unauthorized.rb
|
|
83
86
|
- lib/api_client/version.rb
|
|
84
87
|
- spec/api_client_spec.rb
|
|
@@ -97,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
97
100
|
version: '0'
|
|
98
101
|
segments:
|
|
99
102
|
- 0
|
|
100
|
-
hash:
|
|
103
|
+
hash: -2990378140644206917
|
|
101
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
105
|
none: false
|
|
103
106
|
requirements:
|
|
@@ -106,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
106
109
|
version: '0'
|
|
107
110
|
segments:
|
|
108
111
|
- 0
|
|
109
|
-
hash:
|
|
112
|
+
hash: -2990378140644206917
|
|
110
113
|
requirements: []
|
|
111
114
|
rubyforge_project:
|
|
112
115
|
rubygems_version: 1.8.24
|