increase 0.2.0 → 0.3.0

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: a5ebc261a44d0f2a6df7fc703886dcc18e11a3c54bd2f04742b783e46fedc1f7
4
- data.tar.gz: '073485629ad76bc387aa0a51d954a86bb93c9884bd90baccedeaa2cbf483efaa'
3
+ metadata.gz: a945cde9440a62a76cd7a95c5bc91b7dfea452fada50349e3d749c6fc95fa72e
4
+ data.tar.gz: b6ce6f53d72e35e027287feff54fc47c7e855fa364fc11040646efd92c8ce028
5
5
  SHA512:
6
- metadata.gz: c2b625211c3e9ad0a7588caaeda4eaea8e216569e3efd2f83afaf48d0c8fed23794d0f8a0d4bdab6a0024115836cab51979a4731ea2fc0d4400de1967e0d9c93
7
- data.tar.gz: ede3ef495349bf6c7cf6acacba84101061aa3740170ca3b7fea1fb4ec8e2c7e8df61b0654e9919e158c1bc033f8ef37ec4171538aeb485eae6f0c1f3cd619da5
6
+ metadata.gz: 30fb2ded08ba6aa27adfa4f85932e941d4e727ae069ab8df915c2dd001cdd35779b8b58090e29695100270ec66da45cd6d495efdd0b7acc4bf747473b3a5970a
7
+ data.tar.gz: 5a591e007db71c14a1a4e827650bea8a6eda56d68e248eb2988e02380c6de4ccdc5054963c09bda8f2797c36a7dc148fb5a14de58105ff535cbc56bd137f7698
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.0
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.0
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
 
@@ -0,0 +1,50 @@
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
+ Faraday::Multipart::FilePart.new(
37
+ @file,
38
+ @content_type,
39
+ @filename
40
+ )
41
+ end
42
+
43
+ private
44
+
45
+ def default_filename
46
+ "file upload #{Time.now}"
47
+ end
48
+
49
+ end
50
+ end
@@ -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
 
@@ -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.0"
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,14 +1,14 @@
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.0
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
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: marcel
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -158,6 +172,7 @@ files:
158
172
  - lib/increase/client.rb
159
173
  - lib/increase/configuration.rb
160
174
  - lib/increase/errors.rb
175
+ - lib/increase/file_upload.rb
161
176
  - lib/increase/resource.rb
162
177
  - lib/increase/resources.rb
163
178
  - lib/increase/resources/account_numbers.rb