frederick_api 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/frederick_api.rb +3 -2
- data/lib/frederick_api/v2/helpers/paginator.rb +31 -0
- data/lib/frederick_api/v2/helpers/query_builder.rb +37 -0
- data/lib/frederick_api/v2/helpers/requestor.rb +18 -0
- data/lib/frederick_api/v2/resource.rb +3 -2
- data/lib/frederick_api/version.rb +1 -1
- metadata +5 -4
- data/lib/frederick_api/v2/paginator.rb +0 -29
- data/lib/frederick_api/v2/query_builder.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb8dca5b04ce66431f7b3d0a64691e65c6f60c26
|
4
|
+
data.tar.gz: 14db44aaa05c3c7eece1429ed5b7b7665f43e22d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17942a838abbcd627cea925ebe3b4ae084fe49907e2e158cfa994fa2dcb1e388cc54f92390d321d11523f6119fa4c42d105f5ff05002db9c5280cef7674d7715
|
7
|
+
data.tar.gz: ad0a698d3ebf401a9808bb0523f5c8d26a8d7580a3a6b753ce08ccfa72085707162a4a9b9b8f399aa2fdff9c9fac025cb86489078ab5537d0069f472e2d1659c
|
data/lib/frederick_api.rb
CHANGED
@@ -6,8 +6,9 @@ require 'active_support/core_ext/class/attribute.rb'
|
|
6
6
|
|
7
7
|
# FrederickAPI libs
|
8
8
|
require 'frederick_api/configuration'
|
9
|
-
require 'frederick_api/v2/paginator'
|
10
|
-
require 'frederick_api/v2/query_builder'
|
9
|
+
require 'frederick_api/v2/helpers/paginator'
|
10
|
+
require 'frederick_api/v2/helpers/query_builder'
|
11
|
+
require 'frederick_api/v2/helpers/requestor'
|
11
12
|
require 'frederick_api/v2/resource'
|
12
13
|
|
13
14
|
require 'frederick_api/v2/user'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FrederickAPI
|
4
|
+
module V2
|
5
|
+
module Helpers
|
6
|
+
# Custom paginator for json api client
|
7
|
+
# Fixes param names for pagination
|
8
|
+
# Also adds ability to get all records from a paginated API
|
9
|
+
class Paginator < JsonApiClient::Paginating::Paginator
|
10
|
+
self.page_param = 'page.number'
|
11
|
+
self.per_page_param = 'page.size'
|
12
|
+
|
13
|
+
def all_records
|
14
|
+
current_result_set = nil
|
15
|
+
results = self.result_set.to_a
|
16
|
+
first_resource = self.result_set.first
|
17
|
+
|
18
|
+
(total_pages - current_page).times do
|
19
|
+
first_resource.class.with_headers(first_resource.custom_headers) do
|
20
|
+
current_result_set = current_result_set ? current_result_set.pages.next : self.result_set.pages.next
|
21
|
+
raise 'next link not found' unless current_result_set
|
22
|
+
results.push(*current_result_set.to_a)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
results
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/module'
|
4
|
+
|
5
|
+
module FrederickAPI
|
6
|
+
module V2
|
7
|
+
module Helpers
|
8
|
+
# Used to convert nested params to dot notation for Frederick API
|
9
|
+
class QueryBuilder < JsonApiClient::Query::Builder
|
10
|
+
def params
|
11
|
+
to_dot_params(
|
12
|
+
filter_params.merge(pagination_params.merge(includes_params).merge(select_params))
|
13
|
+
).merge(order_params)
|
14
|
+
.merge(primary_key_params)
|
15
|
+
.merge(path_params)
|
16
|
+
.merge(additional_params)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_dot_params(object, prefix = nil)
|
20
|
+
return {} if object == {}
|
21
|
+
|
22
|
+
if object.is_a? Hash
|
23
|
+
object.map do |key, value|
|
24
|
+
if prefix
|
25
|
+
to_dot_params value, "#{prefix}.#{key}"
|
26
|
+
else
|
27
|
+
to_dot_params value, key.to_s
|
28
|
+
end
|
29
|
+
end.reduce(&:merge)
|
30
|
+
else
|
31
|
+
{ prefix => object }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FrederickAPI
|
4
|
+
module V2
|
5
|
+
module Helpers
|
6
|
+
# Requestor for v2 client to use built on top of JsonApiClient::Query::Requestor
|
7
|
+
class Requestor < JsonApiClient::Query::Requestor
|
8
|
+
# Retry once on unhandled server errors
|
9
|
+
def request(type, path, params)
|
10
|
+
super
|
11
|
+
rescue JsonApiClient::Errors::ConnectionError, JsonApiClient::Errors::ServerError => ex
|
12
|
+
raise ex if ex.is_a?(JsonApiClient::Errors::NotFound) || ex.is_a?(JsonApiClient::Errors::Conflict)
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -5,8 +5,9 @@ module FrederickAPI
|
|
5
5
|
# Class from which Frederick V2 Resources inherit
|
6
6
|
# Inherits functionality from JsonApiClient::Resource
|
7
7
|
class Resource < JsonApiClient::Resource
|
8
|
-
self.query_builder = FrederickAPI::V2::QueryBuilder
|
9
|
-
self.paginator = FrederickAPI::V2::Paginator
|
8
|
+
self.query_builder = FrederickAPI::V2::Helpers::QueryBuilder
|
9
|
+
self.paginator = FrederickAPI::V2::Helpers::Paginator
|
10
|
+
self.requestor_class = FrederickAPI::V2::Helpers::Requestor
|
10
11
|
|
11
12
|
attr_accessor :custom_headers
|
12
13
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frederick_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frederick Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_api_client
|
@@ -39,10 +39,11 @@ files:
|
|
39
39
|
- lib/frederick_api/v2/contact_list.rb
|
40
40
|
- lib/frederick_api/v2/contact_property.rb
|
41
41
|
- lib/frederick_api/v2/contact_type.rb
|
42
|
+
- lib/frederick_api/v2/helpers/paginator.rb
|
43
|
+
- lib/frederick_api/v2/helpers/query_builder.rb
|
44
|
+
- lib/frederick_api/v2/helpers/requestor.rb
|
42
45
|
- lib/frederick_api/v2/interaction.rb
|
43
46
|
- lib/frederick_api/v2/location.rb
|
44
|
-
- lib/frederick_api/v2/paginator.rb
|
45
|
-
- lib/frederick_api/v2/query_builder.rb
|
46
47
|
- lib/frederick_api/v2/resource.rb
|
47
48
|
- lib/frederick_api/v2/user.rb
|
48
49
|
- lib/frederick_api/version.rb
|
@@ -1,29 +0,0 @@
|
|
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
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'active_support/core_ext/module'
|
4
|
-
|
5
|
-
module FrederickAPI
|
6
|
-
module V2
|
7
|
-
# Used to convert nested params to dot notation for Frederick API
|
8
|
-
class QueryBuilder < JsonApiClient::Query::Builder
|
9
|
-
def params
|
10
|
-
to_dot_params(
|
11
|
-
filter_params.merge(pagination_params.merge(includes_params).merge(select_params))
|
12
|
-
).merge(order_params)
|
13
|
-
.merge(primary_key_params)
|
14
|
-
.merge(path_params)
|
15
|
-
.merge(additional_params)
|
16
|
-
end
|
17
|
-
|
18
|
-
def to_dot_params(object, prefix = nil)
|
19
|
-
return {} if object == {}
|
20
|
-
|
21
|
-
if object.is_a? Hash
|
22
|
-
object.map do |key, value|
|
23
|
-
if prefix
|
24
|
-
to_dot_params value, "#{prefix}.#{key}"
|
25
|
-
else
|
26
|
-
to_dot_params value, key.to_s
|
27
|
-
end
|
28
|
-
end.reduce(&:merge)
|
29
|
-
else
|
30
|
-
{ prefix => object }
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|