brick_ftp 0.8.4 → 1.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +0 -5
  3. data/.rubocop.yml +2 -1
  4. data/.yardopts +1 -0
  5. data/CHANGELOG.md +16 -12
  6. data/Gemfile +2 -0
  7. data/README.md +24 -43
  8. data/Rakefile +2 -0
  9. data/bin/console +1 -0
  10. data/brick_ftp.gemspec +10 -9
  11. data/exe/brick_ftp +1 -0
  12. data/lib/brick_ftp.rb +5 -78
  13. data/lib/brick_ftp/client.rb +35 -411
  14. data/lib/brick_ftp/core_ext.rb +8 -0
  15. data/lib/brick_ftp/core_ext/hash.rb +13 -0
  16. data/lib/brick_ftp/core_ext/hash/compact.rb +13 -0
  17. data/lib/brick_ftp/core_ext/struct.rb +13 -0
  18. data/lib/brick_ftp/core_ext/struct/new.rb +16 -0
  19. data/lib/brick_ftp/restful_api.rb +82 -0
  20. data/lib/brick_ftp/restful_api/add_group_member.rb +44 -0
  21. data/lib/brick_ftp/restful_api/client.rb +179 -0
  22. data/lib/brick_ftp/restful_api/command.rb +21 -0
  23. data/lib/brick_ftp/restful_api/complete_upload.rb +46 -0
  24. data/lib/brick_ftp/restful_api/continue_upload.rb +50 -0
  25. data/lib/brick_ftp/restful_api/copy_folder.rb +46 -0
  26. data/lib/brick_ftp/restful_api/count_folder_contents.rb +36 -0
  27. data/lib/brick_ftp/restful_api/count_users.rb +22 -0
  28. data/lib/brick_ftp/restful_api/create_api_key.rb +46 -0
  29. data/lib/brick_ftp/restful_api/create_behavior.rb +42 -0
  30. data/lib/brick_ftp/restful_api/create_bundle.rb +40 -0
  31. data/lib/brick_ftp/restful_api/create_folder.rb +25 -0
  32. data/lib/brick_ftp/restful_api/create_group.rb +42 -0
  33. data/lib/brick_ftp/restful_api/create_notification.rb +44 -0
  34. data/lib/brick_ftp/restful_api/create_permission.rb +48 -0
  35. data/lib/brick_ftp/restful_api/create_public_key.rb +42 -0
  36. data/lib/brick_ftp/restful_api/create_user.rb +90 -0
  37. data/lib/brick_ftp/restful_api/create_user_in_group.rb +60 -0
  38. data/lib/brick_ftp/restful_api/delete_api_key.rb +23 -0
  39. data/lib/brick_ftp/restful_api/delete_behavior.rb +22 -0
  40. data/lib/brick_ftp/restful_api/delete_bundle.rb +22 -0
  41. data/lib/brick_ftp/restful_api/delete_folder.rb +32 -0
  42. data/lib/brick_ftp/restful_api/delete_group.rb +23 -0
  43. data/lib/brick_ftp/restful_api/delete_notification.rb +23 -0
  44. data/lib/brick_ftp/restful_api/delete_permission.rb +23 -0
  45. data/lib/brick_ftp/restful_api/delete_public_key.rb +23 -0
  46. data/lib/brick_ftp/restful_api/delete_user.rb +25 -0
  47. data/lib/brick_ftp/restful_api/download_file.rb +44 -0
  48. data/lib/brick_ftp/restful_api/get_api_key.rb +25 -0
  49. data/lib/brick_ftp/restful_api/get_behavior.rb +25 -0
  50. data/lib/brick_ftp/restful_api/get_bundle.rb +25 -0
  51. data/lib/brick_ftp/restful_api/get_bundle_zip.rb +48 -0
  52. data/lib/brick_ftp/restful_api/get_file_in_bundle.rb +49 -0
  53. data/lib/brick_ftp/restful_api/get_folder_size.rb +25 -0
  54. data/lib/brick_ftp/restful_api/get_group.rb +26 -0
  55. data/lib/brick_ftp/restful_api/get_public_key.rb +25 -0
  56. data/lib/brick_ftp/restful_api/get_site_usage.rb +19 -0
  57. data/lib/brick_ftp/restful_api/get_user.rb +26 -0
  58. data/lib/brick_ftp/restful_api/list_api_keys.rb +25 -0
  59. data/lib/brick_ftp/restful_api/list_behaviors.rb +23 -0
  60. data/lib/brick_ftp/restful_api/list_bundle_contents.rb +58 -0
  61. data/lib/brick_ftp/restful_api/list_bundles.rb +23 -0
  62. data/lib/brick_ftp/restful_api/list_folder_behaviors.rb +39 -0
  63. data/lib/brick_ftp/restful_api/list_folders.rb +108 -0
  64. data/lib/brick_ftp/restful_api/list_groups.rb +23 -0
  65. data/lib/brick_ftp/restful_api/list_notifications.rb +23 -0
  66. data/lib/brick_ftp/restful_api/list_permissions.rb +41 -0
  67. data/lib/brick_ftp/restful_api/list_public_keys.rb +25 -0
  68. data/lib/brick_ftp/restful_api/list_users.rb +60 -0
  69. data/lib/brick_ftp/restful_api/move_folder.rb +41 -0
  70. data/lib/brick_ftp/restful_api/remove_group_member.rb +23 -0
  71. data/lib/brick_ftp/restful_api/retrieve_file_history.rb +41 -0
  72. data/lib/brick_ftp/restful_api/retrieve_folder_history.rb +41 -0
  73. data/lib/brick_ftp/restful_api/retrieve_history.rb +54 -0
  74. data/lib/brick_ftp/restful_api/retrieve_login_history.rb +38 -0
  75. data/lib/brick_ftp/restful_api/retrieve_site_history.rb +38 -0
  76. data/lib/brick_ftp/restful_api/retrieve_user_history.rb +40 -0
  77. data/lib/brick_ftp/restful_api/search_user.rb +28 -0
  78. data/lib/brick_ftp/restful_api/start_upload.rb +27 -0
  79. data/lib/brick_ftp/restful_api/unlock_user.rb +25 -0
  80. data/lib/brick_ftp/restful_api/update_behavior.rb +39 -0
  81. data/lib/brick_ftp/restful_api/update_group.rb +44 -0
  82. data/lib/brick_ftp/restful_api/update_group_member.rb +40 -0
  83. data/lib/brick_ftp/restful_api/update_user.rb +101 -0
  84. data/lib/brick_ftp/restful_api/upload_file.rb +65 -0
  85. data/lib/brick_ftp/types.rb +23 -0
  86. data/lib/brick_ftp/types/behavior.rb +27 -0
  87. data/lib/brick_ftp/types/bundle.rb +34 -0
  88. data/lib/brick_ftp/types/bundle_content.rb +25 -0
  89. data/lib/brick_ftp/types/bundle_zip.rb +19 -0
  90. data/lib/brick_ftp/types/file.rb +45 -0
  91. data/lib/brick_ftp/types/file_in_bundle.rb +25 -0
  92. data/lib/brick_ftp/types/folder_contents_count.rb +24 -0
  93. data/lib/brick_ftp/types/group.rb +31 -0
  94. data/lib/brick_ftp/types/group_membership.rb +27 -0
  95. data/lib/brick_ftp/types/history.rb +43 -0
  96. data/lib/brick_ftp/types/notification.rb +31 -0
  97. data/lib/brick_ftp/types/permission.rb +35 -0
  98. data/lib/brick_ftp/types/site_usage.rb +23 -0
  99. data/lib/brick_ftp/types/upload.rb +45 -0
  100. data/lib/brick_ftp/types/user.rb +79 -0
  101. data/lib/brick_ftp/types/user_api_key.rb +33 -0
  102. data/lib/brick_ftp/types/user_public_key.rb +28 -0
  103. data/lib/brick_ftp/utils.rb +2 -0
  104. data/lib/brick_ftp/utils/chunk_io.rb +5 -4
  105. data/lib/brick_ftp/version.rb +3 -1
  106. metadata +123 -86
  107. data/lib/brick_ftp/api.rb +0 -9
  108. data/lib/brick_ftp/api/authentication.rb +0 -28
  109. data/lib/brick_ftp/api/authentication/session.rb +0 -25
  110. data/lib/brick_ftp/api/base.rb +0 -119
  111. data/lib/brick_ftp/api/behavior.rb +0 -19
  112. data/lib/brick_ftp/api/bundle.rb +0 -17
  113. data/lib/brick_ftp/api/bundle_content.rb +0 -18
  114. data/lib/brick_ftp/api/bundle_download.rb +0 -18
  115. data/lib/brick_ftp/api/file.rb +0 -20
  116. data/lib/brick_ftp/api/file_operation.rb +0 -6
  117. data/lib/brick_ftp/api/file_operation/copy.rb +0 -10
  118. data/lib/brick_ftp/api/file_operation/move.rb +0 -10
  119. data/lib/brick_ftp/api/file_operation/upload.rb +0 -66
  120. data/lib/brick_ftp/api/file_operation/uploading_result.rb +0 -22
  121. data/lib/brick_ftp/api/file_operation/uploading_session.rb +0 -95
  122. data/lib/brick_ftp/api/folder.rb +0 -22
  123. data/lib/brick_ftp/api/folder_behavior.rb +0 -12
  124. data/lib/brick_ftp/api/group.rb +0 -16
  125. data/lib/brick_ftp/api/history.rb +0 -6
  126. data/lib/brick_ftp/api/history/file.rb +0 -23
  127. data/lib/brick_ftp/api/history/folder.rb +0 -23
  128. data/lib/brick_ftp/api/history/login.rb +0 -23
  129. data/lib/brick_ftp/api/history/site.rb +0 -23
  130. data/lib/brick_ftp/api/history/user.rb +0 -23
  131. data/lib/brick_ftp/api/notification.rb +0 -14
  132. data/lib/brick_ftp/api/permission.rb +0 -17
  133. data/lib/brick_ftp/api/public_key.rb +0 -15
  134. data/lib/brick_ftp/api/site_usage.rb +0 -21
  135. data/lib/brick_ftp/api/user.rb +0 -36
  136. data/lib/brick_ftp/api_component.rb +0 -81
  137. data/lib/brick_ftp/api_definition.rb +0 -65
  138. data/lib/brick_ftp/cli.rb +0 -7
  139. data/lib/brick_ftp/cli/config.rb +0 -20
  140. data/lib/brick_ftp/cli/main.rb +0 -26
  141. data/lib/brick_ftp/cli/site.rb +0 -10
  142. data/lib/brick_ftp/configuration.rb +0 -121
  143. data/lib/brick_ftp/http_client.rb +0 -130
  144. data/lib/brick_ftp/log_formatter.rb +0 -15
  145. data/lib/brick_ftp/webhook.rb +0 -4
  146. data/lib/brick_ftp/webhook/request.rb +0 -28
data/lib/brick_ftp/api.rb DELETED
@@ -1,9 +0,0 @@
1
- module BrickFTP
2
- module API
3
- class Error < StandardError
4
- end
5
-
6
- class NoSuchAPI < Error
7
- end
8
- end
9
- end
@@ -1,28 +0,0 @@
1
- require 'cgi'
2
-
3
- module BrickFTP
4
- module API
5
- module Authentication
6
- COOKIE_NAME = 'BrickAPI'.freeze
7
-
8
- # Generate authentication cookie.
9
- # @param session [BrickFTP::API::Authentication::Session] authentication session object.
10
- # @return [CGI::Cookie] authentication cookie.
11
- def self.cookie(session)
12
- CGI::Cookie.new(COOKIE_NAME, session.id)
13
- end
14
-
15
- # Alias for `BrickFTP::API::Authentication::Session.create`.
16
- # @param username [String] username of BrickFTP's user.
17
- # @param password [String] password of BrickFTP's user.
18
- def self.login(username, password)
19
- Session.create(username: username, password: password)
20
- end
21
-
22
- # Alias for `BrickFTP::API::Authentication::Session#destroy`.
23
- def self.logout
24
- BrickFTP.config.session.destroy
25
- end
26
- end
27
- end
28
- end
@@ -1,25 +0,0 @@
1
- module BrickFTP
2
- module API
3
- module Authentication
4
- class Session < BrickFTP::API::Base
5
- endpoint :post, :create, '/api/rest/v1/sessions.json'
6
- endpoint :delete, :delete, '/api/rest/v1/sessions.json'
7
-
8
- attribute :id
9
- attribute :username, writable: true
10
- attribute :password, writable: true
11
-
12
- def self.create(params = {})
13
- super.tap { |x| BrickFTP.config.session = x }
14
- end
15
-
16
- def destroy
17
- super.tap do
18
- delete_property(:id)
19
- BrickFTP.config.session = nil
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,119 +0,0 @@
1
- require 'cgi'
2
-
3
- module BrickFTP
4
- module API
5
- class Base
6
- def self.inherited(subclass)
7
- subclass.include APIDefinition
8
- end
9
-
10
- def self.all(params = {})
11
- params.symbolize_keys!
12
-
13
- data = BrickFTP::HTTPClient.new.send(
14
- endpoints[:index][:http_method],
15
- api_path_for(:index, params),
16
- params: api_component_for(:index).except_path_and_query(params)
17
- )
18
- data.map { |x| new(x.symbolize_keys) }
19
- end
20
-
21
- def self.find(id, params: {})
22
- data = BrickFTP::HTTPClient.new.send(
23
- endpoints[:show][:http_method],
24
- api_path_for(:show, id),
25
- params: params
26
- )
27
- data.empty? ? nil : new(data.symbolize_keys)
28
- end
29
-
30
- def self.create(params = {})
31
- params.symbolize_keys!
32
-
33
- data = BrickFTP::HTTPClient.new.send(
34
- endpoints[:create][:http_method],
35
- api_path_for(:create, params),
36
- params: api_component_for(:create).except_path_and_query(params)
37
- )
38
- data = {} if data.is_a?(Array)
39
- new(data.symbolize_keys)
40
- end
41
-
42
- # @return [Hash{String => Object}] Key Value pairs of API properties
43
- attr_reader :properties
44
-
45
- def initialize(params = {})
46
- initialize_properties
47
- params.each { |k, v| write_property(k, v) }
48
- end
49
-
50
- def update(params = {})
51
- params.symbolize_keys!
52
-
53
- data = BrickFTP::HTTPClient.new.send(
54
- self.class.endpoints[:update][:http_method],
55
- self.class.api_path_for(:update, self),
56
- params: self.class.api_component_for(:update).except_path_and_query(params)
57
- )
58
- data.each { |k, v| write_property(k, v) }
59
-
60
- self
61
- end
62
-
63
- def destroy(recursive: false)
64
- headers = {}
65
- headers['Depth'] = 'infinity' if recursive
66
-
67
- BrickFTP::HTTPClient.new.send(
68
- self.class.endpoints[:delete][:http_method],
69
- self.class.api_path_for(:delete, self),
70
- headers: headers
71
- )
72
- true
73
- end
74
-
75
- def as_json(*_args)
76
- properties.dup
77
- end
78
-
79
- def to_json(*args)
80
- as_json.to_json(*args)
81
- end
82
-
83
- def write_property(key, value)
84
- properties[key.to_s] = value
85
- end
86
-
87
- def read_property(key)
88
- properties[key.to_s]
89
- end
90
-
91
- def delete_property(key)
92
- properties.delete(key.to_s)
93
- end
94
-
95
- private
96
-
97
- def initialize_properties
98
- @properties = {}
99
- self.class.attributes.each { |key| write_property(key, nil) }
100
- end
101
-
102
- def respond_to_missing?(method_name, _include_private)
103
- self.class.attributes.include?(method_name.to_sym)
104
- end
105
-
106
- def method_missing(method_name, *args)
107
- super unless self.class.attributes.include?(method_name.to_sym)
108
-
109
- read_property(method_name)
110
- end
111
-
112
- def display
113
- # attribute on history objects
114
- # explicitly defined because display is a method on Object
115
- read_property(:display)
116
- end
117
- end
118
- end
119
- end
@@ -1,19 +0,0 @@
1
- module BrickFTP
2
- module API
3
- class Behavior < Base
4
- endpoint :get, :index, '/api/rest/v1/behaviors.json'
5
- endpoint :get, :show, '/api/rest/v1/behaviors/%{id}.json'
6
- endpoint :post, :create, '/api/rest/v1/behaviors.json'
7
- endpoint :put, :update, '/api/rest/v1/behaviors/%{id}.json'
8
- endpoint :delete, :delete, '/api/rest/v1/behaviors/%{id}.json'
9
-
10
- attribute :id
11
- attribute :path
12
- attribute :behavior
13
- attribute :value
14
- attribute :path, writable: true
15
- attribute :behavior, writable: true
16
- attribute :value, writable: true
17
- end
18
- end
19
- end
@@ -1,17 +0,0 @@
1
- module BrickFTP
2
- module API
3
- class Bundle < Base
4
- endpoint :get, :index, '/api/rest/v1/bundles.json'
5
- endpoint :get, :show, '/api/rest/v1/bundles/%{id}.json'
6
- endpoint :post, :create, '/api/rest/v1/bundles.json'
7
- endpoint :delete, :delete, '/api/rest/v1/bundles/%{id}.json'
8
-
9
- attribute :id
10
- attribute :code
11
- attribute :url
12
- attribute :user_id
13
- attribute :created_at
14
- attribute :paths, writable: true
15
- end
16
- end
17
- end
@@ -1,18 +0,0 @@
1
- module BrickFTP
2
- module API
3
- class BundleContent < Base
4
- endpoint :post, :index, ->(params) do
5
- params.key?(:path) ? '/api/rest/v1/bundles/folders/%{path}' : '/api/rest/v1/bundles/folders'
6
- end
7
-
8
- attribute :id
9
- attribute :path
10
- attribute :type
11
- attribute :size
12
- attribute :crc32
13
- attribute :md5
14
- attribute :code, writable: true
15
- attribute :host, writable: true
16
- end
17
- end
18
- end
@@ -1,18 +0,0 @@
1
- module BrickFTP
2
- module API
3
- class BundleDownload < Base
4
- endpoint :post, :index, '/api/rest/v1/bundles/files.json'
5
-
6
- attribute :id
7
- attribute :path
8
- attribute :type
9
- attribute :size
10
- attribute :crc32
11
- attribute :md5
12
- attribute :download_uri
13
- attribute :code, writable: true
14
- attribute :host, writable: true
15
- attribute :paths, writable: true
16
- end
17
- end
18
- end
@@ -1,20 +0,0 @@
1
- module BrickFTP
2
- module API
3
- class File < Base
4
- endpoint :get, :show, '/api/rest/v1/files/%{path}'
5
- endpoint :delete, :delete, '/api/rest/v1/files/%{path}'
6
-
7
- attribute :id
8
- attribute :path
9
- attribute :type
10
- attribute :size
11
- attribute :mtime
12
- attribute :crc32
13
- attribute :md5
14
- attribute :download_uri
15
- attribute :display_name
16
- attribute :provided_mtime
17
- attribute :permissions
18
- end
19
- end
20
- end
@@ -1,6 +0,0 @@
1
- module BrickFTP
2
- module API
3
- module FileOperation
4
- end
5
- end
6
- end
@@ -1,10 +0,0 @@
1
- module BrickFTP
2
- module API
3
- module FileOperation
4
- class Copy < BrickFTP::API::Base
5
- endpoint :post, :create, '/api/rest/v1/files/%{path}'
6
- attribute :'copy-destination', writable: true
7
- end
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module BrickFTP
2
- module API
3
- module FileOperation
4
- class Move < BrickFTP::API::Base
5
- endpoint :post, :create, '/api/rest/v1/files/%{path}'
6
- attribute :'move-destination', writable: true
7
- end
8
- end
9
- end
10
- end
@@ -1,66 +0,0 @@
1
- module BrickFTP
2
- module API
3
- module FileOperation
4
- class Upload < BrickFTP::API::Base
5
- endpoint :post, :create, '/api/rest/v1/files/%{path}'
6
-
7
- attribute :id
8
- attribute :ref
9
- attribute :http_method
10
- attribute :upload_uri
11
- attribute :partsize
12
- attribute :part_number
13
- attribute :available_parts
14
- attribute :headers
15
- attribute :parameters
16
- attribute :send
17
- attribute :path
18
- attribute :action
19
- attribute :ask_about_overwrites
20
- attribute :type
21
- attribute :size
22
- attribute :mtime
23
- attribute :crc32
24
- attribute :md5
25
- attribute :expires
26
- attribute :next_partsize
27
- attribute :provided_mtime
28
- attribute :permission
29
- attribute :action, writable: true
30
- attribute :ref, writable: true
31
- attribute :part, writable: true
32
- attribute :restart, writable: true
33
-
34
- # Upload file.
35
- #
36
- # @see https://brickftp.com/docs/rest-api/file-uploading/
37
- # @param [String] path Remote file path.
38
- # @param [IO] source Source `data` (not `path`) to upload.
39
- # @param [Integer] chunk_size Size of chunk to multi-part upload.
40
- # @return [BrickFTP::API::FileOperation::Upload] An instance of BrickFTP::API::FileOperation::Upload.
41
- #
42
- def self.create(path:, source:, chunk_size: nil)
43
- api_client = BrickFTP::HTTPClient.new
44
- chunk_io = BrickFTP::Utils::ChunkIO.new(source, chunk_size: chunk_size)
45
-
46
- ref = nil
47
- params_for_request_upload_url = { action: 'put' }
48
- upload_info = {}
49
- chunk_io.each.with_index(1) do |chunk, part|
50
- params_for_request_upload_url.update(part: part, ref: ref) if part > 1
51
- upload_info = api_client.post(api_path_for(:create, path: path), params: params_for_request_upload_url)
52
- ref = upload_info['ref']
53
-
54
- upload_uri = URI.parse(upload_info['upload_uri'])
55
- upload_client = BrickFTP::HTTPClient.new(upload_uri.host)
56
- upload_client.put(upload_info['upload_uri'], params: chunk)
57
- end
58
-
59
- uploaded_info = api_client.post(api_path_for(:create, path: path), params: { action: 'end', ref: ref })
60
-
61
- new(upload_info.merge(uploaded_info).symbolize_keys)
62
- end
63
- end
64
- end
65
- end
66
- end
@@ -1,22 +0,0 @@
1
- module BrickFTP
2
- module API
3
- module FileOperation
4
- class UploadingResult < BrickFTP::API::Base
5
- endpoint :post, :create, '/api/rest/v1/files/%{path}'
6
-
7
- attribute :path
8
- attribute :type
9
- attribute :size
10
- attribute :mtime
11
- attribute :crc32
12
- attribute :md5
13
-
14
- def self.create(path:, ref:)
15
- api_client = BrickFTP::HTTPClient.new
16
- res = api_client.post(api_path_for(:create, path: path), params: { action: 'end', ref: ref })
17
- new(res.symbolize_keys)
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,95 +0,0 @@
1
- module BrickFTP
2
- module API
3
- module FileOperation
4
- class UploadingSession < BrickFTP::API::Base
5
- include Enumerable
6
-
7
- endpoint :post, :create, '/api/rest/v1/files/%{path}'
8
-
9
- attribute :ref
10
- attribute :http_method
11
- attribute :upload_uri
12
- attribute :partsize
13
- attribute :part_number
14
- attribute :available_parts
15
- attribute :headers
16
- attribute :parameters
17
- attribute :send
18
- attribute :path
19
- attribute :action
20
- attribute :ask_about_overwrites
21
- attribute :expires
22
- attribute :next_partsize
23
- attribute :provided_mtime
24
- attribute :permission
25
-
26
- # Get uploading URL.
27
- #
28
- # @see https://brickftp.com/docs/rest-api/file-uploading/
29
- # @param [String] path Remote file path.
30
- # @return [BrickFTP::API::FileOperation::UploadingSession] A session object of uploading file.
31
- #
32
- def self.create(path:)
33
- api_client = BrickFTP::HTTPClient.new
34
- res = api_client.post(api_path_for(:create, path: path), params: { action: 'put' })
35
- new(res.symbolize_keys)
36
- end
37
-
38
- # Upload data.
39
- #
40
- # @param [String] upload_uri A uplading URL.
41
- # @param [IO] data An IO object to upload.
42
- #
43
- def self.upload(upload_uri:, data:)
44
- uri = URI.parse(upload_uri)
45
- upload_client = BrickFTP::HTTPClient.new(uri.host)
46
- upload_client.put(uri.to_s, params: data)
47
- end
48
-
49
- # Get uploading URL for multi part uploading.
50
- #
51
- # @param [Integer] part_number The part number.
52
- # @return [BrickFTP::API::FileOperation::UploadingSession] A session object of uploading file.
53
- #
54
- def at(part_number)
55
- params = { action: 'put', ref: ref, part: part_number }
56
- api_client = BrickFTP::HTTPClient.new
57
- res = api_client.post(self.class.api_path_for(:create, path: path), params: params)
58
- self.class.new(res.symbolize_keys)
59
- end
60
-
61
- # Get each uploading URLs.
62
- #
63
- # @yield [session] Gives uploading session object to the block.
64
- # @yieldparam [BrickFTP::API::FileOperation::UploadingSession] session A session object of uploading file.
65
- #
66
- def each
67
- return enum_for(__method__) unless block_given?
68
-
69
- yield self
70
- (part_number + 1).upto(available_parts) do |n|
71
- yield at(n)
72
- end
73
- end
74
-
75
- # Complete uploading file.
76
- #
77
- # @return [BrickFTP::API::FileOperation::UploadingResult] A result of uploading file.
78
- #
79
- def commit
80
- UploadingResult.create(path: path, ref: ref)
81
- end
82
-
83
- # Return single uploading session object.
84
- #
85
- # NOTE: The `#as_json` method will be overwritten by active_supprt.
86
- #
87
- # @return [Hash] a JSON serializable object
88
- #
89
- def as_json(*_args)
90
- properties.dup
91
- end
92
- end
93
- end
94
- end
95
- end