json_api_client 1.14.0 → 1.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +2 -2
- data/lib/json_api_client.rb +1 -1
- data/lib/json_api_client/connection.rb +1 -0
- data/lib/json_api_client/errors.rb +6 -0
- data/lib/json_api_client/included_data.rb +3 -4
- data/lib/json_api_client/resource.rb +26 -0
- data/lib/json_api_client/version.rb +1 -1
- metadata +19 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dcb3e63c09c75358b9d182615b3b895fbd045f9e86e1bf43c0890afbdc256dc2
|
4
|
+
data.tar.gz: 68cb03b8cf7f9e7e9041ee410578dc2b9a1e07ea9eb63ae9606ff4bf34c1ca20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 440f012b8cb173af6a577a5d46aac0cfac4c6e6cb9f281e1760353db09e86d0f48900531b1ac9b58e785ea3627d79870f1b9862c40deeac229116e4413bb86e4
|
7
|
+
data.tar.gz: 19d2186f54fa0a91787d6e258d556622c9b57c2374fbb98c21956ffe5a9d32592fbf352ebd8a466657a3063c1ab29443bde2841669e15e9834a6ae921a433673
|
data/README.md
CHANGED
data/lib/json_api_client.rb
CHANGED
@@ -2,6 +2,7 @@ require 'faraday'
|
|
2
2
|
require 'faraday_middleware'
|
3
3
|
require 'json'
|
4
4
|
require 'addressable/uri'
|
5
|
+
require 'json_api_client/formatter'
|
5
6
|
|
6
7
|
module JsonApiClient
|
7
8
|
autoload :Associations, 'json_api_client/associations'
|
@@ -9,7 +10,6 @@ module JsonApiClient
|
|
9
10
|
autoload :Connection, 'json_api_client/connection'
|
10
11
|
autoload :Errors, 'json_api_client/errors'
|
11
12
|
autoload :ErrorCollector, 'json_api_client/error_collector'
|
12
|
-
autoload :Formatter, 'json_api_client/formatter'
|
13
13
|
autoload :Helpers, 'json_api_client/helpers'
|
14
14
|
autoload :Implementation, 'json_api_client/implementation'
|
15
15
|
autoload :IncludedData, 'json_api_client/included_data'
|
@@ -14,6 +14,7 @@ module JsonApiClient
|
|
14
14
|
builder.use Middleware::JsonRequest
|
15
15
|
builder.use Middleware::Status, status_middleware_options
|
16
16
|
builder.use Middleware::ParseJson
|
17
|
+
builder.use ::FaradayMiddleware::Gzip
|
17
18
|
builder.adapter(*adapter_options)
|
18
19
|
end
|
19
20
|
yield(self) if block_given?
|
@@ -36,9 +36,7 @@ module JsonApiClient
|
|
36
36
|
|
37
37
|
if data.is_a?(Array)
|
38
38
|
# has_many link
|
39
|
-
data.map
|
40
|
-
record_for(link_def)
|
41
|
-
end
|
39
|
+
data.map(&method(:record_for)).compact
|
42
40
|
else
|
43
41
|
# has_one link
|
44
42
|
record_for(data)
|
@@ -53,7 +51,8 @@ module JsonApiClient
|
|
53
51
|
|
54
52
|
# should return a resource record of some type for this linked document
|
55
53
|
def record_for(link_def)
|
56
|
-
data[link_def["type"]]
|
54
|
+
record = data[link_def["type"]]
|
55
|
+
record[link_def["id"]] if record
|
57
56
|
end
|
58
57
|
end
|
59
58
|
end
|
@@ -40,6 +40,11 @@ module JsonApiClient
|
|
40
40
|
instance_accessor: false
|
41
41
|
class_attribute :add_defaults_to_changes,
|
42
42
|
instance_writer: false
|
43
|
+
|
44
|
+
class_attribute :_immutable,
|
45
|
+
instance_writer: false,
|
46
|
+
default: false
|
47
|
+
|
43
48
|
self.primary_key = :id
|
44
49
|
self.parser = Parsers::Parser
|
45
50
|
self.paginator = Paginating::Paginator
|
@@ -94,6 +99,19 @@ module JsonApiClient
|
|
94
99
|
table_name
|
95
100
|
end
|
96
101
|
|
102
|
+
# Indicates whether this resource is mutable or immutable;
|
103
|
+
# by default, all resources are mutable.
|
104
|
+
#
|
105
|
+
# @return [Boolean]
|
106
|
+
def immutable(flag = true)
|
107
|
+
self._immutable = flag
|
108
|
+
end
|
109
|
+
|
110
|
+
def inherited(subclass)
|
111
|
+
subclass._immutable = false
|
112
|
+
super
|
113
|
+
end
|
114
|
+
|
97
115
|
# Specifies the relative path that should be used for this resource;
|
98
116
|
# by default, this is inferred from the resource class name.
|
99
117
|
#
|
@@ -215,6 +233,11 @@ module JsonApiClient
|
|
215
233
|
# @option [Symbol] :on One of [:collection or :member] to decide whether it's a collect or member method
|
216
234
|
# @option [Symbol] :request_method The request method (:get, :post, etc)
|
217
235
|
def custom_endpoint(name, options = {})
|
236
|
+
if _immutable
|
237
|
+
request_method = options.fetch(:request_method, :get).to_sym
|
238
|
+
raise JsonApiClient::Errors::ResourceImmutableError if request_method != :get
|
239
|
+
end
|
240
|
+
|
218
241
|
if :collection == options.delete(:on)
|
219
242
|
collection_endpoint(name, options)
|
220
243
|
else
|
@@ -440,6 +463,7 @@ module JsonApiClient
|
|
440
463
|
# @return [Boolean] Whether or not the save succeeded
|
441
464
|
def save
|
442
465
|
return false unless valid?
|
466
|
+
raise JsonApiClient::Errors::ResourceImmutableError if _immutable
|
443
467
|
|
444
468
|
self.last_result_set = if persisted?
|
445
469
|
self.class.requestor.update(self)
|
@@ -470,6 +494,8 @@ module JsonApiClient
|
|
470
494
|
#
|
471
495
|
# @return [Boolean] Whether or not the destroy succeeded
|
472
496
|
def destroy
|
497
|
+
raise JsonApiClient::Errors::ResourceImmutableError if _immutable
|
498
|
+
|
473
499
|
self.last_result_set = self.class.requestor.destroy(self)
|
474
500
|
if last_result_set.has_errors?
|
475
501
|
fill_errors
|
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.17.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: 2020-08-17 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:
|
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:
|
66
|
+
version: 1.2.0
|
61
67
|
- !ruby/object:Gem::Dependency
|
62
68
|
name: addressable
|
63
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -199,8 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
205
|
- !ruby/object:Gem::Version
|
200
206
|
version: '0'
|
201
207
|
requirements: []
|
202
|
-
|
203
|
-
rubygems_version: 2.6.14
|
208
|
+
rubygems_version: 3.0.1
|
204
209
|
signing_key:
|
205
210
|
specification_version: 4
|
206
211
|
summary: Build client libraries compliant with specification defined by jsonapi.org
|