api-model 2.7.0 → 2.7.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: 7d0dd9a26e6eafcc5cfde5f0f7efe1fb7f1ef3e4
4
- data.tar.gz: efea549d31e9bc395b67f02f02d0bd9e2761e191
3
+ metadata.gz: 5e41c1272409fdd0188dea83e2ee242b0b092cc8
4
+ data.tar.gz: 13473a46e7d27da470c303f21a294b7d12efcb61
5
5
  SHA512:
6
- metadata.gz: 0151bb44bddbf6764c40719142841857b1ee27d5dd0ce2a67f7dccb541862c54129eef6b035d1a501a13909ac9eb151c3e2efb62a3b08eba11c4882d50a91c1d
7
- data.tar.gz: 0d2abb36cbc68bdc02555f99fb8ae9435fc4822b2c76d9ccd682974f91d461a17b1d02f2a90339830718a27e148cd4bfe19b2565ef942268729dcd9bd01c189a
6
+ metadata.gz: 398b23a5b722f8ee17dfd9a7d41905784baa472fd638d04f3c7e4dcb34d972815f417e5eb849d38a18856d20e6a49c1b3ea097b5ff6b7c7bfd72da8ab7c49e8d
7
+ data.tar.gz: 54abb47e9d2ac4f36f2f172a71304e1366f3d5b04a88090b604a36c4c8757f5ed581369a2d83ca88e2d874c3ad6ece34534b9fff717305c800dee254b927a584
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- api-model (2.7.0)
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.7.4)
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.7.0)
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.7.2)
69
- ethon (>= 0.7.4)
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
@@ -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.0"
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']
@@ -19,9 +19,7 @@ module ApiModel
19
19
  end
20
20
 
21
21
  def build_objects
22
- raise UnauthenticatedError if @_config.raise_on_unauthenticated && http_response.api_call.response_code == 401
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.0
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-07-03 00:00:00.000000000 Z
12
+ date: 2015-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport