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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/platform_api_client.rb +10 -9
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05c91cd9d8cd4ffd258f3a2c1f9b3cb41c2c6cf9b5df78d21f1483510e34c544
4
- data.tar.gz: 55e61c0097b9721728b147b6201e0856e815c3de8631e3f41ed78b00c12d11bb
3
+ metadata.gz: 5c6574f7bf8717173b11a9635daacec8d49be69a7fc35e5584d713f8ef37c673
4
+ data.tar.gz: 5035a2920d8c8f012c711050604f1ecd12832b4e8df3661eb0a16f707735c9d6
5
5
  SHA512:
6
- metadata.gz: 6c2042cc492affeb2ae6d60d6c96fb6d0db3ea69c23f1ad6a31da3ff5025c52cd4d5f669112e174153e88b84dde7395f59b23b12182017c079f1ce6a024807f6
7
- data.tar.gz: 832f11059c1267393afb6b2f5140dd5a8f98950f9e69c495e6fa1cfa31af947c78fbf4cd740016214b4fe1dc4bce939a6f57de295039a3673aa195da0ce2be2c
6
+ metadata.gz: 9349fa7cc85b2429daef2ecd358392f58425a107516f1392d8fbbdb8861e460ec4dd48fab3d4163f58e351dc3001a1981efcaa86b76e5758442510e06ccb7ac3
7
+ data.tar.gz: 7a1e9057927bad0ff9425617f534abf17e63e2cb25cabb651bc2dd10fe234c5ca9c0d80c8d4dc54c51539a8cede92a82ce289f35e10dd64031d0c9c7a34d4332
@@ -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
- if @try_count < 1
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
- @try_count += 1
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.9
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.4
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