├── .circleci └── config.yml ├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md ├── action │ ├── publish_gem │ │ ├── Dockerfile │ │ └── entrypoint.sh │ └── write_github_release │ │ ├── Dockerfile │ │ └── entrypoint.sh └── main.workflow ├── .gitignore ├── .rspec ├── .rubocop.yml ├── .rubocop_todo.yml ├── .yardopts ├── CHANGELOG.md ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── bin ├── console └── setup ├── brick_ftp.gemspec ├── docker-compose.yml ├── lib ├── brick_ftp.rb └── brick_ftp │ ├── client.rb │ ├── core_ext.rb │ ├── core_ext │ ├── hash.rb │ ├── hash │ │ ├── compact.rb │ │ └── symbolize_keys.rb │ ├── struct.rb │ └── struct │ │ └── new.rb │ ├── restful_api.rb │ ├── restful_api │ ├── add_group_member.rb │ ├── client.rb │ ├── command.rb │ ├── complete_upload.rb │ ├── continue_upload.rb │ ├── copy_folder.rb │ ├── count_folder_contents.rb │ ├── count_users.rb │ ├── create_api_key.rb │ ├── create_behavior.rb │ ├── create_bundle.rb │ ├── create_folder.rb │ ├── create_group.rb │ ├── create_notification.rb │ ├── create_permission.rb │ ├── create_public_key.rb │ ├── create_user.rb │ ├── create_user_in_group.rb │ ├── delete_api_key.rb │ ├── delete_behavior.rb │ ├── delete_bundle.rb │ ├── delete_folder.rb │ ├── delete_group.rb │ ├── delete_notification.rb │ ├── delete_permission.rb │ ├── delete_public_key.rb │ ├── delete_user.rb │ ├── download_file.rb │ ├── get_api_key.rb │ ├── get_behavior.rb │ ├── get_bundle.rb │ ├── get_bundle_zip.rb │ ├── get_file_in_bundle.rb │ ├── get_folder_size.rb │ ├── get_group.rb │ ├── get_public_key.rb │ ├── get_site_usage.rb │ ├── get_user.rb │ ├── list_api_keys.rb │ ├── list_behaviors.rb │ ├── list_bundle_contents.rb │ ├── list_bundles.rb │ ├── list_folder_behaviors.rb │ ├── list_folders.rb │ ├── list_groups.rb │ ├── list_notifications.rb │ ├── list_permissions.rb │ ├── list_public_keys.rb │ ├── list_users.rb │ ├── move_folder.rb │ ├── remove_group_member.rb │ ├── retrieve_file_history.rb │ ├── retrieve_folder_history.rb │ ├── retrieve_history.rb │ ├── retrieve_login_history.rb │ ├── retrieve_site_history.rb │ ├── retrieve_user_history.rb │ ├── search_user.rb │ ├── start_upload.rb │ ├── unlock_user.rb │ ├── update_behavior.rb │ ├── update_group.rb │ ├── update_group_member.rb │ ├── update_user.rb │ └── upload_file.rb │ ├── types.rb │ ├── types │ ├── behavior.rb │ ├── bundle.rb │ ├── bundle_content.rb │ ├── bundle_zip.rb │ ├── file.rb │ ├── file_in_bundle.rb │ ├── folder_contents_count.rb │ ├── group.rb │ ├── group_membership.rb │ ├── history.rb │ ├── ignore_undefined_attributes.rb │ ├── notification.rb │ ├── permission.rb │ ├── site_usage.rb │ ├── upload.rb │ ├── user.rb │ ├── user_api_key.rb │ └── user_public_key.rb │ ├── utils.rb │ ├── utils │ └── chunk_io.rb │ └── version.rb └── spec ├── brick_ftp ├── client_spec.rb ├── core_ext │ └── hash │ │ └── symbolize_keys_spec.rb ├── restful_api │ ├── add_group_member_spec.rb │ ├── client_spec.rb │ ├── complete_upload_spec.rb │ ├── continue_upload_spec.rb │ ├── copy_folder_spec.rb │ ├── count_folder_contents_spec.rb │ ├── count_users_spec.rb │ ├── create_api_key_spec.rb │ ├── create_behavior_spec.rb │ ├── create_bundle_spec.rb │ ├── create_folder_spec.rb │ ├── create_group_spec.rb │ ├── create_notification_spec.rb │ ├── create_permission_spec.rb │ ├── create_public_key_spec.rb │ ├── create_user_in_group_spec.rb │ ├── create_user_spec.rb │ ├── delete_api_key_spec.rb │ ├── delete_behavior_spec.rb │ ├── delete_bundle_spec.rb │ ├── delete_folder_spec.rb │ ├── delete_group_spec.rb │ ├── delete_notification_spec.rb │ ├── delete_permission_spec.rb │ ├── delete_public_key_spec.rb │ ├── delete_user_spec.rb │ ├── download_file_spec.rb │ ├── get_api_key_spec.rb │ ├── get_behavior_spec.rb │ ├── get_bundle_spec.rb │ ├── get_bundle_zip_spec.rb │ ├── get_file_in_bundle_spec.rb │ ├── get_folder_size_spec.rb │ ├── get_group_spec.rb │ ├── get_public_key_spec.rb │ ├── get_site_usage_spec.rb │ ├── get_user_spec.rb │ ├── list_api_keys_spec.rb │ ├── list_behaviors_spec.rb │ ├── list_bundle_contents_spec.rb │ ├── list_bundles_spec.rb │ ├── list_folder_behaviors_spec.rb │ ├── list_folders_spec.rb │ ├── list_groups_spec.rb │ ├── list_notifications_spec.rb │ ├── list_permissions_spec.rb │ ├── list_public_keys_spec.rb │ ├── list_users_spec.rb │ ├── move_folder_spec.rb │ ├── remove_group_member_spec.rb │ ├── retrieve_file_history_spec.rb │ ├── retrieve_folder_history_spec.rb │ ├── retrieve_login_history_spec.rb │ ├── retrieve_site_history_spec.rb │ ├── retrieve_user_history_spec.rb │ ├── search_user_spec.rb │ ├── start_upload_spec.rb │ ├── unlock_user_spec.rb │ ├── update_behavior_spec.rb │ ├── update_group_member_spec.rb │ ├── update_group_spec.rb │ ├── update_user_spec.rb │ └── upload_file_spec.rb └── utils │ └── chunk_io_spec.rb ├── brick_ftp_spec.rb └── spec_helper.rb /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: &build 4 | docker: 5 | - image: cimg/ruby:latest 6 | working_directory: /home/circleci/app 7 | steps: 8 | - checkout 9 | - run: 10 | name: Install gems 11 | command: bundle install 12 | - run: 13 | name: Rubocop 14 | command: rubocop 15 | - run: 16 | name: YARDoc 17 | command: yardoc --fail-on-warning lib 18 | - run: 19 | name: RSpec 20 | command: rspec 21 | ruby-2.6: 22 | <<: *build 23 | docker: 24 | - image: cimg/ruby:2.6 25 | ruby-2.7: 26 | <<: *build 27 | docker: 28 | - image: cimg/ruby:2.7 29 | ruby-3.0: 30 | <<: *build 31 | docker: 32 | - image: cimg/ruby:3.0 33 | 34 | workflows: 35 | version: 2 36 | build-using-multi-rubies: 37 | jobs: 38 | - ruby-2.6 39 | - ruby-2.7 40 | - ruby-3.0 41 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 8 | 9 | # This is a (Bug Report / Feature Proposal) 10 | 11 | ## Description 12 | 13 | For bug reports: 14 | * What went wrong? 15 | * What did you expect should have happened? 16 | * What was the config you used? 17 | * What stacktrace or error message from your provider did you see? 18 | 19 | For feature proposals: 20 | * What is the use case that should be solved. The more detail you describe this in the easier it is to understand for us. 21 | * If there is additional config how would it look 22 | 23 | Similar or dependent issues: 24 | * #12345 25 | 26 | ## Additional Data 27 | 28 | * ***Serverless Framework Version you're using***: 29 | * ***Operating System***: 30 | * ***Stack Trace***: 31 | * ***Provider Error messages***: 32 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | ## What did you implement: 8 | 9 | Closes #XXXXX 10 | 11 | 14 | 15 | ## How did you implement it: 16 | 17 | 20 | 21 | ## How can we verify it: 22 | 23 | 34 | 35 | ## Todos: 36 | 37 | - [ ] Write tests 38 | - [ ] Write documentation 39 | - [ ] Fix linting errors 40 | - [ ] Make sure code coverage hasn't dropped 41 | - [ ] Provide verification config / commands / resources 42 | - [ ] Enable "Allow edits from maintainers" for this PR 43 | - [ ] Update the messages below 44 | 45 | ***Is this ready for review?:*** NO 46 | ***Is it a breaking change?:*** NO 47 | -------------------------------------------------------------------------------- /.github/action/publish_gem/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:alpine 2 | LABEL "com.github.actions.name"="Publish Gem" 3 | LABEL "com.github.actions.description"="Publish gem to rubygems.org" 4 | LABEL "com.github.actions.icon"="truck" 5 | LABEL "com.github.actions.color"="green" 6 | LABEL "repository"="https://github.com/koshigoe/brick_ftp" 7 | LABEL "homepage"="https://github.com/koshigoe/brick_ftp" 8 | LABEL "maintainer"="koshigoe " 9 | 10 | RUN apk update -q \ 11 | && apk add -q --no-cache curl jq git 12 | 13 | ADD entrypoint.sh /entrypoint.sh 14 | ENTRYPOINT ["/entrypoint.sh"] 15 | -------------------------------------------------------------------------------- /.github/action/publish_gem/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/ash -eu 2 | 3 | action=$(jq -r '.action' $GITHUB_EVENT_PATH) 4 | if [ "$action" != "published" ]; then 5 | exit 0 6 | fi 7 | 8 | cd $GITHUB_WORKSPACE 9 | 10 | mkdir -p ~/.gem 11 | cat < ~/.gem/credentials 12 | --- 13 | :rubygems_api_key: $RUBYGEMS_TOKEN 14 | EOF 15 | chmod 0600 ~/.gem/credentials 16 | 17 | gem build *.gemspec 18 | gem push *.gem 19 | -------------------------------------------------------------------------------- /.github/action/write_github_release/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.8 2 | LABEL "com.github.actions.name"="Write GitHub Release" 3 | LABEL "com.github.actions.description"="Write merged PRs into latest GitHub Release" 4 | LABEL "com.github.actions.icon"="edit" 5 | LABEL "com.github.actions.color"="blue" 6 | LABEL "repository"="https://github.com/koshigoe/brick_ftp" 7 | LABEL "homepage"="https://github.com/koshigoe/brick_ftp" 8 | LABEL "maintainer"="koshigoe " 9 | 10 | RUN apk update -q \ 11 | && apk add -q --no-cache curl jq 12 | 13 | ADD entrypoint.sh /entrypoint.sh 14 | ENTRYPOINT ["/entrypoint.sh"] 15 | -------------------------------------------------------------------------------- /.github/action/write_github_release/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/ash -eu 2 | 3 | action=$(jq -r '.action' $GITHUB_EVENT_PATH) 4 | if [ "$action" != "published" ]; then 5 | exit 0 6 | fi 7 | 8 | # Get previous GitHub Release. 9 | curl --fail -s \ 10 | -u $GITHUB_ACTOR:$GITHUB_TOKEN \ 11 | https://api.github.com/repos/$GITHUB_REPOSITORY/releases \ 12 | | jq -r '.[1]' \ 13 | > previous_release.json 14 | previous_published_date=$(jq -r '.published_at' previous_release.json) 15 | 16 | # Get latest published date. 17 | latest_published_date=$(jq -r '.release.published_at' $GITHUB_EVENT_PATH) 18 | 19 | # Get latest GitHub Release ID. 20 | latest_release_id=$(jq -r '.release.id' $GITHUB_EVENT_PATH) 21 | 22 | # Get merged PRs 23 | merged_pr_list=$( 24 | curl --fail -s \ 25 | -u $GITHUB_ACTOR:$GITHUB_TOKEN \ 26 | "https://api.github.com/search/issues?q=repo:${GITHUB_REPOSITORY}+is:pr+base:master+merged:${previous_published_date}..${latest_published_date}" \ 27 | | jq -r '.items[] | ["- #" + (.number | tostring) + " " + .title] | @tsv' \ 28 | | sort -k 3) 29 | 30 | # Get comparable tags 31 | previous_tag_name=$(jq -r '.tag_name' previous_release.json) 32 | latest_tag_name=$(jq -r '.release.tag_name' $GITHUB_EVENT_PATH) 33 | 34 | # Make release note. 35 | release_note=$(cat < client = BrickFTP::Client.new(base_url: 'http://localhost:40410', api_key: 'dummy') 39 | > client.list_users 40 | ``` 41 | 42 | ### Environment Variables 43 | 44 | Name | Description 45 | --------------------- | ----------- 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/`) 48 | `BRICK_FTP_API_KEY` | Default API key 49 | 50 | 51 | Development 52 | ---- 53 | 54 | After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. 55 | 56 | To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). 57 | 58 | 59 | Contributing 60 | ---- 61 | 62 | Bug reports and pull requests are welcome on GitHub at https://github.com/koshigoe/brick_ftp. 63 | 64 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'bundler/gem_tasks' 4 | require 'rspec/core/rake_task' 5 | require 'rubocop/rake_task' 6 | 7 | RSpec::Core::RakeTask.new(:spec) 8 | RuboCop::RakeTask.new 9 | 10 | task default: %i[rubocop spec] 11 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | require 'bundler/setup' 5 | require 'brick_ftp' 6 | 7 | # You can add fixtures and/or initialization code here to make experimenting 8 | # with your gem easier. You can also use a different console, if you like. 9 | 10 | require 'pry' 11 | Pry.start 12 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /brick_ftp.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | lib = File.expand_path('lib', __dir__) 4 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 5 | require 'brick_ftp/version' 6 | 7 | Gem::Specification.new do |spec| 8 | spec.name = 'brick_ftp' 9 | spec.version = BrickFTP::VERSION 10 | spec.license = 'MIT' 11 | spec.authors = ['koshigoe'] 12 | spec.email = ['koshigoeb@gmail.com'] 13 | 14 | spec.summary = "BrickFTP's REST API client." 15 | spec.description = "BrickFTP's REST API client." 16 | spec.homepage = 'https://github.com/koshigoe/brick_ftp' 17 | 18 | spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 19 | spec.bindir = 'exe' 20 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 21 | spec.require_paths = ['lib'] 22 | 23 | spec.required_ruby_version = '>= 2.6.0' 24 | 25 | spec.add_runtime_dependency 'ruby2_keywords' 26 | 27 | spec.add_development_dependency 'bundler', '>= 1.16' 28 | spec.add_development_dependency 'pry', '~> 0.11' 29 | spec.add_development_dependency 'rake', '~> 12.0' 30 | spec.add_development_dependency 'redcarpet', '~> 3.4' 31 | spec.add_development_dependency 'rspec', '~> 3.7' 32 | spec.add_development_dependency 'rubocop', '~> 1.23' 33 | spec.add_development_dependency 'simplecov', '~> 0.15' 34 | spec.add_development_dependency 'webmock', '~> 3.4' 35 | spec.add_development_dependency 'yard', '~> 0.9' 36 | end 37 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | files-mock-server: 5 | image: filescom/files-mock-server:latest 6 | ports: 7 | - 40410:4041 8 | -------------------------------------------------------------------------------- /lib/brick_ftp.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'brick_ftp/version' 4 | require 'brick_ftp/client' 5 | require 'brick_ftp/core_ext' 6 | require 'brick_ftp/utils' 7 | require 'brick_ftp/utils/chunk_io' 8 | require 'brick_ftp/types' 9 | require 'brick_ftp/types/ignore_undefined_attributes' 10 | require 'brick_ftp/restful_api' 11 | 12 | module BrickFTP 13 | # https://files.com/redundancy/ 14 | IP_ADDRESSES = %w[ 15 | 54.193.69.72 16 | 54.193.69.200 17 | 54.193.65.189 18 | 54.193.69.198 19 | 54.208.20.30 20 | 54.209.242.244 21 | 54.209.231.233 22 | 54.208.198.60 23 | 54.209.231.99 24 | 54.209.246.178 25 | 54.209.91.52 26 | 54.208.63.151 27 | 54.209.246.217 28 | 54.209.222.205 29 | 54.208.169.75 30 | 52.8.210.89 31 | 52.74.166.120 32 | 52.64.2.88 33 | 52.17.96.203 34 | 52.28.101.76 35 | 54.232.253.47 36 | 54.64.240.152 37 | 52.74.188.115 38 | 52.64.6.120 39 | 52.18.87.39 40 | 52.29.176.178 41 | 54.207.27.239 42 | 52.68.4.44 43 | ].freeze 44 | end 45 | -------------------------------------------------------------------------------- /lib/brick_ftp/client.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'brick_ftp/restful_api' 4 | 5 | module BrickFTP 6 | # To delegate commands. 7 | # 8 | # @see BrickFTP::RESTfulAPI 9 | # @example Call {BrickFTP::RESTfulAPI::ListUser#call} 10 | # BrickFTP::Client.new.list_users 11 | # 12 | class Client 13 | attr_reader :base_url, :api_key, :api_client 14 | 15 | # @param [String] base_url 16 | # @param [String] subdomain (deprecated) 17 | # @param [String] api_key 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 | 24 | @subdomain = subdomain || ENV['BRICK_FTP_SUBDOMAIN'] 25 | @base_url = base_url || ENV['BRICK_FTP_BASE_URL'] 26 | @api_key = api_key || ENV['BRICK_FTP_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 33 | end 34 | 35 | private 36 | 37 | def command_class(symbol) 38 | name = symbol.to_s.split('_').map(&:capitalize).join 39 | return unless BrickFTP::RESTfulAPI.const_defined?(name) 40 | 41 | klass = BrickFTP::RESTfulAPI.const_get(name) 42 | return unless klass < BrickFTP::RESTfulAPI::Command 43 | 44 | klass 45 | end 46 | 47 | def respond_to_missing?(symbol, include_private) 48 | return true if command_class(symbol) 49 | 50 | super 51 | end 52 | 53 | def method_missing(name, *args) 54 | klass = command_class(name) 55 | if klass 56 | dispatch_command(klass, *args) 57 | else 58 | super 59 | end 60 | end 61 | ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true) 62 | 63 | def dispatch_command(klass, *args) 64 | klass.new(api_client).call(*args) 65 | end 66 | ruby2_keywords :dispatch_command if respond_to?(:ruby2_keywords, true) 67 | end 68 | end 69 | -------------------------------------------------------------------------------- /lib/brick_ftp/core_ext.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module CoreExt 5 | autoload :Struct, 'brick_ftp/core_ext/struct' 6 | autoload :Hash, 'brick_ftp/core_ext/hash' 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/brick_ftp/core_ext/hash.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module CoreExt 5 | module Hash 6 | autoload :Compact, 'brick_ftp/core_ext/hash/compact' 7 | autoload :SymbolizeKeys, 'brick_ftp/core_ext/hash/symbolize_keys' 8 | 9 | refine ::Hash do 10 | include(BrickFTP::CoreExt::Hash::Compact) unless ::Hash.instance_methods(false).include?(:compact) 11 | include(BrickFTP::CoreExt::Hash::SymbolizeKeys) unless ::Hash.instance_methods(false).include?(:symbolize_keys) 12 | end 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/brick_ftp/core_ext/hash/compact.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module CoreExt 5 | module Hash 6 | module Compact 7 | def compact 8 | select { |_, value| !value.nil? } 9 | end 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/brick_ftp/core_ext/hash/symbolize_keys.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module CoreExt 5 | module Hash 6 | module SymbolizeKeys 7 | def symbolize_keys 8 | each_key.each_with_object({}) do |key, mem| 9 | symbolized_key = begin 10 | key.to_sym 11 | rescue StandardError 12 | key 13 | end 14 | mem[symbolized_key] = self[key] 15 | end 16 | end 17 | end 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /lib/brick_ftp/core_ext/struct.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module CoreExt 5 | module Struct 6 | autoload :New, 'brick_ftp/core_ext/struct/new' 7 | 8 | refine ::Struct do 9 | ::Struct.singleton_class.prepend(BrickFTP::CoreExt::Struct::New) if RUBY_VERSION < '2.5.0' 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/brick_ftp/core_ext/struct/new.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module CoreExt 5 | module Struct 6 | module New 7 | def new(*args, keyword_init: false, &block) 8 | super(*args) do 9 | define_method(:initialize) { |**kwargs| super(*members.map { |k| kwargs[k] }) } if keyword_init 10 | class_eval(&block) if block 11 | end 12 | end 13 | end 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/add_group_member.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Add a member 6 | # 7 | # @see https://developers.files.com/#add-a-member Add 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 AddGroupMember 16 | include Command 17 | using BrickFTP::CoreExt::Struct 18 | using BrickFTP::CoreExt::Hash 19 | 20 | Params = Struct.new( 21 | 'AddGroupMemberParams', 22 | :admin, 23 | keyword_init: true 24 | ) 25 | 26 | # Adds a user to a group. 27 | # 28 | # - By default, the member will not be an admin. 29 | # - If the user is already a member of the group, their attributes will be updated to match the request. 30 | # 31 | # @param [Integer] group_id ID of the group the membership is associated with. 32 | # @param [Integer] user_id ID of the user the membership is associated with. 33 | # @param [BrickFTP::RESTfulAPI::AddGroupMember::Params] params parameters 34 | # @return [BrickFTP::Types::GroupMembership] group membership 35 | # @raise [BrickFTP::RESTfulAPI::Error] exception 36 | # 37 | def call(group_id, user_id, params) 38 | res = client.put("/api/rest/v1/groups/#{group_id}/memberships/#{user_id}.json", membership: params.to_h.compact) 39 | 40 | BrickFTP::Types::GroupMembership.new(**res.symbolize_keys) 41 | end 42 | end 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/command.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | module Command 6 | def self.included(klass) 7 | klass.class_eval do 8 | attr_reader :client 9 | end 10 | end 11 | 12 | # Initialize command. 13 | # 14 | # @param [BrickFTP::RESTfulAPI::Client] client RESTful API client. 15 | # 16 | def initialize(client) 17 | @client = client 18 | end 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/complete_upload.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'erb' 4 | 5 | module BrickFTP 6 | module RESTfulAPI 7 | # Completing an upload 8 | # 9 | # @see https://developers.files.com/#completing-an-upload Completing an upload 10 | # 11 | # ### Params 12 | # 13 | # PARAMETER | TYPE | DESCRIPTION 14 | # --------- | ------- | ----------- 15 | # ref | string | Unique identifier to reference this file upload. This identifier is needed for subsequent requests to the REST API to complete the upload or request more upload URLs. 16 | # 17 | class CompleteUpload 18 | include Command 19 | using BrickFTP::CoreExt::Struct 20 | using BrickFTP::CoreExt::Hash 21 | 22 | Params = Struct.new( 23 | 'CompleteUploadParams', 24 | :ref, 25 | keyword_init: true 26 | ) 27 | 28 | # After uploading the file to the file storage environment, 29 | # the REST API needs to be notified that the upload was completed. 30 | # 31 | # This is done by sending another POST request to `/files/PATH_AND_FILENAME.EXT` with 32 | # parameter `action` set to end and parameter `ref` set to the reference ID returned at the start of the upload. 33 | # 34 | # @param [String] path Full path of the file or folder. Maximum of 550 characters. 35 | # @param [BrickFTP::RESTfulAPI::CompleteUpload::Params] params parameters 36 | # @return [BrickFTP::Types::File] File object 37 | # @raise [BrickFTP::RESTfulAPI::Error] exception 38 | # 39 | def call(path, params) 40 | res = client.post("/api/rest/v1/files/#{ERB::Util.url_encode(path)}", params.to_h.compact.merge(action: 'end')) 41 | 42 | BrickFTP::Types::File.new(**res.symbolize_keys) 43 | end 44 | end 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/continue_upload.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'erb' 4 | 5 | module BrickFTP 6 | module RESTfulAPI 7 | # Requesting additional upload URLs 8 | # 9 | # @see https://developers.files.com/#requesting-additional-upload-urls Requesting additional upload URLs 10 | # 11 | # ### Params 12 | # 13 | # PARAMETER | TYPE | DESCRIPTION 14 | # --------- | ------- | ----------- 15 | # ref | string | Unique identifier to reference this file upload. This identifier is needed for subsequent requests to the REST API to complete the upload or request more upload URLs. 16 | # part | integer | part number of multi part uploads. 17 | # 18 | class ContinueUpload 19 | include Command 20 | using BrickFTP::CoreExt::Struct 21 | using BrickFTP::CoreExt::Hash 22 | 23 | Params = Struct.new( 24 | 'ContinueUploadParams', 25 | :ref, 26 | :part, 27 | keyword_init: true 28 | ) 29 | 30 | # Once an upload has been opened and before it is completed, 31 | # additional upload URLs can be requested from the REST API. 32 | # 33 | # Send a POST request to `/files/PATH_AND_FILENAME.EXT` with parameter `action` set to `put`, parameter `ref` set to 34 | # the reference ID returned at the start of the upload, and parameter `part` set to the part number the upload URL 35 | # should refer to. The part number can be the same as one previously used if a new URL is required, either 36 | # because the part is to be re-uploaded or because a prior upload attempt failed and the prior URL's signature 37 | # has expired. 38 | # 39 | # @param [String] path Full path of the file or folder. Maximum of 550 characters. 40 | # @param [BrickFTP::RESTfulAPI::ContinueUpload::Params] params parameters 41 | # @return [BrickFTP::Types::Upload] Upload object 42 | # 43 | def call(path, params) 44 | res = client.post("/api/rest/v1/files/#{ERB::Util.url_encode(path)}", params.to_h.compact.merge(action: 'put')) 45 | 46 | BrickFTP::Types::Upload.new(**res.symbolize_keys) 47 | end 48 | end 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/copy_folder.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'erb' 4 | 5 | module BrickFTP 6 | module RESTfulAPI 7 | # Copy a file or folder 8 | # 9 | # @see https://developers.files.com/#copy-a-file-or-folder Copy a file or folder 10 | # 11 | # ### Params 12 | # 13 | # PARAMETER | TYPE | DESCRIPTION 14 | # ---------------- | ------ | ----------- 15 | # copy-destination | string | Full path of the file or folder. Maximum of 550 characters. 16 | # structure | any | Optionally, provide the parameter `structure` and set it to any value to only copy the folder structure without copying any files. 17 | # 18 | class CopyFolder 19 | include Command 20 | using BrickFTP::CoreExt::Struct 21 | using BrickFTP::CoreExt::Hash 22 | 23 | Params = Struct.new( 24 | 'CopyFolderParams', 25 | :'copy-destination', 26 | :structure, 27 | keyword_init: true 28 | ) 29 | 30 | # Copies a file or folder to the destination provided in the 31 | # `copy-destination` parameter in the request body. 32 | # Note that a copy will fail if the destination already exists. 33 | # 34 | # Optionally, provide the parameter `structure` and set it to any value 35 | # to only copy the folder structure without copying any files. 36 | # 37 | # @param [String] path Full path of the file or folder. Maximum of 550 characters. 38 | # @param [BrickFTP::RESTfulAPI::CopyFolder::Params] params parameters 39 | # 40 | def call(path, params) 41 | client.post("/api/rest/v1/files/#{ERB::Util.url_encode(path)}", params.to_h.compact) 42 | true 43 | end 44 | end 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/count_folder_contents.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'erb' 4 | 5 | module BrickFTP 6 | module RESTfulAPI 7 | # Count folder contents 8 | # 9 | # @see https://developers.files.com/#count-folder-contents-recursively Count folder contents recursively 10 | # @see https://developers.files.com/#count-folder-contents-non-recursively Count folder contents non-recursively 11 | # 12 | class CountFolderContents 13 | include Command 14 | using BrickFTP::CoreExt::Hash 15 | 16 | # Returns number of files and folders. 17 | # 18 | # - Returns the combined total number of files and subfolders in a given folder recursively. 19 | # - Returns the number of files and folders, separately, located inside a given folder (non-recursively). 20 | # 21 | # @param [String] path 22 | # @param [Boolean] recursive 23 | # @return [BrickFTP::Types::FolderContentsCount] count 24 | # 25 | def call(path, recursive: false) 26 | action = recursive ? 'count' : 'count_nrs' 27 | res = client.get("/api/rest/v1/folders/#{ERB::Util.url_encode(path)}?action=#{action}") 28 | 29 | if recursive 30 | BrickFTP::Types::FolderContentsCount.new(total: res['data']['count']) 31 | else 32 | BrickFTP::Types::FolderContentsCount.new(**res['data']['count'].symbolize_keys) 33 | end 34 | end 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/count_users.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Count users 6 | # 7 | # @see https://developers.files.com/#count-users Count users 8 | # 9 | class CountUsers 10 | include Command 11 | 12 | # Returns a count of the number of users for the current site. 13 | # 14 | # @return [Integer] count 15 | # 16 | def call 17 | res = client.get('/api/rest/v1/users.json?action=count') 18 | res['data']['count'] 19 | end 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/create_api_key.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Create an API key 6 | # 7 | # @see https://developers.files.com/#create-an-api-key Create an API key 8 | # 9 | # ### Params 10 | # 11 | # PARAMETER | TYPE | DESCRIPTION 12 | # -------------- | -------- | ----------- 13 | # name | string | Name to identify the user API key. For your reference. Maximum of 100 characters. 14 | # permission_set | string | The permission set for the user API key. Can be desktop_app or full. 15 | # platform | string | The platform for the user API key. Can be win32, macos, linux, or none. Applies only to API keys with a permission_set of desktop_app. 16 | # expires_at | datetime | The date that this API key is valid through. 17 | # 18 | class CreateAPIKey 19 | include Command 20 | using BrickFTP::CoreExt::Struct 21 | using BrickFTP::CoreExt::Hash 22 | 23 | Params = Struct.new( 24 | 'CreateAPIKeyParams', 25 | :name, 26 | :permission_set, 27 | :platform, 28 | :expires_at, 29 | keyword_init: true 30 | ) 31 | 32 | # Creates a new API key for a user on the current site. 33 | # 34 | # @param [Integer] id Globally unique identifier of each user. 35 | # Each user is given an ID automatically upon creation. 36 | # @param [BrickFTP::RESTfulAPI::CreateAPIKey::Params] params parameters for creating an API key 37 | # @return [BrickFTP::Types::UserAPIKey] User's API key 38 | # 39 | def call(id, params) 40 | res = client.post("/api/rest/v1/users/#{id}/api_keys.json", params.to_h.compact) 41 | 42 | BrickFTP::Types::UserAPIKey.new(**res.symbolize_keys) 43 | end 44 | end 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/create_behavior.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Create a behavior 6 | # 7 | # @see https://developers.files.com/#create-a-behavior Create a behavior 8 | # 9 | # ### Params 10 | # 11 | # PARAMETER | TYPE | DESCRIPTION 12 | # --------- | ------ | ----------- 13 | # path | string | Folder path for behaviors. This must be slash-delimited, but it must neither start nor end with a slash. Maximum of 5000 characters. 14 | # behavior | string | The behavior type. Can be one of the following: webhook, file_expiration, auto_encrypt, lock_subfolders. 15 | # value | array | Array of values associated with the behavior. 16 | # 17 | class CreateBehavior 18 | include Command 19 | using BrickFTP::CoreExt::Struct 20 | using BrickFTP::CoreExt::Hash 21 | 22 | Params = Struct.new( 23 | 'CreateBehaviorParams', 24 | :path, 25 | :behavior, 26 | :value, 27 | keyword_init: true 28 | ) 29 | 30 | # Creates a new behavior. 31 | # 32 | # @param [BrickFTP::RESTfulAPI::CreateBehavior::Params] params parameters 33 | # @return [BrickFTP::Types::Behavior] Behavior 34 | # 35 | def call(params) 36 | res = client.post('/api/rest/v1/behaviors.json', params.to_h.compact) 37 | 38 | BrickFTP::Types::Behavior.new(**res.symbolize_keys) 39 | end 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/create_bundle.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Create a bundle 6 | # 7 | # @see https://developers.files.com/#create-a-bundle Create a bundle 8 | # 9 | # ### Params 10 | # 11 | # PARAMETER | TYPE | DESCRIPTION 12 | # --------- | ------ | ----------- 13 | # paths | array | List of the paths associated with the bundle. 14 | # password | string | Optional password to password-protect the bundle. This property is write-only. It cannot be retrieved via the API. 15 | # 16 | class CreateBundle 17 | include Command 18 | using BrickFTP::CoreExt::Struct 19 | using BrickFTP::CoreExt::Hash 20 | 21 | Params = Struct.new( 22 | 'CreateBundleParams', 23 | :paths, 24 | :password, 25 | keyword_init: true 26 | ) 27 | 28 | # Creates a new group on the current site. 29 | # 30 | # @param [BrickFTP::RESTfulAPI::CreateBundle::Params] params parameters 31 | # @return [BrickFTP::Types::Bundle] Bundle 32 | # 33 | def call(params) 34 | res = client.post('/api/rest/v1/bundles.json', params.to_h.compact) 35 | 36 | BrickFTP::Types::Bundle.new(**res.symbolize_keys) 37 | end 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/create_folder.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'erb' 4 | 5 | module BrickFTP 6 | module RESTfulAPI 7 | # Create a folder 8 | # 9 | # @see https://developers.files.com/#create-a-folder Create a folder 10 | # 11 | class CreateFolder 12 | include Command 13 | 14 | # Creates a folder. 15 | # 16 | # @param [String] path 17 | # @return [BrickFTP::Types::Folder] Folders 18 | # 19 | def call(path) 20 | client.post("/api/rest/v1/folders/#{ERB::Util.url_encode(path)}") 21 | true 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/create_group.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Create a group 6 | # 7 | # @see https://developers.files.com/#create-a-group Create 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 CreateGroup 18 | include Command 19 | using BrickFTP::CoreExt::Struct 20 | using BrickFTP::CoreExt::Hash 21 | 22 | Params = Struct.new( 23 | 'CreateGroupParams', 24 | :name, 25 | :notes, 26 | :user_ids, 27 | keyword_init: true 28 | ) 29 | 30 | # Creates a new group on the current site. 31 | # 32 | # @param [BrickFTP::RESTfulAPI::CreateGroup::Params] params parameters for creating a Group 33 | # @return [BrickFTP::Types::Group] created Group 34 | # 35 | def call(params) 36 | res = client.post('/api/rest/v1/groups.json', params.to_h.compact) 37 | 38 | BrickFTP::Types::Group.new(**res.symbolize_keys) 39 | end 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/create_notification.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Create a notification 6 | # 7 | # @see https://developers.files.com/#create-a-notification Create a notification 8 | # 9 | # ### Params 10 | # 11 | # PARAMETER | TYPE | DESCRIPTION 12 | # ------------- | ------- | ----------- 13 | # path | string | Folder path for notifications. This must be slash-delimited, but it must neither start nor end with a slash. Maximum of 5000 characters. 14 | # user_id | integer | Unique identifier for the user being notified. Each user is given an ID automatically upon creation. You can look up user IDs by using the User resource of this REST API. 15 | # username | string | Username for the user given by user_id. If this value is set during creation and user_id is not set, the user_id is looked up from the username and set. Maximum of 50 characters. 16 | # send_interval | string | The send interval for notifications. Can be one of the following: five_minutes (default), fifteen_minutes, hourly, daily. 17 | # 18 | class CreateNotification 19 | include Command 20 | using BrickFTP::CoreExt::Struct 21 | using BrickFTP::CoreExt::Hash 22 | 23 | Params = Struct.new( 24 | 'CreateNotificationParams', 25 | :path, 26 | :user_id, 27 | :username, 28 | :send_interval, 29 | keyword_init: true 30 | ) 31 | 32 | # Creates a new notification on the current site. 33 | # 34 | # @param [BrickFTP::RESTfulAPI::CreateNotification::Params] params parameters 35 | # @return [BrickFTP::Types::Notification] Notification 36 | # 37 | def call(params) 38 | res = client.post('/api/rest/v1/notifications.json', params.to_h.compact) 39 | 40 | BrickFTP::Types::Notification.new(**res.symbolize_keys) 41 | end 42 | end 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/create_permission.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Create a permission 6 | # 7 | # @see https://developers.files.com/#create-a-permission Create a permission 8 | # 9 | # ### Params 10 | # 11 | # PARAMETER | TYPE | DESCRIPTION 12 | # ---------- | ------- | ----------- 13 | # user_id | integer | Unique identifier for the user being granted a permission. Each user is given an ID automatically upon creation. The user_id and group_id fields cannot both be set. 14 | # username | string | Username for the user, if user_id is set. If this value is set during creation and user_id is not set, the user_id is looked up from the username and set. Maximum of 50 characters. 15 | # group_id | integer | Unique identifier for the group being granted a permission. Each group is given an ID automatically upon creation. The user_id and group_id fields cannot both be set. 16 | # path | string | Folder path for the permission to apply to. This must be slash-delimited, but it must neither start nor end with a slash. Maximum of 5000 characters. 17 | # permission | enum | Value must be set to full, readonly, writeonly, previewonly, or history, depending on the type of access to be granted by the Permission. 18 | # recursive | boolean | If set to false, the permission will be non-recursive, and will not apply to subfolders of the folder specified by the path property. Default is true. 19 | # 20 | class CreatePermission 21 | include Command 22 | using BrickFTP::CoreExt::Struct 23 | using BrickFTP::CoreExt::Hash 24 | 25 | Params = Struct.new( 26 | 'CreatePermissionParams', 27 | :user_id, 28 | :username, 29 | :group_id, 30 | :path, 31 | :permission, 32 | :recursive, 33 | keyword_init: true 34 | ) 35 | 36 | # Creates a new permission record. 37 | # 38 | # @param [BrickFTP::RESTfulAPI::CreatePermission::Params] params parameters 39 | # @return [BrickFTP::Types::Permission] Permissions 40 | # 41 | def call(params) 42 | res = client.post('/api/rest/v1/permissions.json', params.to_h.compact) 43 | 44 | BrickFTP::Types::Permission.new(**res.symbolize_keys) 45 | end 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/create_public_key.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Create a public key 6 | # 7 | # @see https://developers.files.com/#create-a-public-key Create a public key 8 | # 9 | # ### Params 10 | # 11 | # PARAMETER | TYPE | DESCRIPTION 12 | # ---------- | ------- | ----------- 13 | # title | string | Title to identify the public key. For your reference. Maximum of 50 characters. 14 | # public_key | string | The public key itself. This property is write-only. It cannot be retrieved via the API. 15 | # 16 | class CreatePublicKey 17 | include Command 18 | using BrickFTP::CoreExt::Struct 19 | using BrickFTP::CoreExt::Hash 20 | 21 | Params = Struct.new( 22 | 'CreatePublicKeyParams', 23 | :title, 24 | :public_key, 25 | keyword_init: true 26 | ) 27 | 28 | # Creates a new public key for a user on the current site. 29 | # 30 | # @param [Integer] id Globally unique identifier of each user. 31 | # Each user is given an ID automatically upon creation. 32 | # @param [BrickFTP::RESTfulAPI::CreatePublicKey::Params] params parameters for creating an Public key 33 | # @return [BrickFTP::Types::UserPublicKey] User's Public key 34 | # 35 | def call(id, params) 36 | res = client.post("/api/rest/v1/users/#{id}/public_keys.json", params.to_h.compact) 37 | 38 | BrickFTP::Types::UserPublicKey.new(**res.symbolize_keys) 39 | end 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/delete_api_key.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Delete an API key 6 | # 7 | # @see https://developers.files.com/#delete-an-api-key Delete an API key 8 | # 9 | class DeleteAPIKey 10 | include Command 11 | 12 | # Deletes the specified API key. 13 | # 14 | # @param [Integer] id Globally unique identifier of each user API key. 15 | # Each user API key is given an ID automatically upon creation. 16 | # 17 | def call(id) 18 | client.delete("/api/rest/v1/api_keys/#{id}.json") 19 | true 20 | end 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/delete_behavior.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Delete a behavior 6 | # 7 | # @see https://developers.files.com/#delete-a-behavior Delete a behavior 8 | # 9 | class DeleteBehavior 10 | include Command 11 | 12 | # Deletes a behavior. 13 | # 14 | # @param [Integer] id Globally unique identifier of each behavior. 15 | # 16 | def call(id) 17 | client.delete("/api/rest/v1/behaviors/#{id}.json") 18 | true 19 | end 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/delete_bundle.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Delete a bundle 6 | # 7 | # @see https://developers.files.com/#delete-a-bundle Delete a bundle 8 | # 9 | class DeleteBundle 10 | include Command 11 | 12 | # Deletes the specified bundle. 13 | # 14 | # @param [Integer] id Globally unique identifier of each bundle. 15 | # 16 | def call(id) 17 | client.delete("/api/rest/v1/bundles/#{id}.json") 18 | true 19 | end 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/delete_folder.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'erb' 4 | 5 | module BrickFTP 6 | module RESTfulAPI 7 | # Delete a file or folder 8 | # 9 | # @see https://developers.files.com/#delete-file-folder Delete file/folder 10 | # 11 | class DeleteFolder 12 | include Command 13 | 14 | # Deletes a file or folder. 15 | # 16 | # > If true, will recursively delete folers. Otherwise, will error on non-empty folders. 17 | # 18 | # @param [String] path Full path of the file or folder. Maximum of 550 characters. 19 | # @param [Boolean] recursive 20 | # 21 | def call(path, recursive: false) 22 | url = "/api/rest/v1/files/#{ERB::Util.url_encode(path)}" 23 | url += '?recursive=true' if recursive 24 | 25 | client.delete(url) 26 | true 27 | end 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/delete_group.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Delete a group 6 | # 7 | # @see https://developers.files.com/#delete-a-group Delete a group 8 | # 9 | class DeleteGroup 10 | include Command 11 | 12 | # Deletes the specified group. 13 | # 14 | # @param [Integer] id Globally unique identifier of each group. 15 | # Each group is given an ID automatically upon creation. 16 | # 17 | def call(id) 18 | client.delete("/api/rest/v1/groups/#{id}.json") 19 | true 20 | end 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/delete_notification.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Delete a notification 6 | # 7 | # @see https://developers.files.com/#delete-a-notification Delete a notification 8 | # 9 | class DeleteNotification 10 | include Command 11 | 12 | # Deletes the specified notification. 13 | # 14 | # @param [Integer] id Globally unique identifier of each notification. 15 | # Each notification is given an ID automatically upon creation. 16 | # 17 | def call(id) 18 | client.delete("/api/rest/v1/notifications/#{id}.json") 19 | true 20 | end 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/delete_permission.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Delete a permission 6 | # 7 | # @see https://developers.files.com/#delete-a-permission Delete a permission 8 | # 9 | class DeletePermission 10 | include Command 11 | 12 | # Deletes the specified group. 13 | # 14 | # @param [Integer] id Globally unique identifier of each permission. 15 | # Each permission is given an ID automatically upon creation. 16 | # 17 | def call(id) 18 | client.delete("/api/rest/v1/permissions/#{id}.json") 19 | true 20 | end 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/delete_public_key.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Delete a public key 6 | # 7 | # @see https://developers.files.com/#delete-a-public-key Delete a public key 8 | # 9 | class DeletePublicKey 10 | include Command 11 | 12 | # Deletes the specified public key. 13 | # 14 | # @param [Integer] id Globally unique identifier of each public key. 15 | # Each public key is given an ID automatically upon creation. 16 | # 17 | def call(id) 18 | client.delete("/api/rest/v1/public_keys/#{id}.json") 19 | true 20 | end 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/delete_user.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Delete a user 6 | # 7 | # @see https://developers.files.com/#delete-a-user Delete a user 8 | # 9 | class DeleteUser 10 | include Command 11 | 12 | # Deletes the specified user. 13 | # 14 | # For additional security, this method requires reauthentication when updating a password unless an API key is used. 15 | # 16 | # @param [Integer] id Globally unique identifier of each user. 17 | # Each user is given an ID automatically upon creation. 18 | # 19 | def call(id) 20 | client.delete("/api/rest/v1/users/#{id}.json") 21 | true 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/download_file.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Download a file 6 | # 7 | # @see https://developers.files.com/#download-a-file Download a file 8 | # 9 | # ### Params 10 | # 11 | # PARAMETER | TYPE | DESCRIPTION 12 | # --------- | -------- | ----------- 13 | # action | string | Optionally set to `stat` to have the `download_uri` field omitted in the response and no download action logged. 14 | # 15 | class DownloadFile 16 | include Command 17 | using BrickFTP::CoreExt::Hash 18 | 19 | # Provides a download URL that will enable you to download a file. 20 | # 21 | # The download URL is a direct URL to Amazon S3 that has been signed by BrickFTP to provide temporary 22 | # access to the file. The download links are valid for 3 minutes. 23 | # 24 | # By default this request assumes that the file will be downloaded, and therefore a download action is 25 | # logged for the user that is logged into the REST API session. If downloading the file is not desired, 26 | # but rather one is just looking at the information associated with the file such as the MD5 checksum or 27 | # file size, then the action query parameter can be passed in on the URL with the value of stat. 28 | # This causes the download_uri field to be omitted in the response and no download action to be logged. 29 | # 30 | # @param [String] path Full path of the file or folder. Maximum of 550 characters. 31 | # @param [Boolean] stat Optionally set to stat to have the `download_uri` field 32 | # omitted in the response and no download action logged. 33 | # @return [BrickFTP::Types::File] File 34 | # 35 | def call(path, stat: false) 36 | endpoint = "/api/rest/v1/files/#{ERB::Util.url_encode(path)}" 37 | endpoint = "#{endpoint}?action=stat" if stat 38 | res = client.get(endpoint) 39 | return nil if !res || res.empty? 40 | 41 | BrickFTP::Types::File.new(**res.symbolize_keys) 42 | end 43 | end 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/get_api_key.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Show an API key 6 | # 7 | # @see https://developers.files.com/#show-an-api-key Show an API key 8 | # 9 | class GetAPIKey 10 | include Command 11 | using BrickFTP::CoreExt::Hash 12 | 13 | # Returns a single API key. 14 | # 15 | # @param [Integer] id Globally unique identifier of each user API key. 16 | # Each user API key is given an ID automatically upon creation. 17 | # @return [BrickFTP::Types::UserAPIKey] User's API key 18 | # 19 | def call(id) 20 | res = client.get("/api/rest/v1/api_keys/#{id}.json") 21 | 22 | BrickFTP::Types::UserAPIKey.new(**res.symbolize_keys) 23 | end 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/get_behavior.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Show a behavior 6 | # 7 | # @see https://developers.files.com/#show-a-behavior Show a behavior 8 | # 9 | class GetBehavior 10 | include Command 11 | using BrickFTP::CoreExt::Hash 12 | 13 | # Returns a single behavior. 14 | # 15 | # @param [Integer] id Globally unique identifier of each behavior. 16 | # @return [BrickFTP::Types::Behavior, nil] found Behavior or nil 17 | # 18 | def call(id) 19 | res = client.get("/api/rest/v1/behaviors/#{id}.json") 20 | return nil if !res || res.empty? 21 | 22 | BrickFTP::Types::Behavior.new(**res.symbolize_keys) 23 | end 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/get_bundle.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Show a bundle 6 | # 7 | # @see https://developers.files.com/#show-a-bundle Show a bundle 8 | # 9 | class GetBundle 10 | include Command 11 | using BrickFTP::CoreExt::Hash 12 | 13 | # Returns a single bundle. 14 | # 15 | # @param [Integer] id Globally unique identifier of each bundle. 16 | # @return [BrickFTP::Types::Bundle] Bundle 17 | # 18 | def call(id) 19 | res = client.get("/api/rest/v1/bundles/#{id}.json") 20 | return nil if !res || res.empty? 21 | 22 | BrickFTP::Types::Bundle.new(**res.symbolize_keys) 23 | end 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/get_bundle_zip.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Download entire bundle as ZIP 6 | # 7 | # @see https://developers.files.com/#download-entire-bundle-as-zip Download entire bundle as ZIP 8 | # 9 | # ### Params 10 | # 11 | # PARAMETER | TYPE | DESCRIPTION 12 | # --------- | ------ | ----------- 13 | # code, | string | Unique code string identifier for the bundle. 14 | # password | string | Optional password to password-protect the bundle. This property is write-only. It cannot be retrieved via the API. 15 | # 16 | class GetBundleZip 17 | include Command 18 | using BrickFTP::CoreExt::Struct 19 | using BrickFTP::CoreExt::Hash 20 | 21 | Params = Struct.new( 22 | 'GetBundleZipParams', 23 | :code, 24 | :password, 25 | keyword_init: true 26 | ) 27 | 28 | # Provides a download URL that will enable you to download all the files in a bundle as a single ZIP. 29 | # 30 | # The download URLs can be downloaded using an HTTP GET to the same hostname providing the download_uri 31 | # as the URL path. This will be routed by our frontend proxies to our ZIP server that will stream the ZIP. 32 | # The ZIP download link is valid for 3 minutes. 33 | # 34 | # The password parameter is required only for bundles that are password-protected. 35 | # If a bundle is password-protected and the password is missing or incorrect, an error message will 36 | # specify that the correct password is required. 37 | # 38 | # @param [BrickFTP::RESTfulAPI::GetFileInBundle::Params] params parameters 39 | # @return [BrickFTP::Types::BundleZip] BundleZip 40 | # 41 | def call(params) 42 | res = client.post('/api/rest/v1/bundles/zip.json', params.to_h.compact) 43 | 44 | BrickFTP::Types::BundleZip.new(**res.symbolize_keys) 45 | end 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/get_file_in_bundle.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Download one file in a bundle 6 | # 7 | # @see https://developers.files.com/#download-one-file-in-a-bundle Download one file in a bundle 8 | # 9 | # ### Params 10 | # 11 | # PARAMETER | TYPE | DESCRIPTION 12 | # --------- | ------ | ----------- 13 | # code | string | Unique code string identifier for the bundle. 14 | # path | string | 15 | # password | string | Optional password to password-protect the bundle. This property is write-only. It cannot be retrieved via the API. 16 | # 17 | class GetFileInBundle 18 | include Command 19 | using BrickFTP::CoreExt::Struct 20 | using BrickFTP::CoreExt::Hash 21 | 22 | Params = Struct.new( 23 | 'GetFileInBundleParams', 24 | :code, 25 | :path, 26 | :password, 27 | keyword_init: true 28 | ) 29 | 30 | # Provides a download URL to download a single file in the bundle. 31 | # 32 | # The download URL is a direct URL to Amazon S3 that has been signed by BrickFTP to provide temporary access to the 33 | # file. The download links are valid for 3 minutes. For details on the attributes in the response body from this 34 | # endpoint, please see The file object. 35 | # 36 | # The password parameter is required only for bundles that are password-protected. If a bundle is password-protected 37 | # and the password is missing or incorrect, an error message will specify that the correct password is required. 38 | # 39 | # @param [BrickFTP::RESTfulAPI::GetFileInBundle::Params] params parameters 40 | # @return [BrickFTP::Types::FileInBundle] FileInBundle 41 | # 42 | def call(params) 43 | res = client.post('/api/rest/v1/bundles/download.json', params.to_h.compact) 44 | 45 | BrickFTP::Types::FileInBundle.new(**res.symbolize_keys) 46 | end 47 | end 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/get_folder_size.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'erb' 4 | 5 | module BrickFTP 6 | module RESTfulAPI 7 | # Get folder size 8 | # 9 | # @see https://developers.files.com/#get-folder-size Get folder size 10 | # 11 | class GetFolderSize 12 | include Command 13 | 14 | # Returns the size (in bytes) of the specified folder, recursively. 15 | # 16 | # @param [String] path 17 | # @return [Integer] 18 | # 19 | def call(path) 20 | res = client.get("/api/rest/v1/folders/#{ERB::Util.url_encode(path)}?action=size") 21 | res['data']['size'] 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/get_group.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Show a group 6 | # 7 | # @see https://developers.files.com/#show-a-group Show a group 8 | # 9 | class GetGroup 10 | include Command 11 | using BrickFTP::CoreExt::Hash 12 | 13 | # Returns a single group. 14 | # 15 | # @param [Integer] id Globally unique identifier of each group. 16 | # Each group is given an ID automatically upon creation. 17 | # @return [BrickFTP::Types::Group, nil] found Group or nil 18 | # 19 | def call(id) 20 | res = client.get("/api/rest/v1/groups/#{id}.json") 21 | return nil if !res || res.empty? 22 | 23 | BrickFTP::Types::Group.new(**res.symbolize_keys) 24 | end 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/get_public_key.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Show a public key 6 | # 7 | # @see https://developers.files.com/#show-a-public-key Show a public key 8 | # 9 | class GetPublicKey 10 | include Command 11 | using BrickFTP::CoreExt::Hash 12 | 13 | # Returns a single public key. 14 | # 15 | # @param [Integer] id Globally unique identifier of each public key. 16 | # Each public key is given an ID automatically upon creation. 17 | # @return [BrickFTP::Types::UserPublicKey] User's Public key 18 | # 19 | def call(id) 20 | res = client.get("/api/rest/v1/public_keys/#{id}.json") 21 | 22 | BrickFTP::Types::UserPublicKey.new(**res.symbolize_keys) 23 | end 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/get_site_usage.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | class GetSiteUsage 6 | include Command 7 | using BrickFTP::CoreExt::Hash 8 | 9 | # Returns site usage 10 | # 11 | # @return [BrickFTP::Types::SiteUsage] site usage 12 | # 13 | def call 14 | res = client.get('/api/rest/v1/site/usage.json') 15 | 16 | BrickFTP::Types::SiteUsage.new(**res.symbolize_keys) 17 | end 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/get_user.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Show a user 6 | # 7 | # @see https://developers.files.com/#show-a-user Show a user 8 | # 9 | class GetUser 10 | include Command 11 | using BrickFTP::CoreExt::Hash 12 | 13 | # Returns a single user. 14 | # 15 | # @param [Integer] id Globally unique identifier of each user. 16 | # Each user is given an ID automatically upon creation. 17 | # @return [BrickFTP::Types::User, nil] found User or nil 18 | # 19 | def call(id) 20 | res = client.get("/api/rest/v1/users/#{id}.json") 21 | return nil if !res || res.empty? 22 | 23 | BrickFTP::Types::User.new(**res.symbolize_keys) 24 | end 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/list_api_keys.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # List API keys 6 | # 7 | # @see https://developers.files.com/#list-api-keys List API keys 8 | # 9 | class ListAPIKeys 10 | include Command 11 | using BrickFTP::CoreExt::Hash 12 | 13 | # Returns a list of all API keys for a user on the current site. 14 | # 15 | # @param [Integer] id Globally unique identifier of each user. 16 | # Each user is given an ID automatically upon creation. 17 | # @return [Array] User's API keys 18 | # 19 | def call(id) 20 | res = client.get("/api/rest/v1/users/#{id}/api_keys.json") 21 | 22 | res.map { |i| BrickFTP::Types::UserAPIKey.new(**i.symbolize_keys) } 23 | end 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/list_behaviors.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # List all behaviors 6 | # 7 | # @see https://developers.files.com/#list-all-behaviors List all behaviors 8 | # 9 | class ListBehaviors 10 | include Command 11 | using BrickFTP::CoreExt::Hash 12 | 13 | # Returns a list of all behaviors on the current site. 14 | # 15 | # @return [Array] Behaviors 16 | # 17 | def call 18 | res = client.get('/api/rest/v1/behaviors.json') 19 | 20 | res.map { |i| BrickFTP::Types::Behavior.new(**i.symbolize_keys) } 21 | end 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/list_bundle_contents.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'erb' 4 | 5 | module BrickFTP 6 | module RESTfulAPI 7 | # List bundle contents 8 | # 9 | # @see https://developers.files.com/#list-bundle-contents List bundle contents 10 | # 11 | # ### Params 12 | # 13 | # PARAMETER | TYPE | DESCRIPTION 14 | # --------- | ------ | ----------- 15 | # code | string | Unique code string identifier for the bundle. 16 | # password | string | Optional password to password-protect the bundle. This property is write-only. It cannot be retrieved via the API. 17 | # 18 | class ListBundleContents 19 | include Command 20 | using BrickFTP::CoreExt::Struct 21 | using BrickFTP::CoreExt::Hash 22 | 23 | Params = Struct.new( 24 | 'ListBundleContentsParams', 25 | :code, 26 | :password, 27 | keyword_init: true 28 | ) 29 | 30 | # This unauthenticated (public) endpoint lists the contents of a bundle. 31 | # 32 | # When no path is specified, the contents of the root of the bundle will be listed. The contents of a subfolder 33 | # can be listed by providing its path in the URL after /contents, for example: /bundles/contents/cloud/images. 34 | # Alternatively, you can provide path as a parameter in the request body instead of in the URL. 35 | # 36 | # This endpoint only reveals the public part of the file paths (i.e. relative to the root of the bundle). 37 | # To view the full path of included files, use the authenticated Show Bundle endpoint above. 38 | # 39 | # The password parameter is required only for bundles that are password-protected. If a bundle is password-protected 40 | # and the password is missing or incorrect, an error message will specify that the correct password is required. 41 | # 42 | # @param [String, nil] path 43 | # @param [BrickFTP::RESTfulAPI::ListBundleContents::Params] params parameters 44 | # @return [Array] BundleContent 45 | # 46 | def call(params, path: nil) 47 | endpoint = if path 48 | "/api/rest/v1/bundles/contents/#{ERB::Util.url_encode(path)}" 49 | else 50 | '/api/rest/v1/bundles/contents.json' 51 | end 52 | res = client.post(endpoint, params.to_h.compact) 53 | 54 | res.map { |i| BrickFTP::Types::BundleContent.new(**i.symbolize_keys) } 55 | end 56 | end 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/list_bundles.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # List all bundles 6 | # 7 | # @see https://developers.files.com/#list-all-bundles List all bundles 8 | # 9 | class ListBundles 10 | include Command 11 | using BrickFTP::CoreExt::Hash 12 | 13 | # Returns a list of all bundles on the current site. 14 | # 15 | # @return [Array] Bundle 16 | # 17 | def call 18 | res = client.get('/api/rest/v1/bundles.json') 19 | 20 | res.map { |i| BrickFTP::Types::Bundle.new(**i.symbolize_keys) } 21 | end 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/list_folder_behaviors.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'erb' 4 | 5 | module BrickFTP 6 | module RESTfulAPI 7 | # List behaviors for a folder 8 | # 9 | # @see https://developers.files.com/#list-behaviors-for-a-folder List behaviors for a folder 10 | # 11 | # ### Params 12 | # 13 | # PARAMETER | TYPE | DESCRIPTION 14 | # --------- | -------- | ----------- 15 | # recursive | integer | Optionally set to 1 to have response include behaviors inherited from parent folders. 16 | # 17 | class ListFolderBehaviors 18 | include Command 19 | using BrickFTP::CoreExt::Hash 20 | 21 | # Returns the behaviors that apply to the given path. 22 | # 23 | # By default, only behaviors applied directly on the the given path will be returned. 24 | # If you would also like behaviors that are inherited from parent folders to be returned, 25 | # the recursive query parameter can be passed in on the URL with the value of 1. 26 | # 27 | # @param [String] path 28 | # @param [Boolean] recursive 29 | # @return [Array] Behaviors 30 | # 31 | def call(path, recursive: false) 32 | endpoint = "/api/rest/v1/behaviors/folders/#{ERB::Util.url_encode(path)}" 33 | endpoint = "#{endpoint}?recursive=1" if recursive 34 | res = client.get(endpoint) 35 | 36 | res.map { |i| BrickFTP::Types::Behavior.new(**i.symbolize_keys) } 37 | end 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/list_groups.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # List all groups 6 | # 7 | # @see https://developers.files.com/#list-all-groups List all groups 8 | # 9 | class ListGroups 10 | include Command 11 | using BrickFTP::CoreExt::Hash 12 | 13 | # Returns a list of all groups on the current site. 14 | # 15 | # @return [Array] Groups 16 | # 17 | def call 18 | res = client.get('/api/rest/v1/groups.json') 19 | 20 | res.map { |i| BrickFTP::Types::Group.new(**i.symbolize_keys) } 21 | end 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/list_notifications.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # List all notifications 6 | # 7 | # @see https://developers.files.com/#list-all-notifications List all notifications 8 | # 9 | class ListNotifications 10 | include Command 11 | using BrickFTP::CoreExt::Hash 12 | 13 | # Returns a list of all notifications on the current site. 14 | # 15 | # @return [Array] Notifications 16 | # 17 | def call 18 | res = client.get('/api/rest/v1/notifications.json') 19 | 20 | res.map { |i| BrickFTP::Types::Notification.new(**i.symbolize_keys) } 21 | end 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/list_permissions.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'erb' 4 | 5 | module BrickFTP 6 | module RESTfulAPI 7 | # List permissions 8 | # 9 | # @see https://developers.files.com/#list-permissions List permissions 10 | # 11 | # ### Params 12 | # 13 | # PARAMETER | TYPE | DESCRIPTION 14 | # --------- | ------ | ----------- 15 | # path | string | Optional path to focus the result set on. 16 | # 17 | class ListPermissions 18 | include Command 19 | using BrickFTP::CoreExt::Hash 20 | 21 | # Returns a list of permissions on the current site. 22 | # 23 | # - By default all permissions for the entire site are returned. 24 | # - When given a path parameter, then only permissions immediately relevant to the given path are returned. 25 | # - When using a path parameter, the result will include permissions on the current path and recursive 26 | # permissions that are inherited from parent paths, except that lesser permissions will be excluded 27 | # if a greater permission applies on the given path for a particular user or group. 28 | # 29 | # @param [String] path Folder path for the permission to apply to. This must be slash-delimited, 30 | # but it must neither start nor end with a slash. Maximum of 5000 characters. 31 | # @return [Array] Permissions 32 | # 33 | def call(path: nil) 34 | endpoint = '/api/rest/v1/permissions.json' 35 | endpoint = "#{endpoint}?path=#{ERB::Util.url_encode(path)}" unless path.nil? 36 | res = client.get(endpoint) 37 | 38 | res.map { |i| BrickFTP::Types::Permission.new(**i.symbolize_keys) } 39 | end 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/list_public_keys.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # List public keys 6 | # 7 | # @see https://developers.files.com/#list-public-keys List public keys 8 | # 9 | class ListPublicKeys 10 | include Command 11 | using BrickFTP::CoreExt::Hash 12 | 13 | # Returns a list of all public keys for a user on the current site. 14 | # 15 | # @param [Integer] id Globally unique identifier of each user. 16 | # Each user is given an ID automatically upon creation. 17 | # @return [Array] User's Public keys 18 | # 19 | def call(id) 20 | res = client.get("/api/rest/v1/users/#{id}/public_keys.json") 21 | 22 | res.map { |i| BrickFTP::Types::UserPublicKey.new(**i.symbolize_keys) } 23 | end 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/list_users.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # List users 6 | # 7 | # @see https://developers.files.com/#list-users List users 8 | # 9 | # ### Params 10 | # 11 | # PARAMETER | TYPE | DESCRIPTION 12 | # --------- | ------- | ----------- 13 | # page | integer | Optional page number of items to return in this request. Default: 1. 14 | # per_page | integer | Optional requested number of items returned per request. Default: 1000. Leave blank for default (strongly recommended). 15 | # 16 | class ListUsers 17 | include Command 18 | using BrickFTP::CoreExt::Hash 19 | 20 | # Returns a list of users on the current site. 21 | # 22 | # @param [Integer] page Optional page number of items to return in this request. 23 | # Default: 1. 24 | # @param [Integer] per_page Optional requested number of items returned per request. 25 | # Default: 1000. Leave blank for default (strongly recommended). 26 | # @return [Array] Users 27 | # 28 | def call(page: nil, per_page: nil) 29 | validate_page!(page) 30 | validate_per_page!(per_page) 31 | 32 | params = {} 33 | params[:page] = page if page 34 | params[:per_page] = per_page if per_page 35 | query = params.map { |k, v| "#{k}=#{v}" }.join('&') 36 | 37 | endpoint = '/api/rest/v1/users.json' 38 | endpoint = "#{endpoint}?#{query}" unless query.empty? 39 | res = client.get(endpoint) 40 | 41 | res.map { |i| BrickFTP::Types::User.new(**i.symbolize_keys) } 42 | end 43 | 44 | private 45 | 46 | def validate_page!(page) 47 | return if page.nil? 48 | return if page.is_a?(Integer) && page.positive? 49 | 50 | raise ArgumentError, 'page must be greater than 0.' 51 | end 52 | 53 | def validate_per_page!(per_page) 54 | return if per_page.nil? 55 | return if per_page.is_a?(Integer) && per_page.positive? 56 | 57 | raise ArgumentError, 'per_page must be greater than 0.' 58 | end 59 | end 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/move_folder.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'erb' 4 | 5 | module BrickFTP 6 | module RESTfulAPI 7 | # Move or rename a file or folder 8 | # 9 | # @see https://developers.files.com/#move-or-rename-a-file-or-folder Move or rename a file or folder 10 | # 11 | # ### Params 12 | # 13 | # PARAMETER | TYPE | DESCRIPTION 14 | # ---------------- | ------ | ----------- 15 | # move-destination | string | Full path of the file or folder. Maximum of 550 characters. 16 | # 17 | class MoveFolder 18 | include Command 19 | using BrickFTP::CoreExt::Struct 20 | using BrickFTP::CoreExt::Hash 21 | 22 | Params = Struct.new( 23 | 'MoveFolderParams', 24 | :'move-destination', 25 | keyword_init: true 26 | ) 27 | 28 | # Moves or renames a file or folder to the destination provided in 29 | # the `move-destination` parameter in the request body. 30 | # Note that a move/rename will fail if the destination already exists. 31 | # 32 | # @param [String] path Full path of the file or folder. Maximum of 550 characters. 33 | # @param [BrickFTP::RESTfulAPI::MoveFolder::Params] params parameters 34 | # 35 | def call(path, params) 36 | client.post("/api/rest/v1/files/#{ERB::Util.url_encode(path)}", params.to_h.compact) 37 | true 38 | end 39 | end 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/remove_group_member.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Remove a member 6 | # 7 | # @see https://developers.files.com/#remove-a-member Remove a member 8 | # 9 | class RemoveGroupMember 10 | include Command 11 | 12 | # Removes a user from a group. No action will be taken if the user is not already in the group. 13 | # 14 | # @param [Integer] group_id ID of the group the membership is associated with. 15 | # @param [Integer] user_id ID of the user the membership is associated with. 16 | # 17 | def call(group_id, user_id) 18 | client.delete("/api/rest/v1/groups/#{group_id}/memberships/#{user_id}.json") 19 | true 20 | end 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/retrieve_file_history.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'erb' 4 | 5 | module BrickFTP 6 | module RESTfulAPI 7 | # Retrieve file history 8 | # 9 | # @see https://developers.files.com/#retrieve-file-history Retrieve file history 10 | # 11 | # ### Params 12 | # 13 | # PARAMETER | TYPE | DESCRIPTION 14 | # --------- | -------- | ----------- 15 | # page | integer | Optional page number of items to return in this request. 16 | # per_page | integer | Optional requested number of items returned per request. Default: 1000, maximum: 10000. Leave blank for default (strongly recommended). 17 | # start_at | datetime | Optional date and time in the history to start from. 18 | # 19 | class RetrieveFileHistory 20 | include Command 21 | include RetrieveHistory 22 | using BrickFTP::CoreExt::Hash 23 | 24 | # Returns all history for a specific file. 25 | # 26 | # - The history starts with the most recent entries and proceeds back in time. 27 | # - There is a maximum number of records that will be returned with a single request 28 | # (default 1000 or whatever value you provide as the per_page parameter, up to a maximum of 10,000). 29 | # 30 | # @param [String] path Path of the file or folder associated with the history entry. 31 | # @param [Integer] page Optional page number of items to return in this request. 32 | # @param [Integer] per_page Optional requested number of items returned per request. 33 | # Default: 1000, maximum: 10000. Leave blank for default (strongly recommended). 34 | # @param [Time] start_at Optional date and time in the history to start from. 35 | # @return [Array] History 36 | # 37 | def call(path, page: nil, per_page: nil, start_at: nil) 38 | retrieve("/api/rest/v1/history/files/#{ERB::Util.url_encode(path)}", page, per_page, start_at) 39 | end 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/retrieve_folder_history.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'erb' 4 | 5 | module BrickFTP 6 | module RESTfulAPI 7 | # Retrieve folder history 8 | # 9 | # @see https://developers.files.com/#retrieve-folder-history Retrieve folder history 10 | # 11 | # ### Params 12 | # 13 | # PARAMETER | TYPE | DESCRIPTION 14 | # --------- | -------- | ----------- 15 | # page | integer | Optional page number of items to return in this request. 16 | # per_page | integer | Optional requested number of items returned per request. Default: 1000, maximum: 10000. Leave blank for default (strongly recommended). 17 | # start_at | datetime | Optional date and time in the history to start from. 18 | # 19 | class RetrieveFolderHistory 20 | include Command 21 | include RetrieveHistory 22 | using BrickFTP::CoreExt::Hash 23 | 24 | # Returns all history for a specific folder. 25 | # 26 | # - The history starts with the most recent entries and proceeds back in time. 27 | # - There is a maximum number of records that will be returned with a single request 28 | # (default 1000 or whatever value you provide as the per_page parameter, up to a maximum of 10,000). 29 | # 30 | # @param [String] path Path of the file or folder associated with the history entry. 31 | # @param [Integer] page Optional page number of items to return in this request. 32 | # @param [Integer] per_page Optional requested number of items returned per request. 33 | # Default: 1000, maximum: 10000. Leave blank for default (strongly recommended). 34 | # @param [Time] start_at Optional date and time in the history to start from. 35 | # @return [Array] History 36 | # 37 | def call(path, page: nil, per_page: nil, start_at: nil) 38 | retrieve("/api/rest/v1/history/folders/#{ERB::Util.url_encode(path)}", page, per_page, start_at) 39 | end 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/retrieve_history.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'erb' 4 | 5 | module BrickFTP 6 | module RESTfulAPI 7 | module RetrieveHistory 8 | using BrickFTP::CoreExt::Hash 9 | 10 | def retrieve(path, page, per_page, start_at) 11 | validate_page!(page) 12 | validate_per_page!(per_page) 13 | validate_start_at!(start_at) 14 | 15 | query = build_query(page, per_page, start_at) 16 | endpoint = path 17 | endpoint = "#{path}?#{query}" unless query.empty? 18 | res = client.get(endpoint) 19 | 20 | res.map { |i| BrickFTP::Types::History.new(**i.symbolize_keys) } 21 | end 22 | 23 | def validate_page!(page) 24 | return if page.nil? 25 | return if page.is_a?(Integer) && page.positive? 26 | 27 | raise ArgumentError, 'page must be greater than 0.' 28 | end 29 | 30 | MAX_PER_PAGE = 10_000 31 | 32 | def validate_per_page!(per_page) 33 | return if per_page.nil? 34 | return if per_page.is_a?(Integer) && per_page.positive? && per_page <= MAX_PER_PAGE 35 | 36 | raise ArgumentError, "per_page must be greater than 0 and less than equal #{MAX_PER_PAGE}." 37 | end 38 | 39 | def validate_start_at!(start_at) 40 | return if start_at.nil? 41 | return if start_at.is_a?(Time) 42 | 43 | raise ArgumentError, 'start_at must be a Time.' 44 | end 45 | 46 | def build_query(page, per_page, start_at) 47 | params = {} 48 | params[:page] = page if page 49 | params[:per_page] = per_page if per_page 50 | params[:start_at] = start_at.utc.iso8601 if start_at 51 | 52 | params.map { |k, v| "#{k}=#{ERB::Util.url_encode(v.to_s)}" }.join('&') 53 | end 54 | end 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/retrieve_login_history.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Retrieve login history 6 | # 7 | # @see https://developers.files.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] 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 39 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/retrieve_site_history.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Retrieve site history 6 | # 7 | # @see https://developers.files.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] 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 39 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/retrieve_user_history.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Retrieve user history 6 | # 7 | # @see https://developers.files.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] 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 41 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/search_user.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'erb' 4 | 5 | module BrickFTP 6 | module RESTfulAPI 7 | # Search users 8 | # 9 | # @see https://developers.files.com/#search-users Search users 10 | # 11 | class SearchUser 12 | include Command 13 | using BrickFTP::CoreExt::Hash 14 | 15 | # Returns a single user. 16 | # 17 | # @param [String] username Username for the user. This is how the user will be displayed on the site. 18 | # Maximum of 50 characters. 19 | # @return [BrickFTP::Types::User, nil] found User or nil 20 | # 21 | def call(username) 22 | res = client.get("/api/rest/v1/users.json?q[username]=#{ERB::Util.url_encode(username)}") 23 | return nil if !res || res.empty? 24 | 25 | BrickFTP::Types::User.new(**res.first.symbolize_keys) 26 | end 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/start_upload.rb: -------------------------------------------------------------------------------- 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.files.com/#starting-a-new-upload Starting a new upload 10 | # 11 | class StartUpload 12 | include Command 13 | using BrickFTP::CoreExt::Hash 14 | 15 | # The first request to upload a new file is a POST request to /files/PATH_AND_FILENAME.EXT 16 | # with an action parameter with the value of put. 17 | # 18 | # @param [String] path Full path of the file or folder. Maximum of 550 characters. 19 | # @return [BrickFTP::Types::Upload] Upload object 20 | # 21 | def call(path) 22 | res = client.post("/api/rest/v1/files/#{ERB::Util.url_encode(path)}", action: 'put') 23 | 24 | BrickFTP::Types::Upload.new(**res.symbolize_keys) 25 | end 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/unlock_user.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Unlock a user 6 | # 7 | # @see https://developers.files.com/#unlock-a-user Unlock a user 8 | # 9 | class UnlockUser 10 | include Command 11 | using BrickFTP::CoreExt::Hash 12 | 13 | # Unlocks a user that has been locked out by Brute Force Login Protection. 14 | # 15 | # @param [Integer] id Globally unique identifier of each user. 16 | # Each user is given an ID automatically upon creation. 17 | # @return [BrickFTP::Types::User, nil] unlocked User or nil 18 | # 19 | def call(id) 20 | res = client.post("/api/rest/v1/users/#{id}/unlock.json") 21 | 22 | BrickFTP::Types::User.new(**res.symbolize_keys) 23 | end 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/update_behavior.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Update a behavior 6 | # 7 | # @see https://developers.files.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 40 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/update_group.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Update a group 6 | # 7 | # @see https://developers.files.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 45 | -------------------------------------------------------------------------------- /lib/brick_ftp/restful_api/update_group_member.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module RESTfulAPI 5 | # Update a member 6 | # 7 | # @see https://developers.files.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 41 | -------------------------------------------------------------------------------- /lib/brick_ftp/types.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module Types 5 | autoload :User, 'brick_ftp/types/user' 6 | autoload :UserAPIKey, 'brick_ftp/types/user_api_key' 7 | autoload :UserPublicKey, 'brick_ftp/types/user_public_key' 8 | autoload :Group, 'brick_ftp/types/group' 9 | autoload :GroupMembership, 'brick_ftp/types/group_membership' 10 | autoload :Permission, 'brick_ftp/types/permission' 11 | autoload :Notification, 'brick_ftp/types/notification' 12 | autoload :History, 'brick_ftp/types/history' 13 | autoload :Bundle, 'brick_ftp/types/bundle' 14 | autoload :BundleContent, 'brick_ftp/types/bundle_content' 15 | autoload :FileInBundle, 'brick_ftp/types/file_in_bundle' 16 | autoload :BundleZip, 'brick_ftp/types/bundle_zip' 17 | autoload :Behavior, 'brick_ftp/types/behavior' 18 | autoload :File, 'brick_ftp/types/file' 19 | autoload :FolderContentsCount, 'brick_ftp/types/folder_contents_count' 20 | autoload :Upload, 'brick_ftp/types/upload' 21 | autoload :SiteUsage, 'brick_ftp/types/site_usage' 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/brick_ftp/types/behavior.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module Types 5 | using BrickFTP::CoreExt::Struct 6 | 7 | # ## The behavior object 8 | # 9 | # @see https://developers.files.com/#the-behavior-object The behavior object 10 | # 11 | # ATTRIBUTE | TYPE | DESCRIPTION 12 | # ---------- | -------- | ----------- 13 | # id | integer | Globally unique identifier of each behavior. 14 | # path | string | Folder path for behaviors. This must be slash-delimited, but it must neither start nor end with a slash. Maximum of 5000 characters. 15 | # behavior | string | The behavior type. Can be one of the following: webhook, file_expiration, auto_encrypt, lock_subfolders. 16 | # value | array | Array of values associated with the behavior. 17 | # 18 | Behavior = Struct.new( 19 | 'Behavior', 20 | :id, 21 | :path, 22 | :behavior, 23 | :value, 24 | keyword_init: true 25 | ) do 26 | prepend IgnoreUndefinedAttributes 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /lib/brick_ftp/types/bundle.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module Types 5 | using BrickFTP::CoreExt::Struct 6 | 7 | # The bundle object 8 | # 9 | # @see https://developers.files.com/#the-bundle-object The bundle object 10 | # 11 | # ATTRIBUTE | TYPE | DESCRIPTION 12 | # ---------- | -------- | ----------- 13 | # id | integer | Globally unique identifier of each bundle. 14 | # code | string | Unique code string identifier for the bundle. 15 | # url | string | Public sharing URL for the bundle. 16 | # user_id | integer | ID of the user that created the bundle. 17 | # created_at | datetime | Creation date of the bundle. 18 | # paths | array | List of the paths associated with the bundle. 19 | # password | string | Optional password to password-protect the bundle. This property is write-only. It cannot be retrieved via the API. 20 | # 21 | Bundle = Struct.new( 22 | 'Bundle', 23 | :id, 24 | :code, 25 | :url, 26 | :user_id, 27 | :created_at, 28 | :paths, 29 | :expires_at, 30 | :username, 31 | keyword_init: true 32 | ) do 33 | prepend IgnoreUndefinedAttributes 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /lib/brick_ftp/types/bundle_content.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module Types 5 | using BrickFTP::CoreExt::Struct 6 | 7 | # An element of bundle contents 8 | # 9 | # @see https://developers.files.com/#list-bundle-contents List bundle contents 10 | # 11 | # ATTRIBUTE | TYPE | DESCRIPTION 12 | # --------- | ------- | ----------- 13 | # path | string | undocumented 14 | # type | string | undocumented 15 | # size | integer | undocumented 16 | # 17 | BundleContent = Struct.new( 18 | 'BundleContent', 19 | :path, 20 | :type, 21 | :size, 22 | keyword_init: true 23 | ) do 24 | prepend IgnoreUndefinedAttributes 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/brick_ftp/types/bundle_zip.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module Types 5 | using BrickFTP::CoreExt::Struct 6 | 7 | # @see https://developers.files.com/#download-entire-bundle-as-zip Download entire bundle as ZIP 8 | # 9 | # ATTRIBUTE | TYPE | DESCRIPTION 10 | # ------------ | -------- | ----------- 11 | # download_uri | string | undocumented 12 | # 13 | BundleZip = Struct.new( 14 | 'BundleZip', 15 | :download_uri, 16 | keyword_init: true 17 | ) do 18 | prepend IgnoreUndefinedAttributes 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /lib/brick_ftp/types/file.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module Types 5 | using BrickFTP::CoreExt::Struct 6 | 7 | # The file/folder object 8 | # 9 | # @see https://developers.files.com/#the-file-folder-object The file/folder object 10 | # 11 | # ATTRIBUTE | TYPE | DESCRIPTION 12 | # ------------------ | -------- | ----------- 13 | # id | integer | Globally unique identifier of each file. 14 | # path | string | Full path of the file or folder. Maximum of 550 characters. 15 | # display_name | string | Name of the file or folder without path. 16 | # type | enum | Either `file` or `directory` (meaning folder). 17 | # size | integer | Size of the file in bytes. Will be 0 for a folder. 18 | # mtime | datetime | Date of the file/folder's last modification. 19 | # provided_mtime | datetime | Client-provided date of the file/folder's last modification. 20 | # crc32 | string | CRC32 for the file, if available. 21 | # md5 | string | MD5 hash for the file, if available. 22 | # region | string | The geographic region that a file is stored in. 23 | # permissions | string | Your permissions on the file/folder. Will be one of the following:
`p` (list/preview only), `r` (read-only), `w` (write-only), `rw` (read/write), `rwd` (read/write/delete). 24 | # download_uri | string | URL to download the file, if requested. 25 | # subfolders_locked? | integer | A value of `1` indicates that the Lock-subfolders setting is enabled on a folder. 26 | # 27 | File = Struct.new( 28 | 'File', 29 | :id, 30 | :path, 31 | :display_name, 32 | :type, 33 | :size, 34 | :mtime, 35 | :provided_mtime, 36 | :crc32, 37 | :md5, 38 | :region, 39 | :permissions, 40 | :download_uri, 41 | :subfolders_locked?, 42 | keyword_init: true 43 | ) do 44 | prepend IgnoreUndefinedAttributes 45 | end 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /lib/brick_ftp/types/file_in_bundle.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module Types 5 | using BrickFTP::CoreExt::Struct 6 | 7 | # @see https://developers.files.com/#download-one-file-in-a-bundle Download one file in a bundle 8 | # 9 | # ATTRIBUTE | TYPE | DESCRIPTION 10 | # ------------ | -------- | ----------- 11 | # path | string | undocumented 12 | # type | string | undocumented 13 | # size | integer | undocumented 14 | # download_uri | string | undocumented 15 | # 16 | FileInBundle = Struct.new( 17 | 'FileInBundle', 18 | :path, 19 | :type, 20 | :size, 21 | :download_uri, 22 | keyword_init: true 23 | ) do 24 | prepend IgnoreUndefinedAttributes 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/brick_ftp/types/folder_contents_count.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module Types 5 | using BrickFTP::CoreExt::Struct 6 | 7 | # @see https://developers.files.com/#count-folder-contents-recursively Count folder contents recursively 8 | # @see https://developers.files.com/#count-folder-contents-non-recursively Count folder contents non-recursively 9 | # 10 | # ATTRIBUTE | TYPE | DESCRIPTION 11 | # ---------- | ------- | ----------- 12 | # total | integer | undocumented 13 | # files | integer | undocumented 14 | # folders | integer | undocumented 15 | # 16 | FolderContentsCount = Struct.new( 17 | 'FolderContentsCount', 18 | :total, 19 | :files, 20 | :folders, 21 | keyword_init: true 22 | ) do 23 | prepend IgnoreUndefinedAttributes 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/brick_ftp/types/group.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module Types 5 | using BrickFTP::CoreExt::Struct 6 | 7 | # The group object 8 | # 9 | # @see https://developers.files.com/#the-group-object The group object 10 | # 11 | # ATTRIBUTE | TYPE | DESCRIPTION 12 | # --------- | ------------------------ | ----------- 13 | # id | integer | Globally unique identifier of each group. Each group is given an ID automatically upon creation. 14 | # name | string | Name of the group. This is how the group will be displayed on the site. Maximum of 50 characters. 15 | # notes | text | You may use this property to store any additional information you require. There are no restrictions on its formatting. 16 | # user_ids | comma-separated integers | IDs of the users that are in this group. 17 | # usernames | string | Usernames of the users that are in this group. 18 | # admin_ids | comma-separated integers | IDs of the users that are in this group and are administrators of this group. 19 | # 20 | Group = Struct.new( 21 | 'Group', 22 | :id, 23 | :name, 24 | :notes, 25 | :user_ids, 26 | :usernames, 27 | :admin_ids, 28 | keyword_init: true 29 | ) do 30 | prepend IgnoreUndefinedAttributes 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/brick_ftp/types/group_membership.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module Types 5 | using BrickFTP::CoreExt::Struct 6 | 7 | # membership object 8 | # 9 | # @see https://developers.files.com/#add-a-member membership object 10 | # 11 | # ATTRIBUTE | TYPE | DESCRIPTION 12 | # --------- | ------- | ----------- 13 | # id | integer | Globally unique identifier for the membership. 14 | # group_id | integer | ID of the group the membership is associated with. 15 | # user_id | integer | ID of the user the membership is associated with. 16 | # admin | boolean | Indicates whether the user is an administrator of the group. 17 | # 18 | GroupMembership = Struct.new( 19 | 'GroupMembership', 20 | :id, 21 | :group_id, 22 | :user_id, 23 | :admin, 24 | keyword_init: true 25 | ) do 26 | prepend IgnoreUndefinedAttributes 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /lib/brick_ftp/types/history.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module Types 5 | using BrickFTP::CoreExt::Struct 6 | 7 | # The notification object 8 | # 9 | # @see https://developers.files.com/#the-notification-object The notification object 10 | # 11 | # ATTRIBUTE | TYPE | DESCRIPTION 12 | # ------------- | -------- | ----------- 13 | # id | integer | Globally unique identifier of each history entry. 14 | # when | datetime | Date of the history entry. 15 | # user_id | integer | ID of the user associated with the history entry. 16 | # username | string | Username of the user associated with the history entry. 17 | # action | string | Type of action that occurred. Will be one of the following:
`create`, `read`, `update`, `destroy`, `move`, `login`, `failedlogin`, `copy`, `user_create`, `user_destroy`, `group_create`, `group_destroy`, `permission_create`, `permission_destroy`. 18 | # failure_type | string | Type of failure that occurred, if any. 19 | # path | string | Path of the file or folder associated with the history entry. 20 | # source | string | Source path associated with the history entry. 21 | # destination | string | Destination path associated with the history entry. 22 | # targets | object | Object containing the target object(s) for `user_create`, `user_destroy`, `group_create`, `group_destroy`, `permission_create`, and `permission_destroy` actions.
A `user` target will include an `id` and `username`. A `group` target will include an `id` and `name`. A `permission` target will include an `id`, `permission`, and a `recursive` parameter. 23 | # ip | string | IP address associated with the history entry. 24 | # interface | string | Interface associated with the history entry. Will be one of the following: web, ftp, robot, jsapi, restapi, sftp, dav. 25 | # 26 | History = Struct.new( 27 | 'History', 28 | :id, 29 | :when, 30 | :user_id, 31 | :username, 32 | :action, 33 | :failure_type, 34 | :path, 35 | :source, 36 | :destination, 37 | :targets, 38 | :ip, 39 | :interface, 40 | keyword_init: true 41 | ) do 42 | prepend IgnoreUndefinedAttributes 43 | end 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /lib/brick_ftp/types/ignore_undefined_attributes.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module Types 5 | module IgnoreUndefinedAttributes 6 | def initialize(**kwargs) 7 | super(**members.each_with_object({}) { |k, m| m[k] = kwargs[k] }) 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/brick_ftp/types/notification.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module Types 5 | using BrickFTP::CoreExt::Struct 6 | 7 | # The notification object 8 | # 9 | # @see https://developers.files.com/#the-notification-object The notification object 10 | # 11 | # ATTRIBUTE | TYPE | DESCRIPTION 12 | # ------------- | ------- | ----------- 13 | # id | integer | Globally unique identifier of each notification. Each notification is given an ID automatically upon creation. 14 | # path | string | Folder path for notifications. This must be slash-delimited, but it must neither start nor end with a slash. Maximum of 5000 characters. 15 | # user_id | integer | Unique identifier for the user being notified. Each user is given an ID automatically upon creation. You can look up user IDs by using the User resource of this REST API. 16 | # username | string | Username for the user given by user_id. If this value is set during creation and user_id is not set, the user_id is looked up from the username and set. Maximum of 50 characters. 17 | # send_interval | string | The send interval for notifications. Can be one of the following: five_minutes (default), fifteen_minutes, hourly, daily. 18 | # unsubscribed | boolean | If true, the user has unsubscribed from receiving this notification. This property is read-only. 19 | # 20 | Notification = Struct.new( 21 | 'Notification', 22 | :id, 23 | :path, 24 | :user_id, 25 | :username, 26 | :send_interval, 27 | :unsubscribed, 28 | keyword_init: true 29 | ) do 30 | prepend IgnoreUndefinedAttributes 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/brick_ftp/types/permission.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module Types 5 | using BrickFTP::CoreExt::Struct 6 | 7 | # The permission object 8 | # 9 | # @see https://developers.files.com/#the-permission-object The permission object 10 | # 11 | # ATTRIBUTE | TYPE | DESCRIPTION 12 | # ---------- | ------- | ----------- 13 | # id | integer | Globally unique identifier of each permission. Each permission is given an ID automatically upon creation. 14 | # user_id | integer | Unique identifier for the user being granted a permission. Each user is given an ID automatically upon creation. The user_id and group_id fields cannot both be set. 15 | # username | string | Username for the user, if user_id is set. If this value is set during creation and user_id is not set, the user_id is looked up from the username and set. Maximum of 50 characters. 16 | # group_id | integer | Unique identifier for the group being granted a permission. Each group is given an ID automatically upon creation. The user_id and group_id fields cannot both be set. 17 | # group_name | string | Name of the group, if group_id is set. This property is read-only. 18 | # path | string | Folder path for the permission to apply to. This must be slash-delimited, but it must neither start nor end with a slash. Maximum of 5000 characters. 19 | # permission | enum | Value must be set to full, readonly, writeonly, previewonly, or history, depending on the type of access to be granted by the Permission. 20 | # recursive | boolean | If set to false, the permission will be non-recursive, and will not apply to subfolders of the folder specified by the path property. Default is true. 21 | # 22 | Permission = Struct.new( 23 | 'Permission', 24 | :id, 25 | :user_id, 26 | :username, 27 | :group_id, 28 | :group_name, 29 | :path, 30 | :permission, 31 | :recursive, 32 | keyword_init: true 33 | ) do 34 | prepend IgnoreUndefinedAttributes 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /lib/brick_ftp/types/site_usage.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module Types 5 | using BrickFTP::CoreExt::Struct 6 | 7 | SiteUsage = Struct.new( 8 | 'SiteUsage', 9 | :id, 10 | :live_current_storage, 11 | :current_storage, 12 | :usage_by_top_level_dir, 13 | :high_water_storage, 14 | :start_at, 15 | :end_at, 16 | :created_at, 17 | :updated_at, 18 | :total_uploads, 19 | :total_downloads, 20 | keyword_init: true 21 | ) do 22 | prepend IgnoreUndefinedAttributes 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /lib/brick_ftp/types/user_api_key.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module Types 5 | using BrickFTP::CoreExt::Struct 6 | 7 | # The API key object 8 | # 9 | # @see https://developers.files.com/#the-api-key-object The API key object 10 | # 11 | # ATTRIBUTE | TYPE | DESCRIPTION 12 | # -------------- | -------- | ----------- 13 | # id | integer | Globally unique identifier of each user API key. Each user API key is given an ID automatically upon creation. 14 | # key | string | The API key itself. This property is read-only. 15 | # name | string | Name to identify the user API key. For your reference. Maximum of 100 characters. 16 | # permission_set | string | The permission set for the user API key. Can be desktop_app or full. 17 | # platform | string | The platform for the user API key. Can be win32, macos, linux, or none. Applies only to API keys with a permission_set of desktop_app. 18 | # expires_at | datetime | The date that this API key is valid through. 19 | # created_at | datetime | Creation date of the user API key. This property is read-only. 20 | # 21 | UserAPIKey = Struct.new( 22 | 'UserAPIKey', 23 | :id, 24 | :key, 25 | :name, 26 | :permission_set, 27 | :platform, 28 | :expires_at, 29 | :created_at, 30 | keyword_init: true 31 | ) do 32 | prepend IgnoreUndefinedAttributes 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /lib/brick_ftp/types/user_public_key.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module Types 5 | using BrickFTP::CoreExt::Struct 6 | 7 | # The public key object 8 | # 9 | # @see https://developers.files.com/#the-public-key-object The public key object 10 | # 11 | # ATTRIBUTE | TYPE | DESCRIPTION 12 | # ----------- | -------- | ----------- 13 | # id | integer | Globally unique identifier of each public key. Each public key is given an ID automatically upon creation. 14 | # title | string | Title to identify the public key. For your reference. Maximum of 50 characters. 15 | # fingerprint | string | RSA fingerprint of the public key. This property is read-only. 16 | # public_key | string | The public key itself. This property is write-only. It cannot be retrieved via the API. 17 | # created_at | datetime | Creation date of the public key. This property is read-only. 18 | # 19 | UserPublicKey = Struct.new( 20 | 'UserPublicKey', 21 | :id, 22 | :title, 23 | :fingerprint, 24 | :created_at, 25 | keyword_init: true 26 | ) do 27 | prepend IgnoreUndefinedAttributes 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /lib/brick_ftp/utils.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | module Utils 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/brick_ftp/utils/chunk_io.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'tempfile' 4 | 5 | module BrickFTP 6 | module Utils 7 | class ChunkIO 8 | include Enumerable 9 | 10 | attr_reader :io, :chunk_size 11 | 12 | # Wrap IO object. 13 | # 14 | # @param [IO, StringIO] io an IO object. 15 | # @param [Integer] chunk_size Size of chunk. 16 | # This option is ignored if `io` is `StringIO`. 17 | # 18 | def initialize(io, chunk_size: nil) 19 | @io = io 20 | @chunk_size = chunk_size 21 | end 22 | 23 | # Iterate with chunked IO object. 24 | # 25 | # @yield [chunk] Give a chunk IO object to block. 26 | # @yieldparam [StringIO] chunk a chunked IO object. 27 | # 28 | def each(&block) 29 | return enum_for(__method__) unless block 30 | 31 | if chunk_size && io.is_a?(IO) 32 | each_chunk(&block) 33 | else 34 | whole(&block) 35 | end 36 | end 37 | 38 | private 39 | 40 | def whole 41 | yield io 42 | end 43 | 44 | def each_chunk 45 | eof = false 46 | offset = 0 47 | until eof 48 | Tempfile.create('chunk-io') do |chunk| 49 | copied = IO.copy_stream(io, chunk, chunk_size, offset) 50 | eof = copied.zero? 51 | next if eof 52 | 53 | offset += copied 54 | chunk.rewind 55 | 56 | yield chunk 57 | end 58 | end 59 | end 60 | end 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /lib/brick_ftp/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BrickFTP 4 | VERSION = '2.1.3' 5 | end 6 | -------------------------------------------------------------------------------- /spec/brick_ftp/core_ext/hash/symbolize_keys_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::CoreExt::Hash::SymbolizeKeys, type: :lib do 6 | describe '#symbolize_keys' do 7 | it 'convert keys to symbol' do 8 | hash = { 'str' => 1, nil => 2 } 9 | hash.extend(BrickFTP::CoreExt::Hash::SymbolizeKeys) 10 | 11 | expect(hash.symbolize_keys).to eq(str: 1, nil => 2) 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/add_group_member_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::AddGroupMember, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'return created Group Membership object' do 9 | created_group_membership = BrickFTP::Types::GroupMembership.new( 10 | id: 1234, 11 | group_id: 1, 12 | user_id: 2, 13 | admin: true 14 | ) 15 | 16 | stub_request(:put, 'https://subdomain.files.com/api/rest/v1/groups/1/memberships/2.json') 17 | .with( 18 | basic_auth: %w[api-key x], 19 | headers: { 20 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 21 | }, 22 | body: { membership: { admin: true } }.to_json 23 | ) 24 | .to_return(body: created_group_membership.to_h.to_json) 25 | 26 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 27 | params = BrickFTP::RESTfulAPI::AddGroupMember::Params.new(admin: true) 28 | command = BrickFTP::RESTfulAPI::AddGroupMember.new(rest) 29 | 30 | expect(command.call(1, 2, params)).to eq created_group_membership 31 | end 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/complete_upload_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::CompleteUpload, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'complete upload' do 9 | expected_file = BrickFTP::Types::File.new( 10 | id: 1_020_304_050, 11 | path: 'NewFile.txt', 12 | display_name: 'NewFile.txt', 13 | type: 'file', 14 | size: 412, 15 | mtime: '2014-05-17T05:14:35+00:00', 16 | provided_mtime: nil, 17 | crc32: nil, 18 | md5: nil, 19 | region: 'us-east-1', 20 | permissions: 'rwd' 21 | ) 22 | 23 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/files/a%20b%2Fc') 24 | .with( 25 | basic_auth: %w[api-key x], 26 | headers: { 27 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 28 | }, 29 | body: { ref: 'put-378670', action: 'end' }.to_json 30 | ) 31 | .to_return(body: expected_file.to_h.to_json) 32 | 33 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 34 | params = BrickFTP::RESTfulAPI::CompleteUpload::Params.new(ref: 'put-378670') 35 | command = BrickFTP::RESTfulAPI::CompleteUpload.new(rest) 36 | 37 | expect(command.call('a b/c', params)).to eq expected_file 38 | end 39 | end 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/continue_upload_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::ContinueUpload, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'continue upload' do 9 | expected_upload = BrickFTP::Types::Upload.new( 10 | ref: 'put-378670', 11 | path: 'NewFile.txt', 12 | action: 'put/write', 13 | ask_about_overwrites: false, 14 | http_method: 'PUT', 15 | upload_uri: 'https://s3.amazonaws.com/objects.files.com/..', 16 | partsize: 5_242_880, 17 | part_number: 2, 18 | available_parts: 10_000, 19 | send: { 20 | 'partsize' => 'required-parameter Content-Length', 21 | 'partdata' => 'body', 22 | }, 23 | headers: {}, 24 | parameters: {} 25 | ) 26 | 27 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/files/a%20b%2Fc') 28 | .with( 29 | basic_auth: %w[api-key x], 30 | headers: { 31 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 32 | }, 33 | body: { ref: 'put-378670', part: 2, action: 'put' }.to_json 34 | ) 35 | .to_return(body: expected_upload.to_h.to_json) 36 | 37 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 38 | params = BrickFTP::RESTfulAPI::ContinueUpload::Params.new(ref: 'put-378670', part: 2) 39 | command = BrickFTP::RESTfulAPI::ContinueUpload.new(rest) 40 | 41 | expect(command.call('a b/c', params)).to eq expected_upload 42 | end 43 | end 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/copy_folder_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::CopyFolder, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'copy folder' do 9 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/files/a%20b%2Fc') 10 | .with( 11 | basic_auth: %w[api-key x], 12 | headers: { 13 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 14 | }, 15 | body: { 'copy-destination': 'a b/d' }.to_json 16 | ) 17 | .to_return(body: '[]') 18 | 19 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 20 | params = BrickFTP::RESTfulAPI::CopyFolder::Params.new('copy-destination': 'a b/d') 21 | command = BrickFTP::RESTfulAPI::CopyFolder.new(rest) 22 | 23 | expect(command.call('a b/c', params)).to be_truthy 24 | end 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/count_folder_contents_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::CountFolderContents, type: :lib do 6 | describe '#call' do 7 | context 'recursive: true' do 8 | it 'return count' do 9 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/folders/path?action=count') 10 | .with( 11 | basic_auth: %w[api-key x], 12 | headers: { 13 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 14 | } 15 | ) 16 | .to_return(body: { data: { count: 3 } }.to_json) 17 | 18 | client = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 19 | command = BrickFTP::RESTfulAPI::CountFolderContents.new(client) 20 | 21 | expected_count = BrickFTP::Types::FolderContentsCount.new(total: 3) 22 | expect(command.call('path', recursive: true)).to eq expected_count 23 | end 24 | end 25 | 26 | context 'recursive: false' do 27 | it 'return count' do 28 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/folders/path?action=count_nrs') 29 | .with( 30 | basic_auth: %w[api-key x], 31 | headers: { 32 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 33 | } 34 | ) 35 | .to_return(body: { data: { count: { files: 1, folders: 2 } } }.to_json) 36 | 37 | client = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 38 | command = BrickFTP::RESTfulAPI::CountFolderContents.new(client) 39 | 40 | expected_count = BrickFTP::Types::FolderContentsCount.new(files: 1, folders: 2) 41 | expect(command.call('path')).to eq expected_count 42 | end 43 | end 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/count_users_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::CountUsers, type: :lib do 6 | describe '#call' do 7 | it 'return count' do 8 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/users.json?action=count') 9 | .with( 10 | basic_auth: %w[api-key x], 11 | headers: { 12 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 13 | } 14 | ) 15 | .to_return(body: '{"data":{"count":1234}}') 16 | 17 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 18 | command = BrickFTP::RESTfulAPI::CountUsers.new(rest) 19 | 20 | expect(command.call).to eq 1234 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/create_api_key_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::CreateAPIKey, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'return created User API key object' do 9 | created_api_key = BrickFTP::Types::UserAPIKey.new( 10 | id: 12_345, 11 | key: 'api-key', 12 | name: 'mykey', 13 | permission_set: 'full', 14 | platform: 'none', 15 | expires_at: nil, 16 | created_at: '2018-08-17T00:00:00Z' 17 | ) 18 | 19 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/users/1234/api_keys.json') 20 | .with( 21 | basic_auth: %w[api-key x], 22 | headers: { 23 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 24 | }, 25 | body: { name: 'mykey' }.to_json 26 | ) 27 | .to_return(body: created_api_key.to_h.to_json) 28 | 29 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 30 | params = BrickFTP::RESTfulAPI::CreateAPIKey::Params.new(name: 'mykey') 31 | command = BrickFTP::RESTfulAPI::CreateAPIKey.new(rest) 32 | 33 | expect(command.call(1234, params)).to eq created_api_key 34 | end 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/create_behavior_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::CreateBehavior, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'return created Behavior object' do 9 | created_behavior = BrickFTP::Types::Behavior.new( 10 | id: 38, 11 | path: 'a', 12 | behavior: 'webhook', 13 | value: %w[https://a.mywebhookhandler.com] 14 | ) 15 | 16 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/behaviors.json') 17 | .with( 18 | basic_auth: %w[api-key x], 19 | headers: { 20 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 21 | }, 22 | body: { path: 'a', behavior: 'webhook', value: %w[https://a.mywebhookhandler.com] }.to_json 23 | ) 24 | .to_return(body: created_behavior.to_h.to_json) 25 | 26 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 27 | params = BrickFTP::RESTfulAPI::CreateBehavior::Params.new( 28 | path: 'a', 29 | behavior: 'webhook', 30 | value: %w[https://a.mywebhookhandler.com] 31 | ) 32 | command = BrickFTP::RESTfulAPI::CreateBehavior.new(rest) 33 | 34 | expect(command.call(params)).to eq created_behavior 35 | end 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/create_bundle_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::CreateBundle, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'return created Bundle object' do 9 | created_bundle = BrickFTP::Types::Bundle.new( 10 | id: 212_228, 11 | code: '4d3d3d3d3', 12 | url: 'https://site.files.com/f/4d3d3d3d3', 13 | user_id: 12_345, 14 | created_at: '2015-10-14T12:52:25-04:00', 15 | paths: %w[accounts.xls] 16 | ) 17 | 18 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/bundles.json') 19 | .with( 20 | basic_auth: %w[api-key x], 21 | headers: { 22 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 23 | }, 24 | body: { paths: %w[accounts.xls], password: 'pass' }.to_json 25 | ) 26 | .to_return(body: created_bundle.to_h.to_json) 27 | 28 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 29 | params = BrickFTP::RESTfulAPI::CreateBundle::Params.new(paths: %w[accounts.xls], password: 'pass') 30 | command = BrickFTP::RESTfulAPI::CreateBundle.new(rest) 31 | 32 | expect(command.call(params)).to eq created_bundle 33 | end 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/create_folder_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::CreateFolder, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'return created Folder object' do 9 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/folders/a%20b%2Fc') 10 | .with( 11 | basic_auth: %w[api-key x], 12 | headers: { 13 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 14 | } 15 | ) 16 | .to_return(body: nil, status: 204) 17 | 18 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 19 | command = BrickFTP::RESTfulAPI::CreateFolder.new(rest) 20 | 21 | expect(command.call('a b/c')).to be_truthy 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/create_group_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::CreateGroup, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'return created Group object' do 9 | created_group = BrickFTP::Types::Group.new( 10 | id: 1234, 11 | name: 'group', 12 | notes: 'notes', 13 | user_ids: '1,2,3', 14 | usernames: 'a,b,c', 15 | admin_ids: [1, 2, 3] 16 | ) 17 | 18 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/groups.json') 19 | .with( 20 | basic_auth: %w[api-key x], 21 | headers: { 22 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 23 | }, 24 | body: { name: 'group' }.to_json 25 | ) 26 | .to_return(body: created_group.to_h.to_json) 27 | 28 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 29 | params = BrickFTP::RESTfulAPI::CreateGroup::Params.new(name: 'group') 30 | command = BrickFTP::RESTfulAPI::CreateGroup.new(rest) 31 | 32 | expect(command.call(params)).to eq created_group 33 | end 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/create_notification_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::CreateNotification, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'return created Notification object' do 9 | created_notification = BrickFTP::Types::Notification.new( 10 | id: 1234, 11 | path: 'a/b/c', 12 | user_id: '1', 13 | username: 'user', 14 | send_interval: 'daily', 15 | unsubscribed: false 16 | ) 17 | 18 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/notifications.json') 19 | .with( 20 | basic_auth: %w[api-key x], 21 | headers: { 22 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 23 | }, 24 | body: { path: 'a/b/c', user_id: 1 }.to_json 25 | ) 26 | .to_return(body: created_notification.to_h.to_json) 27 | 28 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 29 | params = BrickFTP::RESTfulAPI::CreateNotification::Params.new(path: 'a/b/c', user_id: 1) 30 | command = BrickFTP::RESTfulAPI::CreateNotification.new(rest) 31 | 32 | expect(command.call(params)).to eq created_notification 33 | end 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/create_permission_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::CreatePermission, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'return created Permission object' do 9 | created_permission = BrickFTP::Types::Permission.new( 10 | id: 1234, 11 | user_id: 1, 12 | path: 'a/b/c', 13 | permission: 'writeonly' 14 | ) 15 | 16 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/permissions.json') 17 | .with( 18 | basic_auth: %w[api-key x], 19 | headers: { 20 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 21 | }, 22 | body: { user_id: 1, path: 'a/b/c', permission: 'writeonly' }.to_json 23 | ) 24 | .to_return(body: created_permission.to_h.to_json) 25 | 26 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 27 | params = BrickFTP::RESTfulAPI::CreatePermission::Params.new(user_id: 1, path: 'a/b/c', permission: 'writeonly') 28 | command = BrickFTP::RESTfulAPI::CreatePermission.new(rest) 29 | 30 | expect(command.call(params)).to eq created_permission 31 | end 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/create_public_key_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::CreatePublicKey, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'return created User Public key object' do 9 | created_public_key = BrickFTP::Types::UserPublicKey.new( 10 | id: 12_345, 11 | title: 'test', 12 | fingerprint: 'finger-pring', 13 | created_at: '2018-08-17T08:16:52-04:00' 14 | ) 15 | 16 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/users/1234/public_keys.json') 17 | .with( 18 | basic_auth: %w[api-key x], 19 | headers: { 20 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 21 | }, 22 | body: { title: 'mykey' }.to_json 23 | ) 24 | .to_return(body: created_public_key.to_h.to_json) 25 | 26 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 27 | params = BrickFTP::RESTfulAPI::CreatePublicKey::Params.new(title: 'mykey') 28 | command = BrickFTP::RESTfulAPI::CreatePublicKey.new(rest) 29 | 30 | expect(command.call(1234, params)).to eq created_public_key 31 | end 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/create_user_in_group_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::CreateUserInGroup, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'return created User object' do 9 | created_user = BrickFTP::Types::User.new( 10 | id: 1234, 11 | username: 'user', 12 | authentication_method: 'password', 13 | last_login_at: nil, 14 | authenticate_until: nil, 15 | name: nil, 16 | email: 'user@example.com', 17 | notes: nil, 18 | group_ids: '1', 19 | ftp_permission: true, 20 | sftp_permission: true, 21 | dav_permission: true, 22 | restapi_permission: true, 23 | attachments_permission: true, 24 | self_managed: true, 25 | require_password_change: false, 26 | require_2fa: false, 27 | allowed_ips: nil, 28 | user_root: '', 29 | time_zone: 'Eastern Time (US & Canada)', 30 | language: '', 31 | ssl_required: 'use_system_setting', 32 | site_admin: true, 33 | password_set_at: nil, 34 | receive_admin_alerts: true, 35 | subscribe_to_newsletter: false, 36 | last_protocol_cipher: nil, 37 | lockout_expires: nil, 38 | admin_group_ids: [] 39 | ) 40 | 41 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/groups/1/users.json') 42 | .with( 43 | basic_auth: %w[api-key x], 44 | headers: { 45 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 46 | }, 47 | body: { user: { username: 'user' } }.to_json 48 | ) 49 | .to_return(body: created_user.to_h.to_json) 50 | 51 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 52 | params = BrickFTP::RESTfulAPI::CreateUserInGroup::Params.new(username: 'user') 53 | command = BrickFTP::RESTfulAPI::CreateUserInGroup.new(rest) 54 | 55 | expect(command.call(1, params)).to eq created_user 56 | end 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/create_user_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::CreateUser, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'return created User object' do 9 | created_user = BrickFTP::Types::User.new( 10 | id: 1234, 11 | username: 'user', 12 | authentication_method: 'password', 13 | last_login_at: nil, 14 | authenticate_until: nil, 15 | name: nil, 16 | email: 'user@example.com', 17 | notes: nil, 18 | group_ids: '', 19 | ftp_permission: true, 20 | sftp_permission: true, 21 | dav_permission: true, 22 | restapi_permission: true, 23 | attachments_permission: true, 24 | self_managed: true, 25 | require_password_change: false, 26 | require_2fa: false, 27 | allowed_ips: nil, 28 | user_root: '', 29 | time_zone: 'Eastern Time (US & Canada)', 30 | language: '', 31 | ssl_required: 'use_system_setting', 32 | site_admin: true, 33 | password_set_at: nil, 34 | receive_admin_alerts: true, 35 | subscribe_to_newsletter: false, 36 | last_protocol_cipher: nil, 37 | lockout_expires: nil, 38 | admin_group_ids: [] 39 | ) 40 | 41 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/users.json') 42 | .with( 43 | basic_auth: %w[api-key x], 44 | headers: { 45 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 46 | }, 47 | body: { username: 'user' }.to_json 48 | ) 49 | .to_return(body: created_user.to_h.to_json) 50 | 51 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 52 | params = BrickFTP::RESTfulAPI::CreateUser::Params.new(username: 'user') 53 | command = BrickFTP::RESTfulAPI::CreateUser.new(rest) 54 | 55 | expect(command.call(params)).to eq created_user 56 | end 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/delete_api_key_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::DeleteAPIKey, type: :lib do 6 | describe '#call' do 7 | context 'given correct User API key ID' do 8 | it 'return true' do 9 | stub_request(:delete, 'https://subdomain.files.com/api/rest/v1/api_keys/1234.json') 10 | .with( 11 | basic_auth: %w[api-key x], 12 | headers: { 13 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 14 | } 15 | ) 16 | .to_return(body: '[]') 17 | 18 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 19 | command = BrickFTP::RESTfulAPI::DeleteAPIKey.new(rest) 20 | 21 | expect(command.call(1234)).to be_truthy 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/delete_behavior_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::DeleteBehavior, type: :lib do 6 | describe '#call' do 7 | context 'given correct Behavior ID' do 8 | it 'return true' do 9 | stub_request(:delete, 'https://subdomain.files.com/api/rest/v1/behaviors/1234.json') 10 | .with( 11 | basic_auth: %w[api-key x], 12 | headers: { 13 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 14 | } 15 | ) 16 | .to_return(body: '[]') 17 | 18 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 19 | command = BrickFTP::RESTfulAPI::DeleteBehavior.new(rest) 20 | 21 | expect(command.call(1234)).to be_truthy 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/delete_bundle_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::DeleteBundle, type: :lib do 6 | describe '#call' do 7 | context 'given correct Bundle ID' do 8 | it 'return true' do 9 | stub_request(:delete, 'https://subdomain.files.com/api/rest/v1/bundles/1234.json') 10 | .with( 11 | basic_auth: %w[api-key x], 12 | headers: { 13 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 14 | } 15 | ) 16 | .to_return(body: '[]') 17 | 18 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 19 | command = BrickFTP::RESTfulAPI::DeleteBundle.new(rest) 20 | 21 | expect(command.call(1234)).to be_truthy 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/delete_folder_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::DeleteFolder, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'delete folder' do 9 | stub_request(:delete, 'https://subdomain.files.com/api/rest/v1/files/a%20b%2Fc?recursive=true') 10 | .with( 11 | basic_auth: %w[api-key x], 12 | headers: { 13 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 14 | } 15 | ) 16 | .to_return(body: '[]') 17 | 18 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 19 | command = BrickFTP::RESTfulAPI::DeleteFolder.new(rest) 20 | 21 | expect(command.call('a b/c', recursive: true)).to be_truthy 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/delete_group_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::DeleteGroup, type: :lib do 6 | describe '#call' do 7 | context 'given correct Group ID' do 8 | it 'return true' do 9 | stub_request(:delete, 'https://subdomain.files.com/api/rest/v1/groups/1234.json') 10 | .with( 11 | basic_auth: %w[api-key x], 12 | headers: { 13 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 14 | } 15 | ) 16 | .to_return(body: '[]') 17 | 18 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 19 | command = BrickFTP::RESTfulAPI::DeleteGroup.new(rest) 20 | 21 | expect(command.call(1234)).to be_truthy 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/delete_notification_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::DeleteNotification, type: :lib do 6 | describe '#call' do 7 | context 'given correct Notification ID' do 8 | it 'return true' do 9 | stub_request(:delete, 'https://subdomain.files.com/api/rest/v1/notifications/1234.json') 10 | .with( 11 | basic_auth: %w[api-key x], 12 | headers: { 13 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 14 | } 15 | ) 16 | .to_return(body: '[]') 17 | 18 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 19 | command = BrickFTP::RESTfulAPI::DeleteNotification.new(rest) 20 | 21 | expect(command.call(1234)).to be_truthy 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/delete_permission_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::DeletePermission, type: :lib do 6 | describe '#call' do 7 | context 'given correct Permission ID' do 8 | it 'return true' do 9 | stub_request(:delete, 'https://subdomain.files.com/api/rest/v1/permissions/1234.json') 10 | .with( 11 | basic_auth: %w[api-key x], 12 | headers: { 13 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 14 | } 15 | ) 16 | .to_return(body: '[]') 17 | 18 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 19 | command = BrickFTP::RESTfulAPI::DeletePermission.new(rest) 20 | 21 | expect(command.call(1234)).to be_truthy 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/delete_public_key_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::DeletePublicKey, type: :lib do 6 | describe '#call' do 7 | context 'given correct User Public key ID' do 8 | it 'return true' do 9 | stub_request(:delete, 'https://subdomain.files.com/api/rest/v1/public_keys/1234.json') 10 | .with( 11 | basic_auth: %w[api-key x], 12 | headers: { 13 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 14 | } 15 | ) 16 | .to_return(body: '[]') 17 | 18 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 19 | command = BrickFTP::RESTfulAPI::DeletePublicKey.new(rest) 20 | 21 | expect(command.call(1234)).to be_truthy 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/delete_user_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::DeleteUser, type: :lib do 6 | describe '#call' do 7 | context 'given correct User ID' do 8 | it 'return true' do 9 | stub_request(:delete, 'https://subdomain.files.com/api/rest/v1/users/1234.json') 10 | .with( 11 | basic_auth: %w[api-key x], 12 | headers: { 13 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 14 | } 15 | ) 16 | .to_return(body: '[]') 17 | 18 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 19 | command = BrickFTP::RESTfulAPI::DeleteUser.new(rest) 20 | 21 | expect(command.call(1234)).to be_truthy 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/get_api_key_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::GetAPIKey, type: :lib do 6 | describe '#call' do 7 | context 'correct request' do 8 | it 'return User API key object' do 9 | expected_user_api_key = BrickFTP::Types::UserAPIKey.new( 10 | id: 12_345, 11 | name: 'test', 12 | permission_set: 'full', 13 | platform: 'none', 14 | expires_at: nil, 15 | created_at: '2018-08-17T08:16:52-04:00' 16 | ) 17 | 18 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/api_keys/12345.json') 19 | .with( 20 | basic_auth: %w[api-key x], 21 | headers: { 22 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 23 | } 24 | ) 25 | .to_return(body: expected_user_api_key.to_h.to_json) 26 | 27 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 28 | command = BrickFTP::RESTfulAPI::GetAPIKey.new(rest) 29 | 30 | expect(command.call(12_345)).to eq(expected_user_api_key) 31 | end 32 | end 33 | 34 | context 'API key not found' do 35 | it 'raise exception' do 36 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/api_keys/1234.json') 37 | .with( 38 | basic_auth: %w[api-key x], 39 | headers: { 40 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 41 | } 42 | ) 43 | .to_return(body: '[]', status: 404) 44 | 45 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 46 | command = BrickFTP::RESTfulAPI::GetAPIKey.new(rest) 47 | 48 | expect { command.call(1234) }.to raise_error(BrickFTP::RESTfulAPI::Client::Error) 49 | end 50 | end 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/get_behavior_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::GetBehavior, type: :lib do 6 | describe '#call' do 7 | context 'given correct Behavior ID' do 8 | it 'return Behavior object' do 9 | expected_behavior = BrickFTP::Types::Behavior.new( 10 | id: 38, 11 | path: 'Finance', 12 | behavior: 'webhook', 13 | value: %w[https://a.mywebhookhandler.com] 14 | ) 15 | 16 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/behaviors/1234.json') 17 | .with( 18 | basic_auth: %w[api-key x], 19 | headers: { 20 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 21 | } 22 | ) 23 | .to_return(body: expected_behavior.to_h.to_json) 24 | 25 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 26 | command = BrickFTP::RESTfulAPI::GetBehavior.new(rest) 27 | 28 | expect(command.call(1234)).to eq expected_behavior 29 | end 30 | end 31 | 32 | context 'Behavior not found' do 33 | it 'return nil' do 34 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/behaviors/1234.json') 35 | .with( 36 | basic_auth: %w[api-key x], 37 | headers: { 38 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 39 | } 40 | ) 41 | .to_return(body: '[]') 42 | 43 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 44 | command = BrickFTP::RESTfulAPI::GetBehavior.new(rest) 45 | 46 | expect(command.call(1234)).to be_nil 47 | end 48 | end 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/get_bundle_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::GetBundle, type: :lib do 6 | describe '#call' do 7 | context 'given correct Bundle ID' do 8 | it 'return Bundle object' do 9 | expected_bundle = BrickFTP::Types::Bundle.new( 10 | id: 212_228, 11 | code: '4d3d3d3d3', 12 | url: 'https://site.files.com/f/4d3d3d3d3', 13 | user_id: 12_345, 14 | created_at: '2015-10-14T12:52:25-04:00', 15 | paths: %w[accounts.xls] 16 | ) 17 | 18 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/bundles/1234.json') 19 | .with( 20 | basic_auth: %w[api-key x], 21 | headers: { 22 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 23 | } 24 | ) 25 | .to_return(body: expected_bundle.to_h.to_json) 26 | 27 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 28 | command = BrickFTP::RESTfulAPI::GetBundle.new(rest) 29 | 30 | expect(command.call(1234)).to eq expected_bundle 31 | end 32 | end 33 | 34 | context 'Bundle not found' do 35 | it 'return nil' do 36 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/bundles/1234.json') 37 | .with( 38 | basic_auth: %w[api-key x], 39 | headers: { 40 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 41 | } 42 | ) 43 | .to_return(body: '[]') 44 | 45 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 46 | command = BrickFTP::RESTfulAPI::GetBundle.new(rest) 47 | 48 | expect(command.call(1234)).to be_nil 49 | end 50 | end 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/get_bundle_zip_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::GetBundleZip, type: :lib do 6 | describe '#call' do 7 | context 'correct request' do 8 | it 'return FileInBundle object' do 9 | expected_bundle_zip = BrickFTP::Types::BundleZip.new( 10 | download_uri: 'https://s3.amazonaws.com/objects.files.com/metadata/10099/2e2376c0-7527-0133-21fb-0a2d4abb99a7?..' 11 | ) 12 | 13 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/bundles/zip.json') 14 | .with( 15 | basic_auth: %w[api-key x], 16 | headers: { 17 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 18 | }, 19 | body: { code: 'a', password: 'p' }.to_json 20 | ) 21 | .to_return(body: expected_bundle_zip.to_h.to_json) 22 | 23 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 24 | command = BrickFTP::RESTfulAPI::GetBundleZip.new(rest) 25 | params = BrickFTP::RESTfulAPI::GetBundleZip::Params.new(code: 'a', password: 'p') 26 | 27 | expect(command.call(params)).to eq(expected_bundle_zip) 28 | end 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/get_file_in_bundle_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::GetFileInBundle, type: :lib do 6 | describe '#call' do 7 | context 'correct request' do 8 | it 'return FileInBundle object' do 9 | expected_bundle_file = BrickFTP::Types::FileInBundle.new( 10 | path: 'a/b', 11 | type: 'file', 12 | size: 842_665, 13 | download_uri: 'https://s3.amazonaws.com/objects.files.com/metadata/10099/2e2376c0-7527-0133-21fb-0a2d4abb99a7?..' 14 | ) 15 | 16 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/bundles/download.json') 17 | .with( 18 | basic_auth: %w[api-key x], 19 | headers: { 20 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 21 | }, 22 | body: { code: 'a', path: 'a/b', password: 'p' }.to_json 23 | ) 24 | .to_return(body: expected_bundle_file.to_h.to_json) 25 | 26 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 27 | command = BrickFTP::RESTfulAPI::GetFileInBundle.new(rest) 28 | params = BrickFTP::RESTfulAPI::GetFileInBundle::Params.new(code: 'a', path: 'a/b', password: 'p') 29 | 30 | expect(command.call(params)).to eq(expected_bundle_file) 31 | end 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/get_folder_size_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::GetFolderSize, type: :lib do 6 | describe '#call' do 7 | it 'return size' do 8 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/folders/path?action=size') 9 | .with( 10 | basic_auth: %w[api-key x], 11 | headers: { 12 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 13 | } 14 | ) 15 | .to_return(body: '{"data":{"size":1234}}') 16 | 17 | client = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 18 | command = BrickFTP::RESTfulAPI::GetFolderSize.new(client) 19 | 20 | expect(command.call('path')).to eq 1234 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/get_group_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::GetGroup, type: :lib do 6 | describe '#call' do 7 | context 'given correct Group ID' do 8 | it 'return Group object' do 9 | expected_group = BrickFTP::Types::Group.new( 10 | id: 1234, 11 | name: 'group', 12 | notes: 'notes', 13 | user_ids: '1,2,3', 14 | usernames: 'a,b,c', 15 | admin_ids: [1, 2, 3] 16 | ) 17 | 18 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/groups/1234.json') 19 | .with( 20 | basic_auth: %w[api-key x], 21 | headers: { 22 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 23 | } 24 | ) 25 | .to_return(body: expected_group.to_h.to_json) 26 | 27 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 28 | command = BrickFTP::RESTfulAPI::GetGroup.new(rest) 29 | 30 | expect(command.call(1234)).to eq expected_group 31 | end 32 | end 33 | 34 | context 'Group not found' do 35 | it 'return nil' do 36 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/groups/1234.json') 37 | .with( 38 | basic_auth: %w[api-key x], 39 | headers: { 40 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 41 | } 42 | ) 43 | .to_return(body: '[]') 44 | 45 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 46 | command = BrickFTP::RESTfulAPI::GetGroup.new(rest) 47 | 48 | expect(command.call(1234)).to be_nil 49 | end 50 | end 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/get_public_key_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::GetPublicKey, type: :lib do 6 | describe '#call' do 7 | context 'correct request' do 8 | it 'return User Public key object' do 9 | expected_user_public_key = BrickFTP::Types::UserPublicKey.new( 10 | id: 12_345, 11 | title: 'test', 12 | fingerprint: 'finger-pring', 13 | created_at: '2018-08-17T08:16:52-04:00' 14 | ) 15 | 16 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/public_keys/12345.json') 17 | .with( 18 | basic_auth: %w[api-key x], 19 | headers: { 20 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 21 | } 22 | ) 23 | .to_return(body: expected_user_public_key.to_h.to_json) 24 | 25 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 26 | command = BrickFTP::RESTfulAPI::GetPublicKey.new(rest) 27 | 28 | expect(command.call(12_345)).to eq(expected_user_public_key) 29 | end 30 | end 31 | 32 | context 'Public key not found' do 33 | it 'raise exception' do 34 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/public_keys/1234.json') 35 | .with( 36 | basic_auth: %w[api-key x], 37 | headers: { 38 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 39 | } 40 | ) 41 | .to_return(body: '[]', status: 404) 42 | 43 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 44 | command = BrickFTP::RESTfulAPI::GetPublicKey.new(rest) 45 | 46 | expect { command.call(1234) }.to raise_error(BrickFTP::RESTfulAPI::Client::Error) 47 | end 48 | end 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/get_site_usage_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::GetSiteUsage, type: :lib do 6 | describe '#call' do 7 | context 'given correct Site ID' do 8 | it 'return Site object' do 9 | expected_site_usage = BrickFTP::Types::SiteUsage.new( 10 | id: 107_748, 11 | live_current_storage: 11_731_830, 12 | current_storage: 655_370, 13 | usage_by_top_level_dir: [ 14 | ['koshigoe-user01', 65_536], 15 | ['koshigoe-user04', 65_536], 16 | ['a b', 262_149], 17 | ['b c', 65_536], 18 | ['* Files In Root Folder', 0], 19 | ['* Files Deleted But Retained As Backups Under Your Backup Settings', 131_077], 20 | ['* Files Deleted But Uploaded Within Past 30 Days (minimum file billing length)', 0], 21 | ], 22 | high_water_storage: 655_370, 23 | start_at: '2018-08-17T02:59:44-04:00', 24 | end_at: nil, 25 | created_at: '2018-08-17T02:59:45-04:00', 26 | updated_at: '2018-08-24T05:50:03-04:00', 27 | total_uploads: 5, 28 | total_downloads: 0 29 | ) 30 | 31 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/site/usage.json') 32 | .with( 33 | basic_auth: %w[api-key x], 34 | headers: { 35 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 36 | } 37 | ) 38 | .to_return(body: expected_site_usage.to_h.to_json) 39 | 40 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 41 | command = BrickFTP::RESTfulAPI::GetSiteUsage.new(rest) 42 | 43 | expect(command.call).to eq expected_site_usage 44 | end 45 | end 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/get_user_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::GetUser, type: :lib do 6 | describe '#call' do 7 | context 'given correct User ID' do 8 | it 'return User object' do 9 | expected_user = BrickFTP::Types::User.new( 10 | id: 1234, 11 | username: 'user', 12 | authentication_method: 'password', 13 | last_login_at: nil, 14 | authenticate_until: nil, 15 | name: nil, 16 | email: 'user@example.com', 17 | notes: nil, 18 | group_ids: '', 19 | ftp_permission: true, 20 | sftp_permission: true, 21 | dav_permission: true, 22 | restapi_permission: true, 23 | attachments_permission: true, 24 | self_managed: true, 25 | require_password_change: false, 26 | require_2fa: false, 27 | allowed_ips: nil, 28 | user_root: '', 29 | time_zone: 'Eastern Time (US & Canada)', 30 | language: '', 31 | ssl_required: 'use_system_setting', 32 | site_admin: true, 33 | password_set_at: nil, 34 | receive_admin_alerts: true, 35 | subscribe_to_newsletter: false, 36 | last_protocol_cipher: nil, 37 | lockout_expires: nil, 38 | admin_group_ids: [] 39 | ) 40 | 41 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/users/1234.json') 42 | .with( 43 | basic_auth: %w[api-key x], 44 | headers: { 45 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 46 | } 47 | ) 48 | .to_return(body: expected_user.to_h.to_json) 49 | 50 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 51 | command = BrickFTP::RESTfulAPI::GetUser.new(rest) 52 | 53 | expect(command.call(1234)).to eq expected_user 54 | end 55 | end 56 | 57 | context 'User not found' do 58 | it 'return nil' do 59 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/users/1234.json') 60 | .with( 61 | basic_auth: %w[api-key x], 62 | headers: { 63 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 64 | } 65 | ) 66 | .to_return(body: '[]') 67 | 68 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 69 | command = BrickFTP::RESTfulAPI::GetUser.new(rest) 70 | 71 | expect(command.call(1234)).to be_nil 72 | end 73 | end 74 | end 75 | end 76 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/list_api_keys_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::ListAPIKeys, type: :lib do 6 | describe '#call' do 7 | context 'correct request' do 8 | it 'return Array of User API key object' do 9 | expected_user_api_key = BrickFTP::Types::UserAPIKey.new( 10 | id: 12_345, 11 | name: 'test', 12 | permission_set: 'full', 13 | platform: 'none', 14 | expires_at: nil, 15 | created_at: '2018-08-17T08:16:52-04:00' 16 | ) 17 | 18 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/users/1234/api_keys.json') 19 | .with( 20 | basic_auth: %w[api-key x], 21 | headers: { 22 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 23 | } 24 | ) 25 | .to_return(body: [expected_user_api_key.to_h].to_json) 26 | 27 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 28 | command = BrickFTP::RESTfulAPI::ListAPIKeys.new(rest) 29 | 30 | expect(command.call(1234)).to eq([expected_user_api_key]) 31 | end 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/list_behaviors_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::ListBehaviors, type: :lib do 6 | describe '#call' do 7 | context 'correct request' do 8 | it 'return Array of Behavior object' do 9 | expected_behavior = BrickFTP::Types::Behavior.new( 10 | id: 38, 11 | path: 'Finance', 12 | behavior: 'webhook', 13 | value: %w[https://a.mywebhookhandler.com] 14 | ) 15 | 16 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/behaviors.json') 17 | .with( 18 | basic_auth: %w[api-key x], 19 | headers: { 20 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 21 | } 22 | ) 23 | .to_return(body: [expected_behavior.to_h].to_json) 24 | 25 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 26 | command = BrickFTP::RESTfulAPI::ListBehaviors.new(rest) 27 | 28 | expect(command.call).to eq([expected_behavior]) 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/list_bundle_contents_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::ListBundleContents, type: :lib do 6 | describe '#call' do 7 | context 'correct request' do 8 | context 'with path' do 9 | it 'return Array of BundleContent object' do 10 | expected_bundle_content = BrickFTP::Types::BundleContent.new( 11 | path: 'cloud', 12 | type: 'directory', 13 | size: nil 14 | ) 15 | 16 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/bundles/contents/a%20b') 17 | .with( 18 | basic_auth: %w[api-key x], 19 | headers: { 20 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 21 | }, 22 | body: { code: 'a', password: 'p' }.to_json 23 | ) 24 | .to_return(body: [expected_bundle_content.to_h].to_json) 25 | 26 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 27 | command = BrickFTP::RESTfulAPI::ListBundleContents.new(rest) 28 | params = BrickFTP::RESTfulAPI::ListBundleContents::Params.new(code: 'a', password: 'p') 29 | 30 | expect(command.call(params, path: 'a b')).to eq([expected_bundle_content]) 31 | end 32 | end 33 | 34 | context 'without path' do 35 | it 'return Array of BundleContent object' do 36 | expected_bundle_content = BrickFTP::Types::BundleContent.new( 37 | path: 'cloud', 38 | type: 'directory', 39 | size: nil 40 | ) 41 | 42 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/bundles/contents.json') 43 | .with( 44 | basic_auth: %w[api-key x], 45 | headers: { 46 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 47 | }, 48 | body: { code: 'a', password: 'p' }.to_json 49 | ) 50 | .to_return(body: [expected_bundle_content.to_h].to_json) 51 | 52 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 53 | command = BrickFTP::RESTfulAPI::ListBundleContents.new(rest) 54 | params = BrickFTP::RESTfulAPI::ListBundleContents::Params.new(code: 'a', password: 'p') 55 | 56 | expect(command.call(params)).to eq([expected_bundle_content]) 57 | end 58 | end 59 | end 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/list_bundles_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::ListBundles, type: :lib do 6 | describe '#call' do 7 | context 'correct request' do 8 | it 'return Array of Bundle object' do 9 | expected_bundle = BrickFTP::Types::Bundle.new( 10 | id: 212_228, 11 | code: '4d3d3d3d3', 12 | url: 'https://site.files.com/f/4d3d3d3d3', 13 | user_id: 12_345, 14 | created_at: '2015-10-14T12:52:25-04:00', 15 | paths: %w[accounts.xls] 16 | ) 17 | 18 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/bundles.json') 19 | .with( 20 | basic_auth: %w[api-key x], 21 | headers: { 22 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 23 | } 24 | ) 25 | .to_return(body: [expected_bundle.to_h].to_json) 26 | 27 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 28 | command = BrickFTP::RESTfulAPI::ListBundles.new(rest) 29 | 30 | expect(command.call).to eq([expected_bundle]) 31 | end 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/list_folder_behaviors_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::ListFolderBehaviors, type: :lib do 6 | describe '#call' do 7 | context 'correct request' do 8 | it 'return Array of Behavior object' do 9 | expected_behavior = BrickFTP::Types::Behavior.new( 10 | id: 38, 11 | path: 'Finance', 12 | behavior: 'webhook', 13 | value: %w[https://a.mywebhookhandler.com] 14 | ) 15 | 16 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/behaviors/folders/a?recursive=1') 17 | .with( 18 | basic_auth: %w[api-key x], 19 | headers: { 20 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 21 | } 22 | ) 23 | .to_return(body: [expected_behavior.to_h].to_json) 24 | 25 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 26 | command = BrickFTP::RESTfulAPI::ListFolderBehaviors.new(rest) 27 | 28 | expect(command.call('a', recursive: true)).to eq([expected_behavior]) 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/list_groups_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::ListGroups, type: :lib do 6 | describe '#call' do 7 | context 'correct request' do 8 | it 'return Array of Group object' do 9 | expected_group = BrickFTP::Types::Group.new( 10 | id: 1234, 11 | name: 'test', 12 | notes: 'notes', 13 | user_ids: '', 14 | usernames: nil, 15 | admin_ids: [] 16 | ) 17 | 18 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/groups.json') 19 | .with( 20 | basic_auth: %w[api-key x], 21 | headers: { 22 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 23 | } 24 | ) 25 | .to_return(body: [expected_group.to_h].to_json) 26 | 27 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 28 | command = BrickFTP::RESTfulAPI::ListGroups.new(rest) 29 | 30 | expect(command.call).to eq([expected_group]) 31 | end 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/list_notifications_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::ListNotifications, type: :lib do 6 | describe '#call' do 7 | context 'correct request' do 8 | it 'return Array of Notification object' do 9 | expected_notification = BrickFTP::Types::Notification.new( 10 | id: 1234, 11 | path: 'a/b/c', 12 | user_id: 1, 13 | username: 'user', 14 | send_interval: 'daily', 15 | unsubscribed: false 16 | ) 17 | 18 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/notifications.json') 19 | .with( 20 | basic_auth: %w[api-key x], 21 | headers: { 22 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 23 | } 24 | ) 25 | .to_return(body: [expected_notification.to_h].to_json) 26 | 27 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 28 | command = BrickFTP::RESTfulAPI::ListNotifications.new(rest) 29 | 30 | expect(command.call).to eq([expected_notification]) 31 | end 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/list_permissions_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::ListPermissions, type: :lib do 6 | describe '#call' do 7 | context 'correct request' do 8 | it 'return Array of Permission object' do 9 | expected_permission = BrickFTP::Types::Permission.new( 10 | id: 1234, 11 | user_id: 1234, 12 | username: 'user', 13 | group_id: 1234, 14 | group_name: 'group', 15 | path: 'path', 16 | permission: 'full', 17 | recursive: true 18 | ) 19 | 20 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/permissions.json?path=path') 21 | .with( 22 | basic_auth: %w[api-key x], 23 | headers: { 24 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 25 | } 26 | ) 27 | .to_return(body: [expected_permission.to_h].to_json) 28 | 29 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 30 | command = BrickFTP::RESTfulAPI::ListPermissions.new(rest) 31 | 32 | expect(command.call(path: 'path')).to eq([expected_permission]) 33 | end 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/list_public_keys_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::ListPublicKeys, type: :lib do 6 | describe '#call' do 7 | context 'correct request' do 8 | it 'return Array of User Public key object' do 9 | expected_user_public_key = BrickFTP::Types::UserPublicKey.new( 10 | id: 12_345, 11 | title: 'test', 12 | fingerprint: 'finger-pring', 13 | created_at: '2018-08-17T08:16:52-04:00' 14 | ) 15 | 16 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/users/1234/public_keys.json') 17 | .with( 18 | basic_auth: %w[api-key x], 19 | headers: { 20 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 21 | } 22 | ) 23 | .to_return(body: [expected_user_public_key.to_h].to_json) 24 | 25 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 26 | command = BrickFTP::RESTfulAPI::ListPublicKeys.new(rest) 27 | 28 | expect(command.call(1234)).to eq([expected_user_public_key]) 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/move_folder_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::MoveFolder, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'move folder' do 9 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/files/a%20b%2Fc') 10 | .with( 11 | basic_auth: %w[api-key x], 12 | headers: { 13 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 14 | }, 15 | body: { 'move-destination': 'a b/d' }.to_json 16 | ) 17 | .to_return(body: '[]') 18 | 19 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 20 | params = BrickFTP::RESTfulAPI::MoveFolder::Params.new('move-destination': 'a b/d') 21 | command = BrickFTP::RESTfulAPI::MoveFolder.new(rest) 22 | 23 | expect(command.call('a b/c', params)).to be_truthy 24 | end 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/remove_group_member_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::RemoveGroupMember, type: :lib do 6 | describe '#call' do 7 | context 'given correct group id and user id' do 8 | it 'return true' do 9 | stub_request(:delete, 'https://subdomain.files.com/api/rest/v1/groups/1/memberships/2.json') 10 | .with( 11 | basic_auth: %w[api-key x], 12 | headers: { 13 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 14 | } 15 | ) 16 | .to_return(body: '[]') 17 | 18 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 19 | command = BrickFTP::RESTfulAPI::RemoveGroupMember.new(rest) 20 | 21 | expect(command.call(1, 2)).to be_truthy 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/retrieve_file_history_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::RetrieveFileHistory, type: :lib do 6 | describe '#call' do 7 | context 'correct request' do 8 | it 'return Array of History object' do 9 | expected_history = BrickFTP::Types::History.new( 10 | id: 904_650_651, 11 | when: '2015-10-28T15:50:52-04:00', 12 | action: 'read', 13 | path: 'phun/physics1.png', 14 | source: 'phun/physics1.png', 15 | ip: '86.79.30.9', 16 | interface: 'web' 17 | ) 18 | 19 | url = 'https://subdomain.files.com/api/rest/v1/history/files/phun%2Fphysics1.png?page=1&per_page=1&start_at=2018-08-17T00:00:00Z' 20 | stub_request(:get, url) 21 | .with( 22 | basic_auth: %w[api-key x], 23 | headers: { 24 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 25 | } 26 | ) 27 | .to_return(body: [expected_history.to_h].to_json) 28 | 29 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 30 | command = BrickFTP::RESTfulAPI::RetrieveFileHistory.new(rest) 31 | 32 | res = command.call('phun/physics1.png', page: 1, per_page: 1, start_at: Time.parse('2018-08-17T00:00:00Z')) 33 | expect(res).to eq([expected_history]) 34 | end 35 | end 36 | 37 | context 'incorrect page' do 38 | it 'raise exception' do 39 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 40 | command = BrickFTP::RESTfulAPI::RetrieveFileHistory.new(rest) 41 | 42 | expect { command.call('phun/physics1.png', page: 'a') } 43 | .to raise_error(ArgumentError, 'page must be greater than 0.') 44 | end 45 | end 46 | 47 | context 'incorrect per_page' do 48 | it 'raise exception' do 49 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 50 | command = BrickFTP::RESTfulAPI::RetrieveFileHistory.new(rest) 51 | 52 | expect { command.call('phun/physics1.png', per_page: 'a') } 53 | .to raise_error(ArgumentError, 'per_page must be greater than 0 and less than equal 10000.') 54 | end 55 | end 56 | 57 | context 'incorrect start_at' do 58 | it 'raise exception' do 59 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 60 | command = BrickFTP::RESTfulAPI::RetrieveFileHistory.new(rest) 61 | 62 | expect { command.call('phun/physics1.png', start_at: 'a') } 63 | .to raise_error(ArgumentError, 'start_at must be a Time.') 64 | end 65 | end 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/retrieve_folder_history_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::RetrieveFolderHistory, type: :lib do 6 | describe '#call' do 7 | context 'correct request' do 8 | it 'return Array of History object' do 9 | expected_history = BrickFTP::Types::History.new( 10 | id: 904_650_651, 11 | when: '2015-10-28T15:50:52-04:00', 12 | action: 'read', 13 | path: 'phun/physics1.png', 14 | source: 'phun/physics1.png', 15 | ip: '86.79.30.9', 16 | interface: 'web' 17 | ) 18 | 19 | url = 'https://subdomain.files.com/api/rest/v1/history/folders/phun?page=1&per_page=1&start_at=2018-08-17T00:00:00Z' 20 | stub_request(:get, url) 21 | .with( 22 | basic_auth: %w[api-key x], 23 | headers: { 24 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 25 | } 26 | ) 27 | .to_return(body: [expected_history.to_h].to_json) 28 | 29 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 30 | command = BrickFTP::RESTfulAPI::RetrieveFolderHistory.new(rest) 31 | 32 | res = command.call('phun', page: 1, per_page: 1, start_at: Time.parse('2018-08-17T00:00:00Z')) 33 | expect(res).to eq([expected_history]) 34 | end 35 | end 36 | 37 | context 'incorrect page' do 38 | it 'raise exception' do 39 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 40 | command = BrickFTP::RESTfulAPI::RetrieveFolderHistory.new(rest) 41 | 42 | expect { command.call('phun', page: 'a') }.to raise_error(ArgumentError, 'page must be greater than 0.') 43 | end 44 | end 45 | 46 | context 'incorrect per_page' do 47 | it 'raise exception' do 48 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 49 | command = BrickFTP::RESTfulAPI::RetrieveFolderHistory.new(rest) 50 | 51 | expect { command.call('phun', per_page: 'a') } 52 | .to raise_error(ArgumentError, 'per_page must be greater than 0 and less than equal 10000.') 53 | end 54 | end 55 | 56 | context 'incorrect start_at' do 57 | it 'raise exception' do 58 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 59 | command = BrickFTP::RESTfulAPI::RetrieveFolderHistory.new(rest) 60 | 61 | expect { command.call('phun', start_at: 'a') }.to raise_error(ArgumentError, 'start_at must be a Time.') 62 | end 63 | end 64 | end 65 | end 66 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/retrieve_login_history_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::RetrieveLoginHistory, type: :lib do 6 | describe '#call' do 7 | context 'correct request' do 8 | it 'return Array of History object' do 9 | expected_history = BrickFTP::Types::History.new( 10 | id: 904_593_281, 11 | when: '2015-10-28T14:03:08-04:00', 12 | user_id: 54_321, 13 | username: 'justice.london', 14 | action: 'login', 15 | ip: '86.75.30.9', 16 | interface: 'web' 17 | ) 18 | 19 | url = 'https://subdomain.files.com/api/rest/v1/history/login.json?page=1&per_page=1&start_at=2018-08-17T00:00:00Z' 20 | stub_request(:get, url) 21 | .with( 22 | basic_auth: %w[api-key x], 23 | headers: { 24 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 25 | } 26 | ) 27 | .to_return(body: [expected_history.to_h].to_json) 28 | 29 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 30 | command = BrickFTP::RESTfulAPI::RetrieveLoginHistory.new(rest) 31 | 32 | res = command.call(page: 1, per_page: 1, start_at: Time.parse('2018-08-17T00:00:00Z')) 33 | expect(res).to eq([expected_history]) 34 | end 35 | end 36 | 37 | context 'incorrect page' do 38 | it 'raise exception' do 39 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 40 | command = BrickFTP::RESTfulAPI::RetrieveLoginHistory.new(rest) 41 | 42 | expect { command.call(page: 'a') }.to raise_error(ArgumentError, 'page must be greater than 0.') 43 | end 44 | end 45 | 46 | context 'incorrect per_page' do 47 | it 'raise exception' do 48 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 49 | command = BrickFTP::RESTfulAPI::RetrieveLoginHistory.new(rest) 50 | 51 | expect { command.call(per_page: 'a') } 52 | .to raise_error(ArgumentError, 'per_page must be greater than 0 and less than equal 10000.') 53 | end 54 | end 55 | 56 | context 'incorrect start_at' do 57 | it 'raise exception' do 58 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 59 | command = BrickFTP::RESTfulAPI::RetrieveLoginHistory.new(rest) 60 | 61 | expect { command.call(start_at: 'a') }.to raise_error(ArgumentError, 'start_at must be a Time.') 62 | end 63 | end 64 | end 65 | end 66 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/retrieve_site_history_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::RetrieveSiteHistory, type: :lib do 6 | describe '#call' do 7 | context 'correct request' do 8 | it 'return Array of History object' do 9 | expected_history = BrickFTP::Types::History.new( 10 | id: 869_831_023, 11 | when: '2015-09-19T22:30:20-04:00', 12 | user_id: 12_345, 13 | username: 'fred.admin', 14 | action: 'login', 15 | ip: '172.19.113.171', 16 | interface: 'ftp' 17 | ) 18 | 19 | url = 'https://subdomain.files.com/api/rest/v1/history.json?page=1&per_page=1&start_at=2018-08-17T00:00:00Z' 20 | stub_request(:get, url) 21 | .with( 22 | basic_auth: %w[api-key x], 23 | headers: { 24 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 25 | } 26 | ) 27 | .to_return(body: [expected_history.to_h].to_json) 28 | 29 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 30 | command = BrickFTP::RESTfulAPI::RetrieveSiteHistory.new(rest) 31 | 32 | res = command.call(page: 1, per_page: 1, start_at: Time.parse('2018-08-17T00:00:00Z')) 33 | expect(res).to eq([expected_history]) 34 | end 35 | end 36 | 37 | context 'incorrect page' do 38 | it 'raise exception' do 39 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 40 | command = BrickFTP::RESTfulAPI::RetrieveSiteHistory.new(rest) 41 | 42 | expect { command.call(page: 'a') }.to raise_error(ArgumentError, 'page must be greater than 0.') 43 | end 44 | end 45 | 46 | context 'incorrect per_page' do 47 | it 'raise exception' do 48 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 49 | command = BrickFTP::RESTfulAPI::RetrieveSiteHistory.new(rest) 50 | 51 | expect { command.call(per_page: 'a') } 52 | .to raise_error(ArgumentError, 'per_page must be greater than 0 and less than equal 10000.') 53 | end 54 | end 55 | 56 | context 'incorrect start_at' do 57 | it 'raise exception' do 58 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 59 | command = BrickFTP::RESTfulAPI::RetrieveSiteHistory.new(rest) 60 | 61 | expect { command.call(start_at: 'a') }.to raise_error(ArgumentError, 'start_at must be a Time.') 62 | end 63 | end 64 | end 65 | end 66 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/retrieve_user_history_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::RetrieveUserHistory, type: :lib do 6 | describe '#call' do 7 | context 'correct request' do 8 | it 'return Array of History object' do 9 | expected_history = BrickFTP::Types::History.new( 10 | id: 903_767_970, 11 | when: '2015-10-27T15:09:55-04:00', 12 | user_id: 54_321, 13 | username: 'justice.london', 14 | action: 'create', 15 | path: 'accounts.xls', 16 | destination: 'accounts.xls', 17 | ip: '86.75.30.9', 18 | interface: 'ftp' 19 | ) 20 | 21 | url = 'https://subdomain.files.com/api/rest/v1/history/users/54321.json?page=1&per_page=1&start_at=2018-08-17T00:00:00Z' 22 | stub_request(:get, url) 23 | .with( 24 | basic_auth: %w[api-key x], 25 | headers: { 26 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 27 | } 28 | ) 29 | .to_return(body: [expected_history.to_h].to_json) 30 | 31 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 32 | command = BrickFTP::RESTfulAPI::RetrieveUserHistory.new(rest) 33 | 34 | res = command.call(54_321, page: 1, per_page: 1, start_at: Time.parse('2018-08-17T00:00:00Z')) 35 | expect(res).to eq([expected_history]) 36 | end 37 | end 38 | 39 | context 'incorrect page' do 40 | it 'raise exception' do 41 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 42 | command = BrickFTP::RESTfulAPI::RetrieveUserHistory.new(rest) 43 | 44 | expect { command.call(54_321, page: 'a') }.to raise_error(ArgumentError, 'page must be greater than 0.') 45 | end 46 | end 47 | 48 | context 'incorrect per_page' do 49 | it 'raise exception' do 50 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 51 | command = BrickFTP::RESTfulAPI::RetrieveUserHistory.new(rest) 52 | 53 | expect { command.call(54_321, per_page: 'a') } 54 | .to raise_error(ArgumentError, 'per_page must be greater than 0 and less than equal 10000.') 55 | end 56 | end 57 | 58 | context 'incorrect start_at' do 59 | it 'raise exception' do 60 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 61 | command = BrickFTP::RESTfulAPI::RetrieveUserHistory.new(rest) 62 | 63 | expect { command.call(54_321, start_at: 'a') }.to raise_error(ArgumentError, 'start_at must be a Time.') 64 | end 65 | end 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/search_user_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::SearchUser, type: :lib do 6 | describe '#call' do 7 | context 'given correct username' do 8 | it 'return User object' do 9 | expected_user = BrickFTP::Types::User.new( 10 | id: 1234, 11 | username: 'user', 12 | authentication_method: 'password', 13 | last_login_at: nil, 14 | authenticate_until: nil, 15 | name: nil, 16 | email: 'user@example.com', 17 | notes: nil, 18 | group_ids: '', 19 | ftp_permission: true, 20 | sftp_permission: true, 21 | dav_permission: true, 22 | restapi_permission: true, 23 | attachments_permission: true, 24 | self_managed: true, 25 | require_password_change: false, 26 | require_2fa: false, 27 | allowed_ips: nil, 28 | user_root: '', 29 | time_zone: 'Eastern Time (US & Canada)', 30 | language: '', 31 | ssl_required: 'use_system_setting', 32 | site_admin: true, 33 | password_set_at: nil, 34 | receive_admin_alerts: true, 35 | subscribe_to_newsletter: false, 36 | last_protocol_cipher: nil, 37 | lockout_expires: nil, 38 | admin_group_ids: [] 39 | ) 40 | 41 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/users.json?q[username]=user') 42 | .with( 43 | basic_auth: %w[api-key x], 44 | headers: { 45 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 46 | } 47 | ) 48 | .to_return(body: [expected_user.to_h].to_json) 49 | 50 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 51 | command = BrickFTP::RESTfulAPI::SearchUser.new(rest) 52 | 53 | expect(command.call('user')).to eq expected_user 54 | end 55 | end 56 | 57 | context 'User not found' do 58 | it 'return nil' do 59 | stub_request(:get, 'https://subdomain.files.com/api/rest/v1/users.json?q[username]=a%26b') 60 | .with( 61 | basic_auth: %w[api-key x], 62 | headers: { 63 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 64 | } 65 | ) 66 | .to_return(body: '[]') 67 | 68 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 69 | command = BrickFTP::RESTfulAPI::SearchUser.new(rest) 70 | 71 | expect(command.call('a&b')).to be_nil 72 | end 73 | end 74 | end 75 | end 76 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/start_upload_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::StartUpload, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'start upload' do 9 | expected_upload = BrickFTP::Types::Upload.new( 10 | ref: 'put-378670', 11 | path: 'NewFile.txt', 12 | action: 'put/write', 13 | ask_about_overwrites: false, 14 | http_method: 'PUT', 15 | upload_uri: 'https://s3.amazonaws.com/objects.files.com/...', 16 | partsize: 5_242_880, 17 | part_number: 1, 18 | available_parts: 10_000, 19 | send: { 20 | 'partsize' => 'required-parameter Content-Length', 21 | 'partdata' => 'body', 22 | }, 23 | headers: {}, 24 | parameters: {} 25 | ) 26 | 27 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/files/a%20b%2Fc') 28 | .with( 29 | basic_auth: %w[api-key x], 30 | headers: { 31 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 32 | }, 33 | body: { action: 'put' }.to_json 34 | ) 35 | .to_return(body: expected_upload.to_h.to_json) 36 | 37 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 38 | command = BrickFTP::RESTfulAPI::StartUpload.new(rest) 39 | 40 | expect(command.call('a b/c')).to eq expected_upload 41 | end 42 | end 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/unlock_user_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::UnlockUser, type: :lib do 6 | describe '#call' do 7 | context 'given correct User ID' do 8 | it 'return User object' do 9 | expected_user = BrickFTP::Types::User.new( 10 | id: 1234, 11 | username: 'user', 12 | authentication_method: 'password', 13 | last_login_at: nil, 14 | authenticate_until: nil, 15 | name: nil, 16 | email: 'user@example.com', 17 | notes: nil, 18 | group_ids: '', 19 | ftp_permission: true, 20 | sftp_permission: true, 21 | dav_permission: true, 22 | restapi_permission: true, 23 | attachments_permission: true, 24 | self_managed: true, 25 | require_password_change: false, 26 | require_2fa: false, 27 | allowed_ips: nil, 28 | user_root: '', 29 | time_zone: 'Eastern Time (US & Canada)', 30 | language: '', 31 | ssl_required: 'use_system_setting', 32 | site_admin: true, 33 | password_set_at: nil, 34 | receive_admin_alerts: true, 35 | subscribe_to_newsletter: false, 36 | last_protocol_cipher: nil, 37 | lockout_expires: nil, 38 | admin_group_ids: [] 39 | ) 40 | 41 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/users/1234/unlock.json') 42 | .with( 43 | basic_auth: %w[api-key x], 44 | headers: { 45 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 46 | } 47 | ) 48 | .to_return(body: expected_user.to_h.to_json) 49 | 50 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 51 | command = BrickFTP::RESTfulAPI::UnlockUser.new(rest) 52 | 53 | expect(command.call(1234)).to eq expected_user 54 | end 55 | end 56 | 57 | context 'User not found' do 58 | it 'raise exception' do 59 | stub_request(:post, 'https://subdomain.files.com/api/rest/v1/users/1234/unlock.json') 60 | .with( 61 | basic_auth: %w[api-key x], 62 | headers: { 63 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 64 | } 65 | ) 66 | .to_return(body: '[]', status: 404) 67 | 68 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 69 | command = BrickFTP::RESTfulAPI::UnlockUser.new(rest) 70 | 71 | expect { command.call(1234) }.to raise_error(BrickFTP::RESTfulAPI::Client::Error) 72 | end 73 | end 74 | end 75 | end 76 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/update_behavior_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::UpdateBehavior, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'return updated Behavior object' do 9 | updated_behavior = BrickFTP::Types::Behavior.new( 10 | id: 38, 11 | path: 'a', 12 | behavior: 'webhook', 13 | value: %w[https://a.mywebhookhandler.com] 14 | ) 15 | 16 | stub_request(:patch, 'https://subdomain.files.com/api/rest/v1/behaviors/38.json') 17 | .with( 18 | basic_auth: %w[api-key x], 19 | headers: { 20 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 21 | }, 22 | body: { value: %w[https://a.mywebhookhandler.com] }.to_json 23 | ) 24 | .to_return(body: updated_behavior.to_h.to_json) 25 | 26 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 27 | params = BrickFTP::RESTfulAPI::UpdateBehavior::Params.new(value: %w[https://a.mywebhookhandler.com]) 28 | command = BrickFTP::RESTfulAPI::UpdateBehavior.new(rest) 29 | 30 | expect(command.call(38, params)).to eq updated_behavior 31 | end 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/update_group_member_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::UpdateGroupMember, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'return created Group Membership object' do 9 | created_group_membership = BrickFTP::Types::GroupMembership.new( 10 | id: 1234, 11 | group_id: 1, 12 | user_id: 2, 13 | admin: true 14 | ) 15 | 16 | stub_request(:patch, 'https://subdomain.files.com/api/rest/v1/groups/1/memberships/2.json') 17 | .with( 18 | basic_auth: %w[api-key x], 19 | headers: { 20 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 21 | }, 22 | body: { membership: { admin: true } }.to_json 23 | ) 24 | .to_return(body: created_group_membership.to_h.to_json) 25 | 26 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 27 | params = BrickFTP::RESTfulAPI::UpdateGroupMember::Params.new(admin: true) 28 | command = BrickFTP::RESTfulAPI::UpdateGroupMember.new(rest) 29 | 30 | expect(command.call(1, 2, params)).to eq created_group_membership 31 | end 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/update_group_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::UpdateGroup, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'return updated Group object' do 9 | updated_group = BrickFTP::Types::Group.new( 10 | id: 1234, 11 | name: 'group', 12 | notes: 'notes', 13 | user_ids: '1,2,3', 14 | usernames: 'a,b,c', 15 | admin_ids: [1, 2, 3] 16 | ) 17 | 18 | stub_request(:put, 'https://subdomain.files.com/api/rest/v1/groups/1234.json') 19 | .with( 20 | basic_auth: %w[api-key x], 21 | headers: { 22 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 23 | }, 24 | body: { name: 'group' }.to_json 25 | ) 26 | .to_return(body: updated_group.to_h.to_json) 27 | 28 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 29 | params = BrickFTP::RESTfulAPI::UpdateGroup::Params.new(name: 'group') 30 | command = BrickFTP::RESTfulAPI::UpdateGroup.new(rest) 31 | 32 | expect(command.call(1234, params)).to eq updated_group 33 | end 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /spec/brick_ftp/restful_api/update_user_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | RSpec.describe BrickFTP::RESTfulAPI::UpdateUser, type: :lib do 6 | describe '#call' do 7 | context 'given correct parameters' do 8 | it 'return updated User object' do 9 | updated_user = BrickFTP::Types::User.new( 10 | id: 1234, 11 | username: 'user', 12 | authentication_method: 'password', 13 | last_login_at: nil, 14 | authenticate_until: nil, 15 | name: nil, 16 | email: 'user@example.com', 17 | notes: nil, 18 | group_ids: '', 19 | ftp_permission: true, 20 | sftp_permission: true, 21 | dav_permission: true, 22 | restapi_permission: true, 23 | attachments_permission: true, 24 | self_managed: true, 25 | require_password_change: false, 26 | require_2fa: false, 27 | allowed_ips: nil, 28 | user_root: '', 29 | time_zone: 'Eastern Time (US & Canada)', 30 | language: '', 31 | ssl_required: 'use_system_setting', 32 | site_admin: true, 33 | password_set_at: nil, 34 | receive_admin_alerts: true, 35 | subscribe_to_newsletter: false, 36 | last_protocol_cipher: nil, 37 | lockout_expires: nil, 38 | admin_group_ids: [] 39 | ) 40 | 41 | stub_request(:patch, 'https://subdomain.files.com/api/rest/v1/users/1234.json') 42 | .with( 43 | basic_auth: %w[api-key x], 44 | headers: { 45 | 'User-Agent' => 'BrickFTP Client/1.0 (https://github.com/koshigoe/brick_ftp)', 46 | }, 47 | body: { username: 'user' }.to_json 48 | ) 49 | .to_return(body: updated_user.to_h.to_json) 50 | 51 | rest = BrickFTP::RESTfulAPI::Client.new('subdomain', 'api-key') 52 | params = BrickFTP::RESTfulAPI::UpdateUser::Params.new(username: 'user') 53 | command = BrickFTP::RESTfulAPI::UpdateUser.new(rest) 54 | 55 | expect(command.call(1234, params)).to eq updated_user 56 | end 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /spec/brick_ftp/utils/chunk_io_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | require 'tempfile' 5 | 6 | RSpec.describe BrickFTP::Utils::ChunkIO do 7 | describe '#each' do 8 | context 'chunk_size is nil' do 9 | it 'chunk has whole data' do 10 | Tempfile.create('spec') do |io| 11 | io.write('DATA') 12 | io.rewind 13 | 14 | res = +'' 15 | called = 0 16 | described_class.new(io).each do |chunk| 17 | res << chunk.read 18 | called += 1 19 | end 20 | expect(res).to eq 'DATA' 21 | expect(called).to eq 1 22 | end 23 | end 24 | end 25 | 26 | context 'chunk_size is not nil' do 27 | context 'data is a StringIO' do 28 | it 'chunk has whole data' do 29 | io = StringIO.new('DATA') 30 | io.rewind 31 | 32 | res = +'' 33 | called = 0 34 | described_class.new(io, chunk_size: 1).each do |chunk| 35 | res << chunk.read 36 | called += 1 37 | end 38 | expect(res).to eq 'DATA' 39 | expect(called).to eq 1 40 | end 41 | end 42 | 43 | context 'data is not a StringIO' do 44 | it 'split by chunk_size' do 45 | Tempfile.create('spec') do |io| 46 | io.write('DATA') 47 | io.rewind 48 | 49 | res = +'' 50 | called = 0 51 | described_class.new(io, chunk_size: 1).each do |chunk| 52 | res << chunk.read 53 | called += 1 54 | end 55 | expect(res).to eq 'DATA' 56 | expect(called).to eq 4 57 | end 58 | end 59 | end 60 | end 61 | 62 | context 'without block' do 63 | it 'return Enumerator' do 64 | Tempfile.create('spec') do |io| 65 | io.write('DATA') 66 | io.rewind 67 | 68 | enum = described_class.new(io, chunk_size: 1).each 69 | expect(enum).to be_an_instance_of(Enumerator) 70 | 71 | res = +'' 72 | called = 0 73 | enum.each do |chunk| 74 | res << chunk.read 75 | called += 1 76 | end 77 | expect(res).to eq 'DATA' 78 | expect(called).to eq 4 79 | end 80 | end 81 | end 82 | end 83 | end 84 | -------------------------------------------------------------------------------- /spec/brick_ftp_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | describe BrickFTP do 6 | it 'has a version number' do 7 | expect(BrickFTP::VERSION).not_to be nil 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Warning[:deprecated] = true if Warning.respond_to?(:[]=) 4 | 5 | $LOAD_PATH.unshift File.expand_path('../lib', __dir__) 6 | require 'simplecov' 7 | SimpleCov.start do 8 | add_filter '/spec/' 9 | end 10 | 11 | require 'brick_ftp' 12 | require 'webmock/rspec' 13 | --------------------------------------------------------------------------------