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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b344ac77904ab206407b2762d68f50890933f40a73f63de5c3eefb68d154f78
4
- data.tar.gz: bf43a3bfcfb727ad27957682edacd67cde85731207ebc5d57bff41932a6839dc
3
+ metadata.gz: f25b09191c1800508f8b50afd1c81e9ea7f29670da428a58d5e653322d42bf8b
4
+ data.tar.gz: 1958857fa83311a7540fa1418d78a7196917cc35013cdda8ec1a9d5020342d4c
5
5
  SHA512:
6
- metadata.gz: a647053d57bc28663f66500b7d168bfb014509aac6d27e5d68e24be3220c3484f1d65215ed0d8f4e14ab3a0cc1d92f68b38bbaadca3ac8773794c0606337e373
7
- data.tar.gz: 53bd6cda8ffd1ea66bf228cdb75ec6f44a552799a1c967e4ccdc639e68aa100d458e0b5c468dc1a904e1f33e317627edf676e8ad74ca8e77a2eda7da5150806f
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
- attr_reader :connection, :base_url, :login, :password
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 => exception
173
- handle_error(exception)
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: parse(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
@@ -1,5 +1,5 @@
1
1
  module Revo
2
2
  module LoansApi
3
- VERSION = '0.0.9'
3
+ VERSION = '0.0.10'
4
4
  end
5
5
  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.9
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-23 00:00:00.000000000 Z
11
+ date: 2019-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http