ubiquity-mediasilo-api-v3 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/Gemfile +6 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +100 -0
  6. data/Rakefile +2 -0
  7. data/bin/ubiquity-mediasilo-api-v3 +26 -0
  8. data/lib/ubiquity/cli.rb +127 -0
  9. data/lib/ubiquity/mediasilo/api/v3.rb +11 -0
  10. data/lib/ubiquity/mediasilo/api/v3/cli.rb +94 -0
  11. data/lib/ubiquity/mediasilo/api/v3/client.rb +712 -0
  12. data/lib/ubiquity/mediasilo/api/v3/client/paginator.rb +133 -0
  13. data/lib/ubiquity/mediasilo/api/v3/client/requests.rb +18 -0
  14. data/lib/ubiquity/mediasilo/api/v3/client/requests/asset_copy_to_folder.rb +19 -0
  15. data/lib/ubiquity/mediasilo/api/v3/client/requests/asset_copy_to_project.rb +19 -0
  16. data/lib/ubiquity/mediasilo/api/v3/client/requests/asset_create.rb +25 -0
  17. data/lib/ubiquity/mediasilo/api/v3/client/requests/asset_delete.rb +15 -0
  18. data/lib/ubiquity/mediasilo/api/v3/client/requests/asset_get_by_id.rb +14 -0
  19. data/lib/ubiquity/mediasilo/api/v3/client/requests/asset_move_to_folder.rb +16 -0
  20. data/lib/ubiquity/mediasilo/api/v3/client/requests/asset_move_to_project.rb +16 -0
  21. data/lib/ubiquity/mediasilo/api/v3/client/requests/assets_get.rb +56 -0
  22. data/lib/ubiquity/mediasilo/api/v3/client/requests/assets_get_by_folder_id.rb +14 -0
  23. data/lib/ubiquity/mediasilo/api/v3/client/requests/assets_get_by_project_id.rb +14 -0
  24. data/lib/ubiquity/mediasilo/api/v3/client/requests/base_request.rb +250 -0
  25. data/lib/ubiquity/mediasilo/api/v3/client/requests/batch.rb +20 -0
  26. data/lib/ubiquity/mediasilo/api/v3/client/requests/project_create.rb +15 -0
  27. data/lib/ubiquity/mediasilo/api/v3/client/requests/quicklink_create.rb +54 -0
  28. data/lib/ubiquity/mediasilo/api/v3/client/requests/quicklink_share.rb +32 -0
  29. data/lib/ubiquity/mediasilo/api/v3/http_client.rb +259 -0
  30. data/lib/ubiquity/mediasilo/api/v3/utilities.rb +1145 -0
  31. data/lib/ubiquity/mediasilo/api/v3/version.rb +9 -0
  32. data/ubiquity-mediasilo-api-v3.gemspec +23 -0
  33. metadata +104 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 54cf59a7ea65c7df96f0719811903d39bfcb6c1b97ae5cec0b4f008798f93d2b
4
+ data.tar.gz: 9cfdf801968ce36e807aa7feda43962694cbe05f26fea7ef5f5edad09797f03a
5
+ SHA512:
6
+ metadata.gz: 28e4ca082b3acd5e2dc89af4d2279f28aae7106cd5ac811daf7ae383ea967d0a436db49a188bafe5e53cf62be632e212bfe885cd0665be31f67c96e1dd1ec330
7
+ data.tar.gz: ea6480782a75acaeffff0aedbeeef60aea157936ca61283536407dd4e40c5cb63d680b991619b1dca1f2ae7f84335c808813922d35b9cb184a2818ba8447249c
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /dev/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'json', '~>1.8', :platforms => :mri_18
4
+
5
+ # Specify your gem's dependencies in ubiquity-mediasilo-api-v3.gemspec
6
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 John Whitson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,100 @@
1
+ # Ubiquity::Mediasilo::Api::V3
2
+
3
+ A Library and Utilities to Interact with the MediaSilo API v3
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ubiquity-mediasilo-api-v3'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ubiquity-mediasilo-api-v3
20
+
21
+ ## MediaSilo API V3 Executable [bin/ubiquity-mediasilo-api-v3](./bin/ubiquity-mediasilo-api-v3)
22
+ An executable to interact with the MediaSilo API
23
+
24
+ ### Usage
25
+ Usage:
26
+
27
+ ubiquity-mediasilo-api-v3 -h | --help
28
+ ubiquity-mediasilo-api-v3 --hostname <HOSTNAME> --username <USERNAME> --password <PASSWORD> --method-name <METHOD NAME> --method-arguments <JSON>
29
+
30
+ Options:
31
+ --hostname HOSTNAME The hostname to authenticate with.
32
+ --username USERNAME The username to authenticate with.
33
+ --password PASSWORD The password to authenticate with.
34
+ --method-name METHODNAME The name of the method to call.
35
+ --method-arguments JSON The arguments to pass when calling the method.
36
+ --pretty-print Will format the output to be more human readable.
37
+ --[no-]options-file [FILENAME]
38
+ Path to a file which contains default command line arguments.
39
+ default: ~/.options/ubiquity-mediasilo-api-v3
40
+ -h, --help Display this message.
41
+
42
+
43
+ #### Examples
44
+
45
+ ##### [Assets](http://developers.mediasilo.com/assets)
46
+
47
+ ###### Asset Copy to Folder
48
+
49
+ ###### Asset Copy to Project
50
+
51
+ ###### Asset Create ([Create a new asset](http://developers.mediasilo.com/assets))
52
+
53
+ ubiquity-mediasilo-api-v3 --hostname <HOSTNAME> --username <USERNAME> --password <PASSWORD> --method-name asset_create --method-arguments '{"project_id":"<PROJECT ID (GUID)>","source_url":"<SOURCE URL"}'
54
+
55
+ - project_id [String] (Required) The ID of the Project this asset belongs to.
56
+ - folder_id [String] The ID of the Folder this asset belongs to.
57
+ - title [String] Defaults to filename
58
+ - description [String] A brief description of the asset
59
+ - source_url [String] Must be a publicly-accessible URL. NOTE: ** SPACES MUST BE REPLACED WITH a plus '+'
60
+ - is_private [Boolean] If set to true, only authorized users can view the asset (this value may be overridden by account settings)
61
+
62
+ ###### Asset Delete
63
+
64
+ ubiquity-mediasilo-api-v3 --hostname <HOSTNAME> --username <USERNAME> --password <PASSWORD> --method-name asset_create --method-arguments '{"asset_id":"<ASSET ID (GUID)>"}'
65
+
66
+ - asset_id [String] (Required) The id of the asset to delete.
67
+
68
+ ##### Projects
69
+
70
+ ###### Project Create ([Create a project](http://developers.mediasilo.com/projects)])
71
+
72
+ ubiquity-mediasilo-api-v3 --hostname <HOSTNAME> --username <USERNAME> --password <PASSWORD> --method-name project_create --method-arguments '{"name":"<PROJECT NAME>"}'
73
+
74
+ - name [String] (Required) Name of the project.
75
+ - description [String] Description of the project.
76
+
77
+ ###### Project Delete ([Delete a project](http://developers.mediasilo.com/projects)])
78
+
79
+ ubiquity-mediasilo-api-v3 --hostname <HOSTNAME> --username <USERNAME> --password <PASSWORD> --method-name project_delete --method-arguments '{"id":"<PROJECT ID (GUID)>"}'
80
+
81
+ - project_id [String] (Required) The id of the project to delete.
82
+
83
+ ###### Project Get by Id ([Retrieve a project](http://developers.mediasilo.com/projects))
84
+
85
+ ubiquity-mediasilo-api-v3 --hostname <HOSTNAME> --username <USERNAME> --password <PASSWORD> --method-name project_get_by_id --method-arguments '{"id":"<PROJECT ID (GUID)>"}'
86
+
87
+ - id [String] (Required) Id (GUID) of the project.
88
+
89
+
90
+
91
+ ## Contributing
92
+
93
+ 1. Fork it ( https://github.com/XPlatform-Consulting/ubiquity-mediasilo-api-v3/fork )
94
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
95
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
96
+ 4. Push to the branch (`git push origin my-new-feature`)
97
+ 5. Create a new Pull Request
98
+
99
+
100
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ lib_path = File.expand_path('../../lib', __FILE__)
3
+ $:.unshift(lib_path) unless $:.include?(lib_path) or !File.exists?(lib_path)
4
+
5
+ require 'rubygems'
6
+ require 'ubiquity/mediasilo/api/v3/cli'
7
+
8
+ interactive = ARGV.delete('--interactive')
9
+ begin
10
+ if interactive
11
+ def load_cli; load 'ubiquity/mediasilo/api/v3/cli.rb'; @cli = nil end; load_cli
12
+ require 'irb'; IRB.start
13
+ else
14
+ require 'ubiquity/mediasilo/api/v3/cli'
15
+ ARGV << '--help' if ARGV.empty?
16
+ cli.run
17
+ end
18
+ rescue LoadError
19
+ lib_path = File.expand_path('../../lib', __FILE__)
20
+ unless $:.include?(lib_path)
21
+ $:.unshift(lib_path)
22
+ retry
23
+ end
24
+ abort("Failed to load the required file. Exception: #{$!}")
25
+ end
26
+
@@ -0,0 +1,127 @@
1
+ require 'optparse'
2
+
3
+ module Ubiquity
4
+
5
+ class CLI
6
+
7
+ def self.define_parameters
8
+ # To be implemented by the child class
9
+ argument_parser.on_tail('-h', '--help', 'Display this message.') { puts help; exit }
10
+ end
11
+
12
+ def initialize(args = self.class.parse_arguments)
13
+ # To be implemented by the child class
14
+ end
15
+
16
+ def self.default_options_file_path
17
+ File.expand_path(File.basename($0, '.*'), '~/.options')
18
+ end
19
+
20
+ def self.default_arguments
21
+ @default_arguments ||= {
22
+ :options_file_path => default_options_file_path,
23
+ }
24
+ end
25
+
26
+ def self.help_usage
27
+ # To be implemented by the child class
28
+ help_usage_default
29
+ end
30
+
31
+ def self.help_usage_append(string = '')
32
+ usage_string = "\n #{executable_name} #{string}"
33
+ @help_usage << usage_string unless (@help_usage ||= help_usage_default).include?(usage_string)
34
+ end
35
+
36
+ def self.help_usage_default
37
+ " #{executable_name} -h | --help"
38
+ end
39
+
40
+ def self.help
41
+ @help_usage ||= help_usage_default
42
+ argument_parser.banner = <<-BANNER
43
+ Usage:
44
+ #{help_usage}
45
+
46
+ Options:
47
+ BANNER
48
+ argument_parser
49
+ end
50
+
51
+ ## Methods below this line should not need to be implemented by the child class
52
+
53
+
54
+ class << self
55
+ attr_writer :argument_parser,
56
+ :help_usage,
57
+ :default_arguments, :arguments, :arguments_from_command_line, :arguments_from_options_file
58
+ end
59
+
60
+ def self.argument_parser(options = { })
61
+ return @argument_parser if @argument_parser and !options[:force_new]
62
+ @argument_parser = OptionParser.new
63
+ arguments and define_parameters if options.fetch(:define_parameters, true)
64
+ @argument_parser
65
+ end
66
+
67
+ def self.arguments
68
+ @arguments ||= begin
69
+ default_arguments.dup
70
+ end
71
+ end
72
+
73
+ def self.arguments_from_command_line(array_of_arguments = ARGV)
74
+ @arguments_from_command_line ||= parse_arguments_from_command_line(array_of_arguments)
75
+ end
76
+
77
+ def self.arguments_from_options_file(options_file_path = arguments[:options_file_path])
78
+ @arguments_from_options_file ||= parse_arguments_from_options_file(options_file_path)
79
+ end
80
+
81
+ def self.parse_arguments_from_command_line(array_of_arguments = ARGV)
82
+ arguments_before = arguments.dup
83
+ arguments.clear
84
+
85
+ argument_parser.parse!(array_of_arguments.dup)
86
+ _arguments_from_options_file = arguments.dup
87
+ @arguments = arguments_before
88
+ _arguments_from_options_file
89
+ end
90
+
91
+ def self.parse_arguments_from_options_file(options_file_path = arguments[:options_file_path])
92
+ arguments_before = arguments.dup
93
+ arguments.clear
94
+ argument_parser.load(options_file_path)
95
+ _arguments_from_options_file = arguments.dup
96
+ @arguments = arguments_before
97
+ _arguments_from_options_file
98
+ end
99
+
100
+ def self.parse_arguments
101
+ argument_parser
102
+ @arguments = default_arguments.merge(arguments_from_options_file).merge(arguments_from_command_line)
103
+ end
104
+
105
+ def self.clear_cached_arguments
106
+ @arguments_from_command_line = nil
107
+ @arguments_from_options_file = nil
108
+ @arguments = nil
109
+ @default_arguments = nil
110
+ argument_parser(:force_new => true)
111
+ true
112
+ end
113
+
114
+ def self.executable_name
115
+ @executable_name ||= File.basename($0)
116
+ end
117
+
118
+ def self.run(args = nil, init_options = { }, run_options = { })
119
+ args ||= parse_arguments
120
+ new(args, init_options).run(args, run_options)
121
+ end
122
+
123
+ # CLI
124
+ end
125
+
126
+ # Ubiquity
127
+ end
@@ -0,0 +1,11 @@
1
+ require 'ubiquity/mediasilo/api/v3/version'
2
+
3
+ module Ubiquity
4
+ module Mediasilo
5
+ class API
6
+ module V3
7
+
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,94 @@
1
+ require 'ubiquity/cli'
2
+
3
+ require 'ubiquity/mediasilo/api/v3/client'
4
+
5
+ class Ubiquity::MediaSilo::API::V3::CLI < Ubiquity::CLI
6
+
7
+ def self.help_usage
8
+ help_usage_append '--hostname <HOSTNAME> --username <USERNAME> --password <PASSWORD> --method-name <METHODNAME> --method-arguments <JSON>'
9
+ end
10
+
11
+ def self.define_parameters
12
+ argument_parser.on('--hostname HOSTNAME', 'The account hostname to authenticate with.') { |v| arguments[:hostname] = v }
13
+ argument_parser.on('--username USERNAME', 'The account username to authenticate with.') { |v| arguments[:username] = v }
14
+ argument_parser.on('--password PASSWORD', 'The account password to authenticate with.') { |v| arguments[:password] = v }
15
+
16
+ argument_parser.on('--method-name METHODNAME', 'The name of the method to call.') { |v| arguments[:method_name] = v }
17
+ argument_parser.on('--method-arguments JSON', 'The arguments to pass when calling the method.') { |v| arguments[:method_arguments] = v }
18
+ argument_parser.on('--pretty-print', 'Will format the output to be more human readable.') { |v| arguments[:pretty_print] = v }
19
+
20
+ argument_parser.on('--[no-]options-file [FILENAME]', 'Path to a file which contains default command line arguments.', "\tdefault: #{arguments[:options_file_path]}" ) { |v| arguments[:options_file_path] = v}
21
+ argument_parser.on_tail('-h', '--help', 'Display this message.') { puts help; exit }
22
+ end
23
+
24
+ attr_accessor :logger, :api
25
+
26
+ def initialize(args = self.class.arguments, options = { })
27
+ @initial_args = args.dup
28
+ initialize_logger(args)
29
+ initialize_api(args)
30
+ end
31
+
32
+ # @param [Hash] args
33
+ # @option args [Logger] :logger A logger to be used
34
+ # @option args [IO, String] :log_to An IO device or file to log to
35
+ # @option args [Integer] :log_level (Logger::DEBUG) The logging level to be set to the logger
36
+ def initialize_logger(args = { })
37
+ @logger = args[:logger] ||= Logger.new(args[:log_to] ||= STDERR)
38
+ @logger.level = (log_level = args[:log_level]) ? log_level : Logger::WARN
39
+ args[:logger] = @logger
40
+ args[:log_level] ||= @logger.level
41
+ @logger
42
+ end
43
+
44
+ def initialize_api(args = { })
45
+ @api = Ubiquity::MediaSilo::API::V3::Client.new(args.merge(:parse_response => false))
46
+ end
47
+
48
+ def send(method_name, method_arguments, params = {})
49
+ method_name = method_name.to_sym
50
+ logger.debug { "Executing Method: #{method_name}" }
51
+
52
+ send_arguments = [ method_name ]
53
+
54
+ if method_arguments
55
+ method_arguments = JSON.parse(method_arguments, :symbolize_names => true) if method_arguments.is_a?(String) and method_arguments.start_with?('{', '[')
56
+ send_arguments << method_arguments
57
+ end
58
+
59
+ response = api.__send__(*send_arguments)
60
+
61
+ # if aa.response.code.to_i.between?(500,599)
62
+ # puts aa.parsed_response
63
+ # exit
64
+ # end
65
+ #
66
+ # if ResponseHandler.respond_to?(method_name)
67
+ # ResponseHandler.aa = aa
68
+ # ResponseHandler.response = response
69
+ # response = ResponseHandler.__send__(*send_arguments)
70
+ # end
71
+
72
+ if params[:pretty_print]
73
+ if response.is_a?(String) and response.lstrip.start_with?('{', '[')
74
+ puts JSON.pretty_generate(JSON.parse(response))
75
+ else
76
+ pp response
77
+ end
78
+ else
79
+ response = JSON.generate(response) if response.is_a?(Hash) or response.is_a?(Array)
80
+ puts response
81
+ end
82
+ # send
83
+ end
84
+
85
+ def run(args = self.class.arguments, options = { })
86
+ #puts "#{__FILE__}:#{__LINE__}:#{args}"
87
+ method_name = args[:method_name]
88
+ send(method_name, args[:method_arguments], :pretty_print => args[:pretty_print]) if method_name
89
+
90
+ self
91
+ end
92
+
93
+ end
94
+ def cli; @cli ||= Ubiquity::MediaSilo::API::V3::CLI end
@@ -0,0 +1,712 @@
1
+ require 'ubiquity/mediasilo/api/v3/http_client'
2
+ require 'ubiquity/mediasilo/api/v3/client/requests'
3
+ require 'ubiquity/mediasilo/api/v3/client/paginator'
4
+
5
+ class Ubiquity::MediaSilo::API::V3::Client
6
+
7
+ attr_accessor :logger
8
+
9
+ attr_accessor :http_client, :request, :response, :batch_requests, :http_response
10
+
11
+ def initialize(args = { })
12
+ initialize_logger(args)
13
+ initialize_http_client(args)
14
+
15
+ @batch_mode = false
16
+ @batch_requests = [ ]
17
+ end
18
+
19
+ def initialize_logger(args = { })
20
+ @logger = args[:logger] ||= Logger.new(args[:log_to] || STDOUT)
21
+ log_level = args[:log_level]
22
+ if log_level
23
+ @logger.level = log_level
24
+ args[:logger] = @logger
25
+ end
26
+ @logger
27
+ end
28
+
29
+ def initialize_http_client(args = { })
30
+ @http_client = Ubiquity::MediaSilo::API::V3::HTTPClient.new(args)
31
+ end
32
+
33
+ def error_message
34
+ response.is_a?(String) ? response.gsub(/<[^>]*>/ui,'') : ''
35
+ end
36
+
37
+ def success?
38
+ return request.success? if request.respond_to?(:success?)
39
+
40
+ _code = http_client.response.code
41
+ _code and _code.start_with?('2')
42
+ end
43
+
44
+ # @param [Requests::BaseRequest] request
45
+ # @param [Hash, nil] options
46
+ # @option options [Boolean] :execute_request (true) Will execute the request
47
+ # @option options [Boolean] :return_request (true) Will return the request instance instead of nil. Only applies if
48
+ # execute_request is false.
49
+ def process_request(request, options = nil)
50
+ @paginator = nil
51
+ @response = nil
52
+ @request = request
53
+ logger.warn { "Request is Missing Required Arguments: #{request.missing_required_arguments.inspect}" } unless request.missing_required_arguments.empty?
54
+
55
+ if batch_mode
56
+ logger.debug { "Adding Request to Batch. #{request.inspect}" }
57
+ @batch_requests << request
58
+ return batch_requests
59
+ end
60
+
61
+ if ([:all, 'all'].include?(request.arguments[:_page]))
62
+ request.arguments[:_page] = 1
63
+ include_remaining_pages = true
64
+ else
65
+ include_remaining_pages = false
66
+ end
67
+
68
+ request.client = self unless request.client
69
+ options ||= request.options
70
+
71
+ return (options.fetch(:return_request, true) ? request : nil) unless options.fetch(:execute_request, true)
72
+
73
+ #@response = http_client.call_method(request.http_method, { :path => request.path, :query => request.query, :body => request.body }, options)
74
+ @response = request.execute
75
+
76
+ if include_remaining_pages
77
+ return paginator.include_remaining_pages
78
+ end
79
+
80
+ @response
81
+ end
82
+
83
+ def paginator
84
+ @paginator ||= Paginator.new(self) if @response
85
+ end
86
+
87
+ def process_request_using_class(request_class, args = { }, options = { })
88
+ @response = nil
89
+ @request = request_class.new(args, options)
90
+ process_request(request, options)
91
+ end
92
+
93
+ # ################################################################################################################## #
94
+ # @!group API Methods
95
+
96
+ # @see https://phoenix.readme.io/docs/aspera-file-download
97
+ def aspera_file_download_ticket_create(args = { }, options = { })
98
+ _request = Requests::BaseRequest.new(
99
+ args,
100
+ {
101
+ :http_path => 'aspera/download/#{path_arguments[:asset_id]}/#{path_arguments[:target]}',
102
+ :http_method => :post,
103
+ :parameters => [
104
+ { :name => :asset_id, :send_in => :path },
105
+ { :name => :target, :send_in => :path } # Either 'source' or 'proxy'
106
+ ]
107
+ }
108
+ )
109
+ response = process_request(_request, options)
110
+ response
111
+ end
112
+
113
+ # @see https://phoenix.readme.io/docs/aspera-file-upload
114
+ def aspera_file_upload_ticket_create(args = { }, options = { })
115
+ _request = Requests::BaseRequest.new(
116
+ args,
117
+ {
118
+ :http_path => 'aspera/upload',
119
+ :http_method => :post,
120
+ :parameters => [
121
+ { :name => :fileName, :send_in => :body }
122
+ ]
123
+ }
124
+ )
125
+
126
+ response = process_request(_request, options)
127
+ response
128
+ end
129
+
130
+ def asset_copy_to_folder(args = { }, options = { })
131
+ process_request_using_class(Requests::AssetCopyToFolder, args, options)
132
+ end
133
+
134
+ def asset_copy_to_project(args = { }, options = { })
135
+ process_request_using_class(Requests::AssetCopyToProject, args, options)
136
+ end
137
+
138
+ # @see http://docs.mediasilo.com/v3.0/docs/create-asset
139
+ def asset_create(args = { }, options = { })
140
+ # args_out = Requests::AssetCreate.new(args, options).arguments
141
+ # @response = http_client.post('/assets', args_out)
142
+ process_request_using_class(Requests::AssetCreate, args, options)
143
+ end
144
+
145
+ def asset_delete_by_id(args = { }, options = { })
146
+ # asset_id = asset_id[:id] if asset_id.is_a?(Hash)
147
+ # @response = http_client.delete('/assets/%s' % asset_id)
148
+
149
+ args = { :assetId => args } if args.is_a?(String)
150
+ # _request = Requests::AssetDelete.new(args, options)
151
+ # @response = http_client.delete(_request.path)
152
+ process_request_using_class(Requests::AssetDelete, args, options)
153
+ end
154
+ alias :asset_delete :asset_delete_by_id
155
+
156
+ # @see http://docs.mediasilo.com/v3.0/docs/edit-asset
157
+ def asset_edit(args = { }, options = { })
158
+ _request = Requests::BaseRequest.new(
159
+ args,
160
+ {
161
+ :http_method => :put,
162
+ :http_path => 'assets/#{path_arguments[:asset_id]}',
163
+ :http_success_code => 204,
164
+ :parameters => [
165
+ { :name => :asset_id, :aliases => [ :id ], :send_in => :path, :required => true },
166
+ { :name => :title, :send_in => :body },
167
+ { :name => :description, :send_in => :body }
168
+ ]
169
+ }
170
+ )
171
+ process_request(_request, options)
172
+ end
173
+
174
+ # @see http://docs.mediasilo.com/v3.0/docs/asset-detail
175
+ def asset_get_by_id(args = { }, options = { })
176
+ args = { :asset_id => args } if args.is_a?(String)
177
+ process_request_using_class(Requests::AssetGetById, args, options)
178
+ end
179
+
180
+ # @see http://docs.mediasilo.com/v3.0/docs/all-assets
181
+ def assets_get(args = { }, options = { })
182
+ # query = options[:query] || { :type => '{"in":"video,image,document,archive,audio"}' }
183
+ # @response = http_client.get('/assets', query)
184
+ _response = process_request_using_class(Requests::AssetsGet, args, options)
185
+ _response = [ ] unless _response.is_a?(Array)
186
+ _response
187
+ end
188
+
189
+ # @note This will get all assets for a folder
190
+ # @param [Hash] args
191
+ # @option args [String] folder_id The Id of the folder to get the assets for
192
+ # @return [Array]
193
+ # @see http://docs.mediasilo.com/v3.0/docs/assets-in-folder
194
+ def assets_get_by_folder_id(args = { }, options = { })
195
+ args = { :id => args } if args.is_a?(String)
196
+
197
+ _request = Requests::BaseRequest.new(
198
+ args,
199
+ {
200
+ :http_path => 'folders/#{path_arguments[:folder_id]}/assets',
201
+ :parameters => [
202
+ { :name => :folder_id, :aliases => [ :id ], :send_in => :path, :required => true },
203
+ {
204
+ :name => :type,
205
+ # Received a 500 Request Failed error if 'type' was not set so we default it
206
+ # :default_value => '{"in":"video,image,document,archive,audio"}',
207
+ :send_in => :query
208
+ },
209
+ { :name => :_page, :aliases => [ :page ], :send_in => :query },
210
+ { :name => :_pageSize, :aliases => [ :page_size ], :send_in => :query },
211
+ { :name => :_sort, :aliases => [ :sort ], :send_in => :query },
212
+ { :name => :_sortBy, :aliases => [ :sort_by ], :send_in => :query }
213
+ ]
214
+ }
215
+ )
216
+ response = process_request(_request, options)
217
+ response
218
+ end
219
+
220
+
221
+ # @note This will get all assets for a project
222
+ # @param [Hash] args
223
+ # @option args [String] project_id The Id of the project to get the assets for
224
+ # @return [Array]
225
+ # @see http://docs.mediasilo.com/v3.0/docs/assets-in-project
226
+ def assets_get_by_project_id(args = { }, options = { })
227
+ args = { :id => args } if args.is_a?(String)
228
+
229
+ # return_all_results = options.fetch(:return_all_results, false)
230
+
231
+ _request = Requests::BaseRequest.new(
232
+ args,
233
+ {
234
+ :http_path => 'projects/#{path_arguments[:project_id]}/assets',
235
+ :parameters => [
236
+ { :name => :project_id, :aliases => [ :id ], :send_in => :path, :required => true },
237
+ {
238
+ :name => :type,
239
+ # Received a 500 Request Failed error if 'type' was not set so we default it
240
+ # :default_value => '{"in":"video,image,document,archive,audio"}',
241
+ :send_in => :query
242
+ },
243
+ { :name => :_page, :aliases => [ :page ], :send_in => :query },
244
+ { :name => :_pageSize, :aliases => [ :page_size ], :send_in => :query },
245
+ { :name => :_sort, :aliases => [ :sort ], :send_in => :query },
246
+ { :name => :_sortBy, :aliases => [ :sort_by ], :send_in => :query }
247
+ ]
248
+ }
249
+ )
250
+ response = process_request(_request, args)
251
+
252
+ # response.delete_if { |asset| asset['folderId'] } if response.is_a?(Array) &&!return_all_results
253
+
254
+ response
255
+ end
256
+
257
+ def asset_move_to_folder(args = { }, options = { })
258
+ process_request_using_class(Requests::AssetMoveToFolder, args, options)
259
+ end
260
+
261
+ def asset_move_to_project(args = { }, options = { })
262
+ process_request_using_class(Requests::AssetMoveToProject, args, options)
263
+ end
264
+
265
+ # @see http://docs.mediasilo.com/v3.0/docs/add-tag-to-asset
266
+ def asset_tag_add(args = { }, options = { })
267
+ _request = Requests::BaseRequest.new(
268
+ args,
269
+ {
270
+ :http_method => :post,
271
+ :http_success_code => '204',
272
+ :http_path => 'assets/#{path_arguments[:asset_id]}/tags',
273
+ :parameters => [
274
+ { :name => :asset_id, :aliases => [ :id ], :send_in => :path, :required => true },
275
+ { :name => :tags, :aliases => [ :tag ], :send_in => :body },
276
+ ]
277
+ }
278
+ )
279
+ _tags = _request.arguments[:tags]
280
+ _request.arguments[:tags] = [*_tags] unless _tags.is_a?(Array)
281
+
282
+ process_request(_request, options)
283
+ end
284
+ alias :asset_tags_add :asset_tag_add
285
+ alias :asset_add_tag :asset_tag_add
286
+
287
+ def asset_tag_delete(args = { }, options = { })
288
+ _request = Requests::BaseRequest.new(
289
+ args,
290
+ {
291
+ :http_method => :delete,
292
+ :http_success_code => '204',
293
+ :http_path => 'assets/#{path_arguments[:asset_id]}/tags/#{path_arguments[:tag]}',
294
+ :parameters => [
295
+ { :name => :asset_id, :aliases => [ :id ], :send_in => :path, :required => true },
296
+ { :name => :tag, :send_in => :path },
297
+ ]
298
+ }
299
+ )
300
+ process_request(_request, options)
301
+ end
302
+ alias :asset_tag_remove :asset_tag_delete
303
+
304
+ def asset_upload_ticket_create(args = { }, options = { })
305
+ _request = Requests::BaseRequest.new(
306
+ args,
307
+ {
308
+ :http_method => :post,
309
+ :http_path => 'assets/upload',
310
+ :parameters => [
311
+ { :name => :fileName, :send_in => :body }
312
+ ]
313
+ }
314
+ )
315
+ process_request(_request, options)
316
+ end
317
+
318
+ def asset_upload(args = { }, options = { })
319
+
320
+ end
321
+
322
+ # This endpoint is available to admins on any user id, or the current user on their own user id. It returns
323
+ # immediately, and watermarking runs in the background. To check whether the watermarking is done, you need to get
324
+ # the ‘proxy’ derivative our of the asset response model and check the ‘progress’ key. Be careful, because there are
325
+ # also ‘progress’ values at the base of the asset response model as well as in the ‘preroll’ derivative. You want
326
+ # the ‘proxy’ one. When that hits 100, the video is ready to play back.
327
+ #
328
+ # @param [Hash] args ({ })
329
+ # @option args [String] :asset_id
330
+ # @option args [String] :user_id
331
+ def asset_watermark_trigger(args = { }, options = { })
332
+ _request = Requests::BaseRequest.new(
333
+ args,
334
+ {
335
+ :http_method => :post,
336
+ :http_success_code => '204',
337
+ :http_path => 'assets/#{path_arguments[:asset_id]}/watermark/#{path_arguments[:user_id]}',
338
+ :parameters => [
339
+ { :name => :asset_id, :aliases => [ :id ], :send_in => :path, :required => true },
340
+ { :name => :user_id, :send_in => :path },
341
+ ]
342
+ }
343
+ )
344
+ process_request(_request, options)
345
+ end
346
+
347
+ # Executes the queued requests as a batch
348
+ # @param [Array] requests (@batch_requests)
349
+ # @param [Hash] options
350
+ def batch_execute(requests = nil, options = { })
351
+ if block_given?
352
+ @batch_mode = true
353
+ yield
354
+ _requests = @batch_requests + (requests || [ ])
355
+ else
356
+ _requests = requests.nil? ? @batch_requests.dup : requests.dup
357
+ end
358
+ @batch_mode = false
359
+ return [ ] if _requests.empty?
360
+ _requests.map! { |req| req.respond_to?(:to_batchable_request) ? req.to_batchable_request : req }
361
+ _response = [ ]
362
+
363
+ if requests.nil? and options.fetch(:clear_requests, true)
364
+ @batch_requests = [ ]
365
+ else
366
+ requests = [ ]
367
+ end
368
+
369
+ # @request_history.concat(_requests)
370
+ _requests.each_slice(50) do |_req|
371
+ process_request_using_class(Requests::Batch, { :requests => _req }, options)
372
+ _response << @response
373
+ end
374
+ @response = _response
375
+ end
376
+
377
+ # Sets the batch mode
378
+ # @param [True,False] value
379
+ def batch_mode=(value, options = { })
380
+ @batch_mode = value
381
+ @batch_requests = [ ] if value and options.fetch(:clear_requests, true)
382
+ @batch_mode
383
+ end
384
+
385
+ # Returns true if the client is currently batching requests
386
+ def batch_mode?
387
+ @batch_mode
388
+ end
389
+ alias :batch_mode :batch_mode?
390
+
391
+ def batch_mode_enable
392
+ self.batch_mode = true
393
+ end
394
+
395
+ # @see http://docs.mediasilo.com/v3.0/docs/create-folder
396
+ def folder_create(args = { }, options = { })
397
+ # @response = http_client.post('/folders', args)
398
+
399
+ _request = Requests::BaseRequest.new(
400
+ args,
401
+ {
402
+ :http_method => :post,
403
+ :http_path => 'folders',
404
+ :parameters => [
405
+ { :name => :name, :send_in => :body },
406
+ { :name => :projectId, :send_in => :body },
407
+ { :name => :parentId, :default_value => 0, :send_in => :body }
408
+ ]
409
+ }
410
+ )
411
+
412
+ # arguments = _request.arguments
413
+ # parent_id = arguments[:parentId]
414
+ #
415
+ # if parent_id && parent_id != 0
416
+ # logger.debug { 'Unsetting projectId because parentId is set.' }
417
+ # arguments.delete(:projectId)
418
+ # end
419
+ #
420
+ # _request.arguments = arguments
421
+
422
+ process_request(_request, options)
423
+ end
424
+
425
+ def folder_delete(args = { }, options = { })
426
+ # folder_id = folder_id[:id] if folder_id.is_a?(Hash)
427
+ # @response = http_client.delete('/folders/%s' % folder_id)
428
+
429
+ args = { :folder_id => args } if args.is_a?(String)
430
+ _request = Requests::BaseRequest.new(
431
+ args,
432
+ {
433
+ :http_method => :delete,
434
+ :http_path => 'folders/#{path_arguments[:folder_id]}',
435
+ :parameters => [
436
+ { :name => :folder_id, :aliases => [ :id ], :send_in => :path }
437
+ ]
438
+ }.merge(options)
439
+ )
440
+ process_request(_request, options)
441
+ end
442
+
443
+ def folder_get_by_id(args = { }, options = { })
444
+ args = { :folder_id => args } if args.is_a?(String)
445
+ _request = Requests::BaseRequest.new(
446
+ args,
447
+ {
448
+ :http_path => 'folders/#{path_arguments[:folder_id]}',
449
+ :parameters => [
450
+ { :name => :folder_id, :aliases => [ :id ], :send_in => :path }
451
+ ]
452
+ }.merge(options)
453
+ )
454
+ process_request(_request, options)
455
+ end
456
+
457
+ def folders_get_by_parent_id(args = { })
458
+ folder_id = case args
459
+ when String; args
460
+ when Hash; args[:id] || args[:parent_id]
461
+ end
462
+ @response = http_client.get('/folders/%s/subfolders' % folder_id)
463
+ end
464
+
465
+ def folders_get_by_project_id(args = { })
466
+ project_id = case args
467
+ when String; args
468
+ when Hash; args[:id] || args[:project_id]
469
+ end
470
+ @response = http_client.get('/projects/%s/folders' % project_id)
471
+ end
472
+
473
+ def metadata_get(args = { }, options = { })
474
+ return_as_hash = options.delete(:return_as_hash) { false }
475
+
476
+ args = { :asset_id => args } unless args.is_a?(Hash)
477
+ _request = Requests::BaseRequest.new(
478
+ args,
479
+ {
480
+ :http_path => 'assets/#{path_arguments[:asset_id]}/metadata',
481
+ :http_success_code => %w(200 404),
482
+ :parameters => [
483
+ { :name => :asset_id, :aliases => [ :id ], :send_in => :path }
484
+ ]
485
+ }.merge(options)
486
+ )
487
+ _response = process_request(_request, options)
488
+
489
+ return (return_as_hash ? {} : []) if _request.client.http_client.response.code == '404'
490
+ return false unless _response.is_a?(Array)
491
+
492
+ return Hash[ _response.map { |m| [ m['key'], m['value'] ] } ] if return_as_hash
493
+
494
+ _response
495
+ end
496
+ alias :metadata_get_by_asset_id :metadata_get
497
+ alias :metadata_get_by_asset_uuid :metadata_get
498
+
499
+ # @see http://docs.mediasilo.com/v3.0/docs/add-metadata
500
+ def metadata_create_or_update(args = { }, options = { })
501
+ _request = Requests::BaseRequest.new(
502
+ args,
503
+ {
504
+ :http_path => 'assets/#{path_arguments[:asset_id]}/metadata',
505
+ :http_method => :post,
506
+ :http_success_code => 204,
507
+ :parameters => [
508
+ { :name => :asset_id, :aliases => [ :id ], :send_in => :path, :required => true },
509
+ { :name => :key, :send_in => :body},
510
+ { :name => :value, :send_in => :body},
511
+ { :name => :metadata, :send_in => :body},
512
+ ]
513
+ }.merge(options)
514
+ )
515
+ metadata = _request.body_arguments.delete(:metadata) { }
516
+ metadata = metadata.map { |k,v| { 'key' => k, 'value' => v } } if metadata.is_a?(Hash)
517
+
518
+ _request.body = metadata.delete_if { |h| v = h['value']; (v.respond_to?(:empty?) && v.empty?) } if metadata
519
+ process_request(_request, options)
520
+ end
521
+ alias :metadata_set :metadata_create_or_update
522
+ alias :metadata_add :metadata_create_or_update
523
+ alias :metadata_create_if_not_exists :metadata_create_or_update
524
+
525
+ # @see http://docs.mediasilo.com/v3.0/docs/delete
526
+ def metadata_delete(args = { }, options = { })
527
+ _request = Requests::BaseRequest.new(
528
+ args,
529
+ {
530
+ :http_path => 'assets/#{path_arguments[:asset_id]}/metadata/#{path_arguments[:metadata_key]}',
531
+ :http_method => :delete,
532
+ :parameters => [
533
+ { :name => :asset_id, :aliases => [ :id ], :send_in => :path, :required => true },
534
+ { :name => :metadata_key, :aliases => [ :key ], :send_in => :path },
535
+ ]
536
+ }.merge(options)
537
+ )
538
+ process_request(_request, options)
539
+ end
540
+
541
+ # @see http://docs.mediasilo.com/v3.0/docs/update
542
+ def metadata_replace(args = { }, options = { })
543
+ _request = Requests::BaseRequest.new(
544
+ args,
545
+ {
546
+ :http_path => 'assets/#{path_arguments[:asset_id]}/metadata',
547
+ :http_method => :put,
548
+ :parameters => [
549
+ { :name => :asset_id, :aliases => [ :id ], :send_in => :path, :required => true },
550
+ { :name => :key, :send_in => :body },
551
+ { :name => :value, :send_in => :body },
552
+ { :name => :metadata, :send_in => :body },
553
+ ]
554
+ }.merge(options)
555
+ )
556
+ metadata = _request.body_arguments.delete(:metadata) { }
557
+ metadata = metadata.map { |k,v| { 'key' => k, 'value' => v} } if metadata.is_a?(Hash)
558
+ _request.body = metadata if metadata
559
+ process_request(_request, options)
560
+ end
561
+ alias :metadata_mirror :metadata_replace
562
+
563
+ # @see http://docs.mediasilo.com/v3.0/docs/create-project
564
+ def project_create(args = { }, options = { })
565
+ args = { :name => args } if args.is_a?(String)
566
+ _request = Requests::BaseRequest.new(
567
+ args,
568
+ {
569
+ :http_path => 'projects',
570
+ :http_method => :post,
571
+ :parameters => [
572
+ { :name => :name, :send_in => :body, :required => true },
573
+ { :name => :description, :send_in => :body }
574
+ ]
575
+ }.merge(options)
576
+ )
577
+ process_request(_request, options)
578
+ end
579
+
580
+ def project_delete(args = { }, options = { })
581
+ args = { :project_id => args } if args.is_a?(String)
582
+ _request = Requests::BaseRequest.new(
583
+ args,
584
+ {
585
+ :http_path => 'projects/#{path_arguments[:project_id]}',
586
+ :http_method => :delete,
587
+ :parameters => [
588
+ { :name => :project_id, :aliases => [ :id ], :send_in => :path }
589
+ ]
590
+ }.merge(options)
591
+ )
592
+ process_request(_request, options)
593
+ end
594
+
595
+ def project_get_by_id(args = { }, options = { })
596
+ # project_id = project_id[:id] if project_id.is_a?(Hash)
597
+ # @response = http_client.get('/projects/%s' % project_id)
598
+
599
+ args = { :project_id => args } if args.is_a?(String)
600
+ _request = Requests::BaseRequest.new(
601
+ args,
602
+ {
603
+ :http_path => 'projects/#{path_arguments[:project_id]}',
604
+ :parameters => [
605
+ { :name => :project_id, :aliases => [ :id ], :send_in => :path }
606
+ ]
607
+ }.merge(options)
608
+ )
609
+ process_request(_request, options)
610
+ end
611
+
612
+ def projects_get(options = { })
613
+ #@response = http_client.get('/projects')
614
+
615
+ _request = Requests::BaseRequest.new(
616
+ { },
617
+ {
618
+ :http_path => 'projects',
619
+ :http_success_code => %w(200 404),
620
+ }.merge(options)
621
+ )
622
+ _response = process_request(_request, options)
623
+ return [] if _request.client.http_client.response.code == '404'
624
+
625
+ return _response
626
+ end
627
+
628
+ def project_watermark_settings_get(args = { }, options = { })
629
+ args = { :project_id => args } if args.is_a?(String)
630
+ _request = Requests::BaseRequest.new(
631
+ args,
632
+ {
633
+ :http_path => 'projects/#{path_arguments[:project_id]}/watermarkSettings',
634
+ :parameters => [
635
+ { :name => :project_id, :aliases => [ :id ], :send_in => :path }
636
+ ]
637
+ }.merge(options)
638
+ )
639
+ process_request(_request, options)
640
+ end
641
+
642
+ def project_watermark_settings_set(args = { }, options = { })
643
+ args = { :project_id => args } if args.is_a?(String)
644
+ _request = Requests::BaseRequest.new(
645
+ args,
646
+ {
647
+ :http_path => 'projects/#{body_arguments[:context]}/watermarkSettings',
648
+ :http_method => 'PUT',
649
+ :parameters => [
650
+ { :name => :context, :aliases => [ :project_id ], :send_in => :body },
651
+ { :name => :id, :send_in => :body },
652
+ { :name => :settings, :send_in => :body },
653
+ { :name => :enabled, :send_in => :body },
654
+ ]
655
+ }.merge(options)
656
+ )
657
+ process_request(_request, options)
658
+ end
659
+
660
+ def quicklink_create(args = { }, options = { })
661
+ process_request_using_class(Requests::QuicklinkCreate, args, options)
662
+ end
663
+
664
+ def quicklink_share(args = { }, options = { })
665
+ process_request_using_class(Requests::QuicklinkShare, args, options)
666
+ end
667
+
668
+ def tag_edit(args = { }, options = { })
669
+ _request = Requests::BaseRequest.new(
670
+ args,
671
+ {
672
+ :http_path => 'tags',
673
+ :http_method => :put,
674
+ :http_success_code => '204',
675
+ :parameters => [
676
+ { :name => :currentName, :required => true, :send_in => :body },
677
+ { :name => :newName, :required => true, :send_in => :body }
678
+ ]
679
+ # :http_success_code => %w(200 404),
680
+ }.merge(options)
681
+ )
682
+ process_request(_request, options)
683
+ end
684
+
685
+ def tags_get
686
+ http_client.get('tags')
687
+ end
688
+
689
+ def user_delete(args = { }, options = { })
690
+ args = { :userId => args } if args.is_a?(String)
691
+ _request = Requests::BaseRequest.new(
692
+ args,
693
+ {
694
+ :http_path => '/users/#{arguments[:userId]}',
695
+ :http_method => :delete,
696
+ :http_success_code => '204',
697
+ :parameters => [
698
+ { :name => :userId, :required => true, :send_in => :query },
699
+ ]
700
+ # :http_success_code => %w(200 404),
701
+ }.merge(options)
702
+ )
703
+ process_request(_request, options)
704
+ end
705
+
706
+ def users_get(args = { }, options = { })
707
+ http_client.get('users?_pageSize=250')
708
+ end
709
+
710
+
711
+
712
+ end