revo-loans_api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +84 -0
- data/README.md +301 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/revo/loans_api.rb +11 -0
- data/lib/revo/loans_api/client.rb +166 -0
- data/lib/revo/loans_api/version.rb +5 -0
- data/revo-loans_api.gemspec +41 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2dfb894597f190e75388de268e743f4812ec76eef58f0ff42b3dee7320cd8734
|
4
|
+
data.tar.gz: aa46c90d6fbfd50d9906a7c543308915885445f5231774aa6a0f153e3fb75b32
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c2a5ec880b9f0f8230e2c67bd346be63f4708ef9b00ed72e06b86ab88d55b8078491e1f25b70dfaedbc8eccbf1e871aa14c4c3fafae364645db04f813212f25c
|
7
|
+
data.tar.gz: a1b6f163aa421f56f127b5d995cd2435fc471f5c9cd9277e6cb718fe76b196adddef8cb93fa2ac0e0b70ff92825ff4047c96fafbfa1d64be3e450d8fc9abb946
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
revo-loans_api (0.0.1)
|
5
|
+
activesupport
|
6
|
+
http
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (6.0.0)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
zeitwerk (~> 2.1, >= 2.1.8)
|
17
|
+
addressable (2.7.0)
|
18
|
+
public_suffix (>= 2.0.2, < 5.0)
|
19
|
+
concurrent-ruby (1.1.5)
|
20
|
+
crack (0.4.3)
|
21
|
+
safe_yaml (~> 1.0.0)
|
22
|
+
diff-lcs (1.3)
|
23
|
+
domain_name (0.5.20190701)
|
24
|
+
unf (>= 0.0.5, < 1.0.0)
|
25
|
+
ffi (1.11.1)
|
26
|
+
ffi-compiler (1.0.1)
|
27
|
+
ffi (>= 1.0.0)
|
28
|
+
rake
|
29
|
+
hashdiff (1.0.0)
|
30
|
+
http (4.2.0)
|
31
|
+
addressable (~> 2.3)
|
32
|
+
http-cookie (~> 1.0)
|
33
|
+
http-form_data (~> 2.0)
|
34
|
+
http-parser (~> 1.2.0)
|
35
|
+
http-cookie (1.0.3)
|
36
|
+
domain_name (~> 0.5)
|
37
|
+
http-form_data (2.1.1)
|
38
|
+
http-parser (1.2.1)
|
39
|
+
ffi-compiler (>= 1.0, < 2.0)
|
40
|
+
i18n (1.7.0)
|
41
|
+
concurrent-ruby (~> 1.0)
|
42
|
+
minitest (5.12.2)
|
43
|
+
public_suffix (4.0.1)
|
44
|
+
rake (10.5.0)
|
45
|
+
rspec (3.9.0)
|
46
|
+
rspec-core (~> 3.9.0)
|
47
|
+
rspec-expectations (~> 3.9.0)
|
48
|
+
rspec-mocks (~> 3.9.0)
|
49
|
+
rspec-core (3.9.0)
|
50
|
+
rspec-support (~> 3.9.0)
|
51
|
+
rspec-expectations (3.9.0)
|
52
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
+
rspec-support (~> 3.9.0)
|
54
|
+
rspec-mocks (3.9.0)
|
55
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
56
|
+
rspec-support (~> 3.9.0)
|
57
|
+
rspec-support (3.9.0)
|
58
|
+
safe_yaml (1.0.5)
|
59
|
+
thread_safe (0.3.6)
|
60
|
+
tzinfo (1.2.5)
|
61
|
+
thread_safe (~> 0.1)
|
62
|
+
unf (0.1.4)
|
63
|
+
unf_ext
|
64
|
+
unf_ext (0.0.7.6)
|
65
|
+
vcr (5.0.0)
|
66
|
+
webmock (3.7.6)
|
67
|
+
addressable (>= 2.3.6)
|
68
|
+
crack (>= 0.3.2)
|
69
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
70
|
+
zeitwerk (2.2.0)
|
71
|
+
|
72
|
+
PLATFORMS
|
73
|
+
ruby
|
74
|
+
|
75
|
+
DEPENDENCIES
|
76
|
+
bundler (~> 1.17)
|
77
|
+
rake (~> 10.0)
|
78
|
+
revo-loans_api!
|
79
|
+
rspec (~> 3.0)
|
80
|
+
vcr
|
81
|
+
webmock
|
82
|
+
|
83
|
+
BUNDLED WITH
|
84
|
+
1.17.2
|
data/README.md
ADDED
@@ -0,0 +1,301 @@
|
|
1
|
+
# Revo::LoansApi
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'revo-loans_api'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install revo-loans_api
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Instantiating a client
|
22
|
+
|
23
|
+
Besides providing `base_url`, you must either use your login & password or a sesion token when instantiating the client:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
client = Revo::LoansApi::Client.new(base_url: '...', login: '70001112233', password: '1234')
|
27
|
+
# or session_token:
|
28
|
+
client = Revo::LoansApi::Client.new(base_url: '...', session_token: 'abcdef')
|
29
|
+
```
|
30
|
+
|
31
|
+
### Authenticating
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
result = client.create_session
|
35
|
+
|
36
|
+
# Success:
|
37
|
+
result.success? # => true
|
38
|
+
# the token will automatically be used by the client (it's in `client.session_token`)
|
39
|
+
|
40
|
+
# Failure:
|
41
|
+
result.success? # => false
|
42
|
+
result.response # => `{ errors: { manager: ['list of errors here'] } }`
|
43
|
+
```
|
44
|
+
|
45
|
+
### Creating a loan request
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
result = client.create_loan_request(
|
49
|
+
amount: 3_000,
|
50
|
+
mobile_phone: '78881234567',
|
51
|
+
store_id: 309
|
52
|
+
)
|
53
|
+
|
54
|
+
# Success:
|
55
|
+
result.success? # => true
|
56
|
+
result.response # =>
|
57
|
+
# token: 'some-lr-token', # you'll be using this value on later steps
|
58
|
+
# terms: [
|
59
|
+
# {
|
60
|
+
# term: 3,
|
61
|
+
# term_id: 50,
|
62
|
+
# monthly_payment: 1073.0,
|
63
|
+
# total_of_payments: 3219.0,
|
64
|
+
# sum_with_discount: 3000.0,
|
65
|
+
# total_overpayment: 219.0,
|
66
|
+
# sms_info: 79.0,
|
67
|
+
# product_code: '03',
|
68
|
+
# min_amount: 1000.0,
|
69
|
+
# max_amount: 0.0,
|
70
|
+
# schedule: [
|
71
|
+
# {
|
72
|
+
# date: '26-12-2018',
|
73
|
+
# amount: 1073.0
|
74
|
+
# },
|
75
|
+
# {
|
76
|
+
# date: '27-01-2019',
|
77
|
+
# amount: 1073.0
|
78
|
+
# }
|
79
|
+
# ]
|
80
|
+
# }
|
81
|
+
# ]
|
82
|
+
|
83
|
+
# Failure:
|
84
|
+
result.success? # => false
|
85
|
+
result.response # => `{ errors: { store_id: ['list of errors here'] } }`
|
86
|
+
```
|
87
|
+
|
88
|
+
### Updating a loan request
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
result = client.update_loan_request(
|
92
|
+
token: 'some-lr-token', # use the one you got when creating a loan request
|
93
|
+
options: { amount: 3000 }
|
94
|
+
)
|
95
|
+
|
96
|
+
# Success:
|
97
|
+
result.success? # => true
|
98
|
+
result.response # => `{}`
|
99
|
+
|
100
|
+
# Failure:
|
101
|
+
result.success? # => false
|
102
|
+
result.response # => `{ errors: { amount: ['list of errors here'] } }`
|
103
|
+
```
|
104
|
+
|
105
|
+
### Documents
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
result = client.document(
|
109
|
+
token: 'some-lr-token', # use the one you got when creating a loan request
|
110
|
+
type: :offer,
|
111
|
+
format: :pdf
|
112
|
+
)
|
113
|
+
|
114
|
+
# Success:
|
115
|
+
result.success? # => true
|
116
|
+
result.response # => (the raw data)
|
117
|
+
|
118
|
+
# Failure:
|
119
|
+
result.success? # => false
|
120
|
+
result.response # => `{ errors: { client: ['list of errors here'] } }`
|
121
|
+
```
|
122
|
+
|
123
|
+
### Sending a loan confirmation text
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
result = client.send_loan_confirmation_message(
|
127
|
+
token: 'some-lr-token' # use the one you got when creating a loan request
|
128
|
+
)
|
129
|
+
|
130
|
+
# Success:
|
131
|
+
result.success? # => true
|
132
|
+
result.response # => `nil`
|
133
|
+
|
134
|
+
# Failure:
|
135
|
+
result.success? # => false
|
136
|
+
result.response # => `{ errors: { mobile_phone: ['list of errors here'] } }`
|
137
|
+
```
|
138
|
+
|
139
|
+
### Completing a loan request
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
result = client.complete_loan_request(
|
143
|
+
token: 'some-lr-token', # use the one you got when creating a loan request
|
144
|
+
code: '1234' # use the code from the text you received
|
145
|
+
)
|
146
|
+
|
147
|
+
# Success:
|
148
|
+
result.success? # => true
|
149
|
+
result.response # =>
|
150
|
+
# client: {
|
151
|
+
# first_name: 'Владилен',
|
152
|
+
# middle_name: 'Гарриевич',
|
153
|
+
# last_name: 'Пупкин',
|
154
|
+
# credit_limit: '6000.0',
|
155
|
+
# decision: 'approved',
|
156
|
+
# decision_code: 210,
|
157
|
+
# decision_message: 'Покупка на сумму 3000.0 ₽ успешно совершена!'
|
158
|
+
# }
|
159
|
+
|
160
|
+
# Failure:
|
161
|
+
result.success? # => false
|
162
|
+
result.response # => `{ errors: { code: ['list of errors here'] } }`
|
163
|
+
```
|
164
|
+
|
165
|
+
### Creating a loan
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
result = client.create_loan(
|
169
|
+
token: 'some-lr-token', # use the one you got when creating a loan request
|
170
|
+
term_id: 51 # pick one of those provided when creating a loan request
|
171
|
+
)
|
172
|
+
|
173
|
+
# Success:
|
174
|
+
result.success? # => true
|
175
|
+
result.response # => `nil`
|
176
|
+
|
177
|
+
# Failure:
|
178
|
+
result.success? # => false
|
179
|
+
result.response # => `{ errors: { base: ['list of errors here'] } }`
|
180
|
+
```
|
181
|
+
|
182
|
+
### Finalizing a loan
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
result = client.finalize_loan(
|
186
|
+
token: 'some-lr-token', # use the one you got when creating a loan request
|
187
|
+
code: '1234' # use the code from the text you received (the same one)
|
188
|
+
)
|
189
|
+
|
190
|
+
# Success:
|
191
|
+
result.success? # => true
|
192
|
+
result.response # =>
|
193
|
+
# offer_id: '244244102',
|
194
|
+
# loan_application: {
|
195
|
+
# barcodes: {
|
196
|
+
# image: 'data:image/svg+xml;base64,...',
|
197
|
+
# text: '1ZZ0600023030002442441027'
|
198
|
+
# }
|
199
|
+
# }
|
200
|
+
|
201
|
+
# Failure:
|
202
|
+
result.success? # => false
|
203
|
+
result.response # => `{ errors: { confirmation_code: ['list of errors here'] } }`
|
204
|
+
```
|
205
|
+
|
206
|
+
### List orders
|
207
|
+
|
208
|
+
```ruby
|
209
|
+
result = client.orders(
|
210
|
+
store_id: 1,
|
211
|
+
filters: { mobile_phone: '8881112233' } # optional
|
212
|
+
)
|
213
|
+
|
214
|
+
# Success:
|
215
|
+
result.success? # => true
|
216
|
+
result.response # =>
|
217
|
+
# orders: [
|
218
|
+
# {
|
219
|
+
# id: '1525182',
|
220
|
+
# client_name: 'Иванов Иван Иванович',
|
221
|
+
# mobile_phone: '8882200001',
|
222
|
+
# barcode: '10009302315006587574891'
|
223
|
+
# }
|
224
|
+
# ]
|
225
|
+
```
|
226
|
+
|
227
|
+
### Send return confirmation code
|
228
|
+
|
229
|
+
```ruby
|
230
|
+
result = client.send_return_confirmation_code(
|
231
|
+
order_id: 1
|
232
|
+
)
|
233
|
+
|
234
|
+
# Success:
|
235
|
+
result.success? # => true
|
236
|
+
result.response # => `nil`
|
237
|
+
```
|
238
|
+
|
239
|
+
### Creating a return
|
240
|
+
|
241
|
+
```ruby
|
242
|
+
result = client.create_return(
|
243
|
+
order_id: 1,
|
244
|
+
code: '1234',
|
245
|
+
amount: 3000,
|
246
|
+
store_id: 1
|
247
|
+
)
|
248
|
+
|
249
|
+
# Success:
|
250
|
+
result.success? # => true
|
251
|
+
result.response # =>
|
252
|
+
# return: {
|
253
|
+
# id: '234',
|
254
|
+
# barcode: '2ZZ011235616399006082053267'
|
255
|
+
# }
|
256
|
+
|
257
|
+
# Failure:
|
258
|
+
result.success? # => false
|
259
|
+
result.response # => `{ errors: { amount: ['error'], store_id: ['another error'] } }`
|
260
|
+
```
|
261
|
+
|
262
|
+
### Confirming a return
|
263
|
+
|
264
|
+
```ruby
|
265
|
+
result = client.confirm_return(
|
266
|
+
return_id: 1
|
267
|
+
)
|
268
|
+
|
269
|
+
# Success:
|
270
|
+
result.success? # => true
|
271
|
+
result.response # => `nil`
|
272
|
+
```
|
273
|
+
|
274
|
+
### Cancelling a return
|
275
|
+
|
276
|
+
```ruby
|
277
|
+
result = client.cancel_return(
|
278
|
+
return_id: 1
|
279
|
+
)
|
280
|
+
|
281
|
+
# Success:
|
282
|
+
result.success? # => true
|
283
|
+
result.response # => `nil`
|
284
|
+
```
|
285
|
+
|
286
|
+
### Possible Exceptions
|
287
|
+
|
288
|
+
In case of generic HTTP errors (i.e. server is not reachable or network is down), `Revo::LoansApi::UnexpectedResponseError` will be raised.
|
289
|
+
|
290
|
+
If the provided session token is invalid, you'll get `Revo::LoansApi::InvalidAccessTokenError`.
|
291
|
+
In this case, you have to get a new one using your login and password by calling `#create_session`.
|
292
|
+
|
293
|
+
## Development
|
294
|
+
|
295
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
296
|
+
|
297
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
298
|
+
|
299
|
+
## Contributing
|
300
|
+
|
301
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/RevoTechnology/LoansClient.rb.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "revo/loans_api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'revo/loans_api/version'
|
2
|
+
require 'revo/loans_api/client'
|
3
|
+
|
4
|
+
module Revo
|
5
|
+
module LoansApi
|
6
|
+
class Error < StandardError; end
|
7
|
+
class UnprocessableEntityError < Error; end
|
8
|
+
class UnexpectedResponseError < Error; end
|
9
|
+
class InvalidAccessTokenError < Error; end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'http'
|
2
|
+
require 'active_support/core_ext/object/blank'
|
3
|
+
|
4
|
+
class HTTP::MimeType::JSON
|
5
|
+
def decode(str)
|
6
|
+
::JSON.parse(str, symbolize_names: true)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Revo::LoansApi::Client
|
11
|
+
attr_reader :session_token, :loan_request_token
|
12
|
+
|
13
|
+
Result = Struct.new(:success?, :response, keyword_init: true)
|
14
|
+
|
15
|
+
def initialize(base_url:, login: nil, password: nil, session_token: nil)
|
16
|
+
@base_url = base_url
|
17
|
+
@login = login
|
18
|
+
@password = password
|
19
|
+
@session_token = session_token
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_session
|
23
|
+
make_request(
|
24
|
+
:post, 'sessions',
|
25
|
+
user: { login: login, password: password }
|
26
|
+
).tap do |result|
|
27
|
+
@session_token = result.response.dig(:user, :authentication_token) if result&.success?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_loan_request(options)
|
32
|
+
response = make_request(:post, 'loan_requests', loan_request_params(options))
|
33
|
+
return response unless response.success?
|
34
|
+
|
35
|
+
@loan_request_token = response.response.dig(:loan_request, :token)
|
36
|
+
Result.new(
|
37
|
+
success?: true,
|
38
|
+
response: {
|
39
|
+
token: loan_request_token,
|
40
|
+
terms: loan_request_terms.response[:loan_request]
|
41
|
+
}
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def update_loan_request(token:, options:)
|
46
|
+
update_params = { loan_request: options }
|
47
|
+
response = make_request(:put, "loan_requests/#{token}", update_params)
|
48
|
+
|
49
|
+
return response unless response.success?
|
50
|
+
|
51
|
+
Result.new(
|
52
|
+
success?: true,
|
53
|
+
response: {}
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
# prerequisite: a client with the LR's phone number should already exist
|
58
|
+
def document(token:, type:, format: 'html')
|
59
|
+
make_request(:get, "loan_requests/#{token}/documents/#{type}.#{format}")
|
60
|
+
end
|
61
|
+
|
62
|
+
def send_loan_confirmation_message(token:)
|
63
|
+
make_request(:post, "loan_requests/#{token}/client/confirmation")
|
64
|
+
end
|
65
|
+
|
66
|
+
def complete_loan_request(token:, code:)
|
67
|
+
make_request(:post, "loan_requests/#{token}/confirmation", code: code)
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_loan(token:, term_id:)
|
71
|
+
make_request(:post, "loan_requests/#{token}/loan", term_id: term_id)
|
72
|
+
end
|
73
|
+
|
74
|
+
def finalize_loan(token:, code:)
|
75
|
+
make_request(:post, "loan_requests/#{token}/loan/finalization", loan: { agree_processing: '1', confirmation_code: code })
|
76
|
+
end
|
77
|
+
|
78
|
+
# returns
|
79
|
+
def orders(store_id:, filters: {})
|
80
|
+
make_request(:get, 'orders', store_id: store_id, filters: filters)
|
81
|
+
end
|
82
|
+
|
83
|
+
def send_return_confirmation_code(order_id:)
|
84
|
+
make_request(:post, "orders/#{order_id}/send_return_confirmation_code")
|
85
|
+
end
|
86
|
+
|
87
|
+
def create_return(order_id:, code:, amount:, store_id:)
|
88
|
+
params = {
|
89
|
+
return: {
|
90
|
+
order_id: order_id,
|
91
|
+
confirmation_code: code,
|
92
|
+
amount: amount,
|
93
|
+
store_id: store_id
|
94
|
+
}
|
95
|
+
}
|
96
|
+
make_request(:post, 'returns', params)
|
97
|
+
end
|
98
|
+
|
99
|
+
def confirm_return(return_id:)
|
100
|
+
make_request(:post, "returns/#{return_id}/confirm")
|
101
|
+
end
|
102
|
+
|
103
|
+
def cancel_return(return_id:)
|
104
|
+
make_request(:post, "returns/#{return_id}/cancel")
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
attr_reader :connection, :base_url, :login, :password
|
110
|
+
|
111
|
+
def connection
|
112
|
+
@connection ||= HTTP.persistent(base_url)
|
113
|
+
end
|
114
|
+
|
115
|
+
def loan_request_terms(&block)
|
116
|
+
make_request(:get, "loan_requests/#{loan_request_token}", &block)
|
117
|
+
end
|
118
|
+
|
119
|
+
def make_request(method, endpoint, params = {}, &block)
|
120
|
+
headers = { Authorization: session_token }.compact
|
121
|
+
response = connection.public_send(method, url_for(endpoint), json: params, headers: headers)
|
122
|
+
handle_response(response, &block)
|
123
|
+
rescue HTTP::Error => exception
|
124
|
+
handle_error(exception)
|
125
|
+
end
|
126
|
+
|
127
|
+
def handle_response(response)
|
128
|
+
if response.status.success?
|
129
|
+
if block_given?
|
130
|
+
yield response
|
131
|
+
else
|
132
|
+
response
|
133
|
+
end
|
134
|
+
Result.new(success?: true, response: parse(response))
|
135
|
+
else
|
136
|
+
handle_error(response)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def handle_error(response_or_exception)
|
141
|
+
response = response_or_exception if response_or_exception.respond_to?(:status)
|
142
|
+
if response
|
143
|
+
if response.status.unauthorized?
|
144
|
+
raise Revo::LoansApi::InvalidAccessTokenError
|
145
|
+
else
|
146
|
+
Result.new(success?: false, response: parse(response))
|
147
|
+
end
|
148
|
+
else
|
149
|
+
raise Revo::LoansApi::UnexpectedResponseError, response_or_exception
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def parse(response)
|
154
|
+
response.parse if response.body.present?
|
155
|
+
rescue HTTP::Error
|
156
|
+
response.to_s.presence
|
157
|
+
end
|
158
|
+
|
159
|
+
def url_for(endpoint)
|
160
|
+
[base_url, endpoint].join('/')
|
161
|
+
end
|
162
|
+
|
163
|
+
def loan_request_params(options)
|
164
|
+
{ loan_request: options }
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'revo/loans_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'revo-loans_api'
|
8
|
+
spec.version = Revo::LoansApi::VERSION
|
9
|
+
spec.authors = ['Revo Developers']
|
10
|
+
spec.email = ['support@revoup.ru']
|
11
|
+
|
12
|
+
spec.summary = %q{Revo Loans API client}
|
13
|
+
spec.description = %q{Revo Loans API client}
|
14
|
+
spec.homepage = 'https://github.com/RevoTechnology'
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
+
else
|
21
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
22
|
+
'public gem pushes.'
|
23
|
+
end
|
24
|
+
|
25
|
+
# Specify which files should be added to the gem when it is released.
|
26
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
27
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
28
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
29
|
+
end
|
30
|
+
spec.bindir = 'exe'
|
31
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ['lib']
|
33
|
+
|
34
|
+
spec.add_dependency 'http'
|
35
|
+
spec.add_dependency 'activesupport'
|
36
|
+
spec.add_development_dependency 'bundler', '~> 1.17'
|
37
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
38
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
39
|
+
spec.add_development_dependency 'webmock'
|
40
|
+
spec.add_development_dependency 'vcr'
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: revo-loans_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Revo Developers
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.17'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.17'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: vcr
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Revo Loans API client
|
112
|
+
email:
|
113
|
+
- support@revoup.ru
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- Gemfile
|
122
|
+
- Gemfile.lock
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- bin/console
|
126
|
+
- bin/setup
|
127
|
+
- lib/revo/loans_api.rb
|
128
|
+
- lib/revo/loans_api/client.rb
|
129
|
+
- lib/revo/loans_api/version.rb
|
130
|
+
- revo-loans_api.gemspec
|
131
|
+
homepage: https://github.com/RevoTechnology
|
132
|
+
licenses: []
|
133
|
+
metadata:
|
134
|
+
homepage_uri: https://github.com/RevoTechnology
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubygems_version: 3.0.3
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: Revo Loans API client
|
154
|
+
test_files: []
|