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
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+
5
+ module BrickFTP
6
+ module RESTfulAPI
7
+ module RetrieveHistory
8
+ def retrieve(path, page, per_page, start_at)
9
+ validate_page!(page)
10
+ validate_per_page!(per_page)
11
+ validate_start_at!(start_at)
12
+
13
+ query = build_query(page, per_page, start_at)
14
+ endpoint = path
15
+ endpoint = "#{path}?#{query}" unless query.empty?
16
+ res = client.get(endpoint)
17
+
18
+ res.map { |i| BrickFTP::Types::History.new(i.symbolize_keys) }
19
+ end
20
+
21
+ def validate_page!(page)
22
+ return if page.nil?
23
+ return if page.is_a?(Integer) && page.positive?
24
+
25
+ raise ArgumentError, 'page must be greater than 0.'
26
+ end
27
+
28
+ MAX_PER_PAGE = 10_000
29
+
30
+ def validate_per_page!(per_page)
31
+ return if per_page.nil?
32
+ return if per_page.is_a?(Integer) && per_page.positive? && per_page <= MAX_PER_PAGE
33
+
34
+ raise ArgumentError, "per_page must be greater than 0 and less than equal #{MAX_PER_PAGE}."
35
+ end
36
+
37
+ def validate_start_at!(start_at)
38
+ return if start_at.nil?
39
+ return if start_at.is_a?(Time)
40
+
41
+ raise ArgumentError, 'start_at must be a Time.'
42
+ end
43
+
44
+ def build_query(page, per_page, start_at)
45
+ params = {}
46
+ params[:page] = page if page
47
+ params[:per_page] = per_page if per_page
48
+ params[:start_at] = start_at.utc.iso8601 if start_at
49
+
50
+ params.map { |k, v| "#{k}=#{ERB::Util.url_encode(v.to_s)}" }.join('&')
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BrickFTP
4
+ module RESTfulAPI
5
+ # Retrieve login history
6
+ #
7
+ # @see https://developers.brickftp.com/#retrieve-login-history Retrieve login history
8
+ #
9
+ # ### Params
10
+ #
11
+ # PARAMETER | TYPE | DESCRIPTION
12
+ # --------- | -------- | -----------
13
+ # page | integer | Optional page number of items to return in this request.
14
+ # per_page | integer | Optional requested number of items returned per request. Default: 1000, maximum: 10000. Leave blank for default (strongly recommended).
15
+ # start_at | datetime | Optional date and time in the history to start from.
16
+ #
17
+ class RetrieveLoginHistory
18
+ include Command
19
+ include RetrieveHistory
20
+
21
+ # Returns login history only.
22
+ #
23
+ # - The history starts with the most recent entries and proceeds back in time.
24
+ # - There is a maximum number of records that will be returned with a single request
25
+ # (default 1000 or whatever value you provide as the per_page parameter, up to a maximum of 10,000).
26
+ #
27
+ # @param [Integer] page Optional page number of items to return in this request.
28
+ # @param [Integer] per_page Optional requested number of items returned per request.
29
+ # Default: 1000, maximum: 10000. Leave blank for default (strongly recommended).
30
+ # @param [Time] start_at Optional date and time in the history to start from.
31
+ # @return [Array<BrickFTP::Types::History>] History
32
+ #
33
+ def call(page: nil, per_page: nil, start_at: nil)
34
+ retrieve('/api/rest/v1/history/login.json', page, per_page, start_at)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BrickFTP
4
+ module RESTfulAPI
5
+ # Retrieve site history
6
+ #
7
+ # @see https://developers.brickftp.com/#retrieve-site-history Retrieve site history
8
+ #
9
+ # ### Params
10
+ #
11
+ # PARAMETER | TYPE | DESCRIPTION
12
+ # --------- | -------- | -----------
13
+ # page | integer | Optional page number of items to return in this request.
14
+ # per_page | integer | Optional requested number of items returned per request. Default: 1000, maximum: 10000. Leave blank for default (strongly recommended).
15
+ # start_at | datetime | Optional date and time in the history to start from.
16
+ #
17
+ class RetrieveSiteHistory
18
+ include Command
19
+ include RetrieveHistory
20
+
21
+ # Returns the entire history for the current site.
22
+ #
23
+ # - The history starts with the most recent entries and proceeds back in time.
24
+ # - There is a maximum number of records that will be returned with a single request
25
+ # (default 1000 or whatever value you provide as the per_page parameter, up to a maximum of 10,000).
26
+ #
27
+ # @param [Integer] page Optional page number of items to return in this request.
28
+ # @param [Integer] per_page Optional requested number of items returned per request.
29
+ # Default: 1000, maximum: 10000. Leave blank for default (strongly recommended).
30
+ # @param [Time] start_at Optional date and time in the history to start from.
31
+ # @return [Array<BrickFTP::Types::History>] History
32
+ #
33
+ def call(page: nil, per_page: nil, start_at: nil)
34
+ retrieve('/api/rest/v1/history.json', page, per_page, start_at)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BrickFTP
4
+ module RESTfulAPI
5
+ # Retrieve user history
6
+ #
7
+ # @see https://developers.brickftp.com/#retrieve-user-history Retrieve user history
8
+ #
9
+ # ### Params
10
+ #
11
+ # PARAMETER | TYPE | DESCRIPTION
12
+ # --------- | -------- | -----------
13
+ # page | integer | Optional page number of items to return in this request.
14
+ # per_page | integer | Optional requested number of items returned per request. Default: 1000, maximum: 10000. Leave blank for default (strongly recommended).
15
+ # start_at | datetime | Optional date and time in the history to start from.
16
+ #
17
+ class RetrieveUserHistory
18
+ include Command
19
+ include RetrieveHistory
20
+
21
+ # Returns user history only.
22
+ #
23
+ # - The history starts with the most recent entries and proceeds back in time.
24
+ # - There is a maximum number of records that will be returned with a single request
25
+ # (default 1000 or whatever value you provide as the per_page parameter, up to a maximum of 10,000).
26
+ #
27
+ # @param [Integer] id Globally unique identifier of each user.
28
+ # Each user is given an ID automatically upon creation.
29
+ # @param [Integer] page Optional page number of items to return in this request.
30
+ # @param [Integer] per_page Optional requested number of items returned per request.
31
+ # Default: 1000, maximum: 10000. Leave blank for default (strongly recommended).
32
+ # @param [Time] start_at Optional date and time in the history to start from.
33
+ # @return [Array<BrickFTP::Types::History>] History
34
+ #
35
+ def call(id, page: nil, per_page: nil, start_at: nil)
36
+ retrieve("/api/rest/v1/history/users/#{id}.json", page, per_page, start_at)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+
5
+ module BrickFTP
6
+ module RESTfulAPI
7
+ # Search users
8
+ #
9
+ # @see https://developers.brickftp.com/#search-users Search users
10
+ #
11
+ class SearchUser
12
+ include Command
13
+
14
+ # Returns a single user.
15
+ #
16
+ # @param [String] username Username for the user. This is how the user will be displayed on the site.
17
+ # Maximum of 50 characters.
18
+ # @return [BrickFTP::Types::User, nil] found User or nil
19
+ #
20
+ def call(username)
21
+ res = client.get("/api/rest/v1/users.json?q[username]=#{ERB::Util.url_encode(username)}")
22
+ return nil if !res || res.empty?
23
+
24
+ BrickFTP::Types::User.new(res.first.symbolize_keys)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+
5
+ module BrickFTP
6
+ module RESTfulAPI
7
+ # Starting a new upload
8
+ #
9
+ # @see https://developers.brickftp.com/#starting-a-new-upload Starting a new upload
10
+ #
11
+ class StartUpload
12
+ include Command
13
+
14
+ # The first request to upload a new file is a POST request to /files/PATH_AND_FILENAME.EXT
15
+ # with an action parameter with the value of put.
16
+ #
17
+ # @param [String] path Full path of the file or folder. Maximum of 550 characters.
18
+ # @return [BrickFTP::Types::Upload] Upload object
19
+ #
20
+ def call(path)
21
+ res = client.post("/api/rest/v1/files/#{ERB::Util.url_encode(path)}", action: 'put')
22
+
23
+ BrickFTP::Types::Upload.new(res.symbolize_keys)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BrickFTP
4
+ module RESTfulAPI
5
+ # Unlock a user
6
+ #
7
+ # @see https://developers.brickftp.com/#unlock-a-user Unlock a user
8
+ #
9
+ class UnlockUser
10
+ include Command
11
+
12
+ # Unlocks a user that has been locked out by Brute Force Login Protection.
13
+ #
14
+ # @param [Integer] id Globally unique identifier of each user.
15
+ # Each user is given an ID automatically upon creation.
16
+ # @return [BrickFTP::Types::User, nil] unlocked User or nil
17
+ #
18
+ def call(id)
19
+ res = client.post("/api/rest/v1/users/#{id}/unlock.json")
20
+
21
+ BrickFTP::Types::User.new(res.symbolize_keys)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BrickFTP
4
+ module RESTfulAPI
5
+ # Update a behavior
6
+ #
7
+ # @see https://developers.brickftp.com/#update-a-behavior Update a behavior
8
+ #
9
+ # ### Params
10
+ #
11
+ # PARAMETER | TYPE | DESCRIPTION
12
+ # --------- | ------ | -----------
13
+ # value | array | Array of values associated with the behavior.
14
+ #
15
+ class UpdateBehavior
16
+ include Command
17
+ using BrickFTP::CoreExt::Struct
18
+ using BrickFTP::CoreExt::Hash
19
+
20
+ Params = Struct.new(
21
+ 'UpdateBehaviorParams',
22
+ :value,
23
+ keyword_init: true
24
+ )
25
+
26
+ # Updates an existing behavior.
27
+ #
28
+ # @param [Integer] id Globally unique identifier of each behavior.
29
+ # @param [BrickFTP::RESTfulAPI::UpdateBehavior::Params] params parameters
30
+ # @return [BrickFTP::Types::Behavior] Behavior
31
+ #
32
+ def call(id, params)
33
+ res = client.patch("/api/rest/v1/behaviors/#{id}.json", params.to_h.compact)
34
+
35
+ BrickFTP::Types::Behavior.new(res.symbolize_keys)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BrickFTP
4
+ module RESTfulAPI
5
+ # Update a group
6
+ #
7
+ # @see https://developers.brickftp.com/#update-a-group Update a group
8
+ #
9
+ # ### Params
10
+ #
11
+ # PARAMETER | TYPE | DESCRIPTION
12
+ # --------- | ------------------------ | -----------
13
+ # name | string | Name of the group. This is how the group will be displayed on the site. Maximum of 50 characters.
14
+ # notes | text | You may use this property to store any additional information you require. There are no restrictions on its formatting.
15
+ # user_ids | comma-separated integers | IDs of the users that are in this group.
16
+ #
17
+ class UpdateGroup
18
+ include Command
19
+ using BrickFTP::CoreExt::Struct
20
+ using BrickFTP::CoreExt::Hash
21
+
22
+ Params = Struct.new(
23
+ 'UpdateGroupParams',
24
+ :name,
25
+ :notes,
26
+ :user_ids,
27
+ keyword_init: true
28
+ )
29
+
30
+ # Updates the specified group.
31
+ #
32
+ # @param [Integer] id Globally unique identifier of each group.
33
+ # Each group is given an ID automatically upon creation.
34
+ # @param [BrickFTP::RESTfulAPI::UpdateGroup::Params] params parameters for updating a Group
35
+ # @return [BrickFTP::Types::Group] updated Group
36
+ #
37
+ def call(id, params)
38
+ res = client.put("/api/rest/v1/groups/#{id}.json", params.to_h.compact)
39
+
40
+ BrickFTP::Types::Group.new(res.symbolize_keys)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BrickFTP
4
+ module RESTfulAPI
5
+ # Update a member
6
+ #
7
+ # @see https://developers.brickftp.com/#update-a-member Update a member
8
+ #
9
+ # ### Params
10
+ #
11
+ # PARAMETER | TYPE | DESCRIPTION
12
+ # --------- | ------- | -----------
13
+ # admin | boolean | Indicates whether the user is an administrator of the group.
14
+ #
15
+ class UpdateGroupMember
16
+ include Command
17
+ using BrickFTP::CoreExt::Struct
18
+ using BrickFTP::CoreExt::Hash
19
+
20
+ Params = Struct.new(
21
+ 'UpdateGroupMemberParams',
22
+ :admin,
23
+ keyword_init: true
24
+ )
25
+
26
+ # Updates a user's group membership. No action will be taken if the user is not already in the group.
27
+ #
28
+ # @param [Integer] group_id ID of the group the membership is associated with.
29
+ # @param [Integer] user_id ID of the user the membership is associated with.
30
+ # @param [BrickFTP::RESTfulAPI::UpdateGroupMember::Params] params parameters
31
+ # @return [BrickFTP::Types::GroupMembership] group membership
32
+ #
33
+ def call(group_id, user_id, params)
34
+ res = client.patch("/api/rest/v1/groups/#{group_id}/memberships/#{user_id}.json", membership: params.to_h.compact)
35
+
36
+ BrickFTP::Types::GroupMembership.new(res.symbolize_keys)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BrickFTP
4
+ module RESTfulAPI
5
+ # Update a user
6
+ #
7
+ # @see https://developers.brickftp.com/#update-a-user Update a user
8
+ #
9
+ # ### Params
10
+ #
11
+ # PARAMETER | TYPE | DESCRIPTION
12
+ # ----------------------- | ------------------------ | -----------
13
+ # username | string | Username for the user. This is how the user will be displayed on the site. Maximum of 50 characters.
14
+ # authentication_method | enum | Authentication method for this user. Can be one of the following: password, ldap, or oauth_google. Default is password.
15
+ # password | string | Password for the user. This property is write-only. It cannot be retrieved via the API.
16
+ # password_confirmation | string | Confirms the new password provided in the password field. This field is optional but will be validated if provided.
17
+ # authenticate_until | datetime | If set, the user will be blocked from logging in after this date.
18
+ # name | string | Real name of the user. For your reference. Maximum of 50 characters.
19
+ # email | string | E-Mail address of the user. Maximum of 50 characters.
20
+ # notes | text | You may use this property to store any additional information you require. There are no restrictions on its formatting.
21
+ # group_ids | comma-separated integers | IDs of the Groups that this user is in.
22
+ # ftp_permission | boolean | Allow user access via FTP/FTPS (port 21 or 990) interface. Default is true.
23
+ # sftp_permission | boolean | Allow user access via SFTP (port 22) interface. Default is true.
24
+ # dav_permission | boolean | Allow user access via WebDAV (port 443) interface. Default is true.
25
+ # restapi_permission | boolean | Allow user access the REST API, via HTTP/HTTPS (port 80 or 443), and the desktop application. Default is true.
26
+ # attachments_permission | boolean | Allow user to use Sharing tab in web interface to share files with anonymous users via a unique URL. Default is false.
27
+ # self_managed | boolean | Allow user to change their password and user information via the web interface. Default is true.
28
+ # require_password_change | boolean | Require user to change their password at their next login. Note: requires restapi_permission to be true, as password changes can only occur via the web interface. Default is false.
29
+ # allowed_ips | text | List allowed IPs, one per line. You may specify a range in CIDR format, such as 192.168.1.0/27. Leave blank to allow all IPs. If you are also restricting IP addresses on the Site tab, users matching in either place will be allowed to log in.
30
+ # user_root | string | Folder to show as the root when this user logs in via the FTP interface. Make sure this folder exists, as it will not be automatically created. Does not apply to the web interface! This should not contain a leading slash, but must contain a trailing slash. Example: Users/jenny/. Limit of 250 characters.
31
+ # time_zone | string | File modification times will be displayed in this time zone. Default is Eastern Time (US & Canada).
32
+ # language | string | The language that BrickFTP will be displayed in, if the translation is available. Leave as default (null) to auto-detect or use the site setting.
33
+ # grant_permission | enum | Value must be set to full, read, write, preview, read+write, or preview+write. The user will be granted that permission on their FTP root folder as defined by the user_root. This property is write-only. It cannot be retrieved via the User resource of the REST API, though may be obtained with the Permissions resource of the REST API.
34
+ # ssl_required | enum | Whether or not SSL encryption is required on all connections for this user. Can be one of the following: use_system_setting, always_require, or never_require. Default is use_system_setting.
35
+ # site_admin | boolean | If set to true, this user will be treated as a site-wide administrator. Default is false.
36
+ # receive_admin_alerts | boolean | Enable this user to receive alerts sent to site administrators. This property will only be accepted/returned if site_admin is true. Default is false.
37
+ # subscribe_to_newsletter | boolean | Add this user to the BrickFTP newsletter and our mailing list for notices about product updates. This property will only be accepted/returned if site_admin is true. Default is false.
38
+ # can_create_new_users | boolean | If true, this user will be able to create other users within groups where they have administrator privileges. Default is false.
39
+ # admin_group_ids | comma-separated integers | IDs of the Groups that this user is an administrator of.
40
+ #
41
+ class UpdateUser
42
+ include Command
43
+ using BrickFTP::CoreExt::Struct
44
+ using BrickFTP::CoreExt::Hash
45
+
46
+ Params = Struct.new(
47
+ 'UpdateUserParams',
48
+ :username,
49
+ :authentication_method,
50
+ :password,
51
+ :password_confirmation,
52
+ :authenticate_until,
53
+ :name,
54
+ :email,
55
+ :notes,
56
+ :group_ids,
57
+ :ftp_permission,
58
+ :sftp_permission,
59
+ :dav_permission,
60
+ :restapi_permission,
61
+ :attachments_permission,
62
+ :self_managed,
63
+ :require_password_change,
64
+ :allowed_ips,
65
+ :user_root,
66
+ :time_zone,
67
+ :language,
68
+ :grant_permission,
69
+ :ssl_required,
70
+ :site_admin,
71
+ :receive_admin_alerts,
72
+ :subscribe_to_newsletter,
73
+ :can_create_new_users,
74
+ :admin_group_ids,
75
+ keyword_init: true
76
+ )
77
+
78
+ # Updates the specified user.
79
+ #
80
+ # For additional security, this method requires reauthentication when updating a password unless an API key is used.
81
+ #
82
+ # @note The `allowed_ips` may accept only blank value.
83
+ #
84
+ # e.g. When set `"192.168.1.0/27"` to `allowed_ips`, receive following message with 500 error:
85
+ #
86
+ # An unhandled lowlevel error occurred. The application logs may have details.
87
+ #
88
+ #
89
+ # @param [Integer] id Globally unique identifier of each user.
90
+ # Each user is given an ID automatically upon creation.
91
+ # @param [BrickFTP::RESTfulAPI::CreateUser::Params] params parameters for create a user
92
+ # @return [BrickFTP::Types::User] updated User
93
+ #
94
+ def call(id, params)
95
+ res = client.put("/api/rest/v1/users/#{id}.json", params.to_h.compact)
96
+
97
+ BrickFTP::Types::User.new(res.symbolize_keys)
98
+ end
99
+ end
100
+ end
101
+ end