api-model 2.7.1 → 2.7.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e41c1272409fdd0188dea83e2ee242b0b092cc8
4
- data.tar.gz: 13473a46e7d27da470c303f21a294b7d12efcb61
3
+ metadata.gz: 36ea07b796d901145f5cbe7624c653d94cf4c0aa
4
+ data.tar.gz: ba894307e7de0f3f24a1e18615276d826ca5f0dd
5
5
  SHA512:
6
- metadata.gz: 398b23a5b722f8ee17dfd9a7d41905784baa472fd638d04f3c7e4dcb34d972815f417e5eb849d38a18856d20e6a49c1b3ea097b5ff6b7c7bfd72da8ab7c49e8d
7
- data.tar.gz: 54abb47e9d2ac4f36f2f172a71304e1366f3d5b04a88090b604a36c4c8757f5ed581369a2d83ca88e2d874c3ad6ece34534b9fff717305c800dee254b927a584
6
+ metadata.gz: 8a2f5c4663d3e8fe15b5fd3dc8675cb1972dc3b8970a8c995e4ec5ba0aae91781e7587995e1973016e09b03b6701e204e3c591e238caa0e4a58309500e9c6ca7
7
+ data.tar.gz: 322e4d2cdba72b00469abc60cb84a72a17283dd023c41a2d1c4b8dfeba2415219e478da53ba6eb87a6b2aa385a38879d9c14e0b316b54050d7f974d37f222e86
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- api-model (2.7.1)
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.3)
16
- activesupport (= 4.2.3)
15
+ activemodel (4.2.6)
16
+ activesupport (= 4.2.6)
17
17
  builder (~> 3.1)
18
- activesupport (4.2.3)
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.24)
38
+ domain_name (0.5.20160615)
39
39
  unf (>= 0.0.5, < 1.0.0)
40
40
  equalizer (0.0.11)
41
- ethon (0.8.0)
41
+ ethon (0.9.0)
42
42
  ffi (>= 1.3.0)
43
- ffi (1.9.10)
44
- hash-pipe (0.3.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.1)
49
+ ice_nine (0.11.2)
50
50
  json (1.8.3)
51
51
  method_source (0.8.2)
52
- minitest (5.8.1)
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.1)
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.10.6
96
+ 1.11.2
@@ -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.1"
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']
@@ -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
@@ -0,0 +1,9 @@
1
+ module ApiModel
2
+ class ErrorMessageFormatter
3
+
4
+ def self.format(http_response)
5
+ "#{http_response.api_call.response_code}: #{http_response.api_call.request.url}"
6
+ end
7
+
8
+ end
9
+ end
@@ -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, error_message
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, error_message
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, error_message
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.1
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: 2015-10-01 00:00:00.000000000 Z
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.2.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