nypl_ruby_util 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/platform_api_client.rb +10 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c6574f7bf8717173b11a9635daacec8d49be69a7fc35e5584d713f8ef37c673
|
4
|
+
data.tar.gz: 5035a2920d8c8f012c711050604f1ecd12832b4e8df3661eb0a16f707735c9d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9349fa7cc85b2429daef2ecd358392f58425a107516f1392d8fbbdb8861e460ec4dd48fab3d4163f58e351dc3001a1981efcaa86b76e5758442510e06ccb7ac3
|
7
|
+
data.tar.gz: 7a1e9057927bad0ff9425617f534abf17e63e2cb25cabb651bc2dd10fe234c5ca9c0d80c8d4dc54c51539a8cede92a82ce289f35e10dd64031d0c9c7a34d4332
|
data/lib/platform_api_client.rb
CHANGED
@@ -21,7 +21,7 @@ class PlatformApiClient
|
|
21
21
|
@error_options = default_errors.merge(options[:errors] || {})
|
22
22
|
end
|
23
23
|
|
24
|
-
def get (path)
|
24
|
+
def get (path, transaction_data = {})
|
25
25
|
|
26
26
|
authenticate! if authenticated
|
27
27
|
|
@@ -38,7 +38,7 @@ class PlatformApiClient
|
|
38
38
|
|
39
39
|
$logger.debug "Got platform api response", { code: response.code, body: response.body }
|
40
40
|
|
41
|
-
parse_json_response response, path
|
41
|
+
parse_json_response response, path, transaction_data
|
42
42
|
|
43
43
|
rescue Exception => e
|
44
44
|
raise StandardError.new(e), "Failed to retrieve #{path} #{e.message}"
|
@@ -47,12 +47,12 @@ class PlatformApiClient
|
|
47
47
|
|
48
48
|
private
|
49
49
|
|
50
|
-
def parse_json_response (response, path)
|
50
|
+
def parse_json_response (response, path, transaction_data = {})
|
51
51
|
code = response.code.to_i
|
52
52
|
if code < 400
|
53
53
|
JSON.parse(response.body)
|
54
54
|
elsif error_options[code]
|
55
|
-
instance_exec(response, path, &error_options[code])
|
55
|
+
instance_exec(response, path, transaction_data, &error_options[code])
|
56
56
|
else
|
57
57
|
raise "Error interpretting response for path #{path}: (#{response.code}): #{response.body}"
|
58
58
|
{}
|
@@ -92,12 +92,13 @@ class PlatformApiClient
|
|
92
92
|
|
93
93
|
def default_errors
|
94
94
|
{
|
95
|
-
401 => lambda do |response, path|
|
96
|
-
|
95
|
+
401 => lambda do |response, path, transaction_data = {}|
|
96
|
+
transaction_data[:try_count] ||= 0
|
97
|
+
if transaction_data[:try_count] < 1
|
97
98
|
# Likely an expired access-token; Wipe it for next run
|
98
|
-
|
99
|
-
access_token = nil
|
100
|
-
get(path)
|
99
|
+
transaction_data[:try_count] += 1
|
100
|
+
self.access_token = nil
|
101
|
+
get(path, transaction_data)
|
101
102
|
else
|
102
103
|
raise "Error interpretting response for path #{path}: (#{response.code}): #{response.body}"
|
103
104
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nypl_ruby_util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Appel
|
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
- !ruby/object:Gem::Version
|
142
142
|
version: '0'
|
143
143
|
requirements: []
|
144
|
-
rubygems_version: 3.1.
|
144
|
+
rubygems_version: 3.1.2
|
145
145
|
signing_key:
|
146
146
|
specification_version: 4
|
147
147
|
summary: A repository of common utilities for NYPL Ruby application
|