frederick_api 0.6 → 0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +16 -1
- data/lib/frederick_api/v2/automation.rb +2 -0
- data/lib/frederick_api/v2/automation_step.rb +14 -0
- data/lib/frederick_api/v2/campaign.rb +12 -0
- data/lib/frederick_api/v2/communication_template.rb +8 -0
- data/lib/frederick_api/v2/email_document.rb +12 -0
- data/lib/frederick_api/v2/helpers/paginator.rb +13 -2
- data/lib/frederick_api/v2/helpers/requestor.rb +21 -3
- data/lib/frederick_api/v2/resource.rb +10 -1
- data/lib/frederick_api/version.rb +1 -1
- data/lib/frederick_api.rb +4 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 327163b30ae7b807b87a78479bc2cf6944a30d0fbc98d8c0156aaf557fd55445
|
4
|
+
data.tar.gz: dd84394527eb5bccfa256e2b59d4ed27a172ad7fffec9e1dcd5f83d46d8bd0de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c6109c022a72aacac5e95f66a315226732657b327eed72252ad6df76ed0cc2976e6adc0c1a573d47c5e8335eb6ce0a53401f3dfd9ebe13ab433f530b34a1f48
|
7
|
+
data.tar.gz: b818f0bcaf5a470ce4956e1337b5dd1f8f181fe52b5a30b1c86399d37e17282afa0a3d5dc62d8bd67d3819b55a3015d5824db8e28cb6e7df5252d6490297c05d
|
data/README.md
CHANGED
@@ -88,6 +88,21 @@ FrederickAPI::V2::Location.with_access_token(access_token) do
|
|
88
88
|
end
|
89
89
|
```
|
90
90
|
|
91
|
+
### Using Headers
|
92
|
+
|
93
|
+
`Resource.with_access_token` is extended to take headers in the method `Resource.with_access_token_and_headers`. This is useful when we need to pass the universal customer to services that accept it.
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
access_token = '9jsdo320fjfkfdksls30dfdcd919bcaa1b7804dbbebda0'
|
97
|
+
headers = { 'X-Universal-Customer': '{"source_platform":"mindbody","source_location_id":"1","source_customer_id":"77"}' }
|
98
|
+
|
99
|
+
FrederickAPI::V2::CommunicationTemplate.with_access_token_and_headers(access_token, headers) do
|
100
|
+
template = FrederickAPI::V2::CommunicationTemplate.create(template_attributes)
|
101
|
+
|
102
|
+
template.name
|
103
|
+
# => 'Name from Attrs'
|
104
|
+
end
|
105
|
+
```
|
91
106
|
### Nested Resources
|
92
107
|
|
93
108
|
Nested resources must be accessed using `where` to scope the request:
|
@@ -111,4 +126,4 @@ Polling until the job is complete, fetching and returning the completed resource
|
|
111
126
|
* A FrederickAPI::V2::Errors::BackgroundJobFailure exception is raised if the API returns
|
112
127
|
an error on an asyncronous job.
|
113
128
|
* A BackgroundJob Resource will be returned from the client in the case that a successful
|
114
|
-
job does not return a
|
129
|
+
job does not return a resource.
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FrederickAPI
|
4
|
+
module V2
|
5
|
+
# Resource for automation step
|
6
|
+
class AutomationStep < Resource
|
7
|
+
belongs_to :location
|
8
|
+
has_one :automation
|
9
|
+
has_one :previous_automation_step, class_name: 'FrederickAPI::V2::AutomationStep'
|
10
|
+
|
11
|
+
self.read_only_attributes += %i[location_id]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -17,12 +17,11 @@ module FrederickAPI
|
|
17
17
|
|
18
18
|
(total_pages - current_page).times do
|
19
19
|
first_resource.class.with_headers(first_resource.custom_headers) do
|
20
|
-
current_result_set = current_result_set
|
20
|
+
current_result_set = next_result_set(current_result_set)
|
21
21
|
raise 'next link not found' unless current_result_set
|
22
22
|
results.push(*current_result_set.to_a)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
26
25
|
results
|
27
26
|
end
|
28
27
|
|
@@ -47,6 +46,18 @@ module FrederickAPI
|
|
47
46
|
def current_page
|
48
47
|
params.fetch("page.#{page_param}", 1).to_i
|
49
48
|
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
# refetching the next link if no response is found.
|
53
|
+
def next_result_set(current_result_set)
|
54
|
+
if current_result_set
|
55
|
+
response = current_result_set.pages.next
|
56
|
+
response.present? ? response : current_result_set.pages.next
|
57
|
+
else
|
58
|
+
self.result_set.pages.next
|
59
|
+
end
|
60
|
+
end
|
50
61
|
end
|
51
62
|
end
|
52
63
|
end
|
@@ -7,6 +7,17 @@ module FrederickAPI
|
|
7
7
|
class Requestor < JsonApiClient::Query::Requestor
|
8
8
|
attr_reader :path
|
9
9
|
|
10
|
+
# For backward compatibility, preserve these JSON API client errors instead of raising
|
11
|
+
# FrederickAPI::Errors::Error
|
12
|
+
JSON_API_CLIENT_PASSTHROUGH_ERRORS = [
|
13
|
+
JsonApiClient::Errors::NotAuthorized,
|
14
|
+
JsonApiClient::Errors::AccessDenied,
|
15
|
+
JsonApiClient::Errors::NotFound,
|
16
|
+
JsonApiClient::Errors::Conflict,
|
17
|
+
JsonApiClient::Errors::ServerError,
|
18
|
+
JsonApiClient::Errors::UnexpectedStatus
|
19
|
+
].freeze
|
20
|
+
|
10
21
|
# Paths that may have an unbounded query param length so we should always use a POST
|
11
22
|
# instead of a GET to get around AWS Cloudfront limitations
|
12
23
|
GET_VIA_POST_PATHS = [
|
@@ -45,7 +56,7 @@ module FrederickAPI
|
|
45
56
|
|
46
57
|
path_without_params = "#{uri.scheme}://#{uri.host}#{uri.path}"
|
47
58
|
params = uri.query ? CGI.parse(uri.query).each_with_object({}) { |(k, v), h| h[k] = v[0] } : {}
|
48
|
-
request(:post, path_without_params,
|
59
|
+
request(:post, path_without_params, body: params.to_json, additional_headers: { 'X-Request-Method' => 'GET' })
|
49
60
|
end
|
50
61
|
|
51
62
|
# Retry once on unhandled server errors
|
@@ -82,14 +93,21 @@ module FrederickAPI
|
|
82
93
|
def make_request(type, path, params:, body:, headers:)
|
83
94
|
faraday_response = connection.run(type, path, params: params, body: body, headers: headers)
|
84
95
|
return klass.parser.parse(klass, faraday_response) unless faraday_response.status == 303
|
96
|
+
|
85
97
|
linked(faraday_response.headers['location'])
|
86
|
-
rescue JsonApiClient::Errors::ClientError =>
|
87
|
-
|
98
|
+
rescue JsonApiClient::Errors::ClientError => e
|
99
|
+
handle_json_api_client_error(e)
|
88
100
|
end
|
89
101
|
|
90
102
|
def get_via_post_path?(path)
|
91
103
|
GET_VIA_POST_PATHS.any? { |r| r.match(path) }
|
92
104
|
end
|
105
|
+
|
106
|
+
def handle_json_api_client_error(error)
|
107
|
+
raise error if JSON_API_CLIENT_PASSTHROUGH_ERRORS.include?(error.class)
|
108
|
+
|
109
|
+
klass.parser.parse(klass, error.env.response)
|
110
|
+
end
|
93
111
|
end
|
94
112
|
end
|
95
113
|
end
|
@@ -36,7 +36,16 @@ module FrederickAPI
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.with_access_token(token)
|
39
|
-
|
39
|
+
with_access_token_and_headers(token) do
|
40
|
+
yield
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.with_access_token_and_headers(token, headers = {})
|
45
|
+
with_headers(
|
46
|
+
authorization: "Bearer #{token}",
|
47
|
+
**headers
|
48
|
+
) do
|
40
49
|
yield
|
41
50
|
end
|
42
51
|
end
|
data/lib/frederick_api.rb
CHANGED
@@ -25,6 +25,7 @@ require 'frederick_api/v2/business_category'
|
|
25
25
|
|
26
26
|
# Core resources
|
27
27
|
require 'frederick_api/v2/automation'
|
28
|
+
require 'frederick_api/v2/automation_step'
|
28
29
|
require 'frederick_api/v2/communication_content'
|
29
30
|
require 'frederick_api/v2/contact'
|
30
31
|
require 'frederick_api/v2/contact_property'
|
@@ -32,6 +33,9 @@ require 'frederick_api/v2/contact_list'
|
|
32
33
|
require 'frederick_api/v2/contact_type'
|
33
34
|
require 'frederick_api/v2/interaction'
|
34
35
|
require 'frederick_api/v2/role'
|
36
|
+
require 'frederick_api/v2/campaign'
|
37
|
+
require 'frederick_api/v2/email_document'
|
38
|
+
require 'frederick_api/v2/communication_template'
|
35
39
|
|
36
40
|
# Namespace for all Frederick API client methods/classes
|
37
41
|
module FrederickAPI
|
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.
|
4
|
+
version: '0.10'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frederick Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_api_client
|
@@ -36,13 +36,17 @@ files:
|
|
36
36
|
- lib/frederick_api.rb
|
37
37
|
- lib/frederick_api/configuration.rb
|
38
38
|
- lib/frederick_api/v2/automation.rb
|
39
|
+
- lib/frederick_api/v2/automation_step.rb
|
39
40
|
- lib/frederick_api/v2/background_job.rb
|
40
41
|
- lib/frederick_api/v2/business_category.rb
|
42
|
+
- lib/frederick_api/v2/campaign.rb
|
41
43
|
- lib/frederick_api/v2/communication_content.rb
|
44
|
+
- lib/frederick_api/v2/communication_template.rb
|
42
45
|
- lib/frederick_api/v2/contact.rb
|
43
46
|
- lib/frederick_api/v2/contact_list.rb
|
44
47
|
- lib/frederick_api/v2/contact_property.rb
|
45
48
|
- lib/frederick_api/v2/contact_type.rb
|
49
|
+
- lib/frederick_api/v2/email_document.rb
|
46
50
|
- lib/frederick_api/v2/errors/errors.rb
|
47
51
|
- lib/frederick_api/v2/helpers/backgroundable_parser.rb
|
48
52
|
- lib/frederick_api/v2/helpers/has_many.rb
|
@@ -75,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
79
|
- !ruby/object:Gem::Version
|
76
80
|
version: '0'
|
77
81
|
requirements: []
|
78
|
-
rubygems_version: 3.0.
|
82
|
+
rubygems_version: 3.0.9
|
79
83
|
signing_key:
|
80
84
|
specification_version: 4
|
81
85
|
summary: Frederick API Client
|