simple_jsonapi_client 0.1.0 → 0.1.1
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
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3fe15f10f0376668ba0ac7b35bd384df5a59660d
|
4
|
+
data.tar.gz: ca3c40566dca8a225f2709ca24e29a4c1167635d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1642e90c3547c749da6367962d63bb55ce763146f0446ded5862b4a16dc3476102bb9a38d709ba617ff713e6a3f20c7139cb43ee07883df2f47dfd89a0b7686b
|
7
|
+
data.tar.gz: a875c9a1a68b690019b5e6af989217d5cd3cba07323fb7d5fc2f7e5c9c7029746ad779f41a3a8bc008c89b8891745fd065df9d47b70a684079db1f6f79ae1180
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
[![Build Status](https://travis-ci.org/amcaplan/simple_jsonapi_client.svg?branch=master)](https://travis-ci.org/amcaplan/simple_jsonapi_client)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/simple_jsonapi_client.svg)](https://badge.fury.io/rb/simple_jsonapi_client)
|
2
3
|
|
3
4
|
# What is `SimpleJSONAPIClient`?
|
4
5
|
|
@@ -165,11 +166,28 @@ post.comments.first.author # will not make another web request
|
|
165
166
|
|
166
167
|
`SimpleJSONAPIClient` will check the included records for related records you access through the returned model.
|
167
168
|
|
168
|
-
And finally, you can use JSONAPI-style filtering as well:
|
169
|
+
And finally, you can use JSONAPI-style filtering and pagination as well:
|
169
170
|
|
170
171
|
```ruby
|
172
|
+
# Given 3 authors...
|
173
|
+
JSONAPIAppClient::Author.fetch_all(connection: connection).to_a
|
174
|
+
=> [#<JSONAPIAppClient::Author id=1 name="Filbert" posts=#<SimpleJSONAPIClient::Relationships::ArrayLinkRelationship model_class=JSONAPIAppClient::Post url=http://jsonapi_app_console:3002/authors/1/posts> comments=#<SimpleJSONAPIClient::Relationships::ArrayLinkRelationship model_class=JSONAPIAppClient::Comment url=http://jsonapi_app_console:3002/authors/1/comments>>,
|
175
|
+
#<JSONAPIAppClient::Author id=2 name="Dilbert" posts=#<SimpleJSONAPIClient::Relationships::ArrayLinkRelationship model_class=JSONAPIAppClient::Post url=http://jsonapi_app_console:3002/authors/2/posts> comments=#<SimpleJSONAPIClient::Relationships::ArrayLinkRelationship model_class=JSONAPIAppClient::Comment url=http://jsonapi_app_console:3002/authors/2/comments>>,
|
176
|
+
#<JSONAPIAppClient::Author id=3 name="Wilbert" posts=#<SimpleJSONAPIClient::Relationships::ArrayLinkRelationship model_class=JSONAPIAppClient::Post url=http://jsonapi_app_console:3002/authors/3/posts> comments=#<SimpleJSONAPIClient::Relationships::ArrayLinkRelationship model_class=JSONAPIAppClient::Comment url=http://jsonapi_app_console:3002/authors/3/comments>>]
|
177
|
+
|
178
|
+
# Filtering by name
|
171
179
|
JSONAPIAppClient::Author.fetch_all(connection: connection, filter_opts: { name: 'Filbert' }).to_a
|
172
180
|
=> [#<JSONAPIAppClient::Author id=1 name="Filbert" posts=#<SimpleJSONAPIClient::Relationships::ArrayLinkRelationship model_class=JSONAPIAppClient::Post url=http://jsonapi_app_console:3002/authors/1/posts> comments=#<SimpleJSONAPIClient::Relationships::ArrayLinkRelationship model_class=JSONAPIAppClient::Comment url=http://jsonapi_app_console:3002/authors/1/comments>>]
|
181
|
+
|
182
|
+
# Just grabbing the last page
|
183
|
+
JSONAPIAppClient::Author.fetch_all(connection: connection, page_opts: { size: 1, number: 3 }).to_a
|
184
|
+
=> [#<JSONAPIAppClient::Author id=3 name="Wilbert" posts=#<SimpleJSONAPIClient::Relationships::ArrayLinkRelationship model_class=JSONAPIAppClient::Post url=http://jsonapi_app_console:3002/authors/3/posts> comments=#<SimpleJSONAPIClient::Relationships::ArrayLinkRelationship model_class=JSONAPIAppClient::Comment url=http://jsonapi_app_console:3002/authors/3/comments>>]
|
185
|
+
|
186
|
+
# You can adjust the pagination strategy and SimpleJSONAPIClient will follow it, but return the same results
|
187
|
+
JSONAPIAppClient::Author.fetch_all(connection: connection, page_opts: { size: 1, number: 1 }).to_a
|
188
|
+
=> [#<JSONAPIAppClient::Author id=1 name="Filbert" posts=#<SimpleJSONAPIClient::Relationships::ArrayLinkRelationship model_class=JSONAPIAppClient::Post url=http://jsonapi_app_console:3002/authors/1/posts> comments=#<SimpleJSONAPIClient::Relationships::ArrayLinkRelationship model_class=JSONAPIAppClient::Comment url=http://jsonapi_app_console:3002/authors/1/comments>>,
|
189
|
+
#<JSONAPIAppClient::Author id=2 name="Dilbert" posts=#<SimpleJSONAPIClient::Relationships::ArrayLinkRelationship model_class=JSONAPIAppClient::Post url=http://jsonapi_app_console:3002/authors/2/posts> comments=#<SimpleJSONAPIClient::Relationships::ArrayLinkRelationship model_class=JSONAPIAppClient::Comment url=http://jsonapi_app_console:3002/authors/2/comments>>,
|
190
|
+
#<JSONAPIAppClient::Author id=3 name="Wilbert" posts=#<SimpleJSONAPIClient::Relationships::ArrayLinkRelationship model_class=JSONAPIAppClient::Post url=http://jsonapi_app_console:3002/authors/3/posts> comments=#<SimpleJSONAPIClient::Relationships::ArrayLinkRelationship model_class=JSONAPIAppClient::Comment url=http://jsonapi_app_console:3002/authors/3/comments>>]
|
173
191
|
```
|
174
192
|
|
175
193
|
## Creating
|
@@ -163,10 +163,12 @@ module SimpleJSONAPIClient
|
|
163
163
|
url_opts: {},
|
164
164
|
url: self::COLLECTION_URL % url_opts,
|
165
165
|
filter_opts: {},
|
166
|
+
page_opts: {},
|
166
167
|
includes: [])
|
167
168
|
params = {}
|
168
169
|
params[:include] = includes.join(',') unless includes.empty?
|
169
170
|
params[:filter] = filter_opts unless filter_opts.empty?
|
171
|
+
params[:page] = page_opts unless page_opts.empty?
|
170
172
|
connection.get(url, params)
|
171
173
|
end
|
172
174
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_jsonapi_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ariel Caplan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
173
|
version: '0'
|
174
174
|
requirements: []
|
175
175
|
rubyforge_project:
|
176
|
-
rubygems_version: 2.
|
176
|
+
rubygems_version: 2.2.2
|
177
177
|
signing_key:
|
178
178
|
specification_version: 4
|
179
179
|
summary: Framework for writing clients for JSONAPI APIs in Ruby.
|