simple_jsonapi_client 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +2 -0
- data/Dockerfile +4 -2
- data/docker-compose.yml +10 -8
- data/lib/simple_jsonapi_client/base.rb +23 -13
- data/lib/simple_jsonapi_client/errors/api_error.rb +1 -0
- data/lib/simple_jsonapi_client/redirection/fetch_all.rb +2 -2
- data/lib/simple_jsonapi_client/utils.rb +47 -0
- data/lib/simple_jsonapi_client/version.rb +1 -1
- data/simple_jsonapi_client.gemspec +3 -4
- metadata +23 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8e72a2d0cea7bff8938a532d200fe3da6f87d20050f24fe0b8ddb77cb3b6854c
|
4
|
+
data.tar.gz: 239dd8b6acab3f55408c3335fdc94c475a94f6b69144f8eb26b7082589d4162a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a41f9dcb9329fab138f1034e6a71150d5e0e73feff8b6543b0f441c256169d844f682abf565a6336a7e2b6dafcf43518005563db8d91ebd2fae92e2c1946954f
|
7
|
+
data.tar.gz: f56c4a42c6d07be0edab577677b128aabef784c9c410da23eb656cfae7a09f6a33fd7fc2851d969a7afc7cc430a999b54534b5d6c26bb2bed15dfb718df2d837
|
data/.travis.yml
CHANGED
data/Dockerfile
CHANGED
data/docker-compose.yml
CHANGED
@@ -2,6 +2,10 @@ version: '3'
|
|
2
2
|
services:
|
3
3
|
db:
|
4
4
|
image: postgres
|
5
|
+
environment:
|
6
|
+
POSTGRES_HOST_AUTH_METHOD: trust
|
7
|
+
ports:
|
8
|
+
- "5432:5432"
|
5
9
|
spec:
|
6
10
|
build: .
|
7
11
|
entrypoint: bin/wait_for_it jsonapi_app_spec:3001 -t 30 --
|
@@ -15,10 +19,9 @@ services:
|
|
15
19
|
API_PORT: 3001
|
16
20
|
jsonapi_app_spec:
|
17
21
|
build: ./spec/jsonapi_app
|
18
|
-
entrypoint: bin/wait_for_it db:5432 -t
|
19
|
-
volumes:
|
20
|
-
- ./spec/jsonapi_app:/jsonapi_app
|
21
|
-
- /jsonapi_app/tmp/
|
22
|
+
entrypoint: bin/wait_for_it db:5432 -t 60 --
|
23
|
+
# volumes:
|
24
|
+
# - ./spec/jsonapi_app:/jsonapi_app
|
22
25
|
command: bundle exec rails s -p 3001 -b '0.0.0.0'
|
23
26
|
ports:
|
24
27
|
- "3001:3001"
|
@@ -39,10 +42,9 @@ services:
|
|
39
42
|
API_PORT: 3002
|
40
43
|
jsonapi_app_console:
|
41
44
|
build: ./spec/jsonapi_app
|
42
|
-
entrypoint: bin/wait_for_it db:5432 -t
|
43
|
-
volumes:
|
44
|
-
- ./spec/jsonapi_app:/jsonapi_app
|
45
|
-
- /jsonapi_app/tmp/
|
45
|
+
entrypoint: bin/wait_for_it db:5432 -t 60 --
|
46
|
+
# volumes:
|
47
|
+
# - ./spec/jsonapi_app:/jsonapi_app
|
46
48
|
command: bundle exec rails s -p 3002 -b '0.0.0.0'
|
47
49
|
ports:
|
48
50
|
- "3002:3002"
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'active_support/core_ext/hash/transform_values'
|
1
|
+
require 'simple_jsonapi_client/utils'
|
3
2
|
require 'simple_jsonapi_client/error'
|
4
3
|
require 'simple_jsonapi_client/relationships/relationship'
|
5
4
|
require 'simple_jsonapi_client/redirection/fetch_all'
|
@@ -111,20 +110,21 @@ module SimpleJSONAPIClient
|
|
111
110
|
end
|
112
111
|
|
113
112
|
def operation(request_method, response_type, opts)
|
114
|
-
response = send(request_method, opts)
|
113
|
+
response = send(request_method, **opts)
|
115
114
|
handling_error(response) do
|
116
115
|
send(:"interpret_#{response_type}_response", response, opts[:connection])
|
117
116
|
end
|
118
117
|
end
|
119
118
|
|
120
119
|
def create_request(connection:,
|
120
|
+
id: nil,
|
121
121
|
url_opts: {},
|
122
122
|
url: self::COLLECTION_URL % url_opts,
|
123
123
|
attributes: {},
|
124
124
|
relationships: {},
|
125
125
|
**attrs)
|
126
126
|
attributes, relationships = extract_attrs(attrs, attributes, relationships)
|
127
|
-
body = template(attributes: attributes, relationships: relationships)
|
127
|
+
body = template(id: id, attributes: attributes, relationships: relationships)
|
128
128
|
connection.post(url, body)
|
129
129
|
end
|
130
130
|
|
@@ -208,12 +208,22 @@ module SimpleJSONAPIClient
|
|
208
208
|
def interpret_empty_response(response, connection)
|
209
209
|
end
|
210
210
|
|
211
|
-
|
212
|
-
relationships
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
211
|
+
if {}.respond_to?(:transform_values)
|
212
|
+
def interpreted_relationships(relationships)
|
213
|
+
relationships.transform_values { |value|
|
214
|
+
if (relationship = relationship_from(value))
|
215
|
+
{ data: relationship }
|
216
|
+
end
|
217
|
+
}
|
218
|
+
end
|
219
|
+
else
|
220
|
+
def interpreted_relationships(relationships)
|
221
|
+
Utils.transform_values(relationships) { |value|
|
222
|
+
if (relationship = relationship_from(value))
|
223
|
+
{ data: relationship }
|
224
|
+
end
|
225
|
+
}
|
226
|
+
end
|
217
227
|
end
|
218
228
|
|
219
229
|
def relationship_from(value)
|
@@ -238,12 +248,12 @@ module SimpleJSONAPIClient
|
|
238
248
|
attr_reader :id, :context
|
239
249
|
|
240
250
|
def initialize(meta: nil, id:, attributes: nil, relationships: nil, included: {}, connection:, context: nil)
|
241
|
-
@meta =
|
251
|
+
@meta = Utils.symbolize_keys(meta) if meta
|
242
252
|
@id = id
|
243
253
|
@included = included
|
244
254
|
@connection = connection
|
245
255
|
@context = context
|
246
|
-
@attributes =
|
256
|
+
@attributes = Utils.symbolize_keys(attributes) if attributes
|
247
257
|
@input_relationships = relationships
|
248
258
|
end
|
249
259
|
|
@@ -267,7 +277,7 @@ module SimpleJSONAPIClient
|
|
267
277
|
@relationships ||=
|
268
278
|
begin
|
269
279
|
if input_relationships
|
270
|
-
relationships_to_models(
|
280
|
+
relationships_to_models(Utils.symbolize_keys(input_relationships))
|
271
281
|
else
|
272
282
|
loaded_record.relationships
|
273
283
|
end
|
@@ -3,9 +3,9 @@ require 'simple_jsonapi_client/redirection/proxy'
|
|
3
3
|
module SimpleJSONAPIClient
|
4
4
|
module Redirection
|
5
5
|
class FetchAll < ::SimpleJSONAPIClient::Redirection::Proxy
|
6
|
-
def_delegators :internal_object, *(Array.instance_methods(false) - instance_methods)
|
7
6
|
def_delegators :internal_enumerator, *(Enumerator.instance_methods(false) - instance_methods)
|
8
7
|
def_delegators :internal_enumerator, *(Enumerable.instance_methods(false) - instance_methods)
|
8
|
+
def_delegators :internal_object, :size, *(Array.instance_methods(false) - instance_methods)
|
9
9
|
|
10
10
|
def initialize(base_opts, &operation)
|
11
11
|
@base_opts = base_opts
|
@@ -30,7 +30,7 @@ module SimpleJSONAPIClient
|
|
30
30
|
current_response['data'].each do |record|
|
31
31
|
yielder << record
|
32
32
|
end
|
33
|
-
break unless (next_link =
|
33
|
+
break unless (next_link = Utils.hash_dig(current_response, 'links', 'next'))
|
34
34
|
current_opts.merge!(url_opts: {}, url: next_link)
|
35
35
|
current_opts.delete(:page_opts)
|
36
36
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module SimpleJSONAPIClient
|
2
|
+
module Utils
|
3
|
+
class << self
|
4
|
+
# Implementation adapted from ActiveSupport
|
5
|
+
# Copyright (c) 2005-2019 David Heinemeier Hansson
|
6
|
+
# https://github.com/rails/rails/blob/b9ca94caea2ca6a6cc09abaffaad67b447134079/activesupport/lib/active_support/core_ext/hash/keys.rb
|
7
|
+
def symbolize_keys(hash)
|
8
|
+
result = {}
|
9
|
+
hash.each_key do |key|
|
10
|
+
result[(key.to_sym rescue key)] = hash[key]
|
11
|
+
end
|
12
|
+
result
|
13
|
+
end
|
14
|
+
|
15
|
+
def hash_dig(hash, *keys)
|
16
|
+
if hash.respond_to?(:dig)
|
17
|
+
hash.dig(*keys)
|
18
|
+
else
|
19
|
+
dig(hash, keys)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# Implementation adapted from the hash_dig gem, Copyright (c) 2015 Colin Kelley, MIT License
|
26
|
+
# https://github.com/Invoca/ruby_dig/blob/19fa8c1d2cc7706d015a3004f028169a2ff83391/lib/ruby_dig.rb
|
27
|
+
def dig(hash, key, *rest)
|
28
|
+
value = hash[key]
|
29
|
+
if value.nil? || rest.empty?
|
30
|
+
value
|
31
|
+
elsif value.is_a?(Hash) || value.is_a?(Array)
|
32
|
+
dig(value, *rest)
|
33
|
+
else
|
34
|
+
fail TypeError, "#{value.class} does not work with #dig" # should not happen with our use of #dig
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def transform_values(hash)
|
39
|
+
result = {}
|
40
|
+
hash.each do |key, value|
|
41
|
+
result[key] = yield(value)
|
42
|
+
end
|
43
|
+
result
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -20,11 +20,10 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_dependency "faraday", "
|
24
|
-
spec.add_dependency "faraday_middleware", "
|
25
|
-
spec.add_dependency "activesupport", ">= 3.1.12", "< 6"
|
23
|
+
spec.add_dependency "faraday", ">= 0.12", "< 2.0"
|
24
|
+
spec.add_dependency "faraday_middleware", "> 0.11", "< 2.0"
|
26
25
|
|
27
|
-
spec.add_development_dependency "bundler", "~>
|
26
|
+
spec.add_development_dependency "bundler", "~> 2.2"
|
28
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
29
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
30
29
|
spec.add_development_dependency "pry", "~> 0"
|
metadata
CHANGED
@@ -1,77 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_jsonapi_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ariel Caplan
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0.12'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '0.12'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: faraday_middleware
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
|
-
- - "
|
37
|
+
- - ">"
|
32
38
|
- !ruby/object:Gem::Version
|
33
39
|
version: '0.11'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.11'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: activesupport
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 3.1.12
|
48
40
|
- - "<"
|
49
41
|
- !ruby/object:Gem::Version
|
50
|
-
version: '
|
42
|
+
version: '2.0'
|
51
43
|
type: :runtime
|
52
44
|
prerelease: false
|
53
45
|
version_requirements: !ruby/object:Gem::Requirement
|
54
46
|
requirements:
|
55
|
-
- - "
|
47
|
+
- - ">"
|
56
48
|
- !ruby/object:Gem::Version
|
57
|
-
version:
|
49
|
+
version: '0.11'
|
58
50
|
- - "<"
|
59
51
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
52
|
+
version: '2.0'
|
61
53
|
- !ruby/object:Gem::Dependency
|
62
54
|
name: bundler
|
63
55
|
requirement: !ruby/object:Gem::Requirement
|
64
56
|
requirements:
|
65
57
|
- - "~>"
|
66
58
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
59
|
+
version: '2.2'
|
68
60
|
type: :development
|
69
61
|
prerelease: false
|
70
62
|
version_requirements: !ruby/object:Gem::Requirement
|
71
63
|
requirements:
|
72
64
|
- - "~>"
|
73
65
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
66
|
+
version: '2.2'
|
75
67
|
- !ruby/object:Gem::Dependency
|
76
68
|
name: rake
|
77
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,7 +106,7 @@ dependencies:
|
|
114
106
|
- - "~>"
|
115
107
|
- !ruby/object:Gem::Version
|
116
108
|
version: '0'
|
117
|
-
description:
|
109
|
+
description:
|
118
110
|
email:
|
119
111
|
- arielmcaplan@gmail.com
|
120
112
|
executables: []
|
@@ -151,13 +143,14 @@ files:
|
|
151
143
|
- lib/simple_jsonapi_client/relationships/relationship.rb
|
152
144
|
- lib/simple_jsonapi_client/relationships/singular_data_relationship.rb
|
153
145
|
- lib/simple_jsonapi_client/relationships/singular_link_relationship.rb
|
146
|
+
- lib/simple_jsonapi_client/utils.rb
|
154
147
|
- lib/simple_jsonapi_client/version.rb
|
155
148
|
- simple_jsonapi_client.gemspec
|
156
149
|
homepage: https://github.com/amcaplan/simple_jsonapi_client
|
157
150
|
licenses:
|
158
151
|
- MIT
|
159
152
|
metadata: {}
|
160
|
-
post_install_message:
|
153
|
+
post_install_message:
|
161
154
|
rdoc_options: []
|
162
155
|
require_paths:
|
163
156
|
- lib
|
@@ -172,9 +165,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
165
|
- !ruby/object:Gem::Version
|
173
166
|
version: '0'
|
174
167
|
requirements: []
|
175
|
-
|
176
|
-
|
177
|
-
signing_key:
|
168
|
+
rubygems_version: 3.2.22
|
169
|
+
signing_key:
|
178
170
|
specification_version: 4
|
179
171
|
summary: Framework for writing clients for JSONAPI APIs in Ruby.
|
180
172
|
test_files: []
|