json_api_client 1.21.1 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/json_api_client/connection.rb +3 -3
- data/lib/json_api_client/middleware.rb +1 -2
- data/lib/json_api_client/query/builder.rb +1 -1
- data/lib/json_api_client/resource.rb +15 -2
- data/lib/json_api_client/utils.rb +5 -0
- data/lib/json_api_client/version.rb +1 -1
- data/lib/json_api_client.rb +1 -1
- metadata +30 -17
- data/lib/json_api_client/middleware/parse_json.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15b4315b1e13b217c676e0915ab247724164a6e6debd6c4abf24f881f0fd8285
|
4
|
+
data.tar.gz: 37521318c26c77c27eb76c02e4a1f88c3dd0920cf15a208dd598abe8a23c2c12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8332c87747e3f256c73471867b4c361c2d7d5a2990de0aaa2f928092a1d7e063ad083167bf70dfcbc5275bf1bed100547d959b13444e471050995a2504cd69bc
|
7
|
+
data.tar.gz: 784aa84e674c28c2b77fb97959a8fdb0ebb7258741008cc6983050be3d9264f3b61f0e69bccff5996f24bbab1d265737185dc918aecd5f130aa5c74384538468
|
@@ -13,8 +13,8 @@ module JsonApiClient
|
|
13
13
|
builder.request :json
|
14
14
|
builder.use Middleware::JsonRequest
|
15
15
|
builder.use Middleware::Status, status_middleware_options
|
16
|
-
builder.
|
17
|
-
builder.use ::
|
16
|
+
builder.response :json
|
17
|
+
builder.use ::Faraday::Gzip::Middleware
|
18
18
|
builder.adapter(*adapter_options)
|
19
19
|
end
|
20
20
|
yield(self) if block_given?
|
@@ -24,7 +24,7 @@ module JsonApiClient
|
|
24
24
|
# inserted middleware will run after json parsed
|
25
25
|
def use(middleware, *args, &block)
|
26
26
|
return if faraday.builder.locked?
|
27
|
-
faraday.builder.insert_before(
|
27
|
+
faraday.builder.insert_before(::Faraday::Response::Json, middleware, *args, &block)
|
28
28
|
end
|
29
29
|
|
30
30
|
def delete(middleware)
|
@@ -136,7 +136,7 @@ module JsonApiClient
|
|
136
136
|
primary_key: opts.fetch( :primary_key, @primary_key ),
|
137
137
|
pagination_params: @pagination_params.merge( opts.fetch( :pagination_params, {} ) ),
|
138
138
|
path_params: @path_params.merge( opts.fetch( :path_params, {} ) ),
|
139
|
-
additional_params: @additional_params.
|
139
|
+
additional_params: @additional_params.deep_merge( opts.fetch( :additional_params, {} ) ),
|
140
140
|
filters: @filters.merge( opts.fetch( :filters, {} ) ),
|
141
141
|
includes: @includes + opts.fetch( :includes, [] ),
|
142
142
|
orders: @orders + opts.fetch( :orders, [] ),
|
@@ -260,10 +260,11 @@ module JsonApiClient
|
|
260
260
|
metaclass = class << self
|
261
261
|
self
|
262
262
|
end
|
263
|
+
endpoint_name = _name_for_route_format(name)
|
263
264
|
metaclass.instance_eval do
|
264
265
|
define_method(name) do |*params|
|
265
266
|
request_params = params.first || {}
|
266
|
-
requestor.custom(
|
267
|
+
requestor.custom(endpoint_name, options, request_params)
|
267
268
|
end
|
268
269
|
end
|
269
270
|
end
|
@@ -274,10 +275,11 @@ module JsonApiClient
|
|
274
275
|
# @param options [Hash] endpoint options
|
275
276
|
# @option options [Symbol] :request_method The request method (:get, :post, etc)
|
276
277
|
def member_endpoint(name, options = {})
|
278
|
+
endpoint_name = self._name_for_route_format(name)
|
277
279
|
define_method name do |*params|
|
278
280
|
request_params = params.first || {}
|
279
281
|
request_params[self.class.primary_key] = attributes.fetch(self.class.primary_key)
|
280
|
-
self.class.requestor.custom(
|
282
|
+
self.class.requestor.custom(endpoint_name, options, request_params)
|
281
283
|
end
|
282
284
|
end
|
283
285
|
|
@@ -348,6 +350,17 @@ module JsonApiClient
|
|
348
350
|
yield(conn) if block_given?
|
349
351
|
end
|
350
352
|
end
|
353
|
+
|
354
|
+
def _name_for_route_format(name)
|
355
|
+
case self.route_format
|
356
|
+
when :dasherized_route
|
357
|
+
name.to_s.dasherize
|
358
|
+
when :camelized_route
|
359
|
+
name.to_s.camelize(:lower)
|
360
|
+
else
|
361
|
+
name
|
362
|
+
end
|
363
|
+
end
|
351
364
|
end
|
352
365
|
|
353
366
|
# Instantiate a new resource object
|
@@ -7,6 +7,11 @@ module JsonApiClient
|
|
7
7
|
# the type_name is an absolute reference.
|
8
8
|
return type_name.constantize if type_name.match(/^::/)
|
9
9
|
|
10
|
+
# Check the klass association definitions
|
11
|
+
association_klass_match = klass.associations.find { |a| a.attr_name.to_s.singularize == type_name.underscore }
|
12
|
+
association_klass = association_klass_match.options[:class] if association_klass_match
|
13
|
+
return association_klass if association_klass
|
14
|
+
|
10
15
|
# Build a list of candidates to search for
|
11
16
|
candidates = []
|
12
17
|
klass.name.scan(/::|$/) { candidates.unshift "#{$`}::#{type_name}" }
|
data/lib/json_api_client.rb
CHANGED
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.23.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: 2024-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,54 +16,54 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: faraday
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '1.10'
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: '
|
36
|
+
version: '3.0'
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
43
|
+
version: '1.10'
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
46
|
+
version: '3.0'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
48
|
+
name: faraday-gzip
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: '1.0'
|
54
54
|
- - "<"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: '
|
56
|
+
version: '3.0'
|
57
57
|
type: :runtime
|
58
58
|
prerelease: false
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
61
|
- - ">="
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version:
|
63
|
+
version: '1.0'
|
64
64
|
- - "<"
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: '
|
66
|
+
version: '3.0'
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: addressable
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,14 +84,14 @@ dependencies:
|
|
84
84
|
requirements:
|
85
85
|
- - ">="
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version:
|
87
|
+
version: 6.0.0
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
90
|
version_requirements: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
92
|
- - ">="
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
version:
|
94
|
+
version: 6.0.0
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
96
|
name: rack
|
97
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,6 +134,20 @@ dependencies:
|
|
134
134
|
- - ">="
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '0'
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: appraisal
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
type: :development
|
145
|
+
prerelease: false
|
146
|
+
version_requirements: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
137
151
|
description: Build client libraries compliant with specification defined by jsonapi.org
|
138
152
|
email: ching.jeff@gmail.com
|
139
153
|
executables: []
|
@@ -167,7 +181,6 @@ files:
|
|
167
181
|
- lib/json_api_client/meta_data.rb
|
168
182
|
- lib/json_api_client/middleware.rb
|
169
183
|
- lib/json_api_client/middleware/json_request.rb
|
170
|
-
- lib/json_api_client/middleware/parse_json.rb
|
171
184
|
- lib/json_api_client/middleware/status.rb
|
172
185
|
- lib/json_api_client/paginating.rb
|
173
186
|
- lib/json_api_client/paginating/nested_param_paginator.rb
|
@@ -205,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
218
|
- !ruby/object:Gem::Version
|
206
219
|
version: '0'
|
207
220
|
requirements: []
|
208
|
-
rubygems_version: 3.3
|
221
|
+
rubygems_version: 3.0.3
|
209
222
|
signing_key:
|
210
223
|
specification_version: 4
|
211
224
|
summary: Build client libraries compliant with specification defined by jsonapi.org
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module JsonApiClient
|
2
|
-
module Middleware
|
3
|
-
class ParseJson < Faraday::Middleware
|
4
|
-
|
5
|
-
def call(environment)
|
6
|
-
@app.call(environment).on_complete do |env|
|
7
|
-
if process_response_type?(response_type(env))
|
8
|
-
env[:raw_body] = env[:body]
|
9
|
-
env[:body] = parse(env[:body])
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def parse(body)
|
17
|
-
::JSON.parse(body) unless body.strip.empty?
|
18
|
-
end
|
19
|
-
|
20
|
-
def response_type(env)
|
21
|
-
type = env[:response_headers]['Content-Type'].to_s
|
22
|
-
type = type.split(';', 2).first if type.index(';')
|
23
|
-
type
|
24
|
-
end
|
25
|
-
|
26
|
-
def process_response_type?(type)
|
27
|
-
!!type.match(/\bjson$/)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|