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.
- checksums.yaml +4 -4
- data/.circleci/config.yml +0 -5
- data/.rubocop.yml +2 -1
- data/.yardopts +1 -0
- data/CHANGELOG.md +16 -12
- data/Gemfile +2 -0
- data/README.md +24 -43
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/brick_ftp.gemspec +10 -9
- data/exe/brick_ftp +1 -0
- data/lib/brick_ftp.rb +5 -78
- data/lib/brick_ftp/client.rb +35 -411
- data/lib/brick_ftp/core_ext.rb +8 -0
- data/lib/brick_ftp/core_ext/hash.rb +13 -0
- data/lib/brick_ftp/core_ext/hash/compact.rb +13 -0
- data/lib/brick_ftp/core_ext/struct.rb +13 -0
- data/lib/brick_ftp/core_ext/struct/new.rb +16 -0
- data/lib/brick_ftp/restful_api.rb +82 -0
- data/lib/brick_ftp/restful_api/add_group_member.rb +44 -0
- data/lib/brick_ftp/restful_api/client.rb +179 -0
- data/lib/brick_ftp/restful_api/command.rb +21 -0
- data/lib/brick_ftp/restful_api/complete_upload.rb +46 -0
- data/lib/brick_ftp/restful_api/continue_upload.rb +50 -0
- data/lib/brick_ftp/restful_api/copy_folder.rb +46 -0
- data/lib/brick_ftp/restful_api/count_folder_contents.rb +36 -0
- data/lib/brick_ftp/restful_api/count_users.rb +22 -0
- data/lib/brick_ftp/restful_api/create_api_key.rb +46 -0
- data/lib/brick_ftp/restful_api/create_behavior.rb +42 -0
- data/lib/brick_ftp/restful_api/create_bundle.rb +40 -0
- data/lib/brick_ftp/restful_api/create_folder.rb +25 -0
- data/lib/brick_ftp/restful_api/create_group.rb +42 -0
- data/lib/brick_ftp/restful_api/create_notification.rb +44 -0
- data/lib/brick_ftp/restful_api/create_permission.rb +48 -0
- data/lib/brick_ftp/restful_api/create_public_key.rb +42 -0
- data/lib/brick_ftp/restful_api/create_user.rb +90 -0
- data/lib/brick_ftp/restful_api/create_user_in_group.rb +60 -0
- data/lib/brick_ftp/restful_api/delete_api_key.rb +23 -0
- data/lib/brick_ftp/restful_api/delete_behavior.rb +22 -0
- data/lib/brick_ftp/restful_api/delete_bundle.rb +22 -0
- data/lib/brick_ftp/restful_api/delete_folder.rb +32 -0
- data/lib/brick_ftp/restful_api/delete_group.rb +23 -0
- data/lib/brick_ftp/restful_api/delete_notification.rb +23 -0
- data/lib/brick_ftp/restful_api/delete_permission.rb +23 -0
- data/lib/brick_ftp/restful_api/delete_public_key.rb +23 -0
- data/lib/brick_ftp/restful_api/delete_user.rb +25 -0
- data/lib/brick_ftp/restful_api/download_file.rb +44 -0
- data/lib/brick_ftp/restful_api/get_api_key.rb +25 -0
- data/lib/brick_ftp/restful_api/get_behavior.rb +25 -0
- data/lib/brick_ftp/restful_api/get_bundle.rb +25 -0
- data/lib/brick_ftp/restful_api/get_bundle_zip.rb +48 -0
- data/lib/brick_ftp/restful_api/get_file_in_bundle.rb +49 -0
- data/lib/brick_ftp/restful_api/get_folder_size.rb +25 -0
- data/lib/brick_ftp/restful_api/get_group.rb +26 -0
- data/lib/brick_ftp/restful_api/get_public_key.rb +25 -0
- data/lib/brick_ftp/restful_api/get_site_usage.rb +19 -0
- data/lib/brick_ftp/restful_api/get_user.rb +26 -0
- data/lib/brick_ftp/restful_api/list_api_keys.rb +25 -0
- data/lib/brick_ftp/restful_api/list_behaviors.rb +23 -0
- data/lib/brick_ftp/restful_api/list_bundle_contents.rb +58 -0
- data/lib/brick_ftp/restful_api/list_bundles.rb +23 -0
- data/lib/brick_ftp/restful_api/list_folder_behaviors.rb +39 -0
- data/lib/brick_ftp/restful_api/list_folders.rb +108 -0
- data/lib/brick_ftp/restful_api/list_groups.rb +23 -0
- data/lib/brick_ftp/restful_api/list_notifications.rb +23 -0
- data/lib/brick_ftp/restful_api/list_permissions.rb +41 -0
- data/lib/brick_ftp/restful_api/list_public_keys.rb +25 -0
- data/lib/brick_ftp/restful_api/list_users.rb +60 -0
- data/lib/brick_ftp/restful_api/move_folder.rb +41 -0
- data/lib/brick_ftp/restful_api/remove_group_member.rb +23 -0
- data/lib/brick_ftp/restful_api/retrieve_file_history.rb +41 -0
- data/lib/brick_ftp/restful_api/retrieve_folder_history.rb +41 -0
- data/lib/brick_ftp/restful_api/retrieve_history.rb +54 -0
- data/lib/brick_ftp/restful_api/retrieve_login_history.rb +38 -0
- data/lib/brick_ftp/restful_api/retrieve_site_history.rb +38 -0
- data/lib/brick_ftp/restful_api/retrieve_user_history.rb +40 -0
- data/lib/brick_ftp/restful_api/search_user.rb +28 -0
- data/lib/brick_ftp/restful_api/start_upload.rb +27 -0
- data/lib/brick_ftp/restful_api/unlock_user.rb +25 -0
- data/lib/brick_ftp/restful_api/update_behavior.rb +39 -0
- data/lib/brick_ftp/restful_api/update_group.rb +44 -0
- data/lib/brick_ftp/restful_api/update_group_member.rb +40 -0
- data/lib/brick_ftp/restful_api/update_user.rb +101 -0
- data/lib/brick_ftp/restful_api/upload_file.rb +65 -0
- data/lib/brick_ftp/types.rb +23 -0
- data/lib/brick_ftp/types/behavior.rb +27 -0
- data/lib/brick_ftp/types/bundle.rb +34 -0
- data/lib/brick_ftp/types/bundle_content.rb +25 -0
- data/lib/brick_ftp/types/bundle_zip.rb +19 -0
- data/lib/brick_ftp/types/file.rb +45 -0
- data/lib/brick_ftp/types/file_in_bundle.rb +25 -0
- data/lib/brick_ftp/types/folder_contents_count.rb +24 -0
- data/lib/brick_ftp/types/group.rb +31 -0
- data/lib/brick_ftp/types/group_membership.rb +27 -0
- data/lib/brick_ftp/types/history.rb +43 -0
- data/lib/brick_ftp/types/notification.rb +31 -0
- data/lib/brick_ftp/types/permission.rb +35 -0
- data/lib/brick_ftp/types/site_usage.rb +23 -0
- data/lib/brick_ftp/types/upload.rb +45 -0
- data/lib/brick_ftp/types/user.rb +79 -0
- data/lib/brick_ftp/types/user_api_key.rb +33 -0
- data/lib/brick_ftp/types/user_public_key.rb +28 -0
- data/lib/brick_ftp/utils.rb +2 -0
- data/lib/brick_ftp/utils/chunk_io.rb +5 -4
- data/lib/brick_ftp/version.rb +3 -1
- metadata +123 -86
- data/lib/brick_ftp/api.rb +0 -9
- data/lib/brick_ftp/api/authentication.rb +0 -28
- data/lib/brick_ftp/api/authentication/session.rb +0 -25
- data/lib/brick_ftp/api/base.rb +0 -119
- data/lib/brick_ftp/api/behavior.rb +0 -19
- data/lib/brick_ftp/api/bundle.rb +0 -17
- data/lib/brick_ftp/api/bundle_content.rb +0 -18
- data/lib/brick_ftp/api/bundle_download.rb +0 -18
- data/lib/brick_ftp/api/file.rb +0 -20
- data/lib/brick_ftp/api/file_operation.rb +0 -6
- data/lib/brick_ftp/api/file_operation/copy.rb +0 -10
- data/lib/brick_ftp/api/file_operation/move.rb +0 -10
- data/lib/brick_ftp/api/file_operation/upload.rb +0 -66
- data/lib/brick_ftp/api/file_operation/uploading_result.rb +0 -22
- data/lib/brick_ftp/api/file_operation/uploading_session.rb +0 -95
- data/lib/brick_ftp/api/folder.rb +0 -22
- data/lib/brick_ftp/api/folder_behavior.rb +0 -12
- data/lib/brick_ftp/api/group.rb +0 -16
- data/lib/brick_ftp/api/history.rb +0 -6
- data/lib/brick_ftp/api/history/file.rb +0 -23
- data/lib/brick_ftp/api/history/folder.rb +0 -23
- data/lib/brick_ftp/api/history/login.rb +0 -23
- data/lib/brick_ftp/api/history/site.rb +0 -23
- data/lib/brick_ftp/api/history/user.rb +0 -23
- data/lib/brick_ftp/api/notification.rb +0 -14
- data/lib/brick_ftp/api/permission.rb +0 -17
- data/lib/brick_ftp/api/public_key.rb +0 -15
- data/lib/brick_ftp/api/site_usage.rb +0 -21
- data/lib/brick_ftp/api/user.rb +0 -36
- data/lib/brick_ftp/api_component.rb +0 -81
- data/lib/brick_ftp/api_definition.rb +0 -65
- data/lib/brick_ftp/cli.rb +0 -7
- data/lib/brick_ftp/cli/config.rb +0 -20
- data/lib/brick_ftp/cli/main.rb +0 -26
- data/lib/brick_ftp/cli/site.rb +0 -10
- data/lib/brick_ftp/configuration.rb +0 -121
- data/lib/brick_ftp/http_client.rb +0 -130
- data/lib/brick_ftp/log_formatter.rb +0 -15
- data/lib/brick_ftp/webhook.rb +0 -4
- data/lib/brick_ftp/webhook/request.rb +0 -28
data/lib/brick_ftp/api/folder.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
module BrickFTP
|
2
|
-
module API
|
3
|
-
class Folder < Base
|
4
|
-
# rubocop:disable Metrics/LineLength
|
5
|
-
endpoint :get, :index, '/api/rest/v1/folders/%{path}', :page, :per_page, :search, :'sort_by[path]', :'sort_by[size]', :'sort_by[modified_at_datetime]'
|
6
|
-
# rubocop:enable Metrics/LineLength
|
7
|
-
endpoint :post, :create, '/api/rest/v1/folders/%{path}'
|
8
|
-
|
9
|
-
attribute :id
|
10
|
-
attribute :path
|
11
|
-
attribute :display_name
|
12
|
-
attribute :type
|
13
|
-
attribute :size
|
14
|
-
attribute :mtime
|
15
|
-
attribute :crc32
|
16
|
-
attribute :md5
|
17
|
-
attribute :provided_mtime
|
18
|
-
attribute :permissions
|
19
|
-
attribute :subfolders_locked?
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/lib/brick_ftp/api/group.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module BrickFTP
|
2
|
-
module API
|
3
|
-
class Group < Base
|
4
|
-
endpoint :get, :index, '/api/rest/v1/groups.json'
|
5
|
-
endpoint :get, :show, '/api/rest/v1/groups/%{id}.json'
|
6
|
-
endpoint :post, :create, '/api/rest/v1/groups.json'
|
7
|
-
endpoint :put, :update, '/api/rest/v1/groups/%{id}.json'
|
8
|
-
endpoint :delete, :delete, '/api/rest/v1/groups/%{id}.json'
|
9
|
-
|
10
|
-
attribute :id
|
11
|
-
attribute :name, writable: true
|
12
|
-
attribute :notes, writable: true
|
13
|
-
attribute :user_ids, writable: true
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module BrickFTP
|
2
|
-
module API
|
3
|
-
module History
|
4
|
-
class File < BrickFTP::API::Base
|
5
|
-
endpoint :get, :index, '/api/rest/v1/history/files/%{path}', :page, :per_page, :start_at
|
6
|
-
|
7
|
-
attribute :id
|
8
|
-
attribute :when
|
9
|
-
attribute :user_id
|
10
|
-
attribute :username
|
11
|
-
attribute :action
|
12
|
-
attribute :failure_type
|
13
|
-
attribute :path
|
14
|
-
attribute :source
|
15
|
-
attribute :destination
|
16
|
-
attribute :targets
|
17
|
-
attribute :ip
|
18
|
-
attribute :interface
|
19
|
-
attribute :display
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module BrickFTP
|
2
|
-
module API
|
3
|
-
module History
|
4
|
-
class Folder < BrickFTP::API::Base
|
5
|
-
endpoint :get, :index, '/api/rest/v1/history/folders/%{path}', :page, :per_page, :start_at
|
6
|
-
|
7
|
-
attribute :id
|
8
|
-
attribute :when
|
9
|
-
attribute :user_id
|
10
|
-
attribute :username
|
11
|
-
attribute :action
|
12
|
-
attribute :failure_type
|
13
|
-
attribute :path
|
14
|
-
attribute :source
|
15
|
-
attribute :destination
|
16
|
-
attribute :targets
|
17
|
-
attribute :ip
|
18
|
-
attribute :interface
|
19
|
-
attribute :display
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module BrickFTP
|
2
|
-
module API
|
3
|
-
module History
|
4
|
-
class Login < BrickFTP::API::Base
|
5
|
-
endpoint :get, :index, '/api/rest/v1/history/login.json', :page, :per_page, :start_at
|
6
|
-
|
7
|
-
attribute :id
|
8
|
-
attribute :when
|
9
|
-
attribute :user_id
|
10
|
-
attribute :username
|
11
|
-
attribute :action
|
12
|
-
attribute :failure_type
|
13
|
-
attribute :path
|
14
|
-
attribute :source
|
15
|
-
attribute :destination
|
16
|
-
attribute :targets
|
17
|
-
attribute :ip
|
18
|
-
attribute :interface
|
19
|
-
attribute :display
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module BrickFTP
|
2
|
-
module API
|
3
|
-
module History
|
4
|
-
class Site < BrickFTP::API::Base
|
5
|
-
endpoint :get, :index, '/api/rest/v1/history.json', :page, :per_page, :start_at
|
6
|
-
|
7
|
-
attribute :id
|
8
|
-
attribute :when
|
9
|
-
attribute :user_id
|
10
|
-
attribute :username
|
11
|
-
attribute :action
|
12
|
-
attribute :failure_type
|
13
|
-
attribute :path
|
14
|
-
attribute :source
|
15
|
-
attribute :destination
|
16
|
-
attribute :targets
|
17
|
-
attribute :ip
|
18
|
-
attribute :interface
|
19
|
-
attribute :display
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module BrickFTP
|
2
|
-
module API
|
3
|
-
module History
|
4
|
-
class User < BrickFTP::API::Base
|
5
|
-
endpoint :get, :index, '/api/rest/v1/history/users/%{user_id}.json', :page, :per_page, :start_at
|
6
|
-
|
7
|
-
attribute :id
|
8
|
-
attribute :when
|
9
|
-
attribute :user_id
|
10
|
-
attribute :username
|
11
|
-
attribute :action
|
12
|
-
attribute :failure_type
|
13
|
-
attribute :path
|
14
|
-
attribute :source
|
15
|
-
attribute :destination
|
16
|
-
attribute :targets
|
17
|
-
attribute :ip
|
18
|
-
attribute :interface
|
19
|
-
attribute :display
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module BrickFTP
|
2
|
-
module API
|
3
|
-
class Notification < Base
|
4
|
-
endpoint :get, :index, '/api/rest/v1/notifications.json'
|
5
|
-
endpoint :post, :create, '/api/rest/v1/notifications.json'
|
6
|
-
endpoint :delete, :delete, '/api/rest/v1/notifications/%{id}.json'
|
7
|
-
|
8
|
-
attribute :id
|
9
|
-
attribute :path, writable: true
|
10
|
-
attribute :user_id, writable: true
|
11
|
-
attribute :username, writable: true
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module BrickFTP
|
2
|
-
module API
|
3
|
-
class Permission < Base
|
4
|
-
endpoint :get, :index, '/api/rest/v1/permissions.json'
|
5
|
-
endpoint :post, :create, '/api/rest/v1/permissions.json'
|
6
|
-
endpoint :delete, :delete, '/api/rest/v1/permissions/%{id}.json'
|
7
|
-
|
8
|
-
attribute :id
|
9
|
-
attribute :recursive
|
10
|
-
attribute :path, writable: true
|
11
|
-
attribute :permission, writable: true
|
12
|
-
attribute :user_id, writable: true
|
13
|
-
attribute :username, writable: true
|
14
|
-
attribute :group_id, writable: true
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module BrickFTP
|
2
|
-
module API
|
3
|
-
class PublicKey < Base
|
4
|
-
endpoint :get, :index, '/api/rest/v1/users/%{user_id}/public_keys.json'
|
5
|
-
endpoint :post, :create, '/api/rest/v1/users/%{user_id}/public_keys.json'
|
6
|
-
endpoint :delete, :delete, '/api/rest/v1/public_keys/%{id}.json'
|
7
|
-
|
8
|
-
attribute :id
|
9
|
-
attribute :fingerprint
|
10
|
-
attribute :created_at
|
11
|
-
attribute :title, writable: true
|
12
|
-
attribute :public_key, writable: true
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module BrickFTP
|
2
|
-
module API
|
3
|
-
class SiteUsage < Base
|
4
|
-
endpoint :get, :show, '/api/rest/v1/site/usage'
|
5
|
-
|
6
|
-
attribute :id
|
7
|
-
attribute :live_current_storage
|
8
|
-
attribute :current_storage
|
9
|
-
attribute :usage_by_top_level_dir
|
10
|
-
attribute :high_water_storage
|
11
|
-
attribute :start_at
|
12
|
-
attribute :end_at
|
13
|
-
attribute :created_at
|
14
|
-
attribute :updated_at
|
15
|
-
|
16
|
-
def self.find
|
17
|
-
super('')
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/brick_ftp/api/user.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
module BrickFTP
|
2
|
-
module API
|
3
|
-
class User < Base
|
4
|
-
endpoint :get, :index, '/api/rest/v1/users.json'
|
5
|
-
endpoint :get, :show, '/api/rest/v1/users/%{id}.json'
|
6
|
-
endpoint :post, :create, '/api/rest/v1/users.json'
|
7
|
-
endpoint :put, :update, '/api/rest/v1/users/%{id}.json'
|
8
|
-
endpoint :delete, :delete, '/api/rest/v1/users/%{id}.json'
|
9
|
-
|
10
|
-
attribute :id
|
11
|
-
attribute :last_login_at
|
12
|
-
attribute :time_zone
|
13
|
-
attribute :language
|
14
|
-
attribute :site_admin
|
15
|
-
attribute :username, writable: true
|
16
|
-
attribute :password, writable: true
|
17
|
-
attribute :name, writable: true
|
18
|
-
attribute :email, writable: true
|
19
|
-
attribute :notes, writable: true
|
20
|
-
attribute :group_ids, writable: true
|
21
|
-
attribute :ftp_permission, writable: true
|
22
|
-
attribute :web_permission, writable: true
|
23
|
-
attribute :sftp_permission, writable: true
|
24
|
-
attribute :dav_permission, writable: true
|
25
|
-
attribute :restapi_permission, writable: true
|
26
|
-
attribute :attachments_permission, writable: true
|
27
|
-
attribute :self_managed, writable: true
|
28
|
-
attribute :require_password_change, writable: true
|
29
|
-
attribute :allowed_ips, writable: true
|
30
|
-
attribute :user_root, writable: true
|
31
|
-
attribute :grant_permission, writable: true
|
32
|
-
attribute :ssl_required, writable: true
|
33
|
-
attribute :authentication_method, writable: true
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'erb'
|
2
|
-
|
3
|
-
module BrickFTP
|
4
|
-
class APIComponent
|
5
|
-
attr_reader :path_template, :query_keys
|
6
|
-
|
7
|
-
def initialize(path_template, query_keys = [])
|
8
|
-
@path_template = path_template.respond_to?(:call) ? path_template : ->(_) { path_template }
|
9
|
-
@query_keys = query_keys.map(&:to_sym)
|
10
|
-
end
|
11
|
-
|
12
|
-
def path(params)
|
13
|
-
params = normalize_params(params)
|
14
|
-
|
15
|
-
path_params = build_path_params_from(params)
|
16
|
-
escaped_path_params = path_params.each_with_object({}) do |(k, v), res|
|
17
|
-
res[k] = ERB::Util.url_encode(v.to_s)
|
18
|
-
end
|
19
|
-
|
20
|
-
path = path_template.call(params) % escaped_path_params
|
21
|
-
query = build_query_string_from(params)
|
22
|
-
query.empty? ? path : "#{path}?#{query}"
|
23
|
-
end
|
24
|
-
|
25
|
-
def build_path_params_from(params = {})
|
26
|
-
params = normalize_params(params)
|
27
|
-
|
28
|
-
path_variables(params).each_with_object({}) do |key, res|
|
29
|
-
res[key] = params[key]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def build_query_params_from(params = {})
|
34
|
-
params = normalize_params(params)
|
35
|
-
|
36
|
-
query_keys.each_with_object({}) do |name, res|
|
37
|
-
next unless params.key?(name)
|
38
|
-
res[name] = params[name]
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def build_query_string_from(params = {})
|
43
|
-
params = normalize_params(params)
|
44
|
-
|
45
|
-
pairs = build_query_params_from(params).each_with_object([]) do |(k, v), res|
|
46
|
-
res << "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
|
47
|
-
end
|
48
|
-
pairs.join('&')
|
49
|
-
end
|
50
|
-
|
51
|
-
def except_path_and_query(params = {})
|
52
|
-
params = normalize_params(params)
|
53
|
-
|
54
|
-
exceptions = path_variables(params) + query_keys
|
55
|
-
params.reject { |k, _| exceptions.include?(k) }
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def path_variables(params = {})
|
61
|
-
@path_variables ||= path_template.call(params).scan(/%\{([^}]+)\}/).map { |m| m.first.to_sym }
|
62
|
-
end
|
63
|
-
|
64
|
-
def normalize_params(params = {})
|
65
|
-
case params
|
66
|
-
when Hash
|
67
|
-
params.symbolize_keys
|
68
|
-
when BrickFTP::API::Base
|
69
|
-
keys = path_variables(params) + query_keys
|
70
|
-
keys.each_with_object({}) do |key, res|
|
71
|
-
res[key] = params.read_property(key)
|
72
|
-
end
|
73
|
-
else
|
74
|
-
keys = path_variables(params) + query_keys
|
75
|
-
keys.each_with_object({}) do |key, res|
|
76
|
-
res[key] = params
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
module BrickFTP
|
2
|
-
module APIDefinition
|
3
|
-
def self.included(klass)
|
4
|
-
klass.class_eval do
|
5
|
-
@endpoints = {}
|
6
|
-
@writable_attributes = []
|
7
|
-
@readonly_attributes = []
|
8
|
-
|
9
|
-
class << self
|
10
|
-
attr_reader :endpoints, :writable_attributes, :readonly_attributes
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
klass.extend ClassMethods
|
15
|
-
end
|
16
|
-
|
17
|
-
module ClassMethods
|
18
|
-
# Define API endpoint.
|
19
|
-
# @param http_method [:Symbol] any one of :get, :post, :put, :delete
|
20
|
-
# @param name [Symbol] any one of :index, :show, :create, :update, :destroy
|
21
|
-
# @param path_template [Stryng] template of endpoint path.
|
22
|
-
# @param query_keys [Array] array of query_string's parameter name.
|
23
|
-
def endpoint(http_method, name, path_template, *query_keys)
|
24
|
-
endpoints[name] = {
|
25
|
-
http_method: http_method,
|
26
|
-
path_template: path_template,
|
27
|
-
query_keys: query_keys,
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
# Define attribute.
|
32
|
-
# @param name [Symbol] name of attribute.
|
33
|
-
# @param writable [Boolean]
|
34
|
-
def attribute(name, writable: false)
|
35
|
-
if writable
|
36
|
-
writable_attributes << name.to_sym
|
37
|
-
else
|
38
|
-
readonly_attributes << name.to_sym
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# Return all attributes.
|
43
|
-
# @return [Array]
|
44
|
-
def attributes
|
45
|
-
writable_attributes + readonly_attributes
|
46
|
-
end
|
47
|
-
|
48
|
-
# Build path for API endpoint.
|
49
|
-
# @param name [Symbol]
|
50
|
-
# @param params [Hash] mixed path parameters and query parameters.
|
51
|
-
# @return [String]
|
52
|
-
def api_path_for(name, params = {})
|
53
|
-
api_component_for(name).path(params)
|
54
|
-
end
|
55
|
-
|
56
|
-
# Build BrickFTP::APIComponent.
|
57
|
-
# @param name [Symbol]
|
58
|
-
# @return [BrickFTP::APIComponent]
|
59
|
-
def api_component_for(name)
|
60
|
-
raise BrickFTP::API::NoSuchAPI, "#{name} #{self.name}" unless endpoints.key?(name)
|
61
|
-
BrickFTP::APIComponent.new(endpoints[name][:path_template], endpoints[name][:query_keys])
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|