revo-loans_api 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/revo/loans_api/client.rb +15 -5
- data/lib/revo/loans_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: f25b09191c1800508f8b50afd1c81e9ea7f29670da428a58d5e653322d42bf8b
|
4
|
+
data.tar.gz: 1958857fa83311a7540fa1418d78a7196917cc35013cdda8ec1a9d5020342d4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e7f3171df9b3c3406a57b17958e8ce280bae87d19dc16ad51b33203eb7c4d6e1a0d11e16273be1463fbe15bf561ca5fd2e3d7de0778466e292a0f5d0b0d6e0e
|
7
|
+
data.tar.gz: 72738901d7b8f719efc8f64c5560ec0489f93881bd4c05250dcbf67e60bc8a4bf22820972c1e994cefacf13d4a4bc8225b878b8fdf346b28565b3b751e9fe841
|
@@ -152,7 +152,9 @@ class Revo::LoansApi::Client
|
|
152
152
|
|
153
153
|
private
|
154
154
|
|
155
|
-
|
155
|
+
API_CONTENT_TYPE = 'application/json'.freeze
|
156
|
+
|
157
|
+
attr_reader :base_url, :login, :password
|
156
158
|
|
157
159
|
def connection
|
158
160
|
@connection ||= HTTP.persistent(base_url)
|
@@ -162,15 +164,15 @@ class Revo::LoansApi::Client
|
|
162
164
|
result = make_request(:get, "loan_requests/#{loan_request_token}", &block)
|
163
165
|
return result if result.success?
|
164
166
|
|
165
|
-
Result.new(success?: false, response: { errors: { loan_request_terms: :cant_fetch } })
|
167
|
+
Result.new(success?: false, response: { errors: { loan_request_terms: [:cant_fetch] } })
|
166
168
|
end
|
167
169
|
|
168
170
|
def make_request(method, endpoint, params = {}, &block)
|
169
171
|
headers = { Authorization: session_token }.compact
|
170
172
|
response = connection.public_send(method, url_for(endpoint), json: params, headers: headers)
|
171
173
|
handle_response(response, &block)
|
172
|
-
rescue HTTP::Error =>
|
173
|
-
handle_error(
|
174
|
+
rescue HTTP::Error => e
|
175
|
+
handle_error(e)
|
174
176
|
end
|
175
177
|
|
176
178
|
def handle_response(response)
|
@@ -192,7 +194,7 @@ class Revo::LoansApi::Client
|
|
192
194
|
if response.status.unauthorized?
|
193
195
|
raise Revo::LoansApi::InvalidAccessTokenError
|
194
196
|
else
|
195
|
-
Result.new(success?: false, response:
|
197
|
+
Result.new(success?: false, response: parse_errors(response))
|
196
198
|
end
|
197
199
|
else
|
198
200
|
raise Revo::LoansApi::UnexpectedResponseError, response_or_exception
|
@@ -205,6 +207,14 @@ class Revo::LoansApi::Client
|
|
205
207
|
response.to_s.presence
|
206
208
|
end
|
207
209
|
|
210
|
+
def parse_errors(response)
|
211
|
+
if response.content_type.mime_type == API_CONTENT_TYPE
|
212
|
+
parse(response)
|
213
|
+
else
|
214
|
+
{ errors: { base: [:unexpected_response] } }
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
208
218
|
def url_for(endpoint)
|
209
219
|
[base_url, endpoint].join('/')
|
210
220
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: revo-loans_api
|
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
|
- Revo Developers
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|