json_api_client 1.16.1 → 1.19.0

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
  SHA256:
3
- metadata.gz: 4fca8c458495f8e19df18b859d56e6d6319d2b622be88c56c026d4d5e5edf3cf
4
- data.tar.gz: 2e6dd60b162bf21cf8d4e5b18e95690601d2527d919718f76c33db5a3e1a5ca4
3
+ metadata.gz: 0e8f9fadfa22191ced6400cea007f0f62a05e8e6fbebc2af2fb5ac4180de5fe6
4
+ data.tar.gz: 02eda05ecb80f46b09ce66773c997e00dbb1fa3bb72d340f596b9eb84cee22ff
5
5
  SHA512:
6
- metadata.gz: 64c18ad9536bc2b1d75659c170b49cfec6f12f6989411876ac1eb3dd5360a0ae7d0ea89f0f888a6d3f6df65b1130b4218a620de71277f7cf1ef9887eaf278762
7
- data.tar.gz: 77e3b72879d4b976de3e087caf0043c42f3bc5a9b99b327ea52abd5e0f1938bc3a75bd83beb528ecc6e90b2eee922c4fcdfd1b02797d45eea9d54f968d87e372
6
+ metadata.gz: 98abc203b52e5718f1d8b7ef1427536fd06d6ff257c4c01969a60a87d27eff2a471b46dabcd17917e877233fb810810758e6bcaa277b31708487cdacd322b358
7
+ data.tar.gz: 1526cad7c4c92ebe245d74d7fdf09c803e078f4454be7f351ef5c5644fbc8d78e9a1aa356eecbcbbd0f0d1a310f0e502c0f9cd9100da838271a4fcbf9191d272
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # JsonApiClient [![Build Status](https://travis-ci.org/JsonApiClient/json_api_client.png)](https://travis-ci.org/JsonApiClient/json_api_client) [![Code Climate](https://codeclimate.com/github/JsonApiClient/json_api_client.png)](https://codeclimate.com/github/JsonApiClient/json_api_client) [![Code Coverage](https://codeclimate.com/github/JsonApiClient/json_api_client/coverage.png)](https://codeclimate.com/github/JsonApiClient/json_api_client)
1
+ # JsonApiClient [![Build Status](https://travis-ci.org/JsonApiClient/json_api_client.png?branch=master)](https://travis-ci.org/JsonApiClient/json_api_client) [![Code Climate](https://codeclimate.com/github/JsonApiClient/json_api_client.png)](https://codeclimate.com/github/JsonApiClient/json_api_client) [![Code Coverage](https://codeclimate.com/github/JsonApiClient/json_api_client/coverage.png)](https://codeclimate.com/github/JsonApiClient/json_api_client)
2
2
 
3
3
  This gem is meant to help you build an API client for interacting with REST APIs as laid out by [http://jsonapi.org](http://jsonapi.org). It attempts to give you a query building framework that is easy to understand (it is similar to ActiveRecord scopes).
4
4
 
@@ -24,7 +24,7 @@ module JsonApiClient
24
24
 
25
25
  def load_records(data)
26
26
  data.map do |d|
27
- record_class = Utils.compute_type(klass, d["type"].classify)
27
+ record_class = Utils.compute_type(klass, klass.key_formatter.unformat(d["type"]).classify)
28
28
  record_class.load id: d["id"]
29
29
  end
30
30
  end
@@ -7,7 +7,7 @@ module JsonApiClient
7
7
  end
8
8
 
9
9
  def load_records(data)
10
- record_class = Utils.compute_type(klass, data["type"].classify)
10
+ record_class = Utils.compute_type(klass, klass.key_formatter.unformat(data["type"]).classify)
11
11
  record_class.load id: data["id"]
12
12
  end
13
13
  end
@@ -44,6 +44,28 @@ module JsonApiClient
44
44
  class NotAuthorized < ClientError
45
45
  end
46
46
 
47
+ class NotFound < ClientError
48
+ attr_reader :uri
49
+ def initialize(uri)
50
+ @uri = uri
51
+
52
+ msg = "Resource not found: #{uri.to_s}"
53
+ super nil, msg
54
+ end
55
+ end
56
+
57
+ class RequestTimeout < ClientError
58
+ end
59
+
60
+ class Conflict < ClientError
61
+ def initialize(env, msg = 'Resource already exists')
62
+ super env, msg
63
+ end
64
+ end
65
+
66
+ class TooManyRequests < ClientError
67
+ end
68
+
47
69
  class ConnectionError < ApiError
48
70
  end
49
71
 
@@ -59,23 +81,16 @@ module JsonApiClient
59
81
  end
60
82
  end
61
83
 
62
- class Conflict < ServerError
63
- def initialize(env, msg = 'Resource already exists')
64
- super env, msg
65
- end
84
+ class InternalServerError < ServerError
66
85
  end
67
86
 
68
- class NotFound < ServerError
69
- attr_reader :uri
70
- def initialize(uri)
71
- @uri = uri
87
+ class BadGateway < ServerError
88
+ end
72
89
 
73
- msg = "Couldn't find resource at: #{uri.to_s}"
74
- super nil, msg
75
- end
90
+ class ServiceUnavailable < ServerError
76
91
  end
77
92
 
78
- class InternalServerError < ServerError
93
+ class GatewayTimeout < ServerError
79
94
  end
80
95
 
81
96
  class UnexpectedStatus < ServerError
@@ -38,14 +38,24 @@ module JsonApiClient
38
38
  raise Errors::AccessDenied, env
39
39
  when 404
40
40
  raise Errors::NotFound, env[:url]
41
+ when 408
42
+ raise Errors::RequestTimeout, env
41
43
  when 409
42
44
  raise Errors::Conflict, env
43
45
  when 422
44
46
  # Allow to proceed as resource errors will be populated
47
+ when 429
48
+ raise Errors::TooManyRequests, env
45
49
  when 400..499
46
50
  raise Errors::ClientError, env
47
51
  when 500
48
52
  raise Errors::InternalServerError, env
53
+ when 502
54
+ raise Errors::BadGateway, env
55
+ when 503
56
+ raise Errors::ServiceUnavailable, env
57
+ when 504
58
+ raise Errors::GatewayTimeout, env
49
59
  when 501..599
50
60
  raise Errors::ServerError, env
51
61
  else
@@ -67,11 +67,11 @@ module JsonApiClient
67
67
  end
68
68
 
69
69
  def build(attrs = {})
70
- klass.new @path_params.merge(attrs.symbolize_keys)
70
+ klass.new @path_params.merge(attrs.with_indifferent_access)
71
71
  end
72
72
 
73
73
  def create(attrs = {})
74
- klass.create @path_params.merge(attrs.symbolize_keys)
74
+ klass.create @path_params.merge(attrs.with_indifferent_access)
75
75
  end
76
76
 
77
77
  def params
@@ -10,17 +10,21 @@ module JsonApiClient
10
10
 
11
11
  # expects a record
12
12
  def create(record)
13
- request(:post, klass.path(record.path_attributes), {
14
- body: { data: record.as_json_api },
15
- params: record.request_params.to_params
16
- })
13
+ request(
14
+ :post,
15
+ klass.path(record.path_attributes),
16
+ body: { data: record.as_json_api },
17
+ params: record.request_params.to_params
18
+ )
17
19
  end
18
20
 
19
21
  def update(record)
20
- request(:patch, resource_path(record.path_attributes), {
21
- body: { data: record.as_json_api },
22
- params: record.request_params.to_params
23
- })
22
+ request(
23
+ :patch,
24
+ resource_path(record.path_attributes),
25
+ body: { data: record.as_json_api },
26
+ params: record.request_params.to_params
27
+ )
24
28
  end
25
29
 
26
30
  def get(params = {})
@@ -348,7 +348,7 @@ module JsonApiClient
348
348
  #
349
349
  # @param params [Hash] Attributes, links, and relationships
350
350
  def initialize(params = {})
351
- params = params.symbolize_keys
351
+ params = params.with_indifferent_access
352
352
  @persisted = nil
353
353
  @destroyed = nil
354
354
  self.links = self.class.linker.new(params.delete(:links) || {})
@@ -538,7 +538,7 @@ module JsonApiClient
538
538
  end
539
539
 
540
540
  def path_attributes
541
- _belongs_to_params.merge attributes.slice( self.class.primary_key ).symbolize_keys
541
+ _belongs_to_params.merge attributes.slice( self.class.primary_key ).with_indifferent_access
542
542
  end
543
543
 
544
544
  protected
@@ -29,7 +29,7 @@ module JsonApiClient
29
29
 
30
30
  class Decimal
31
31
  def self.cast(value, _)
32
- BigDecimal.new(value)
32
+ BigDecimal(value)
33
33
  end
34
34
  end
35
35
 
@@ -1,3 +1,3 @@
1
1
  module JsonApiClient
2
- VERSION = "1.16.1"
2
+ VERSION = "1.19.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.1
4
+ version: 1.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Ching
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-04 00:00:00.000000000 Z
11
+ date: 2021-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -28,36 +28,42 @@ dependencies:
28
28
  name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '0.15'
34
31
  - - ">="
35
32
  - !ruby/object:Gem::Version
36
33
  version: 0.15.2
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: 1.2.0
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '0.15'
44
41
  - - ">="
45
42
  - !ruby/object:Gem::Version
46
43
  version: 0.15.2
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: 1.2.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: faraday_middleware
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - "~>"
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.0
54
+ - - "<"
52
55
  - !ruby/object:Gem::Version
53
- version: '0.9'
56
+ version: 1.2.0
54
57
  type: :runtime
55
58
  prerelease: false
56
59
  version_requirements: !ruby/object:Gem::Requirement
57
60
  requirements:
58
- - - "~>"
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 0.9.0
64
+ - - "<"
59
65
  - !ruby/object:Gem::Version
60
- version: '0.9'
66
+ version: 1.2.0
61
67
  - !ruby/object:Gem::Dependency
62
68
  name: addressable
63
69
  requirement: !ruby/object:Gem::Requirement