reso_api 1.8.9 → 1.8.10
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 +4 -4
- data/lib/reso_api/app/models/reso/api/client.rb +36 -6
- data/lib/reso_api/version.rb +1 -1
- data/reso_api.gemspec +1 -0
- metadata +17 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 18e40c3f261c325789a3e55ba23453cc6a199ff05defabef866a7b845c8215c8
|
|
4
|
+
data.tar.gz: d124374abd3661b8ad20a71d6ff5f32df36383d0108828b5ea4f15b7270d5fa2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 453c8f983d9f0332ba1e3ef31a0fcea4d9b93e01bbb3dd6230ab020b7b584b2a4643a54fe133535bca397d69e45bf5978a61fb3f68ff2fcdbd65bb7e51be6579
|
|
7
|
+
data.tar.gz: 23feeb93fe496c10ff89808e5d9d3bd6c22592db8cb492e62b0917a4876cf8b489e7b2bb55b46aff92b794b89c1e75face7c4f469b9c1bbaf171831777631e28
|
|
@@ -5,6 +5,7 @@ module RESO
|
|
|
5
5
|
require 'net/http'
|
|
6
6
|
require 'oauth2'
|
|
7
7
|
require 'json'
|
|
8
|
+
require 'jwt'
|
|
8
9
|
require 'tmpdir'
|
|
9
10
|
|
|
10
11
|
attr_accessor :access_token, :client_id, :client_secret, :auth_url, :base_url, :scope, :osn
|
|
@@ -109,7 +110,31 @@ module RESO
|
|
|
109
110
|
end
|
|
110
111
|
|
|
111
112
|
def auth_token
|
|
112
|
-
|
|
113
|
+
# If access_token is provided, check if it's expired
|
|
114
|
+
if access_token.present?
|
|
115
|
+
# Try to decode as JWT to check expiration
|
|
116
|
+
begin
|
|
117
|
+
token = JWT.decode(access_token, nil, false)
|
|
118
|
+
exp_timestamp = Hash(token.try(:first))["exp"].to_s
|
|
119
|
+
expiration = DateTime.strptime(exp_timestamp, '%s').utc rescue nil
|
|
120
|
+
|
|
121
|
+
# If token is expired and we have OAuth credentials, get a fresh token
|
|
122
|
+
if expiration && expiration <= DateTime.now.utc && can_use_oauth?
|
|
123
|
+
return oauth2_token
|
|
124
|
+
end
|
|
125
|
+
rescue JWT::DecodeError
|
|
126
|
+
# Not a JWT token, just use it as-is
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
return access_token
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# No access_token provided, use OAuth flow
|
|
133
|
+
oauth2_token
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def can_use_oauth?
|
|
137
|
+
client_id.present? && client_secret.present? && auth_url.present?
|
|
113
138
|
end
|
|
114
139
|
|
|
115
140
|
def oauth2_client
|
|
@@ -136,9 +161,13 @@ module RESO
|
|
|
136
161
|
end
|
|
137
162
|
|
|
138
163
|
def fresh_oauth2_payload
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
164
|
+
begin
|
|
165
|
+
@oauth2_payload = oauth2_client.client_credentials.get_token('client_id' => client_id, 'client_secret' => client_secret, 'scope' => scope.presence)
|
|
166
|
+
File.write(oauth2_token_path, @oauth2_payload.to_hash.to_json)
|
|
167
|
+
return @oauth2_payload
|
|
168
|
+
rescue => e
|
|
169
|
+
raise StandardError, "Failed to refresh OAuth token: #{e.message}"
|
|
170
|
+
end
|
|
142
171
|
end
|
|
143
172
|
|
|
144
173
|
def oauth2_token_path
|
|
@@ -189,8 +218,9 @@ module RESO
|
|
|
189
218
|
fresh_oauth2_payload
|
|
190
219
|
raise StandardError
|
|
191
220
|
elsif response.is_a?(Hash) && response.has_key?("error")
|
|
192
|
-
|
|
193
|
-
|
|
221
|
+
error_msg = response.inspect
|
|
222
|
+
puts "Error: #{error_msg}" if debug
|
|
223
|
+
raise StandardError, error_msg
|
|
194
224
|
elsif response.is_a?(Hash) && response.has_key?("retry-after")
|
|
195
225
|
puts "Error: Retrying in #{response["retry-after"].to_i}} seconds." if debug
|
|
196
226
|
sleep response["retry-after"].to_i
|
data/lib/reso_api/version.rb
CHANGED
data/reso_api.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: reso_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.8.
|
|
4
|
+
version: 1.8.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Edlund
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: bundler
|
|
@@ -79,6 +79,20 @@ dependencies:
|
|
|
79
79
|
- - ">="
|
|
80
80
|
- !ruby/object:Gem::Version
|
|
81
81
|
version: '0'
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: jwt
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
type: :runtime
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
82
96
|
description: Ruby wrapper for easy interaction with a RESO Web API compliant server.
|
|
83
97
|
email:
|
|
84
98
|
- medlund@mac.com
|
|
@@ -121,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
121
135
|
- !ruby/object:Gem::Version
|
|
122
136
|
version: '0'
|
|
123
137
|
requirements: []
|
|
124
|
-
rubygems_version: 3.
|
|
138
|
+
rubygems_version: 3.7.2
|
|
125
139
|
specification_version: 4
|
|
126
140
|
summary: RESO Web API Wrapper
|
|
127
141
|
test_files: []
|