frederick_api 0.4.4 → 0.4.6
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/v2/helpers/requestor.rb +41 -5
- data/lib/frederick_api/v2/user.rb +1 -0
- data/lib/frederick_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5ec62b4c9ba2fe7d5e1724f45b0104c95642e82
|
4
|
+
data.tar.gz: 5216931a23bf50e10bf3ff9697c47e0310189dae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8f4e02a2941809f5e92e83120a90cd527a47da319e8e56f557c2cffa939bc4c7e7d63166437325d88285a67d11633a5b3f53ff8dcea6f0ec0ae84bade98c4b4
|
7
|
+
data.tar.gz: a19981df22a71b41c2b896f15af49c146eeccb5802993ade16ed0feadf1c1e6667b38141e1b9e6c8346d2e98c605710e611883b794c708618c5f5b3cf19985e6
|
@@ -7,6 +7,13 @@ module FrederickAPI
|
|
7
7
|
class Requestor < JsonApiClient::Query::Requestor
|
8
8
|
attr_reader :path
|
9
9
|
|
10
|
+
# Paths that may have an unbounded query param length so we should always use a POST
|
11
|
+
# instead of a GET to get around AWS Cloudfront limitations
|
12
|
+
GET_VIA_POST_PATHS = [
|
13
|
+
%r{^.*locations\/[^\/]+\/contacts$},
|
14
|
+
%r{^.*locations\/[^\/]+\/interactions$}
|
15
|
+
].map(&:freeze).freeze
|
16
|
+
|
10
17
|
def initialize(klass, path = nil)
|
11
18
|
@klass = klass
|
12
19
|
@path = path
|
@@ -21,12 +28,33 @@ module FrederickAPI
|
|
21
28
|
end
|
22
29
|
end
|
23
30
|
|
31
|
+
def get(params = {})
|
32
|
+
path = resource_path(params)
|
33
|
+
|
34
|
+
params.delete(klass.primary_key)
|
35
|
+
return request(:post, path, params, 'X-Request-Method' => 'GET') if get_via_post_path?(path)
|
36
|
+
|
37
|
+
request(:get, path, params)
|
38
|
+
end
|
39
|
+
|
40
|
+
def linked(path)
|
41
|
+
uri = URI.parse(path)
|
42
|
+
return super unless get_via_post_path?(uri.path)
|
43
|
+
|
44
|
+
path_without_params = "#{uri.scheme}://#{uri.host}#{uri.path}"
|
45
|
+
params = uri.query ? CGI.parse(uri.query).each_with_object({}) { |(k, v), h| h[k] = v[0] } : {}
|
46
|
+
request(:post, path_without_params, params, 'X-Request-Method' => 'GET')
|
47
|
+
end
|
48
|
+
|
24
49
|
# Retry once on unhandled server errors
|
25
|
-
def request(type, path, params)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
50
|
+
def request(type, path, params, additional_headers = {})
|
51
|
+
headers = klass.custom_headers.merge(additional_headers)
|
52
|
+
begin
|
53
|
+
handle_errors(make_request(type, path, params, headers))
|
54
|
+
rescue JsonApiClient::Errors::ConnectionError, JsonApiClient::Errors::ServerError => ex
|
55
|
+
raise ex if ex.is_a?(JsonApiClient::Errors::NotFound) || ex.is_a?(JsonApiClient::Errors::Conflict)
|
56
|
+
handle_errors(make_request(type, path, params, headers))
|
57
|
+
end
|
30
58
|
end
|
31
59
|
|
32
60
|
private
|
@@ -37,6 +65,14 @@ module FrederickAPI
|
|
37
65
|
FrederickAPI::V2::Errors::Error
|
38
66
|
raise error_klass, result
|
39
67
|
end
|
68
|
+
|
69
|
+
def make_request(type, path, params, headers)
|
70
|
+
klass.parser.parse(klass, connection.run(type, path, params, headers))
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_via_post_path?(path)
|
74
|
+
GET_VIA_POST_PATHS.any? { |r| r.match(path) }
|
75
|
+
end
|
40
76
|
end
|
41
77
|
end
|
42
78
|
end
|
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.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frederick Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_api_client
|