json_api_client 1.18.0 → 1.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/json_api_client/errors.rb +27 -12
- data/lib/json_api_client/middleware/status.rb +10 -0
- data/lib/json_api_client/query/builder.rb +2 -2
- data/lib/json_api_client/resource.rb +2 -2
- data/lib/json_api_client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e8f9fadfa22191ced6400cea007f0f62a05e8e6fbebc2af2fb5ac4180de5fe6
|
4
|
+
data.tar.gz: 02eda05ecb80f46b09ce66773c997e00dbb1fa3bb72d340f596b9eb84cee22ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
@@ -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
|
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
|
69
|
-
|
70
|
-
def initialize(uri)
|
71
|
-
@uri = uri
|
87
|
+
class BadGateway < ServerError
|
88
|
+
end
|
72
89
|
|
73
|
-
|
74
|
-
super nil, msg
|
75
|
-
end
|
90
|
+
class ServiceUnavailable < ServerError
|
76
91
|
end
|
77
92
|
|
78
|
-
class
|
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.
|
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.
|
74
|
+
klass.create @path_params.merge(attrs.with_indifferent_access)
|
75
75
|
end
|
76
76
|
|
77
77
|
def 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.
|
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 ).
|
541
|
+
_belongs_to_params.merge attributes.slice( self.class.primary_key ).with_indifferent_access
|
542
542
|
end
|
543
543
|
|
544
544
|
protected
|
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.
|
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:
|
11
|
+
date: 2021-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|