json_api_client 1.15.0 → 1.18.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: 17005bc88ac7813f9492d669c5eb8ffe2e8f80ca600455f4d563d6d06363f902
4
- data.tar.gz: 150b21556d5a33bea2d9b5d2b12999c5298cf4157bea34869b57324cab94416d
3
+ metadata.gz: 3b057aa807765f05d20cfb89d4eadfe4b88737b246242a33632107fb8d6199c2
4
+ data.tar.gz: 21872ac5864207638b55504eea5fd7e8b7ecbae4e1a35c2fc5e3b89e2245323b
5
5
  SHA512:
6
- metadata.gz: dffeb3fe0e26ea1984a119b19d5d6cd8b97c5c4179e9b02507e21882157f5f595ef71b16d39b977ece158a79fe9ea92b58f386cc71caa61104b6e5832740385a
7
- data.tar.gz: 2a794b74f9ffe077070b3485fe4eea40066a139eed7e2ce07ae97504df7a7ddb01154a02efdbe0509db6dc67f775b11aa72b477f8a7817bc8cb3cb5d1242d623
6
+ metadata.gz: 076ca94be2e0c032aeaf40b282deb7786bf151e493f7bd639523fb5bc6f7b97940c0549e57853f5bb550b903ec84dac2e1c2eb37e676d81055565f3223bfba45
7
+ data.tar.gz: bd0cace4b70cfa5879d06dbb793fcfac842ab589498ec41d4f49542f0519c833f7612d153d64338bc18eb1b778799869feb3bdb5f1d02641038646fd1cf7ffc6
@@ -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
@@ -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?
@@ -32,6 +32,12 @@ module JsonApiClient
32
32
  class ClientError < ApiError
33
33
  end
34
34
 
35
+ class ResourceImmutableError < StandardError
36
+ def initialize(msg = 'Resource immutable')
37
+ super msg
38
+ end
39
+ end
40
+
35
41
  class AccessDenied < ClientError
36
42
  end
37
43
 
@@ -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 = {})
@@ -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
@@ -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.15.0"
2
+ VERSION = "1.18.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.15.0
4
+ version: 1.18.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-08-29 00:00:00.000000000 Z
11
+ date: 2020-12-02 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