increase 0.2.0 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5ebc261a44d0f2a6df7fc703886dcc18e11a3c54bd2f04742b783e46fedc1f7
4
- data.tar.gz: '073485629ad76bc387aa0a51d954a86bb93c9884bd90baccedeaa2cbf483efaa'
3
+ metadata.gz: 9520a7eb024d05477e162e1158a07f54167a6a89297f44d3a71caa01a40599cf
4
+ data.tar.gz: 273bb964f85fb97660212f6a2046a58caf4e7302d07859fe3d562afe8269922d
5
5
  SHA512:
6
- metadata.gz: c2b625211c3e9ad0a7588caaeda4eaea8e216569e3efd2f83afaf48d0c8fed23794d0f8a0d4bdab6a0024115836cab51979a4731ea2fc0d4400de1967e0d9c93
7
- data.tar.gz: ede3ef495349bf6c7cf6acacba84101061aa3740170ca3b7fea1fb4ec8e2c7e8df61b0654e9919e158c1bc033f8ef37ec4171538aeb485eae6f0c1f3cd619da5
6
+ metadata.gz: d4b399cda4f620ca00549831546a4992069eb17cb84f08ce9aa0039744e7d3ea4868dd3498ee593c001678633bf708a6e8257ee093f75922996c0f1012f9aa6d
7
+ data.tar.gz: bfd03c310aaf256d89228e6bcd0da10e3505004ab958c10c30baa51dd6df1c22d09ca974bcd61def524888dc9203a00fef78a51082991d2dd3aa8701f6060294
data/CHANGELOG.md ADDED
@@ -0,0 +1,90 @@
1
+ # Changelog
2
+
3
+ ## [0.3.1] - 2023-03-23
4
+
5
+ ### Enhancements
6
+
7
+ - Support Faraday >= 1.0.1 (https://github.com/garyhtou/increase-ruby/pull/8)
8
+
9
+
10
+ ## [0.3.0] - 2023-03-23
11
+
12
+ ### Enhancements
13
+
14
+ - Better developer experience for file uploads (9fc40df62a537ed3402a0c0deb5bee908d84b671)
15
+
16
+ ### Documentation
17
+
18
+ - Pin gem version in install command (2127f5a04be8832ba5c5c42476e2844fb6ca9c24)
19
+ - Update README to reflect new file upload DX (9fc40df62a537ed3402a0c0deb5bee908d84b671)
20
+
21
+
22
+ ## [0.2.0] - 2023-03-21
23
+
24
+ ### Enhancements
25
+
26
+ - Made webhook verification `verify` raise an error, but `verify?` return a bool (58d462fc648cafdcfdb7b8d2c0e0ec1f45362984)
27
+ - Wrote a generator to generate API resource classes from the OpenAPI spec (8eedc2d4a5daecd97c156546c649f27376eb9762)
28
+ - Added all API resources (2a04096dea06a34ba8ff1d5061475ed1a2354ac2)
29
+ - Supported getting response from `list` operation (a2141f034a4f29cfee0222a4fac32949581adbc6)
30
+
31
+ ### Fixes
32
+
33
+ - Use `ArgumentError` when unknown config passed to `Configuration` (cdd0703febd6f9dec0ecd4ac34fe465697edbf08)
34
+ - File uploads! Increase::Files.create now works (236cad5011b996b40793abe85698ba47fa1ba3f8)
35
+
36
+ ### Documentation
37
+
38
+ - Updated error handling example to be more clear (85d8d6ff102a8ef502040322537b79085f89779d)
39
+ - Fixed idempotency example (343ae6d4cb1b8216192e2f820836ca87cc3a9a36)
40
+ - Added example for passing hash to `with_config` (b82fac134c813d03a31466e83341acc891c1deb6)
41
+ - Updated Rails config example to use Rails credentials (2b4fec9c1d52d04e42760a9889ba1cb313b5bd18)
42
+ - Added list filtering example (6333f982062b2527f676a6aade4e5abf01a7816b)
43
+ - Added table of contents (88e9b6ae05aaa62974514a6c318f35e708e49fb5)
44
+ - Added full example for Idempotency keys (6d5ce8bdd3d4baf13c4d0800a159c784bc1bdc78)
45
+ - Added manual pagination example using `next_cursor` (57157e2965904c9150676696e8567b5518892945)
46
+
47
+
48
+ ## [0.1.3] - 2023-03-20
49
+
50
+ ### Enhancements
51
+
52
+ - Added `Limits` resource (98654433812b202ecfd31ba35d520981529f2e2b)
53
+ - Added `CheckTransfers` resource (a899c9ca6206af78df23ba8b62c8dfc88b7fc22d)
54
+ - Added `RoutingNumbers` resource (209e7f279a1ff648142ac6aca6cfe946fc653845)
55
+
56
+ ### Documentation
57
+
58
+ - Added section about webhook signature verification (650aed416ab820ed55f0ed8936f201274964fc37)
59
+ - Added section about Rails configuration (650aed416ab820ed55f0ed8936f201274964fc37)
60
+
61
+ ## [0.1.2] - 2023-03-20
62
+
63
+ ### Enhancements
64
+
65
+ - Added webhook verification support (ce193fb8888d497817ab5551bf8e9096c5bf7e26)
66
+ - Added user agent to requests (ce44249ead32ba4055b13ba576f0b91f20493cfc)
67
+ - Update supported Ruby version to >= 2.7.4 (c404f8ddc4762615bac660edabf0385716b4bd74)
68
+
69
+ ### Fixes
70
+
71
+ - Always apply default configuration options (079f0ca603a80dd2c9523df23244b64e2e0a5772)
72
+
73
+ ### Documentation
74
+
75
+ - Wrote the README! (aa7c778834cd268ab1318e44fceea0b062a5c5df)
76
+
77
+
78
+ ## [0.1.1] - 2023-03-19
79
+
80
+ ### Enhancements
81
+ - Added client-wide configuration options (c47e32c93371b43f2e0a3ac49525e46fbe9ef326)
82
+ - Load `INCREASE_API_KEY` and `INCREASE_BASE_URL` from environment variables (2e6cbe21a2b37c230dc3f2382613b98ffc3ea4d8, 24cea582c03b64018ed2f0997f99f4bae581a1fa, 4a80e4263c7917bbfa1371c70752476d7f7f0695)
83
+ - Added the following API resources:
84
+ - `AccountNumbers` (209b155c0fa3977c2c19602a2239c8b27001935e)
85
+ - `AccountTransfers` (6065a932522bd582aa4f177037a5eca8e5d1647d)
86
+ - `AchTransfers` (caef61c36bfffc780016880959f067b59bfa288e)
87
+ - `Cards` (b58bccc8aab00fd2ee69f2973898e6a13c1b2544)
88
+ - `Events` (dd3312638227be47f04c8bd740c3dd25104959e7)
89
+ - `PendingTransactions` (b6f4b2c02a9108603b4d1feee9a39c1a7f1086ef)
90
+ - `Transaction` (b6f4b2c02a9108603b4d1feee9a39c1a7f1086ef)
data/README.md CHANGED
@@ -19,14 +19,14 @@ Bare-Metal Banking APIs!
19
19
  Install the gem and add to the application's Gemfile by executing:
20
20
 
21
21
  ```sh
22
- $ bundle add increase
22
+ $ bundle add increase -v 0.3.1
23
23
  ```
24
24
 
25
25
  If bundler is not being used to manage dependencies, install the gem by
26
26
  executing:
27
27
 
28
28
  ```sh
29
- $ gem install increase
29
+ $ gem install increase -v 0.3.1
30
30
  ```
31
31
 
32
32
  ## Usage
@@ -204,21 +204,43 @@ end
204
204
 
205
205
  ### File Uploads
206
206
 
207
+ It's as simple as passing in a file path!
208
+
209
+ ```ruby
210
+ Increase::Files.create(
211
+ purpose: 'identity_document',
212
+ file: '/path/to/file.jpg'
213
+ )
214
+ ```
215
+
216
+ Alternatively, you can pass in a `File` object.
217
+
218
+ ```ruby
219
+ file = File.open('/path/to/file.jpg')
220
+
221
+ Increase::Files.create(
222
+ purpose: 'identity_document',
223
+ file: file
224
+ )
225
+ ```
226
+
227
+ Or, get even fancier and use `Increase::FileUpload` to specify the content type
228
+ and filename.
229
+
207
230
  ```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
231
+ file = Increase::FileUpload.new(
232
+ '/path/to/file.jpg',
233
+ content_type: 'image/jpeg',
234
+ filename: 'my_file.jpg'
212
235
  )
213
236
 
214
237
  Increase::Files.create(
215
238
  purpose: 'identity_document',
216
- file: file_to_upload
239
+ file: file
217
240
  )
218
241
  ```
219
242
 
220
- See [`faraday-multipart`](https://github.com/lostisland/faraday-multipart)'s
221
- documentation for more file upload options.
243
+ If no content type or filename is provided, the client will try to guess it.
222
244
 
223
245
  ### Webhooks
224
246
 
@@ -1,13 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "increase/configuration"
4
+ require "increase/middleware/raise_api_error"
4
5
 
5
6
  require "faraday"
6
- require "faraday/follow_redirects"
7
- require "faraday/multipart"
8
-
9
- # Custom Faraday Middleware to handle raising errors
10
- require "faraday/raise_increase_api_error"
7
+ require "faraday/follow_redirects" # Supports both Faraday 1.0 and 2.0
8
+ if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new("2.0")
9
+ # In Faraday 2.0, multipart support is no longer included by default
10
+ require "faraday/multipart"
11
+ else
12
+ # In Faraday 1.0, the JSON middleware is not included by default
13
+ require "increase/middleware/encode_json"
14
+ require "increase/middleware/parse_json"
15
+ end
11
16
 
12
17
  module Increase
13
18
  class Client
@@ -38,7 +43,7 @@ module Increase
38
43
  if @configuration.raise_api_errors
39
44
  # This custom middleware for raising Increase API errors must be
40
45
  # located before the JSON response middleware.
41
- f.use FaradayMiddleware::RaiseIncreaseApiError
46
+ f.use Increase::Middleware::RaiseApiError
42
47
  end
43
48
 
44
49
  f.response :json
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tempfile"
4
+ require "marcel"
5
+ require "faraday"
6
+ require "pathname"
7
+
8
+ module Increase
9
+ class FileUpload
10
+ attr_reader :file, :filename, :content_type
11
+
12
+ def initialize(file_or_path, filename: nil, content_type: nil)
13
+ @filename = filename
14
+ @content_type = content_type
15
+
16
+ if file_or_path.is_a?(File) || file_or_path.is_a?(Tempfile)
17
+ @file = file_or_path
18
+ @filename ||= File.basename(file_or_path.path)
19
+ elsif file_or_path.is_a?(String)
20
+ # Treat string as a filepath
21
+ @file = File.open(file_or_path)
22
+ @filename ||= File.basename(file_or_path)
23
+ elsif file_or_path.respond_to?(:read)
24
+ @file = Tempfile.new(default_filename)
25
+ @file.write(file_or_path.read)
26
+ else
27
+ raise ArgumentError, "File or path required"
28
+ end
29
+
30
+ # Try to guess content type
31
+ @content_type ||= Marcel::MimeType.for(@file, name: @filename)
32
+ @filename ||= default_filename
33
+ end
34
+
35
+ def file_part
36
+ if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new("2.0")
37
+ Faraday::Multipart::FilePart.new(
38
+ @file,
39
+ @content_type,
40
+ @filename
41
+ )
42
+ else
43
+ Faraday::FilePart.new(
44
+ @file,
45
+ @content_type,
46
+ @filename
47
+ )
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def default_filename
54
+ "file upload #{Time.now}"
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+
5
+ module Increase
6
+ module Middleware
7
+ # JSON request middleware for Faraday 1.0
8
+ # In Faraday 2.0, the JSON middleware is bundled with the Faraday gem itself
9
+ #
10
+ # This middleware is from
11
+ # https://github.com/lostisland/faraday_middleware/blob/main/lib/faraday_middleware/request/encode_json.rb
12
+ class EncodeJson < Faraday::Middleware
13
+ CONTENT_TYPE = "Content-Type"
14
+ MIME_TYPE = "application/json"
15
+ MIME_TYPE_REGEX = %r{^application/(vnd\..+\+)?json$}.freeze
16
+
17
+ dependency do
18
+ require "json" unless defined?(::JSON)
19
+ end
20
+
21
+ def call(env)
22
+ match_content_type(env) do |data|
23
+ env[:body] = encode data
24
+ end
25
+ @app.call env
26
+ end
27
+
28
+ def encode(data)
29
+ ::JSON.generate data
30
+ end
31
+
32
+ def match_content_type(env)
33
+ return unless process_request?(env)
34
+
35
+ env[:request_headers][CONTENT_TYPE] ||= MIME_TYPE
36
+ yield env[:body] unless env[:body].respond_to?(:to_str)
37
+ end
38
+
39
+ def process_request?(env)
40
+ type = request_type(env)
41
+ has_body?(env) && (type.empty? || MIME_TYPE_REGEX =~ type)
42
+ end
43
+
44
+ def has_body?(env)
45
+ (body = env[:body]) && !(body.respond_to?(:to_str) && body.empty?)
46
+ end
47
+
48
+ def request_type(env)
49
+ type = env[:request_headers][CONTENT_TYPE].to_s
50
+ type = type.split(";", 2).first if type.index(";")
51
+ type
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ Faraday::Request.register_middleware(json: Increase::Middleware::EncodeJson)
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "json"
5
+
6
+ module Increase
7
+ module Middleware
8
+ # JSON response middleware for Faraday 1.0
9
+ # In Faraday 2.0, the JSON middleware is bundled with the Faraday gem itself
10
+ #
11
+ # This middleware is from
12
+ # https://github.com/jsmestad/jsonapi-consumer/blob/7d9721ea7feb888ea1e43edb9f1c0c38334762ed/lib/jsonapi/consumer/middleware/parse_json.rb
13
+ class ParseJson < Faraday::Middleware
14
+ def call(environment)
15
+ @app.call(environment).on_complete do |env|
16
+ if process_response_type?(response_type(env))
17
+ env[:raw_body] = env[:body]
18
+ env[:body] = parse(env[:body])
19
+ end
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def parse(body)
26
+ ::JSON.parse(body) unless body.strip.empty?
27
+ end
28
+
29
+ def response_type(env)
30
+ type = env[:response_headers]["Content-Type"].to_s
31
+ type = type.split(";", 2).first if type.index(";")
32
+ type
33
+ end
34
+
35
+ def process_response_type?(type)
36
+ !!type.match(/\bjson$/)
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ Faraday::Response.register_middleware(json: Increase::Middleware::ParseJson)
@@ -0,0 +1,13 @@
1
+ require "faraday"
2
+
3
+ module Increase
4
+ module Middleware
5
+ class RaiseApiError < Faraday::Middleware
6
+ def on_complete(env)
7
+ return if env[:status] < 400
8
+
9
+ raise Increase::ApiError.from_response(env)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -29,7 +29,7 @@ module Increase
29
29
  with = [with].flatten.compact
30
30
 
31
31
  # TODO: This doesn't support multiple path params
32
- is_id = ->(path_segment) { path_segment.is_a?(Symbol) && path_segment.to_s.end_with?('id') }
32
+ is_id = ->(path_segment) { path_segment.is_a?(Symbol) && path_segment.to_s.end_with?("id") }
33
33
  has_id = path.any? is_id
34
34
 
35
35
  request_method = :request
@@ -99,6 +99,7 @@ module Increase
99
99
  private
100
100
 
101
101
  def request(method, path, params = nil, headers = nil, &block)
102
+ params ||= {}
102
103
  headers ||= {}
103
104
 
104
105
  if block
@@ -113,13 +114,12 @@ module Increase
113
114
  # Hack to check for correct file upload params
114
115
  if headers["Content-Type"] == "multipart/form-data"
115
116
  attr = :file # TODO: Make this configurable
116
- if params.nil? || params[attr].nil?
117
- # No file to upload
118
- elsif params[attr].is_a?(Faraday::Multipart::FilePart) || params[attr].is_a?(Faraday::Multipart::ParamPart)
119
- # All is good!
120
- else
121
- # Soft fail
122
- warn "File upload requires a `#{attr}` param with a Faraday::Multipart::FilePart or Faraday::MultiPart::ParamPart object. See docs."
117
+ if params[attr]
118
+ unless params[attr].is_a?(FileUpload)
119
+ params[attr] = FileUpload.new(params[attr])
120
+ end
121
+
122
+ params[attr] = params[attr].file_part
123
123
  end
124
124
  end
125
125
 
@@ -13,7 +13,7 @@ module Increase
13
13
  end
14
14
 
15
15
  def next_cursor
16
- wrapped&.dig('next_cursor')
16
+ wrapped&.dig("next_cursor")
17
17
  end
18
18
  end
19
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Increase
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.1"
5
5
  end
data/lib/increase.rb CHANGED
@@ -4,8 +4,9 @@ require "increase/version"
4
4
  require "increase/client"
5
5
  require "increase/configuration"
6
6
  require "increase/errors"
7
- require "increase/resources"
8
7
  require "increase/webhook/signature"
8
+ require "increase/file_upload"
9
+ require "increase/resources"
9
10
 
10
11
  module Increase
11
12
  PRODUCTION_URL = "https://api.increase.com"
metadata CHANGED
@@ -1,43 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: increase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Tou
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-21 00:00:00.000000000 Z
11
+ date: 2023-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.1
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: '2.7'
22
+ version: '2.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.1
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: '2.7'
32
+ version: '2.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: faraday-follow_redirects
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - '='
37
+ - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: 0.3.0
39
+ version: '0.3'
34
40
  type: :runtime
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
- - - '='
44
+ - - "~>"
39
45
  - !ruby/object:Gem::Version
40
- version: 0.3.0
46
+ version: '0.3'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: faraday-multipart
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +58,20 @@ dependencies:
52
58
  - - "~>"
53
59
  - !ruby/object:Gem::Version
54
60
  version: '1.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: marcel
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.0'
55
75
  - !ruby/object:Gem::Dependency
56
76
  name: rake
57
77
  requirement: !ruby/object:Gem::Requirement
@@ -145,6 +165,7 @@ extra_rdoc_files: []
145
165
  files:
146
166
  - ".rspec"
147
167
  - ".standard.yml"
168
+ - CHANGELOG.md
148
169
  - Gemfile
149
170
  - LICENSE.txt
150
171
  - OPENAPI_VERSION
@@ -153,11 +174,14 @@ files:
153
174
  - bin/generate
154
175
  - bin/setup
155
176
  - generate/resource.rb.erb
156
- - lib/faraday/raise_increase_api_error.rb
157
177
  - lib/increase.rb
158
178
  - lib/increase/client.rb
159
179
  - lib/increase/configuration.rb
160
180
  - lib/increase/errors.rb
181
+ - lib/increase/file_upload.rb
182
+ - lib/increase/middleware/encode_json.rb
183
+ - lib/increase/middleware/parse_json.rb
184
+ - lib/increase/middleware/raise_api_error.rb
161
185
  - lib/increase/resource.rb
162
186
  - lib/increase/resources.rb
163
187
  - lib/increase/resources/account_numbers.rb
@@ -1,11 +0,0 @@
1
- require "faraday"
2
-
3
- module FaradayMiddleware
4
- class RaiseIncreaseApiError < Faraday::Middleware
5
- def on_complete(env)
6
- return if env[:status] < 400
7
-
8
- raise Increase::ApiError.from_response(env)
9
- end
10
- end
11
- end