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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 711d8e8257f97e7ad18803cca7b24e8e87a9f43e
4
- data.tar.gz: baf134c2da2e7da52cfeb7a75ccd5b90a18a2200
3
+ metadata.gz: e5ec62b4c9ba2fe7d5e1724f45b0104c95642e82
4
+ data.tar.gz: 5216931a23bf50e10bf3ff9697c47e0310189dae
5
5
  SHA512:
6
- metadata.gz: 294478020b031f49b7f5ae1a636977ff5301befb4892f44b9526ddec5037c2b2f4f6461a391e7661ed70db4cdf05177f696bb08c63f158c0d6f1ee4ba7855dff
7
- data.tar.gz: fbce1720a78066c1caeeb2e1da9dbf688f250eacea4fa407307a838d492ef898ff8791cbdd83c7cfe1d38462b5f456f1643acc8772063ca7163c5d8effb1df45
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
- handle_errors(super)
27
- rescue JsonApiClient::Errors::ConnectionError, JsonApiClient::Errors::ServerError => ex
28
- raise ex if ex.is_a?(JsonApiClient::Errors::NotFound) || ex.is_a?(JsonApiClient::Errors::Conflict)
29
- handle_errors(super)
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
@@ -5,6 +5,7 @@ module FrederickAPI
5
5
  # /v2/users
6
6
  class User < Resource
7
7
  has_many :roles, class_name: 'FrederickAPI::V2::Role'
8
+ has_many :permitted_locations, class_name: 'FrederickAPI::V2::Location'
8
9
  end
9
10
  end
10
11
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module FrederickAPI
4
4
  # Current gem version
5
- VERSION = '0.4.4'
5
+ VERSION = '0.4.6'
6
6
  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
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-01-11 00:00:00.000000000 Z
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