api-model 2.7.0 → 2.7.1
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +8 -5
- data/api-model.gemspec +1 -1
- data/lib/api_model/response.rb +19 -3
- data/spec/api-model/response_spec.rb +12 -3
- data/spec/support/fixtures/errors.yml +27 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e41c1272409fdd0188dea83e2ee242b0b092cc8
|
4
|
+
data.tar.gz: 13473a46e7d27da470c303f21a294b7d12efcb61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 398b23a5b722f8ee17dfd9a7d41905784baa472fd638d04f3c7e4dcb34d972815f417e5eb849d38a18856d20e6a49c1b3ea097b5ff6b7c7bfd72da8ab7c49e8d
|
7
|
+
data.tar.gz: 54abb47e9d2ac4f36f2f172a71304e1366f3d5b04a88090b604a36c4c8757f5ed581369a2d83ca88e2d874c3ad6ece34534b9fff717305c800dee254b927a584
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
api-model (2.7.
|
4
|
+
api-model (2.7.1)
|
5
5
|
activemodel (~> 4.1)
|
6
6
|
activesupport (~> 4.1)
|
7
7
|
hash-pipe (~> 0.0)
|
@@ -38,7 +38,7 @@ GEM
|
|
38
38
|
domain_name (0.5.24)
|
39
39
|
unf (>= 0.0.5, < 1.0.0)
|
40
40
|
equalizer (0.0.11)
|
41
|
-
ethon (0.
|
41
|
+
ethon (0.8.0)
|
42
42
|
ffi (>= 1.3.0)
|
43
43
|
ffi (1.9.10)
|
44
44
|
hash-pipe (0.3.0)
|
@@ -49,7 +49,7 @@ GEM
|
|
49
49
|
ice_nine (0.11.1)
|
50
50
|
json (1.8.3)
|
51
51
|
method_source (0.8.2)
|
52
|
-
minitest (5.
|
52
|
+
minitest (5.8.1)
|
53
53
|
pry (0.9.12.2)
|
54
54
|
coderay (~> 1.0.5)
|
55
55
|
method_source (~> 0.8)
|
@@ -65,8 +65,8 @@ GEM
|
|
65
65
|
safe_yaml (0.9.7)
|
66
66
|
slop (3.4.6)
|
67
67
|
thread_safe (0.3.5)
|
68
|
-
typhoeus (0.
|
69
|
-
ethon (>= 0.
|
68
|
+
typhoeus (0.8.0)
|
69
|
+
ethon (>= 0.8.0)
|
70
70
|
tzinfo (1.2.2)
|
71
71
|
thread_safe (~> 0.1)
|
72
72
|
unf (0.1.4)
|
@@ -91,3 +91,6 @@ DEPENDENCIES
|
|
91
91
|
rspec (~> 2.14)
|
92
92
|
vcr (= 2.8.0)
|
93
93
|
webmock (= 1.15.0)
|
94
|
+
|
95
|
+
BUNDLED WITH
|
96
|
+
1.10.6
|
data/api-model.gemspec
CHANGED
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "api-model"
|
5
|
-
s.version = "2.7.
|
5
|
+
s.version = "2.7.1"
|
6
6
|
s.authors = ["Damien Timewell", "Erik Rothoff Andersson"]
|
7
7
|
s.email = ["mail@damientimewell.com", "erik.rothoff@gmail.com"]
|
8
8
|
s.licenses = ['MIT']
|
data/lib/api_model/response.rb
CHANGED
@@ -19,9 +19,7 @@ module ApiModel
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def build_objects
|
22
|
-
|
23
|
-
raise NotFoundError if @_config.raise_on_not_found && http_response.api_call.response_code == 404
|
24
|
-
raise ServerError if @_config.raise_on_server_error && http_response.api_call.response_code == 500
|
22
|
+
handle_response_errors
|
25
23
|
return self if response_body.nil?
|
26
24
|
|
27
25
|
if response_build_hash.is_a? Array
|
@@ -119,5 +117,23 @@ module ApiModel
|
|
119
117
|
end
|
120
118
|
end
|
121
119
|
|
120
|
+
private
|
121
|
+
|
122
|
+
def handle_response_errors
|
123
|
+
error_message = "#{http_response.api_call.response_code}: #{http_response.api_call.request.url}"
|
124
|
+
|
125
|
+
if @_config.raise_on_unauthenticated && http_response.api_call.response_code == 401
|
126
|
+
raise UnauthenticatedError, error_message
|
127
|
+
end
|
128
|
+
|
129
|
+
if @_config.raise_on_not_found && http_response.api_call.response_code == 404
|
130
|
+
raise NotFoundError, error_message
|
131
|
+
end
|
132
|
+
|
133
|
+
if @_config.raise_on_server_error && http_response.api_call.response_code.between?(500, 599)
|
134
|
+
raise ServerError, error_message
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
122
138
|
end
|
123
139
|
end
|
@@ -138,7 +138,7 @@ describe ApiModel::Response do
|
|
138
138
|
BlogPost.api_config { |c| c.raise_on_unauthenticated = true }
|
139
139
|
expect {
|
140
140
|
api_request
|
141
|
-
}.to raise_error(ApiModel::UnauthenticatedError)
|
141
|
+
}.to raise_error(ApiModel::UnauthenticatedError, "401: http://api-model-specs.com/needs_auth")
|
142
142
|
end
|
143
143
|
|
144
144
|
it 'should not raise an ApiModel::UnauthenticatedError if raise_on_unauthenticated is false' do
|
@@ -160,7 +160,7 @@ describe ApiModel::Response do
|
|
160
160
|
BlogPost.api_config { |c| c.raise_on_not_found = true }
|
161
161
|
expect {
|
162
162
|
api_request
|
163
|
-
}.to raise_error(ApiModel::NotFoundError)
|
163
|
+
}.to raise_error(ApiModel::NotFoundError, "404: http://api-model-specs.com/not_found")
|
164
164
|
end
|
165
165
|
|
166
166
|
it 'should not raise an ApiModel::NotFoundError if raise_on_not_found is false' do
|
@@ -182,7 +182,7 @@ describe ApiModel::Response do
|
|
182
182
|
BlogPost.api_config { |c| c.raise_on_server_error = true }
|
183
183
|
expect {
|
184
184
|
api_request
|
185
|
-
}.to raise_error(ApiModel::ServerError)
|
185
|
+
}.to raise_error(ApiModel::ServerError, "500: http://api-model-specs.com/server_error")
|
186
186
|
end
|
187
187
|
|
188
188
|
it 'should not raise an ApiModel::ServerError if raise_on_server_error is false' do
|
@@ -191,6 +191,15 @@ describe ApiModel::Response do
|
|
191
191
|
api_request
|
192
192
|
}.to_not raise_error
|
193
193
|
end
|
194
|
+
|
195
|
+
it 'should log any status code in the 500 range when raise_on_server_error is true' do
|
196
|
+
BlogPost.api_config { |c| c.raise_on_server_error = true }
|
197
|
+
expect {
|
198
|
+
VCR.use_cassette('errors') do
|
199
|
+
BlogPost.get_json "http://api-model-specs.com/unavailable"
|
200
|
+
end
|
201
|
+
}.to raise_error(ApiModel::ServerError, "503: http://api-model-specs.com/unavailable")
|
202
|
+
end
|
194
203
|
end
|
195
204
|
end
|
196
205
|
|
@@ -81,4 +81,31 @@ http_interactions:
|
|
81
81
|
http_version:
|
82
82
|
recorded_at: Thu, 28 Nov 2013 16:02:20 GMT
|
83
83
|
|
84
|
+
- request:
|
85
|
+
method: get
|
86
|
+
uri: http://api-model-specs.com/unavailable
|
87
|
+
headers:
|
88
|
+
User-Agent:
|
89
|
+
- Typhoeus - https://github.com/typhoeus/typhoeus
|
90
|
+
response:
|
91
|
+
status:
|
92
|
+
code: 503
|
93
|
+
message: OK
|
94
|
+
headers:
|
95
|
+
Server:
|
96
|
+
- nginx/1.4.1
|
97
|
+
Date:
|
98
|
+
- Thu, 28 Nov 2013 16:02:56 GMT
|
99
|
+
Content-Type:
|
100
|
+
- text/plain; charset=utf-8
|
101
|
+
Content-Length:
|
102
|
+
- '248'
|
103
|
+
Connection:
|
104
|
+
- keep-alive
|
105
|
+
body:
|
106
|
+
encoding: UTF-8
|
107
|
+
string: "Oh no, something went wrong"
|
108
|
+
http_version:
|
109
|
+
recorded_at: Thu, 28 Nov 2013 16:02:20 GMT
|
110
|
+
|
84
111
|
recorded_with: VCR 2.8.0
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.7.
|
4
|
+
version: 2.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damien Timewell
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-10-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|