api-model 2.7.1 → 2.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +12 -12
- data/api-model.gemspec +1 -1
- data/lib/api-model.rb +1 -0
- data/lib/api_model/configuration.rb +5 -1
- data/lib/api_model/error_message_formatter.rb +9 -0
- data/lib/api_model/response.rb +3 -5
- data/spec/api-model/configuration_spec.rb +11 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36ea07b796d901145f5cbe7624c653d94cf4c0aa
|
4
|
+
data.tar.gz: ba894307e7de0f3f24a1e18615276d826ca5f0dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a2f5c4663d3e8fe15b5fd3dc8675cb1972dc3b8970a8c995e4ec5ba0aae91781e7587995e1973016e09b03b6701e204e3c591e238caa0e4a58309500e9c6ca7
|
7
|
+
data.tar.gz: 322e4d2cdba72b00469abc60cb84a72a17283dd023c41a2d1c4b8dfeba2415219e478da53ba6eb87a6b2aa385a38879d9c14e0b316b54050d7f974d37f222e86
|
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.2)
|
5
5
|
activemodel (~> 4.1)
|
6
6
|
activesupport (~> 4.1)
|
7
7
|
hash-pipe (~> 0.0)
|
@@ -12,10 +12,10 @@ PATH
|
|
12
12
|
GEM
|
13
13
|
remote: https://rubygems.org/
|
14
14
|
specs:
|
15
|
-
activemodel (4.2.
|
16
|
-
activesupport (= 4.2.
|
15
|
+
activemodel (4.2.6)
|
16
|
+
activesupport (= 4.2.6)
|
17
17
|
builder (~> 3.1)
|
18
|
-
activesupport (4.2.
|
18
|
+
activesupport (4.2.6)
|
19
19
|
i18n (~> 0.7)
|
20
20
|
json (~> 1.7, >= 1.7.7)
|
21
21
|
minitest (~> 5.1)
|
@@ -35,21 +35,21 @@ GEM
|
|
35
35
|
descendants_tracker (0.0.4)
|
36
36
|
thread_safe (~> 0.3, >= 0.3.1)
|
37
37
|
diff-lcs (1.2.5)
|
38
|
-
domain_name (0.5.
|
38
|
+
domain_name (0.5.20160615)
|
39
39
|
unf (>= 0.0.5, < 1.0.0)
|
40
40
|
equalizer (0.0.11)
|
41
|
-
ethon (0.
|
41
|
+
ethon (0.9.0)
|
42
42
|
ffi (>= 1.3.0)
|
43
|
-
ffi (1.9.
|
44
|
-
hash-pipe (0.
|
43
|
+
ffi (1.9.13)
|
44
|
+
hash-pipe (0.4.0)
|
45
45
|
activesupport (~> 4.1)
|
46
46
|
http-cookie (1.0.2)
|
47
47
|
domain_name (~> 0.5)
|
48
48
|
i18n (0.7.0)
|
49
|
-
ice_nine (0.11.
|
49
|
+
ice_nine (0.11.2)
|
50
50
|
json (1.8.3)
|
51
51
|
method_source (0.8.2)
|
52
|
-
minitest (5.
|
52
|
+
minitest (5.9.0)
|
53
53
|
pry (0.9.12.2)
|
54
54
|
coderay (~> 1.0.5)
|
55
55
|
method_source (~> 0.8)
|
@@ -71,7 +71,7 @@ GEM
|
|
71
71
|
thread_safe (~> 0.1)
|
72
72
|
unf (0.1.4)
|
73
73
|
unf_ext
|
74
|
-
unf_ext (0.0.7.
|
74
|
+
unf_ext (0.0.7.2)
|
75
75
|
vcr (2.8.0)
|
76
76
|
virtus (1.0.5)
|
77
77
|
axiom-types (~> 0.1)
|
@@ -93,4 +93,4 @@ DEPENDENCIES
|
|
93
93
|
webmock (= 1.15.0)
|
94
94
|
|
95
95
|
BUNDLED WITH
|
96
|
-
1.
|
96
|
+
1.11.2
|
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.2"
|
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.rb
CHANGED
@@ -14,6 +14,7 @@ require 'api_model/http_request'
|
|
14
14
|
require 'api_model/response'
|
15
15
|
require 'api_model/class_methods'
|
16
16
|
require 'api_model/instance_methods'
|
17
|
+
require 'api_model/error_message_formatter'
|
17
18
|
require 'api_model/configuration'
|
18
19
|
require 'api_model/cache_stategy/no_cache'
|
19
20
|
require 'api_model/response_parser/json'
|
@@ -4,7 +4,7 @@ module ApiModel
|
|
4
4
|
|
5
5
|
attr_accessor :host, :json_root, :headers, :raise_on_unauthenticated, :cache_settings,
|
6
6
|
:raise_on_not_found, :cache_strategy, :parser, :builder, :raise_on_server_error,
|
7
|
-
:json_errors_root
|
7
|
+
:json_errors_root, :error_message_formatter
|
8
8
|
|
9
9
|
def self.from_inherited_config(config)
|
10
10
|
new config.instance_values.reject {|k,v| v.blank? }
|
@@ -31,6 +31,10 @@ module ApiModel
|
|
31
31
|
def json_errors_root
|
32
32
|
@json_errors_root ||= "errors"
|
33
33
|
end
|
34
|
+
|
35
|
+
def error_message_formatter
|
36
|
+
@error_message_formatter ||= ApiModel::ErrorMessageFormatter
|
37
|
+
end
|
34
38
|
end
|
35
39
|
|
36
40
|
module ConfigurationMethods
|
data/lib/api_model/response.rb
CHANGED
@@ -120,18 +120,16 @@ module ApiModel
|
|
120
120
|
private
|
121
121
|
|
122
122
|
def handle_response_errors
|
123
|
-
error_message = "#{http_response.api_call.response_code}: #{http_response.api_call.request.url}"
|
124
|
-
|
125
123
|
if @_config.raise_on_unauthenticated && http_response.api_call.response_code == 401
|
126
|
-
raise UnauthenticatedError,
|
124
|
+
raise UnauthenticatedError, @_config.error_message_formatter.format(http_response)
|
127
125
|
end
|
128
126
|
|
129
127
|
if @_config.raise_on_not_found && http_response.api_call.response_code == 404
|
130
|
-
raise NotFoundError,
|
128
|
+
raise NotFoundError, @_config.error_message_formatter.format(http_response)
|
131
129
|
end
|
132
130
|
|
133
131
|
if @_config.raise_on_server_error && http_response.api_call.response_code.between?(500, 599)
|
134
|
-
raise ServerError,
|
132
|
+
raise ServerError, @_config.error_message_formatter.format(http_response)
|
135
133
|
end
|
136
134
|
end
|
137
135
|
|
@@ -47,6 +47,17 @@ describe ApiModel, "Configuration" do
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
describe "error_message_formatter" do
|
51
|
+
it 'should default to ApiModel::ErrorMessageFormatter' do
|
52
|
+
Banana.api_model_configuration.error_message_formatter.should eq ApiModel::ErrorMessageFormatter
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should be possible to set on a class' do
|
56
|
+
Banana.api_config { |c| c.error_message_formatter = "foo" }
|
57
|
+
Banana.api_model_configuration.error_message_formatter.should eq "foo"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
50
61
|
describe "headers" do
|
51
62
|
it 'should create default headers for content type and accepts' do
|
52
63
|
headers = Banana.api_model_configuration.headers
|
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.2
|
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:
|
12
|
+
date: 2016-08-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -174,6 +174,7 @@ files:
|
|
174
174
|
- lib/api_model/cache_stategy/no_cache.rb
|
175
175
|
- lib/api_model/class_methods.rb
|
176
176
|
- lib/api_model/configuration.rb
|
177
|
+
- lib/api_model/error_message_formatter.rb
|
177
178
|
- lib/api_model/http_request.rb
|
178
179
|
- lib/api_model/initializer.rb
|
179
180
|
- lib/api_model/instance_methods.rb
|
@@ -217,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
217
218
|
version: '0'
|
218
219
|
requirements: []
|
219
220
|
rubyforge_project:
|
220
|
-
rubygems_version: 2.
|
221
|
+
rubygems_version: 2.5.1
|
221
222
|
signing_key:
|
222
223
|
specification_version: 4
|
223
224
|
summary: A simple way of interacting with rest APIs
|