flexirest 1.10.1 → 1.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/docs/json-api.md +16 -4
- data/docs/plain-requests.md +1 -1
- data/lib/flexirest/json_api_proxy.rb +1 -4
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/json_api_spec.rb +40 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8001a7a20f2054fd34a7f09ae350253da96eba3dc4ff8b390e5b07509f1f09ea
|
4
|
+
data.tar.gz: 8f96916235d0f45fa9aa1c3ff5f37502f81c5d2f2a1c5db079d72e63d0de923c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad2e6dad01ee45f4d0b0540b53e8c6f20329d94cae6364f59d281ede3c45955959d3ecb70762249911cf05cc637840ba7e88a1c2fac49ff329ad3de680f643b3
|
7
|
+
data.tar.gz: de207d3cb3ac7bb243137925217efc0067d7c80950bac1a6a02450f251da0380470866e448ffd5c876e6009ed07b2cf0573ad82ce0782ad07cfb53c839a8e70d
|
data/CHANGELOG.md
CHANGED
data/docs/json-api.md
CHANGED
@@ -12,17 +12,26 @@ This proxy translates requests according to the JSON API specifications, parses
|
|
12
12
|
|
13
13
|
It supports lazy loading by default. Unless a compound document is returned from the connected JSON API service, it will make another request to the service for the specified linked resource.
|
14
14
|
|
15
|
+
|
16
|
+
## Including associations
|
17
|
+
|
15
18
|
To reduce the number of requests to the service, you can ask the service to include the linked resources in the response. Such responses are called "compound documents". To do this, use the `includes` method:
|
16
19
|
|
17
20
|
```ruby
|
18
|
-
# Makes a call to /articles
|
21
|
+
# Makes a call to: /articles?include=images
|
19
22
|
Article.includes(:images).all
|
20
23
|
|
21
|
-
#
|
24
|
+
# Fetch nested resources: /articles?include=images.tags,images.photographer
|
22
25
|
Article.includes(:images => [:tags, :photographer]).all
|
26
|
+
|
27
|
+
# Note: the `includes` method takes precedence over the passed `:include` parameter.
|
28
|
+
# This will result in query: /articles?include=images
|
29
|
+
Article.includes(:images).all(include: "author")
|
23
30
|
```
|
24
31
|
|
25
|
-
|
32
|
+
## Resource type
|
33
|
+
|
34
|
+
The `type` value is guessed from the class name, but it can be set specifically with `alias_type`:
|
26
35
|
|
27
36
|
```ruby
|
28
37
|
class Photographer < Flexirest::Base
|
@@ -34,7 +43,10 @@ class Photographer < Flexirest::Base
|
|
34
43
|
end
|
35
44
|
```
|
36
45
|
|
37
|
-
|
46
|
+
|
47
|
+
## Notes
|
48
|
+
|
49
|
+
Updating relationships is not yet supported.
|
38
50
|
|
39
51
|
|
40
52
|
-----
|
data/docs/plain-requests.md
CHANGED
@@ -7,7 +7,7 @@ class Person < Flexirest::Base
|
|
7
7
|
end
|
8
8
|
|
9
9
|
people = Person._plain_request('http://api.example.com/v1/people') # Defaults to get with no parameters
|
10
|
-
# people is a
|
10
|
+
# people is a string containing the response
|
11
11
|
|
12
12
|
Person._plain_request('http://api.example.com/v1/people', :post, {id:1234,name:"John"}) # Post with parameters
|
13
13
|
```
|
@@ -50,11 +50,8 @@ module Flexirest
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def translate(params, include_associations)
|
53
|
-
# Return to caller if nothing is to be done
|
54
|
-
return params unless params.present? && include_associations.present?
|
55
|
-
|
56
53
|
# Format the linked resources array, and assign to include key
|
57
|
-
params[:include] = format_include_params(include_associations)
|
54
|
+
params[:include] = format_include_params(include_associations) if include_associations.present?
|
58
55
|
end
|
59
56
|
|
60
57
|
private
|
data/lib/flexirest/version.rb
CHANGED
data/spec/lib/json_api_spec.rb
CHANGED
@@ -303,7 +303,7 @@ describe 'JSON API' do
|
|
303
303
|
let(:tags) { JsonAPIExample::Tag }
|
304
304
|
let(:author) { JsonAPIExample::Author }
|
305
305
|
|
306
|
-
|
306
|
+
describe 'responses' do
|
307
307
|
it 'should return the data object if the response contains only one data instance' do
|
308
308
|
expect(subject.find(1)).to be_an_instance_of(JsonAPIExampleArticle)
|
309
309
|
end
|
@@ -370,17 +370,17 @@ describe 'JSON API' do
|
|
370
370
|
end
|
371
371
|
end
|
372
372
|
|
373
|
-
|
373
|
+
describe 'attributes' do
|
374
374
|
it 'should return the attributes as part of the data instance' do
|
375
|
-
expect(subject.find(1).item).
|
375
|
+
expect(subject.find(1).item).to eq("item one")
|
376
376
|
end
|
377
377
|
|
378
378
|
it 'should return the association\'s attributes as part of the association instance' do
|
379
|
-
expect(subject.includes(:author).find_single_author(1).author.item).
|
379
|
+
expect(subject.includes(:author).find_single_author(1).author.item).to eq("item two")
|
380
380
|
end
|
381
381
|
end
|
382
382
|
|
383
|
-
|
383
|
+
describe 'associations' do
|
384
384
|
it 'should retrieve the resource\'s associations via its relationships object' do
|
385
385
|
expect(subject.includes(:tags).find(1).tags.size).to eq(2)
|
386
386
|
end
|
@@ -415,6 +415,40 @@ describe 'JSON API' do
|
|
415
415
|
end
|
416
416
|
end
|
417
417
|
|
418
|
+
describe 'requests' do
|
419
|
+
describe 'the `include=` parameter' do
|
420
|
+
before { stub_request(:get, %r{example\.com/articles}) }
|
421
|
+
|
422
|
+
context 'when using `.includes(:tags)`' do
|
423
|
+
it 'equal "tags"' do
|
424
|
+
JsonAPIExample::Article.includes(:tags).real_index
|
425
|
+
expect(WebMock).to have_requested(:get, 'http://www.example.com/articles?include=tags')
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
context 'when using `.includes(tags: [:authors, :articles])`' do
|
430
|
+
it 'equal "tags.authors,tags.articles"' do
|
431
|
+
JsonAPIExample::Article.includes(tags: [:authors, :articles]).real_index
|
432
|
+
expect(WebMock).to have_requested(:get, 'http://www.example.com/articles?include=tags.authors,tags.articles')
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
context 'when using both `.includes(:tags)` and other params in the final call' do
|
437
|
+
it 'uses the values passed to the `includes() method`' do
|
438
|
+
JsonAPIExample::Article.includes(:tags).real_index(filter: { author_id: 4 })
|
439
|
+
expect(WebMock).to have_requested(:get, 'http://www.example.com/articles?filter%5Bauthor_id%5D=4&include=tags')
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
context 'when using both `.includes(:tags)` and the :include param in final call' do
|
444
|
+
it 'uses the values passed to the `includes() method`' do
|
445
|
+
JsonAPIExample::Article.includes(:tags).real_index(include: "author")
|
446
|
+
expect(WebMock).to have_requested(:get, 'http://www.example.com/articles?include=tags')
|
447
|
+
end
|
448
|
+
end
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
418
452
|
context 'lazy loading' do
|
419
453
|
it 'should fetch association lazily' do
|
420
454
|
stub_request(:get, /www.example.com\/articles\/1\/tags/)
|
@@ -434,7 +468,7 @@ describe 'JSON API' do
|
|
434
468
|
end
|
435
469
|
end
|
436
470
|
|
437
|
-
|
471
|
+
describe 'client' do
|
438
472
|
it 'should request with json api format, and expect a json api response' do
|
439
473
|
expect_any_instance_of(Flexirest::Connection).to receive(:post) { |_, _, _, options|
|
440
474
|
expect(options[:headers]).to include('Content-Type' => 'application/vnd.api+json')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flexirest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.10.
|
4
|
+
version: 1.10.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Jeffries
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|