frederick_api 0.1.1 → 0.1.2

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
2
  SHA1:
3
- metadata.gz: 639b7019e1919ed4998f737434166f9b401484fd
4
- data.tar.gz: c793239bf2e75019ca1efe3b53fe2234bbc98fa3
3
+ metadata.gz: 49e604b17a3e27bba56beaa861431ad3cf06b880
4
+ data.tar.gz: 65d4d51f7e6d34cd7a67f5b8292c104253c4b52b
5
5
  SHA512:
6
- metadata.gz: 5e5bcddde1d02e42f58059e5f194fcd446eb0dad19fe8d111c6098025e8f77e95710c4654d40c279a46c62ca51ffde363cda35cfcc030b35bffaff1a6378404a
7
- data.tar.gz: bd211000835b4b27f72d07841ef83899ae8c79d119ff8dbd402e18dcd3ec40ea8b83c46d3a446e3ccecc5a7a790cf9f0c8b0850a88f98ebe532a8695ab3762ca
6
+ metadata.gz: 14df284fcec910ee7a9769f734944cd577cacff9b94b619cbead4eb8a6b743ff5aab90c21f05e1683fd59511d67e295b2bef60e3b451b5188126164e4aab8d16
7
+ data.tar.gz: 432864cd9629aa3575a230750f8bcb756f9089acdaaad201f3cf96789369076ec968193e4ab2d2cf0650ee516305da460879e53f9bcf19986ba10e278ea9d610
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FrederickAPI
4
+ module V2
5
+ # Custom paginator for json api client
6
+ # Fixes param names for pagination
7
+ # Also adds ability to get all records from a paginated API
8
+ class Paginator < JsonApiClient::Paginating::Paginator
9
+ self.page_param = 'page.number'
10
+ self.per_page_param = 'page.size'
11
+
12
+ def all_records
13
+ current_result_set = nil
14
+ results = self.result_set.to_a
15
+ first_resource = self.result_set.first
16
+
17
+ (total_pages - current_page).times do
18
+ first_resource.class.with_headers(first_resource.custom_headers) do
19
+ current_result_set = current_result_set ? current_result_set.pages.next : self.result_set.pages.next
20
+ raise 'next link not found' unless current_result_set
21
+ results.push(*current_result_set.to_a)
22
+ end
23
+ end
24
+
25
+ results
26
+ end
27
+ end
28
+ end
29
+ end
@@ -6,6 +6,14 @@ module FrederickAPI
6
6
  # Inherits functionality from JsonApiClient::Resource
7
7
  class Resource < JsonApiClient::Resource
8
8
  self.query_builder = FrederickAPI::V2::QueryBuilder
9
+ self.paginator = FrederickAPI::V2::Paginator
10
+
11
+ attr_accessor :custom_headers
12
+
13
+ def initialize(params = {})
14
+ self.custom_headers = self.class.custom_headers
15
+ super
16
+ end
9
17
 
10
18
  def self.site
11
19
  "#{FrederickAPI.config.base_url}/v2/"
@@ -2,5 +2,5 @@
2
2
 
3
3
  module FrederickAPI
4
4
  # Current gem version
5
- VERSION = '0.1.1'
5
+ VERSION = '0.1.2'
6
6
  end
data/lib/frederick_api.rb CHANGED
@@ -2,9 +2,11 @@
2
2
 
3
3
  # Third-party libs
4
4
  require 'json_api_client'
5
+ require 'active_support/core_ext/class/attribute.rb'
5
6
 
6
7
  # FrederickAPI libs
7
8
  require 'frederick_api/configuration'
9
+ require 'frederick_api/v2/paginator'
8
10
  require 'frederick_api/v2/query_builder'
9
11
  require 'frederick_api/v2/resource'
10
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frederick_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frederick Engineering
@@ -41,6 +41,7 @@ files:
41
41
  - lib/frederick_api/v2/contact_type.rb
42
42
  - lib/frederick_api/v2/interaction.rb
43
43
  - lib/frederick_api/v2/location.rb
44
+ - lib/frederick_api/v2/paginator.rb
44
45
  - lib/frederick_api/v2/query_builder.rb
45
46
  - lib/frederick_api/v2/resource.rb
46
47
  - lib/frederick_api/v2/user.rb