json_api_client 1.14.1 → 1.17.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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/query/requestor.rb +12 -8
- data/lib/json_api_client/resource.rb +26 -0
- data/lib/json_api_client/schema.rb +1 -1
- data/lib/json_api_client/version.rb +1 -1
- metadata +18 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0177efb037e8cf64cb3dae65d29ff7dcadb09de9ea502f722da0086db4b7faab
|
4
|
+
data.tar.gz: 71650f09239773eea01bafdc8bc2527ec2f6b6142f268dfe6cba3deccd4bb4a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8d4cde22354f51620a16bbc7b05f7e81a77aaf5a664731af6603d71be81139cafeede497e0f0be539f8d4ecc8b53b83bf01c71fa966ada1fc0904f499baa780
|
7
|
+
data.tar.gz: 0d640bae03a241523468eb1a4d11b2073a65b3fad000d066203ea1ce79c6765700d9a303fda8c1049c25c4fab9d750084bacac97300f6398172b11b0a064fa06
|
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?
|
@@ -10,17 +10,21 @@ module JsonApiClient
|
|
10
10
|
|
11
11
|
# expects a record
|
12
12
|
def create(record)
|
13
|
-
request(
|
14
|
-
|
15
|
-
|
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(
|
21
|
-
|
22
|
-
|
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 = {})
|
@@ -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.1
|
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-09-09 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
|