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
- SHA256:
3
- metadata.gz: 48b579116cf787a39e4a97030ad4961063c4db940ec2fbdee03353ae162d2b6b
4
- data.tar.gz: 26ae2466b469d541e2ce3105db766fbcb4dc72c80d6ba49a284a2b8a432e2341
2
+ SHA1:
3
+ metadata.gz: 3fe15f10f0376668ba0ac7b35bd384df5a59660d
4
+ data.tar.gz: ca3c40566dca8a225f2709ca24e29a4c1167635d
5
5
  SHA512:
6
- metadata.gz: 82279b13b63ae34daec3f2e72118108bf345d847a790e064aca6471b42bbb303d899d29cbafc76930c2738418835a69d4c918a119474d53b00ce06159b43c108
7
- data.tar.gz: 1725ec376ef0e45f8e3a7bc59b59e473a516b047db2d061c5a469330e382eb18996464db771698c59a8cacd7ac21656f6252f1b753f0f5509b1312a8835a8f3c
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
 
@@ -31,6 +31,7 @@ module SimpleJSONAPIClient
31
31
  end
32
32
  break unless (next_link = current_response.dig('links', 'next'))
33
33
  current_opts.merge!(url_opts: {}, url: next_link)
34
+ current_opts.delete(:page_opts)
34
35
  end
35
36
  end
36
37
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleJSONAPIClient
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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: 2017-11-27 00:00:00.000000000 Z
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.7.1
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.