reso_api 0.4.5 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reso_api/app/models/reso/api/client.rb +32 -7
- data/lib/reso_api/version.rb +1 -1
- 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: d52973c086bdbeff331fc267832e7ece9c7002d5f10e9273c619e9ff985a2ffa
|
4
|
+
data.tar.gz: ac5cfd9c1416bb0a43d38d514ca7b3213f133749630869bc55fb2855c797e99c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13689a885600bd73802304c034c9b48bfa1f635fc2016e2be3780575a6a142f6e80809e6af010d65dd4d63be1567c5bf08f33cd89925343932d4dcb1ab3bc455
|
7
|
+
data.tar.gz: c770fb9aba3551dd8ee037a37a8ddb6853af78d6530b78856ad45a5d045caeeba0c32ca70f75889a8182a95f8283ac93e273945894284924210365c32b3d7bb5
|
@@ -50,6 +50,7 @@ module RESO
|
|
50
50
|
define_method method_name do |*args, &block|
|
51
51
|
hash = args.first.is_a?(Hash) ? args.first : {}
|
52
52
|
endpoint = FILTERABLE_ENDPOINTS[method_name]
|
53
|
+
response = {}
|
53
54
|
params = {
|
54
55
|
"$select": hash[:select],
|
55
56
|
"$filter": hash[:filter],
|
@@ -106,12 +107,17 @@ module RESO
|
|
106
107
|
if expiration > DateTime.now.utc
|
107
108
|
return payload.token
|
108
109
|
else
|
109
|
-
@oauth2_payload =
|
110
|
-
File.write(oauth2_token_path, @oauth2_payload.to_hash.to_json)
|
110
|
+
@oauth2_payload = fresh_oauth2_payload
|
111
111
|
return @oauth2_payload.token
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
+
def fresh_oauth2_payload
|
116
|
+
@oauth2_payload = oauth2_client.client_credentials.get_token
|
117
|
+
File.write(oauth2_token_path, @oauth2_payload.to_hash.to_json)
|
118
|
+
return @oauth2_payload
|
119
|
+
end
|
120
|
+
|
115
121
|
def oauth2_token_path
|
116
122
|
File.join(Dir.tmpdir, [base_url.parameterize, "-oauth-token.json"].join)
|
117
123
|
end
|
@@ -137,17 +143,36 @@ module RESO
|
|
137
143
|
|
138
144
|
def perform_call(endpoint, params)
|
139
145
|
uri = uri_for_endpoint(endpoint)
|
146
|
+
retries = 0
|
140
147
|
if params.present?
|
141
148
|
query = params.present? ? URI.encode_www_form(params).gsub("+", " ") : ""
|
142
149
|
uri.query && uri.query.length > 0 ? uri.query += '&' + query : uri.query = query
|
143
150
|
return URI::decode(uri.request_uri) if params.dig(:$debug).present?
|
144
151
|
end
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
152
|
+
begin
|
153
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
154
|
+
req['Authorization'] = "Bearer #{oauth2_token}"
|
155
|
+
res = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
|
156
|
+
http.request(req)
|
157
|
+
end
|
158
|
+
response = JSON(res.body) rescue res.body
|
159
|
+
if response.is_a?(String) && response.include?('Bad Gateway')
|
160
|
+
raise StandardError
|
161
|
+
elsif response.is_a?(String) && response.include?('Unauthorized')
|
162
|
+
fresh_oauth2_payload
|
163
|
+
raise StandardError
|
164
|
+
elsif response.is_a?(Hash) && response.has_key?("error")
|
165
|
+
raise StandardError
|
166
|
+
end
|
167
|
+
rescue Net::ReadTimeout, StandardError
|
168
|
+
if (retries += 1) <= 5
|
169
|
+
sleep 10
|
170
|
+
retry
|
171
|
+
else
|
172
|
+
raise
|
173
|
+
end
|
149
174
|
end
|
150
|
-
return
|
175
|
+
return response
|
151
176
|
end
|
152
177
|
|
153
178
|
end
|
data/lib/reso_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reso_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Edlund
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|