reso_api 1.8.10 → 1.8.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18e40c3f261c325789a3e55ba23453cc6a199ff05defabef866a7b845c8215c8
4
- data.tar.gz: d124374abd3661b8ad20a71d6ff5f32df36383d0108828b5ea4f15b7270d5fa2
3
+ metadata.gz: e81ebb68ef64ed1eb595cf0a92fd03044c03b28e84d40a31fa49e7660ab65a08
4
+ data.tar.gz: 508a035516cbbf60b0d7d606a6277edcf0e72cfb063cf5f2497761f9e1b71d7f
5
5
  SHA512:
6
- metadata.gz: 453c8f983d9f0332ba1e3ef31a0fcea4d9b93e01bbb3dd6230ab020b7b584b2a4643a54fe133535bca397d69e45bf5978a61fb3f68ff2fcdbd65bb7e51be6579
7
- data.tar.gz: 23feeb93fe496c10ff89808e5d9d3bd6c22592db8cb492e62b0917a4876cf8b489e7b2bb55b46aff92b794b89c1e75face7c4f469b9c1bbaf171831777631e28
6
+ metadata.gz: 426229c6c88d7cf4e91f6237989a94b91086af2ef9ad04063638c5ac230851fdccd7a9520d6c30c587cb43009eb93505b93136bb40d2d5894d443fadce286a97
7
+ data.tar.gz: 56f7d6afc8f864cec994b91a1ca8906ef7b48e9209d51fa7e4a8974e03210e254d77f40ccd8e4a238653fbbc47497d6139f3d80d11f161033ac1bb9a5187babc
@@ -165,6 +165,12 @@ module RESO
165
165
  @oauth2_payload = oauth2_client.client_credentials.get_token('client_id' => client_id, 'client_secret' => client_secret, 'scope' => scope.presence)
166
166
  File.write(oauth2_token_path, @oauth2_payload.to_hash.to_json)
167
167
  return @oauth2_payload
168
+ rescue OAuth2::Error => e
169
+ # Provide detailed error message for OAuth failures
170
+ error_details = "OAuth token refresh failed for #{base_url}"
171
+ error_details += "\n Scope attempted: #{scope.inspect}"
172
+ error_details += "\n OAuth error: #{e.message}"
173
+ raise StandardError, error_details
168
174
  rescue => e
169
175
  raise StandardError, "Failed to refresh OAuth token: #{e.message}"
170
176
  end
@@ -180,13 +186,43 @@ module RESO
180
186
 
181
187
  def get_oauth2_payload
182
188
  if File.exist?(oauth2_token_path)
183
- persisted = File.read(oauth2_token_path)
184
- payload = OAuth2::AccessToken.from_hash(oauth2_client, JSON.parse(persisted))
185
- else
189
+ begin
190
+ persisted = File.read(oauth2_token_path)
191
+ parsed = JSON.parse(persisted)
192
+
193
+ # Check if the persisted data is a valid token (has access_token or token field)
194
+ if parsed['access_token'].present? || parsed['token'].present?
195
+ payload = OAuth2::AccessToken.from_hash(oauth2_client, parsed)
196
+
197
+ # Verify the payload actually has a token
198
+ if payload.token.present?
199
+ return payload
200
+ end
201
+ end
202
+
203
+ # If we get here, the cached token is invalid - delete it and get fresh
204
+ File.delete(oauth2_token_path)
205
+ rescue JSON::ParserError, StandardError => e
206
+ # If there's any error reading/parsing the cached token, delete it
207
+ File.delete(oauth2_token_path) if File.exist?(oauth2_token_path)
208
+ end
209
+ end
210
+
211
+ # Get fresh token
212
+ begin
186
213
  payload = oauth2_client.client_credentials.get_token('client_id' => client_id, 'client_secret' => client_secret, 'scope' => scope.presence)
187
214
  File.write(oauth2_token_path, payload.to_hash.to_json)
215
+ return payload
216
+ rescue OAuth2::Error => e
217
+ # Clean up any bad cached token
218
+ File.delete(oauth2_token_path) if File.exist?(oauth2_token_path)
219
+
220
+ # Provide detailed error message
221
+ error_details = "OAuth token request failed for #{base_url}"
222
+ error_details += "\n Scope attempted: #{scope.inspect}"
223
+ error_details += "\n OAuth error: #{e.message}"
224
+ raise StandardError, error_details
188
225
  end
189
- return payload
190
226
  end
191
227
 
192
228
  def uri_for_endpoint endpoint
@@ -1,3 +1,3 @@
1
1
  module ResoApi
2
- VERSION = "1.8.10"
2
+ VERSION = "1.8.11"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reso_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.10
4
+ version: 1.8.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Edlund