increase 0.1.2 → 0.2.0
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/OPENAPI_VERSION +1 -0
- data/README.md +174 -45
- data/bin/generate +152 -0
- data/bin/setup +8 -0
- data/generate/resource.rb.erb +18 -0
- data/lib/increase/client.rb +2 -0
- data/lib/increase/configuration.rb +1 -1
- data/lib/increase/resource.rb +85 -119
- data/lib/increase/resources/account_numbers.rb +7 -0
- data/lib/increase/resources/account_statements.rb +15 -0
- data/lib/increase/resources/account_transfers.rb +10 -2
- data/lib/increase/resources/accounts.rb +9 -1
- data/lib/increase/resources/ach_prenotifications.rb +17 -0
- data/lib/increase/resources/ach_transfers.rb +10 -2
- data/lib/increase/resources/card_disputes.rb +17 -0
- data/lib/increase/resources/card_profiles.rb +17 -0
- data/lib/increase/resources/cards.rb +9 -1
- data/lib/increase/resources/check_deposits.rb +17 -0
- data/lib/increase/resources/check_transfers.rb +23 -0
- data/lib/increase/resources/declined_transactions.rb +15 -0
- data/lib/increase/resources/digital_wallet_tokens.rb +15 -0
- data/lib/increase/resources/documents.rb +15 -0
- data/lib/increase/resources/entities.rb +19 -0
- data/lib/increase/resources/event_subscriptions.rb +19 -0
- data/lib/increase/resources/events.rb +5 -0
- data/lib/increase/resources/external_accounts.rb +19 -0
- data/lib/increase/resources/files.rb +17 -0
- data/lib/increase/resources/groups.rb +13 -0
- data/lib/increase/resources/inbound_ach_transfer_returns.rb +17 -0
- data/lib/increase/resources/inbound_wire_drawdown_requests.rb +15 -0
- data/lib/increase/resources/limits.rb +19 -0
- data/lib/increase/resources/oauth_connections.rb +15 -0
- data/lib/increase/resources/pending_transactions.rb +5 -0
- data/lib/increase/resources/real_time_decisions.rb +15 -0
- data/lib/increase/resources/routing_numbers.rb +13 -0
- data/lib/increase/resources/transactions.rb +5 -0
- data/lib/increase/resources/wire_drawdown_requests.rb +17 -0
- data/lib/increase/resources/wire_transfers.rb +21 -0
- data/lib/increase/response_array.rb +19 -0
- data/lib/increase/version.rb +1 -1
- data/lib/increase/webhook/signature.rb +9 -1
- data/openapi.json +32098 -0
- metadata +62 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5ebc261a44d0f2a6df7fc703886dcc18e11a3c54bd2f04742b783e46fedc1f7
|
4
|
+
data.tar.gz: '073485629ad76bc387aa0a51d954a86bb93c9884bd90baccedeaa2cbf483efaa'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2b625211c3e9ad0a7588caaeda4eaea8e216569e3efd2f83afaf48d0c8fed23794d0f8a0d4bdab6a0024115836cab51979a4731ea2fc0d4400de1967e0d9c93
|
7
|
+
data.tar.gz: ede3ef495349bf6c7cf6acacba84101061aa3740170ca3b7fea1fb4ec8e2c7e8df61b0654e9919e158c1bc033f8ef37ec4171538aeb485eae6f0c1f3cd619da5
|
data/OPENAPI_VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
v0.0.1
|
data/README.md
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
# Increase
|
2
2
|
|
3
|
-
A Ruby API client for [Increase](https://increase.com/), a platform for
|
3
|
+
A Ruby API client for [Increase](https://increase.com/), a platform for
|
4
|
+
Bare-Metal Banking APIs!
|
5
|
+
|
6
|
+
- [Installation](#installation)
|
7
|
+
- [Usage](#usage)
|
8
|
+
- [Per-request Configuration](#per-request-configuration)
|
9
|
+
- [Pagination](#pagination)
|
10
|
+
- [Error Handling](#error-handling)
|
11
|
+
- [Configuration](#configuration)
|
12
|
+
- [File Uploads](#file-uploads)
|
13
|
+
- [Webhooks](#webhooks)
|
14
|
+
- [Idempotency](#idempotency)
|
15
|
+
- [Development](#development)
|
4
16
|
|
5
17
|
## Installation
|
6
18
|
|
@@ -10,7 +22,8 @@ Install the gem and add to the application's Gemfile by executing:
|
|
10
22
|
$ bundle add increase
|
11
23
|
```
|
12
24
|
|
13
|
-
If bundler is not being used to manage dependencies, install the gem by
|
25
|
+
If bundler is not being used to manage dependencies, install the gem by
|
26
|
+
executing:
|
14
27
|
|
15
28
|
```sh
|
16
29
|
$ gem install increase
|
@@ -43,32 +56,42 @@ Increase::AchTransfers.create(
|
|
43
56
|
|
44
57
|
### Per-request Configuration
|
45
58
|
|
46
|
-
By default, the client will use the global API key and configurations. However,
|
47
|
-
used for per-request configuration.
|
59
|
+
By default, the client will use the global API key and configurations. However,
|
60
|
+
you can define a custom client to be used for per-request configuration.
|
48
61
|
|
49
|
-
For example, you may want
|
62
|
+
For example, you may want access to production and sandbox data at the same
|
63
|
+
time.
|
50
64
|
|
51
65
|
```ruby
|
52
66
|
sandbox = Increase::Client.new(
|
53
|
-
api_key: '
|
67
|
+
api_key: 'playing_it_safe',
|
54
68
|
base_url: 'https://sandbox.increase.com'
|
55
69
|
)
|
56
70
|
|
57
71
|
# This request will use the `sandbox` client and its configurations
|
58
72
|
Increase::Transactions.with_config(sandbox).list
|
59
|
-
# => [{some sandbox transactions here}, {transaction}, {transaction}]
|
73
|
+
# => [{some sandbox transactions here}, {transaction}, {transaction}, ...]
|
60
74
|
|
61
|
-
# This request will still use the global configurations (
|
75
|
+
# This request will still use the global configurations (using production key)
|
62
76
|
Increase::Transactions.list
|
63
|
-
# => [{some production transactions here}, {transaction}, {transaction}]
|
77
|
+
# => [{some production transactions here}, {transaction}, {transaction}, ...]
|
64
78
|
```
|
65
79
|
|
66
|
-
|
80
|
+
Alternatively, directly passing as hash to `with_config` works too!
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
Increase::Transactions.with_config(api_key: 'time_is_money', base_url: :sandbox).list
|
84
|
+
# => [{some sandbox transactions here}, {transaction}, {transaction}, ...]
|
85
|
+
```
|
86
|
+
|
87
|
+
See the [Configuration](#configuration) section for more information on the
|
88
|
+
available configurations.
|
67
89
|
|
68
90
|
### Pagination
|
69
91
|
|
70
|
-
When listing resources (e.g. transactions), **Increase** limits the number of
|
71
|
-
|
92
|
+
When listing resources (e.g. transactions), **Increase** limits the number of
|
93
|
+
results per page to 100. Luckily, the client will automatically paginate through
|
94
|
+
all the results for you!
|
72
95
|
|
73
96
|
```ruby
|
74
97
|
Increase::Transactions.list(limit: :all) do |transactions|
|
@@ -78,38 +101,48 @@ end
|
|
78
101
|
|
79
102
|
# Or, if you'd like a gargantuan array of all the transactions
|
80
103
|
Increase::Transactions.list(limit: :all)
|
81
|
-
|
104
|
+
|
105
|
+
# You can also use the `next_cursor` to manually paginate through the results
|
106
|
+
txns = Increase::Transactions.list(
|
107
|
+
limit: 2_000,
|
108
|
+
'created_at.after': '2022-01-15T06:34:23Z'
|
109
|
+
)
|
110
|
+
# => [{transaction}, {transaction}, {transaction}, ...]
|
111
|
+
txns.next_cursor
|
112
|
+
# => "eyJwb2NpdGlvbiI6eyJvZmlzZXQiOjEwMH0sIm3pbHRlclI6e319"
|
82
113
|
```
|
83
114
|
|
84
115
|
Watch out for the rate limit!
|
85
116
|
|
86
117
|
### Error Handling
|
87
118
|
|
88
|
-
Whenever you make an
|
89
|
-
of `Increase::ApiError`.
|
119
|
+
Whenever you make an oopsie, the client will raise an error! Errors originating
|
120
|
+
from the API will be a subclass of `Increase::ApiError`.
|
90
121
|
|
91
122
|
```ruby
|
92
123
|
|
93
124
|
begin
|
94
|
-
Increase::Transactions.retrieve('
|
125
|
+
Increase::Transactions.retrieve('i_dont_exist')
|
95
126
|
rescue Increase::ApiError => e
|
96
|
-
puts e.message # "[404: object_not_found_error] Could not find the
|
127
|
+
puts e.message # "[404: object_not_found_error] Could not find the ..."
|
97
128
|
puts e.title # "Could not find the specified object."
|
98
|
-
puts e.detail # "No resource of type transaction was found with ID
|
129
|
+
puts e.detail # "No resource of type transaction was found with ID ..."
|
99
130
|
puts e.status # 404
|
100
131
|
|
101
|
-
puts e.response # This contains the full response
|
132
|
+
puts e.response # This contains the full response, including headers!
|
133
|
+
# => #<Faraday::Response:0x000000010b1fe2b0 ...>
|
102
134
|
|
103
|
-
puts e.class # Increase::ObjectNotFoundError (
|
135
|
+
puts e.class # Increase::ObjectNotFoundError (subclass of Increase::ApiError)
|
104
136
|
end
|
105
137
|
```
|
106
138
|
|
107
|
-
To disable this behavior, set `Increase.raise_api_errors = false`. Errors will
|
139
|
+
To disable this behavior, set `Increase.raise_api_errors = false`. Errors will
|
140
|
+
then be returned as a normal response.
|
108
141
|
|
109
142
|
```ruby
|
110
143
|
Increase.raise_api_errors = false # Default: true
|
111
144
|
|
112
|
-
Increase::Transactions.retrieve('
|
145
|
+
Increase::Transactions.retrieve('i_dont_exist')
|
113
146
|
# => {"status"=>404, "type"=>"object_not_found_error", ... }
|
114
147
|
```
|
115
148
|
|
@@ -129,21 +162,104 @@ Increase.api_key = 'terabytes_of_cash' # Default: nil (you'll need one tho!)
|
|
129
162
|
Increase.base_url = :production # Default: :production
|
130
163
|
Increase.raise_api_errors = true # Default: true
|
131
164
|
|
132
|
-
# Or, you can
|
165
|
+
# Or, you can pass in a hash
|
166
|
+
Increase.configure(api_key: 'just_my_two_cents')
|
167
|
+
|
168
|
+
# Or, you can use a block!
|
133
169
|
Increase.configure do |config|
|
134
170
|
config.api_key = 'digital_dough'
|
135
|
-
config.base_url = :sandbox
|
136
|
-
config.raise_api_errors = false
|
171
|
+
config.base_url = :sandbox # Default: :production
|
172
|
+
config.raise_api_errors = false # Default: true
|
137
173
|
end
|
174
|
+
```
|
138
175
|
|
139
|
-
|
140
|
-
|
176
|
+
If you are using Rails, the recommended way is to set your configurations as a
|
177
|
+
block in an initializer.
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
# config/initializers/increase.rb
|
181
|
+
|
182
|
+
Increase.configure do |config|
|
183
|
+
# Your Increase API Key!
|
184
|
+
# Grab it from https://dashboard.increase.com/developers/api_keys
|
185
|
+
config.api_key = Rails.application.credentials.dig(:increase, :api_key)
|
186
|
+
|
187
|
+
# The base URL for Increase's API.
|
188
|
+
# You can use
|
189
|
+
# - :production (https://api.increase.com)
|
190
|
+
# - :sandbox (https://sandbox.increase.com)
|
191
|
+
# - or set an actual URL
|
192
|
+
config.base_url = Rails.env.production? ? :production : :sandbox
|
193
|
+
|
194
|
+
# Whether to raise an error when the API returns a non-2XX status.
|
195
|
+
# If disabled (false), the client will return the error response as a normal,
|
196
|
+
# instead of raising an error.
|
197
|
+
#
|
198
|
+
# Learn more about...
|
199
|
+
# - Increase's errors: https://increase.com/documentation/api#errors
|
200
|
+
# - Error classes: https://github.com/garyhtou/increase-ruby/blob/main/lib/increase/errors.rb
|
201
|
+
config.raise_api_errors = true # Default: true
|
202
|
+
end
|
203
|
+
```
|
204
|
+
|
205
|
+
### File Uploads
|
206
|
+
|
207
|
+
```ruby
|
208
|
+
# Creating a file of an image of a government-issued ID
|
209
|
+
file_to_upload = Faraday::Multipart::FilePart.new(
|
210
|
+
'/path/to/file.jpg', # File path
|
211
|
+
'image/jpeg' # File name
|
212
|
+
)
|
213
|
+
|
214
|
+
Increase::Files.create(
|
215
|
+
purpose: 'identity_document',
|
216
|
+
file: file_to_upload
|
217
|
+
)
|
218
|
+
```
|
219
|
+
|
220
|
+
See [`faraday-multipart`](https://github.com/lostisland/faraday-multipart)'s
|
221
|
+
documentation for more file upload options.
|
222
|
+
|
223
|
+
### Webhooks
|
224
|
+
|
225
|
+
**Increase**'s webhooks include a `Increase-Webhook-Signature` header for
|
226
|
+
securing your webhook endpoint. Although not required, it's strongly recommended
|
227
|
+
that you verify the signature to ensure the request is coming from **Increase**.
|
228
|
+
|
229
|
+
Here is an example for Rails.
|
230
|
+
|
231
|
+
```ruby
|
232
|
+
|
233
|
+
class IncreaseController < ApplicationController
|
234
|
+
protect_from_forgery except: :webhook # Ignore CSRF checks
|
235
|
+
|
236
|
+
def webhook
|
237
|
+
payload = request.body.read
|
238
|
+
sig_header = request.headers['Increase-Webhook-Signature']
|
239
|
+
secret = Rails.application.credentials.dig(:increase, :webhook_secret)
|
240
|
+
|
241
|
+
Increase::Webhook::Signature.verify(
|
242
|
+
payload: payload,
|
243
|
+
signature_header: sig_header,
|
244
|
+
secret: secret
|
245
|
+
)
|
246
|
+
|
247
|
+
# It's a valid webhook! Do something with it...
|
248
|
+
|
249
|
+
render json: {success: true}
|
250
|
+
|
251
|
+
rescue Increase::WebhookSignatureVerificationError => e
|
252
|
+
render json: {error: 'Webhook signature verification failed'}, status: :bad_request
|
253
|
+
end
|
254
|
+
end
|
141
255
|
```
|
142
256
|
|
143
257
|
### Idempotency
|
144
258
|
|
145
|
-
**Increase**
|
146
|
-
|
259
|
+
**Increase**
|
260
|
+
supports [idempotent requests](https://increase.com/documentation/api#idempotency)
|
261
|
+
to allow for safely retrying requests without accidentally performing the same
|
262
|
+
operation twice.
|
147
263
|
|
148
264
|
```ruby
|
149
265
|
card = Increase::Cards.create(
|
@@ -159,35 +275,48 @@ card = Increase::Cards.create(
|
|
159
275
|
)
|
160
276
|
# => {"id"=>"card_1234abcd", "type"=>"card", ... }
|
161
277
|
|
162
|
-
|
163
|
-
# =>
|
278
|
+
card.idempotent_replayed
|
279
|
+
# => nil
|
280
|
+
|
281
|
+
# Repeat the exact same request
|
282
|
+
card = Increase::Cards.create(...)
|
283
|
+
# => {"id"=>"card_1234abcd", "type"=>"card", ... }
|
284
|
+
|
285
|
+
card.idempotent_replayed
|
286
|
+
# => "true"
|
164
287
|
```
|
165
288
|
|
166
|
-
Reusing the key in subsequent requests will return the same response code and
|
167
|
-
|
168
|
-
|
169
|
-
|
289
|
+
Reusing the key in subsequent requests will return the same response code and
|
290
|
+
body as the original request along with an additional HTTP
|
291
|
+
header (`Idempotent-Replayed: true`). This applies to both success and error
|
292
|
+
responses. In situations where your request results in a validation error,
|
293
|
+
you'll need to update your request and retry with a new idempotency key.
|
170
294
|
|
171
295
|
## Development
|
172
296
|
|
173
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
174
|
-
|
297
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
298
|
+
run `rake spec` to run the tests. You can also run `bin/console` for an
|
299
|
+
interactive prompt that will allow you to experiment.
|
175
300
|
|
176
|
-
You can also
|
177
|
-
|
301
|
+
You can also
|
302
|
+
run `INCREASE_API_KEY=my_key_here INCREASE_BASE_URL=https://sandbox.increase.com bin/console`
|
303
|
+
to run the console with your Increase sandbox API key pre-filled.
|
178
304
|
|
179
305
|
To install this gem onto your local machine, run `bundle exec rake install`.
|
180
306
|
|
181
|
-
To release a new version, update the version number in `version.rb`, and then
|
182
|
-
|
307
|
+
To release a new version, update the version number in `version.rb`, and then
|
308
|
+
run `bundle exec rake release`, which will create a git tag for the version,
|
309
|
+
push git commits and the created tag, and push the `.gem` file
|
183
310
|
to [rubygems.org](https://rubygems.org).
|
184
311
|
|
185
312
|
Alternatively, use [`gem-release`](https://github.com/svenfuchs/gem-release) and
|
186
|
-
run `gem bump --version patch|minor|major`. Then release the gem by
|
313
|
+
run `gem bump --version patch|minor|major`. Then release the gem by
|
314
|
+
running `bundle exec rake release`.
|
187
315
|
|
188
316
|
## Contributing
|
189
317
|
|
190
|
-
Bug reports and pull requests are welcome on GitHub
|
318
|
+
Bug reports and pull requests are welcome on GitHub
|
319
|
+
at https://github.com/garyhtou/increase.
|
191
320
|
|
192
321
|
## License
|
193
322
|
|
@@ -196,5 +325,5 @@ the [MIT License](https://github.com/garyhtou/increase-ruby/blob/main/LICENSE.tx
|
|
196
325
|
|
197
326
|
---
|
198
327
|
|
199
|
-
Please note that this is not an official library
|
200
|
-
by [Gary Tou](https://garytou.com/)
|
328
|
+
Please note that this is not an official library by **Increase**. This gem was
|
329
|
+
created and maintained by [Gary Tou](https://garytou.com/).
|
data/bin/generate
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# OpenAPI client generators for Ruby seem to be a bit of a mess. I'm
|
5
|
+
# essentially writing my own crude generator here. It's not perfect, but it
|
6
|
+
# gets the job done :)
|
7
|
+
|
8
|
+
require 'bundler/setup'
|
9
|
+
require 'irb'
|
10
|
+
|
11
|
+
require 'json'
|
12
|
+
require 'erb'
|
13
|
+
require 'ostruct'
|
14
|
+
require 'pry'
|
15
|
+
|
16
|
+
spec = JSON.parse(File.read('openapi.json'))
|
17
|
+
|
18
|
+
# Parse OpenAPI spec
|
19
|
+
resources = Hash.new { |h, k| h[k] = [] } # Default value of new keys is []
|
20
|
+
spec['paths'].each do |path, methods|
|
21
|
+
methods.each do |method, details|
|
22
|
+
name = details['x-tag'] # Resource name
|
23
|
+
|
24
|
+
endpoint = {
|
25
|
+
http_method: method.to_sym,
|
26
|
+
path: path.split('/').reject(&:empty?),
|
27
|
+
operation: details['operationId'].split('_').first.downcase,
|
28
|
+
|
29
|
+
# Extra info
|
30
|
+
details: details,
|
31
|
+
}
|
32
|
+
|
33
|
+
# Convert path params to symbols
|
34
|
+
path_params = details['parameters'].select { |p| p['in'] == 'path' }
|
35
|
+
endpoint[:path].map! do |p|
|
36
|
+
# Find path param for this segment
|
37
|
+
param = path_params.find { |param| "{#{param['name']}}" == p }
|
38
|
+
param ? param['name'].to_sym : p
|
39
|
+
end
|
40
|
+
|
41
|
+
# Handle case for "/groups/current".
|
42
|
+
# Changes operation from :retrieve to :current
|
43
|
+
if endpoint[:path].size > 1 && endpoint[:path].last.is_a?(String)
|
44
|
+
endpoint[:operation] = endpoint[:path].last.to_sym
|
45
|
+
end
|
46
|
+
|
47
|
+
# Add endpoint to resource
|
48
|
+
resources[name] << endpoint
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Write OpenAPI version to file
|
53
|
+
api_version = spec['info']['version']
|
54
|
+
File.open('OPENAPI_VERSION', 'w') do |file|
|
55
|
+
file.write("v#{api_version}")
|
56
|
+
end
|
57
|
+
|
58
|
+
# Clear resources directory
|
59
|
+
Dir.glob('lib/increase/resources/*.rb').each do |file|
|
60
|
+
File.delete(file)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Generate code
|
64
|
+
OPERATION_ALIASES = [
|
65
|
+
{
|
66
|
+
name: 'create',
|
67
|
+
operation: 'create',
|
68
|
+
http_method: :post,
|
69
|
+
path_regex: /^\w+$/
|
70
|
+
},
|
71
|
+
{
|
72
|
+
name: 'list',
|
73
|
+
operation: 'list',
|
74
|
+
http_method: :get,
|
75
|
+
path_regex: /^\w+$/
|
76
|
+
},
|
77
|
+
{
|
78
|
+
name: 'update',
|
79
|
+
operation: 'update',
|
80
|
+
http_method: :patch,
|
81
|
+
path_regex: /^\w+\/\w+_id$/
|
82
|
+
},
|
83
|
+
{
|
84
|
+
name: 'retrieve',
|
85
|
+
operation: 'retrieve',
|
86
|
+
http_method: :get,
|
87
|
+
path_regex: /^\w+\/\w+_id$/
|
88
|
+
}
|
89
|
+
]
|
90
|
+
|
91
|
+
template = File.read('generate/resource.rb.erb')
|
92
|
+
render = ERB.new(template, trim_mode: '-')
|
93
|
+
|
94
|
+
resources.delete('Simulations') # TODO
|
95
|
+
|
96
|
+
resources.each do |name, operations|
|
97
|
+
# Convert name to class name (pascal case with no special characters)
|
98
|
+
class_name = name.split(/[\s\W]/).map(&:capitalize).join
|
99
|
+
|
100
|
+
# Resource type
|
101
|
+
resource_type = operations.first[:path].first
|
102
|
+
|
103
|
+
# Format operations
|
104
|
+
ops = operations.each do |op|
|
105
|
+
# Try to find an alias for this operation
|
106
|
+
op_alias = OPERATION_ALIASES.find do |alias_op|
|
107
|
+
op[:operation] == alias_op[:operation] &&
|
108
|
+
op[:http_method] == alias_op[:http_method] &&
|
109
|
+
alias_op[:path_regex].match(op[:path].join('/'))
|
110
|
+
end
|
111
|
+
op.merge!(alias: op_alias&.dig(:name))
|
112
|
+
|
113
|
+
# Check to make sure path doesn't not contain more than 1 param
|
114
|
+
if op[:path].select { |p| p.is_a?(Symbol) }.size > 1
|
115
|
+
raise StandardError, "Multiple path params for #{name} #{op[:path].inspect}"
|
116
|
+
end
|
117
|
+
|
118
|
+
# Remove resource root path segment
|
119
|
+
op[:path].shift
|
120
|
+
if op[:path].size == 1
|
121
|
+
op[:path] = op[:path].first
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Check operation uniqueness
|
126
|
+
if ops.map { |op| op[:operation] }.uniq.size != ops.size
|
127
|
+
raise StandardError, "Duplicate operations for #{name}"
|
128
|
+
end
|
129
|
+
|
130
|
+
# Render template
|
131
|
+
namespace = OpenStruct.new(
|
132
|
+
class_name: class_name,
|
133
|
+
name: name,
|
134
|
+
api_name: resource_type,
|
135
|
+
operations: ops
|
136
|
+
)
|
137
|
+
contents = render.result(namespace.instance_eval { binding })
|
138
|
+
|
139
|
+
# Write to file
|
140
|
+
File.open("lib/increase/resources/#{resource_type}.rb", 'w') do |file|
|
141
|
+
file.write(contents)
|
142
|
+
end
|
143
|
+
|
144
|
+
# Print messages
|
145
|
+
puts "Generated #{class_name}"
|
146
|
+
ops.each do |op|
|
147
|
+
puts " #{op[:operation]}"
|
148
|
+
end
|
149
|
+
puts
|
150
|
+
end
|
151
|
+
|
152
|
+
raise "TODO Reminder: Handle special case for Increase::Files.create"
|
data/bin/setup
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "increase/resource"
|
4
|
+
|
5
|
+
module Increase
|
6
|
+
class <%= class_name %> < Resource
|
7
|
+
NAME = <%= name.inspect %>
|
8
|
+
API_NAME = <%= api_name.inspect %>
|
9
|
+
|
10
|
+
<%- operations.each do |op| -%>
|
11
|
+
# <%= op[:details]['summary'] %>
|
12
|
+
<%- if op[:alias] -%>
|
13
|
+
<%= op[:alias] -%>
|
14
|
+
<%- else -%>
|
15
|
+
endpoint <%= op[:operation].inspect %>, <%= op[:http_method].inspect %>, path: <%= op[:path].inspect -%>
|
16
|
+
<%- end -%><%# close if %>
|
17
|
+
<%- end %><%# close loop %> end
|
18
|
+
end
|
data/lib/increase/client.rb
CHANGED
@@ -4,6 +4,7 @@ require "increase/configuration"
|
|
4
4
|
|
5
5
|
require "faraday"
|
6
6
|
require "faraday/follow_redirects"
|
7
|
+
require "faraday/multipart"
|
7
8
|
|
8
9
|
# Custom Faraday Middleware to handle raising errors
|
9
10
|
require "faraday/raise_increase_api_error"
|
@@ -32,6 +33,7 @@ module Increase
|
|
32
33
|
}
|
33
34
|
) do |f|
|
34
35
|
f.request :json
|
36
|
+
f.request :multipart
|
35
37
|
|
36
38
|
if @configuration.raise_api_errors
|
37
39
|
# This custom middleware for raising Increase API errors must be
|