brick_ftp 2.0.2 → 2.1.2

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: 2493a4c45ab215a268d388cb4b90802b854dac43502ed0b354bcf63bbf4e1741
4
- data.tar.gz: 634f7dde30378cf62549413e408531ed9a1a100bbc91513f7895567bea8955ec
3
+ metadata.gz: 66d70eda3f474960acb06afe4eec881b8ea17e907f08e94e4ad9241769538c82
4
+ data.tar.gz: '0078a0cf19d2dde84398abe6e66c05f17dbeb45e286a4de6f0f49ad2d335fc89'
5
5
  SHA512:
6
- metadata.gz: 333fa26348ec6154b7820cc2a75eb17a08de0b3d62625a028b9040401761e2545b317f34e64b8a5ed5b327ef5a918eedd32b2f23c7787a0e9f6c29f39efdb0d0
7
- data.tar.gz: 39fec430bfab410417b928663bc9ebd226f981377b4680c2b5008c7b7c42660f3769d20563fc4b6abf5ce40869398da9ca78b2ae78f3a8c467ef5dce361be562
6
+ metadata.gz: ff38039f4ced2dbe80ef759e6b0455bc0a0edf1921a35c4a26c9df8a6128c5ef0f7c48f81ee3b976ce169162de78f1d29049948dc736c0539f8ad31e012e3c71
7
+ data.tar.gz: 720a8d65122b6c096317bc5e2008e8301471acca1d1a5ef715361dac65568ee11b6e10f8b81f660be29d1e1a0ffeab856a5650dddc72fe59e52dfb55234f6587
data/.circleci/config.yml CHANGED
@@ -2,7 +2,7 @@ version: 2
2
2
  jobs:
3
3
  build: &build
4
4
  docker:
5
- - image: circleci/ruby:latest
5
+ - image: cimg/ruby:latest
6
6
  working_directory: /home/circleci/app
7
7
  steps:
8
8
  - checkout
@@ -18,33 +18,23 @@ jobs:
18
18
  - run:
19
19
  name: RSpec
20
20
  command: rspec
21
- ruby-2.3:
22
- <<: *build
23
- docker:
24
- - image: circleci/ruby:2.3
25
- ruby-2.4:
26
- <<: *build
27
- docker:
28
- - image: circleci/ruby:2.4
29
- ruby-2.5:
30
- <<: *build
31
- docker:
32
- - image: circleci/ruby:2.5
33
21
  ruby-2.6:
34
22
  <<: *build
35
23
  docker:
36
- - image: circleci/ruby:2.6
24
+ - image: cimg/ruby:2.6
37
25
  ruby-2.7:
38
26
  <<: *build
39
27
  docker:
40
- - image: circleci/ruby:2.7
28
+ - image: cimg/ruby:2.7
29
+ ruby-3.0:
30
+ <<: *build
31
+ docker:
32
+ - image: cimg/ruby:3.0
41
33
 
42
34
  workflows:
43
35
  version: 2
44
36
  build-using-multi-rubies:
45
37
  jobs:
46
- - ruby-2.3
47
- - ruby-2.4
48
- - ruby-2.5
49
38
  - ruby-2.6
50
39
  - ruby-2.7
40
+ - ruby-3.0
data/.rubocop.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
3
  AllCops:
4
- TargetRubyVersion: 2.3
4
+ TargetRubyVersion: 2.6
5
5
 
6
6
  Style/EmptyCaseCondition:
7
7
  Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -40,3 +40,10 @@ Style/Documentation:
40
40
 
41
41
  Style/Lambda:
42
42
  EnforcedStyle: literal
43
+
44
+ Lint/StructNewOverride:
45
+ Enabled: false
46
+
47
+ Style/StringConcatenation:
48
+ Exclude:
49
+ - "spec/**/*_spec.rb"
data/CHANGELOG.md CHANGED
@@ -18,6 +18,74 @@ Files::User.new(params, api_key: 'YOUR_API_KEY')
18
18
  I will archive this repository after found official SDK.
19
19
 
20
20
 
21
+ [v2.1.2](https://github.com/koshigoe/brick_ftp/compare/v2.1.1...v2.1.2)
22
+ ----
23
+
24
+ [Full Changelog](https://github.com/koshigoe/brick_ftp/compare/v2.1.1...v2.1.2)
25
+
26
+ ### Enhancements:
27
+
28
+ - use `ruby2_keywords` to support Ruby 3.0.
29
+
30
+ ### Fixed Bugs:
31
+
32
+ ### Deprecate
33
+
34
+ ### Breaking Changes:
35
+
36
+ - Dropping support for Ruby 2.5
37
+
38
+
39
+ [v2.1.1](https://github.com/koshigoe/brick_ftp/compare/v2.1.0...v2.1.1)
40
+ ----
41
+
42
+ [Full Changelog](https://github.com/koshigoe/brick_ftp/compare/v2.1.0...v2.1.1)
43
+
44
+ ### Enhancements:
45
+
46
+ - [#136](https://github.com/koshigoe/brick_ftp/pull/136) Use `PATCH` instead of `PUT` to update User.
47
+ - see https://developers.files.com/#update-user
48
+
49
+ ### Fixed Bugs:
50
+
51
+ ### Deprecate
52
+
53
+ ### Breaking Changes:
54
+
55
+
56
+ [v2.1.0](https://github.com/koshigoe/brick_ftp/compare/v2.0.3...v2.1.0)
57
+ ----
58
+
59
+ [Full Changelog](https://github.com/koshigoe/brick_ftp/compare/v2.0.3...v2.1.0)
60
+
61
+ ### Enhancements:
62
+
63
+ ### Fixed Bugs:
64
+
65
+ ### Deprecate
66
+
67
+ - Deprecate keyword argument `subdomain:` of `BrickFTP::Client#initialize`
68
+ - To enable to specify base URL of REST API (e.g. `http://127.0.0.1:40410/`)
69
+
70
+ ### Breaking Changes:
71
+
72
+ - Dropping support for Ruby 2.3, 2.4
73
+
74
+
75
+ [v2.0.3](https://github.com/koshigoe/brick_ftp/compare/v2.0.2...v2.0.3)
76
+ ----
77
+
78
+ [Full Changelog](https://github.com/koshigoe/brick_ftp/compare/v2.0.2...v2.0.3)
79
+
80
+ ### Enhancements:
81
+
82
+ ### Fixed Bugs:
83
+
84
+ - [#133](https://github.com/koshigoe/brick_ftp/pull/133) Fix to enable to delete folders recursively
85
+
86
+ ### Breaking Changes:
87
+
88
+
21
89
  [v2.0.2](https://github.com/koshigoe/brick_ftp/compare/v2.0.1...v2.0.2)
22
90
  ----
23
91
 
data/README.md CHANGED
@@ -33,22 +33,18 @@ Usage
33
33
  ----
34
34
 
35
35
  ```
36
+ $ docker compose up -d
36
37
  $ bin/console
37
- > client = BrickFTP::Client.new
38
+ > client = BrickFTP::Client.new(base_url: 'http://localhost:40410', api_key: 'dummy')
38
39
  > client.list_users
39
40
  ```
40
41
 
41
- ```
42
- $ bin/console
43
- > api_client = BrickFTP::RESTfulAPI::Client.new(ENV['BRICK_FTP_SUBDOMAIN'], ENV['BRICK_FTP_API_KEY'])
44
- > BrickFTP::RESTfulAPI::ListUsers.new(api_client).call
45
- ```
46
-
47
42
  ### Environment Variables
48
43
 
49
44
  Name | Description
50
45
  --------------------- | -----------
51
- `BRICK_FTP_SUBDOMAIN` | Default subdomain
46
+ `BRICK_FTP_SUBDOMAIN` | Default subdomain (deprecated)
47
+ `BRICK_FTP_BASE_URL` | Base URL of Files.com's REST API (e.g. `https://{subdomain}.files.com/`)
52
48
  `BRICK_FTP_API_KEY` | Default API key
53
49
 
54
50
 
data/brick_ftp.gemspec CHANGED
@@ -20,14 +20,16 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.required_ruby_version = '>= 2.3.0'
23
+ spec.required_ruby_version = '>= 2.6.0'
24
+
25
+ spec.add_runtime_dependency 'ruby2_keywords'
24
26
 
25
27
  spec.add_development_dependency 'bundler', '>= 1.16'
26
28
  spec.add_development_dependency 'pry', '~> 0.11'
27
29
  spec.add_development_dependency 'rake', '~> 12.0'
28
30
  spec.add_development_dependency 'redcarpet', '~> 3.4'
29
31
  spec.add_development_dependency 'rspec', '~> 3.7'
30
- spec.add_development_dependency 'rubocop', '~> 0.57.0'
32
+ spec.add_development_dependency 'rubocop', '~> 1.23'
31
33
  spec.add_development_dependency 'simplecov', '~> 0.15'
32
34
  spec.add_development_dependency 'webmock', '~> 3.4'
33
35
  spec.add_development_dependency 'yard', '~> 0.9'
@@ -0,0 +1,7 @@
1
+ version: '3'
2
+
3
+ services:
4
+ files-mock-server:
5
+ image: filescom/files-mock-server:latest
6
+ ports:
7
+ - 40410:4041
@@ -10,14 +10,26 @@ module BrickFTP
10
10
  # BrickFTP::Client.new.list_users
11
11
  #
12
12
  class Client
13
- attr_reader :subdomain, :api_key, :api_client
13
+ attr_reader :base_url, :api_key, :api_client
14
14
 
15
- # @param [String] subdomain
15
+ # @param [String] base_url
16
+ # @param [String] subdomain (deprecated)
16
17
  # @param [String] api_key
17
- def initialize(subdomain: nil, api_key: nil)
18
+ def initialize(base_url: nil, subdomain: nil, api_key: nil)
19
+ if subdomain
20
+ warn('DEPRECATION WARNING: The argument `subdomain:` will be deprecated in a future version.' \
21
+ ' Please use `base_url:` instead.')
22
+ end
23
+
18
24
  @subdomain = subdomain || ENV['BRICK_FTP_SUBDOMAIN']
25
+ @base_url = base_url || ENV['BRICK_FTP_BASE_URL']
19
26
  @api_key = api_key || ENV['BRICK_FTP_API_KEY']
20
- @api_client = BrickFTP::RESTfulAPI::Client.new(@subdomain, @api_key)
27
+ @api_client = BrickFTP::RESTfulAPI::Client.new(@base_url || @subdomain, @api_key)
28
+ end
29
+
30
+ def subdomain
31
+ warn("DEPRECATION WARNING: #{self.class.name}##{__method__} will be deprecated in a future version.")
32
+ @subdomain
21
33
  end
22
34
 
23
35
  private
@@ -34,6 +46,7 @@ module BrickFTP
34
46
 
35
47
  def respond_to_missing?(symbol, include_private)
36
48
  return true if command_class(symbol)
49
+
37
50
  super
38
51
  end
39
52
 
@@ -45,9 +58,11 @@ module BrickFTP
45
58
  super
46
59
  end
47
60
  end
61
+ ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
48
62
 
49
63
  def dispatch_command(klass, *args)
50
64
  klass.new(api_client).call(*args)
51
65
  end
66
+ ruby2_keywords :dispatch_command if respond_to?(:ruby2_keywords, true)
52
67
  end
53
68
  end
@@ -7,10 +7,10 @@ module BrickFTP
7
7
  def symbolize_keys
8
8
  each_key.each_with_object({}) do |key, mem|
9
9
  symbolized_key = begin
10
- key.to_sym
11
- rescue StandardError
12
- key
13
- end
10
+ key.to_sym
11
+ rescue StandardError
12
+ key
13
+ end
14
14
  mem[symbolized_key] = self[key]
15
15
  end
16
16
  end
@@ -35,12 +35,13 @@ module BrickFTP
35
35
 
36
36
  # Initialize REST API client.
37
37
  #
38
- # @param [String] subdomain
38
+ # @param [String] base_url
39
39
  # @param [String] api_key
40
40
  #
41
- def initialize(subdomain, api_key)
42
- @http = Net::HTTP.new("#{subdomain}.files.com", 443)
43
- @http.use_ssl = true
41
+ def initialize(base_url, api_key)
42
+ @base_uri = make_base_uri(base_url)
43
+ @http = Net::HTTP.new(@base_uri.host, @base_uri.port)
44
+ @http.use_ssl = (@base_uri.scheme == 'https')
44
45
  @http.open_timeout = OPEN_TIMEOUT
45
46
  @http.read_timeout = READ_TIMEOUT
46
47
  @request_headers = {
@@ -146,11 +147,22 @@ module BrickFTP
146
147
  res = http.start { |session| session.request(req) }
147
148
 
148
149
  return io.size if res.is_a?(Net::HTTPSuccess)
150
+
149
151
  raise Error, parse_error_response(res)
150
152
  end
151
153
 
152
154
  private
153
155
 
156
+ DEFAULT_BASE_URL_TEMPLATE = 'https://%{subdomain}.files.com'
157
+
158
+ def make_base_uri(url_or_subdomain)
159
+ unless /[.:]/.match?(url_or_subdomain)
160
+ url_or_subdomain = format(DEFAULT_BASE_URL_TEMPLATE, subdomain: url_or_subdomain)
161
+ end
162
+
163
+ URI.parse(url_or_subdomain)
164
+ end
165
+
154
166
  def handle_response(response)
155
167
  case response
156
168
  when Net::HTTPNoContent
@@ -169,10 +181,10 @@ module BrickFTP
169
181
 
170
182
  def parse_error_response(response)
171
183
  parsed = begin
172
- JSON.parse(response.body)
173
- rescue StandardError
174
- {}
175
- end
184
+ JSON.parse(response.body)
185
+ rescue StandardError
186
+ {}
187
+ end
176
188
  parsed = {} unless parsed.is_a?(Hash)
177
189
 
178
190
  ErrorResponse.new(parsed.symbolize_keys).tap do |e|
@@ -6,25 +6,23 @@ module BrickFTP
6
6
  module RESTfulAPI
7
7
  # Delete a file or folder
8
8
  #
9
- # @see https://developers.files.com/#delete-a-file-or-folder Delete a file or folder
9
+ # @see https://developers.files.com/#delete-file-folder Delete file/folder
10
10
  #
11
11
  class DeleteFolder
12
12
  include Command
13
13
 
14
14
  # Deletes a file or folder.
15
15
  #
16
- # Note that this operation works for both files and folders, but normally it will only work on empty folders.
17
- # If you want to recursively delete a folder and all its contents, send the request with a `Depth` header
18
- # with the value set to `infinity`.
16
+ # > If true, will recursively delete folers. Otherwise, will error on non-empty folders.
19
17
  #
20
18
  # @param [String] path Full path of the file or folder. Maximum of 550 characters.
21
19
  # @param [Boolean] recursive
22
20
  #
23
21
  def call(path, recursive: false)
24
- headers = {}
25
- headers = { 'Depth' => 'infinity' } if recursive
22
+ url = "/api/rest/v1/files/#{ERB::Util.url_encode(path)}"
23
+ url += '?recursive=true' if recursive
26
24
 
27
- client.delete("/api/rest/v1/files/#{ERB::Util.url_encode(path)}", headers)
25
+ client.delete(url)
28
26
  true
29
27
  end
30
28
  end
@@ -92,7 +92,7 @@ module BrickFTP
92
92
  # @return [BrickFTP::Types::User] updated User
93
93
  #
94
94
  def call(id, params)
95
- res = client.put("/api/rest/v1/users/#{id}.json", params.to_h.compact)
95
+ res = client.patch("/api/rest/v1/users/#{id}.json", params.to_h.compact)
96
96
 
97
97
  BrickFTP::Types::User.new(**res.symbolize_keys)
98
98
  end
@@ -17,7 +17,7 @@ module BrickFTP
17
17
  class UploadFile
18
18
  include Command
19
19
 
20
- CHUNK_SIZE_RANGE = 5_242_880..5_368_709_120
20
+ CHUNK_SIZE_RANGE = (5_242_880..5_368_709_120).freeze
21
21
 
22
22
  # At this point, you are to send a PUT request to the returned upload_uri with the file data,
23
23
  # along with the headers and parameters provided to you from BrickFTP.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BrickFTP
4
- VERSION = '2.0.2'
4
+ VERSION = '2.1.2'
5
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brick_ftp
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - koshigoe
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-13 00:00:00.000000000 Z
11
+ date: 2021-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby2_keywords
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'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +100,14 @@ dependencies:
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: 0.57.0
103
+ version: '1.23'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: 0.57.0
110
+ version: '1.23'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: simplecov
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +178,7 @@ files:
164
178
  - bin/console
165
179
  - bin/setup
166
180
  - brick_ftp.gemspec
181
+ - docker-compose.yml
167
182
  - lib/brick_ftp.rb
168
183
  - lib/brick_ftp/client.rb
169
184
  - lib/brick_ftp/core_ext.rb
@@ -264,7 +279,7 @@ homepage: https://github.com/koshigoe/brick_ftp
264
279
  licenses:
265
280
  - MIT
266
281
  metadata: {}
267
- post_install_message:
282
+ post_install_message:
268
283
  rdoc_options: []
269
284
  require_paths:
270
285
  - lib
@@ -272,15 +287,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
272
287
  requirements:
273
288
  - - ">="
274
289
  - !ruby/object:Gem::Version
275
- version: 2.3.0
290
+ version: 2.6.0
276
291
  required_rubygems_version: !ruby/object:Gem::Requirement
277
292
  requirements:
278
293
  - - ">="
279
294
  - !ruby/object:Gem::Version
280
295
  version: '0'
281
296
  requirements: []
282
- rubygems_version: 3.1.2
283
- signing_key:
297
+ rubygems_version: 3.2.32
298
+ signing_key:
284
299
  specification_version: 4
285
300
  summary: BrickFTP's REST API client.
286
301
  test_files: []