cantemo-portal-agent 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/exe/cantemo-portal-agent +26 -0
- data/lib/cantemo/portal/agent.rb +9 -0
- data/lib/cantemo/portal/agent/version.rb +7 -0
- data/lib/envoi/mam/agent.rb +119 -0
- data/lib/envoi/mam/agent/base_daemon.rb +32 -0
- data/lib/envoi/mam/agent/cli.rb +37 -0
- data/lib/envoi/mam/agent/cli/commands.rb +89 -0
- data/lib/envoi/mam/agent/cli/commands/iconik.rb +61 -0
- data/lib/envoi/mam/agent/cli/commands/mediasilo.rb +296 -0
- data/lib/envoi/mam/agent/cli/commands/vdms.rb +41 -0
- data/lib/envoi/mam/agent/cli/commands/vidispine.rb +57 -0
- data/lib/envoi/mam/agent/cli/commands/wiredrive.rb +223 -0
- data/lib/envoi/mam/agent/client/iconik.rb +0 -0
- data/lib/envoi/mam/agent/client/mediasilo.rb +0 -0
- data/lib/envoi/mam/agent/client/vidispine.rb +0 -0
- data/lib/envoi/mam/agent/config_service_client.rb +60 -0
- data/lib/envoi/mam/agent/generic.rb +0 -0
- data/lib/envoi/mam/agent/notifier.rb +0 -0
- data/lib/envoi/mam/agent/notifier/sns.rb +0 -0
- data/lib/envoi/mam/agent/transfer_client.rb +37 -0
- data/lib/envoi/mam/agent/transfer_client/aspera.rb +91 -0
- data/lib/envoi/mam/agent/transfer_client/http.rb +1 -0
- data/lib/envoi/mam/agent/transfer_client/s3.rb +70 -0
- data/lib/envoi/mam/agent/version.rb +7 -0
- data/lib/envoi/mam/iconik/agent.rb +183 -0
- data/lib/envoi/mam/mediasilo/agent.rb +286 -0
- data/lib/envoi/mam/vdms/agent.rb +183 -0
- data/lib/envoi/mam/vidispine/agent.rb +214 -0
- data/lib/envoi/mam/wiredrive/agent.rb +117 -0
- metadata +172 -0
@@ -0,0 +1,183 @@
|
|
1
|
+
require 'envoi/mam/agent/transfer_client/aspera'
|
2
|
+
require 'envoi/mam/agent/transfer_client/s3'
|
3
|
+
|
4
|
+
require 'ubiquity/vdms/uplynk/api/client'
|
5
|
+
|
6
|
+
module Envoi
|
7
|
+
|
8
|
+
module Mam
|
9
|
+
|
10
|
+
class Vdms
|
11
|
+
|
12
|
+
class Agent < Envoi::Mam::Agent
|
13
|
+
|
14
|
+
DEFAULT_FORMAT_NAME = 'ORIGINAL'
|
15
|
+
DEFAULT_DESTINATION_PATH = '.'
|
16
|
+
|
17
|
+
def after_initialize
|
18
|
+
@default_format_name = initial_args[:default_format_name] || DEFAULT_FORMAT_NAME
|
19
|
+
end
|
20
|
+
|
21
|
+
def iconik_config
|
22
|
+
config['vdms']
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize_api_client(args = { })
|
26
|
+
@api_client = args[:api_client] || begin
|
27
|
+
http_host_address = iconik_config['http_host_address']
|
28
|
+
application_id = iconik_config['application_id']
|
29
|
+
token = iconik_config['token']
|
30
|
+
client_args = { }
|
31
|
+
client_args[:http_host_address] = http_host_address if http_host_address && !http_host_address.empty?
|
32
|
+
client_args[:application_id] = application_id if application_id && !application_id.empty?
|
33
|
+
client_args[:token] = token if token && !token.empty?
|
34
|
+
Ubiquity::Iconik::API::Utilities.new(client_args)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def download(args = { })
|
39
|
+
|
40
|
+
asset_id = args[:asset_id]
|
41
|
+
file_id = args[:file_id]
|
42
|
+
if file_id && !file_id.empty?
|
43
|
+
asset_file = api_client.asset_file_get(asset_id: asset_id, file_id: file_id)
|
44
|
+
else
|
45
|
+
format_name = args[:format_name] || @default_format_name
|
46
|
+
format = api_client.asset_format_get_by_name(asset_id: asset_id, format_name: format_name.upcase)
|
47
|
+
format_id = format['id']
|
48
|
+
|
49
|
+
asset_files_get_response = api_client.asset_files_get(asset_id: asset_id, generate_signed_url: true)
|
50
|
+
asset_files = asset_files_get_response['objects']
|
51
|
+
|
52
|
+
asset_files_for_format = asset_files.find_all { |f| f['format_id'] == format_id }
|
53
|
+
|
54
|
+
asset_file = asset_files_for_format.first
|
55
|
+
end
|
56
|
+
|
57
|
+
# file = files.first
|
58
|
+
files = [ asset_file ] # just do the first file for now
|
59
|
+
files.each do |file|
|
60
|
+
begin
|
61
|
+
download_file(args, file)
|
62
|
+
rescue => e
|
63
|
+
logger.warn { "Exception: #{$!}. #{$@.first}" }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
logger.info { 'DONE' }
|
67
|
+
end
|
68
|
+
|
69
|
+
def download_file(args, file)
|
70
|
+
logger.debug { "File: #{file}"}
|
71
|
+
transfer_type = args[:transfer_type] || ''
|
72
|
+
|
73
|
+
file_storage_id = file['storage_id']
|
74
|
+
file_directory_path = file['directory_path']
|
75
|
+
file_path = !file_directory_path || file_directory_path.empty? ? file['original_name'] : File.join(file_directory_path, file['original_name'])
|
76
|
+
|
77
|
+
file_storage_config = iconik_config['storages'][file_storage_id]
|
78
|
+
|
79
|
+
unless file_storage_config && !file_storage_config.empty?
|
80
|
+
raise Exception, "No configuration found for storage '#{file_storage_id}'"
|
81
|
+
end
|
82
|
+
|
83
|
+
logger.info { "Transferring File Path: '#{file_path}'" }
|
84
|
+
preserve_path = args.fetch(:preserve_path, file_storage_config.fetch('preserve_path', true))
|
85
|
+
|
86
|
+
destination_path = args[:destination_path] || file_storage_config['destination_path'] || DEFAULT_DESTINATION_PATH
|
87
|
+
relative_path = preserve_path ? file_directory_path : nil
|
88
|
+
relative_path = nil if relative_path == '.'
|
89
|
+
|
90
|
+
target_path = relative_path ? File.join(destination_path, relative_path) : destination_path
|
91
|
+
target_path = target_path[0..-1] if target_path.start_with?('/') && !destination_path.start_with?('/')
|
92
|
+
|
93
|
+
aspera_config = file_storage_config['aspera']
|
94
|
+
if (transfer_type.empty? || transfer_type == :aspera) && (aspera_config && !aspera_config.empty?)
|
95
|
+
client = Envoi::Mam::Agent::TransferClient::Aspera.new(agent: self)
|
96
|
+
return client.download(aspera_config, file_path, target_path)
|
97
|
+
end
|
98
|
+
|
99
|
+
s3_config = file_storage_config['s3']
|
100
|
+
if (transfer_type.empty? || transfer_type == :s3) && (s3_config && !s3_config.empty?)
|
101
|
+
target_path = File.expand_path(target_path) if target_path == '.'
|
102
|
+
target_path = File.join(target_path, File.basename(file_path))
|
103
|
+
client = Envoi::Mam::Agent::TransferClient::S3.new(agent: self)
|
104
|
+
return client.download(s3_config, file_path, target_path)
|
105
|
+
end
|
106
|
+
|
107
|
+
logger.warn { "No Supported TransferClient Configuration#{transfer_type && !transfer_type.empty? ? " for transfer type '#{transfer_type}' " : ''}Found in Storage Configuration." }
|
108
|
+
end
|
109
|
+
|
110
|
+
def upload(args = { })
|
111
|
+
file_path = args[:file_path]
|
112
|
+
if File.directory?(file_path)
|
113
|
+
file_paths = Dir.glob(File.join(file_path, '*.*'))
|
114
|
+
logger.debug { "File Paths: #{file_paths}"}
|
115
|
+
file_paths.map { |fp| upload(args.merge(file_path: fp))}
|
116
|
+
return file_paths
|
117
|
+
end
|
118
|
+
logger.debug { "Preparing to upload '#{file_path}'" }
|
119
|
+
|
120
|
+
transfer_type = args[:transfer_type] || ''
|
121
|
+
storage_id = args[:storage_id]
|
122
|
+
path_on_storage = nil
|
123
|
+
iconik_storage_config = iconik_config['storages'][storage_id]
|
124
|
+
|
125
|
+
unless iconik_storage_config && !iconik_storage_config.empty?
|
126
|
+
raise Exception, "No configuration found for storage '#{storage_id}'"
|
127
|
+
end
|
128
|
+
|
129
|
+
preserve_path = args.fetch(:preserve_path, iconik_storage_config.fetch('preserve_path', true))
|
130
|
+
|
131
|
+
destination_path = args[:destination_path] || iconik_storage_config['destination_path'] || '/'
|
132
|
+
relative_path = preserve_path ? File.dirname(file_path) : nil
|
133
|
+
relative_path = File.expand_path(relative_path) if relative_path == '.'
|
134
|
+
|
135
|
+
target_path = relative_path ? File.join(destination_path, relative_path) : destination_path
|
136
|
+
target_path = target_path[1..-1] if target_path.start_with?('/') && !destination_path.start_with?('/')
|
137
|
+
|
138
|
+
# abort("FP: #{file_path} TP: #{target_path}")
|
139
|
+
|
140
|
+
transfer_response = begin
|
141
|
+
aspera_config = iconik_storage_config['aspera']
|
142
|
+
if (transfer_type.empty? || transfer_type == :aspera) && (aspera_config && !aspera_config.empty?)
|
143
|
+
client = Envoi::Mam::Agent::TransferClient::Aspera.new(agent: self)
|
144
|
+
resp = client.upload(aspera_config, file_path, target_path)
|
145
|
+
end
|
146
|
+
|
147
|
+
s3_config = iconik_storage_config['s3']
|
148
|
+
if (!resp) && (transfer_type.empty? || transfer_type == :s3) && (s3_config && !s3_config.empty?)
|
149
|
+
_target_path = target_path
|
150
|
+
_target_path = '' if target_path == '.'
|
151
|
+
_target_path = File.join(_target_path, File.basename(file_path))
|
152
|
+
client = Envoi::Mam::Agent::TransferClient::S3.new(agent: self)
|
153
|
+
resp = client.upload(s3_config, file_path, _target_path)
|
154
|
+
path_on_storage = _target_path
|
155
|
+
end
|
156
|
+
|
157
|
+
resp
|
158
|
+
end
|
159
|
+
|
160
|
+
if transfer_response.nil?
|
161
|
+
logger.warn { "No supported TransferClient configuration#{transfer_type && !transfer_type.empty? ? " for transfer type '#{transfer_type}' " : ''}found in storage configuration." }
|
162
|
+
return false
|
163
|
+
end
|
164
|
+
|
165
|
+
unless transfer_response
|
166
|
+
logger.warn { ""}
|
167
|
+
return false
|
168
|
+
end
|
169
|
+
|
170
|
+
file_size = File.exist?(file_path) ? File.size?(file_path) : 1024
|
171
|
+
path_on_storage ||= File.join(target_path, File.basename(file_path))
|
172
|
+
|
173
|
+
api_client.asset_add_using_file_path(file_path: path_on_storage, storage_id: storage_id, file_size: file_size)
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
@@ -0,0 +1,214 @@
|
|
1
|
+
require 'envoi/mam/agent/transfer_client/aspera'
|
2
|
+
require 'envoi/mam/agent/transfer_client/s3'
|
3
|
+
|
4
|
+
require 'vidispine/api/utilities'
|
5
|
+
|
6
|
+
module Envoi
|
7
|
+
|
8
|
+
module Mam
|
9
|
+
|
10
|
+
class Vidispine
|
11
|
+
|
12
|
+
class Agent < Envoi::Mam::Agent
|
13
|
+
|
14
|
+
DEFAULT_SHAPE_TAG = 'original'
|
15
|
+
DEFAULT_ASPERA_ARGS = '-v -k3 --overwrite=diff -P 33001'
|
16
|
+
DEFAULT_DESTINATION_PATH = '.'
|
17
|
+
|
18
|
+
attr_accessor :default_aspera_ascp_args,
|
19
|
+
:default_aspera_ascp_path,
|
20
|
+
:default_vidispine_shape_tag
|
21
|
+
|
22
|
+
def after_initialize
|
23
|
+
args = initial_args
|
24
|
+
@default_aspera_ascp_path = args[:default_aspera_ascp_path]
|
25
|
+
@default_aspera_args = args[:default_ascp_args] || DEFAULT_ASPERA_ARGS
|
26
|
+
end
|
27
|
+
|
28
|
+
def dry_run?; @dry_run end
|
29
|
+
|
30
|
+
def vidispine_config
|
31
|
+
config['vidispine'] || { }
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize_api_client(args = { })
|
35
|
+
_vidispine_config = vidispine_config
|
36
|
+
@api_client = args[:vidispine_api_client] || begin
|
37
|
+
|
38
|
+
vidispine_host = _vidispine_config['host']
|
39
|
+
vidispine_username = _vidispine_config['username']
|
40
|
+
vidispine_password = _vidispine_config['password']
|
41
|
+
client_args = { }
|
42
|
+
client_args[:http_host_address] = vidispine_host if vidispine_host
|
43
|
+
client_args[:username] = vidispine_username if vidispine_username
|
44
|
+
client_args[:password] = vidispine_password if vidispine_password
|
45
|
+
::Vidispine::API::Utilities.new(client_args)
|
46
|
+
end
|
47
|
+
|
48
|
+
@default_vidispine_shape_tag = args[:default_shape_tag] || _vidispine_config['default_shape_tag'] || _vidispine_config['shape_tag'] || DEFAULT_SHAPE_TAG
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
def item_get_shape_by_tag(item_id, shape_tag)
|
53
|
+
item_shapes_get_response = api_client.item_shapes_get(:item_id => item_id, :tag => shape_tag)
|
54
|
+
shape_id = item_shapes_get_response['uri'].first
|
55
|
+
end
|
56
|
+
|
57
|
+
def download(args = { })
|
58
|
+
|
59
|
+
item_id = args[:item_id]
|
60
|
+
shape_id = args[:shape_id]
|
61
|
+
unless shape_id && !shape_id.empty?
|
62
|
+
shape_tag = args[:shape_tag] || default_vidispine_shape_tag
|
63
|
+
shape_id = item_get_shape_by_tag(item_id, shape_tag)
|
64
|
+
end
|
65
|
+
|
66
|
+
logger.info { "Getting file path for Item ID: #{item_id} Shape ID: #{shape_id}"}
|
67
|
+
item_shape_get_response = api_client.item_shape_get(:item_id => item_id, :shape_id => shape_id)
|
68
|
+
|
69
|
+
files = item_shape_get_response['containerComponent']['file']
|
70
|
+
logger.debug { "Files: #{files}"}
|
71
|
+
|
72
|
+
# file = files.first
|
73
|
+
files = [ files.first ] # just do the first file for now
|
74
|
+
files.each do |file|
|
75
|
+
begin
|
76
|
+
download_file(args, file)
|
77
|
+
rescue => e
|
78
|
+
logger.warn { "Exception: #{$!}" }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
logger.info { 'DONE' }
|
82
|
+
end
|
83
|
+
|
84
|
+
def download_file(args, file)
|
85
|
+
logger.debug { "File: #{file}"}
|
86
|
+
transfer_type = args[:transfer_type]
|
87
|
+
|
88
|
+
file_storage_id = file['storage']
|
89
|
+
file_path = file['path']
|
90
|
+
|
91
|
+
file_storage_config = vidispine_config['storages'][file_storage_id]
|
92
|
+
|
93
|
+
unless file_storage_config && !file_storage_config.empty?
|
94
|
+
raise Exception, "No configuration found for storage '#{file_storage_id}'"
|
95
|
+
end
|
96
|
+
|
97
|
+
logger.info { "Transferring File Path: '#{file_path}'" }
|
98
|
+
preserve_path = args.fetch(:preserve_path, file_storage_config.fetch('preserve_path', true))
|
99
|
+
|
100
|
+
destination_path = args[:destination_path] || file_storage_config['destination_path'] || DEFAULT_DESTINATION_PATH
|
101
|
+
relative_path = preserve_path ? File.dirname(file_path) : nil
|
102
|
+
relative_path = nil if relative_path == '.'
|
103
|
+
|
104
|
+
target_path = relative_path ? File.join(destination_path, relative_path) : destination_path
|
105
|
+
target_path = target_path[0..-1] if target_path.start_with?('/') && !destination_path.start_with?('/')
|
106
|
+
|
107
|
+
aspera_config = file_storage_config['aspera']
|
108
|
+
if (transfer_type.empty? || transfer_type == :aspera) && (aspera_config && !aspera_config.empty?)
|
109
|
+
client = Envoi::Mam::Agent::TransferClient::Aspera.new(agent: self)
|
110
|
+
return client.download(aspera_config, file_path, target_path)
|
111
|
+
# download_using_aspera(aspera_config, file_path, target_path)
|
112
|
+
end
|
113
|
+
|
114
|
+
s3_config = file_storage_config['s3']
|
115
|
+
if (transfer_type.empty? || transfer_type == :s3) && (s3_config && !s3_config.empty?)
|
116
|
+
target_path = File.expand_path(target_path) if target_path == '.'
|
117
|
+
target_path = File.join(target_path, File.basename(file_path))
|
118
|
+
client = Envoi::Mam::Agent::TransferClient::S3.new(agent: self)
|
119
|
+
return client.download(s3_config, file_path, target_path)
|
120
|
+
end
|
121
|
+
|
122
|
+
logger.warn { "No Supported TransferClient Configuration#{transfer_type && !transfer_type.empty? ? " for transfer type '#{transfer_type}' " : ''}Found in Storage Configuration." }
|
123
|
+
end
|
124
|
+
|
125
|
+
def upload(args = { })
|
126
|
+
file_path = args[:file_path]
|
127
|
+
raise ArgumentError, "Path not found: '#{file_path}'" unless File.exists?(file_path)
|
128
|
+
|
129
|
+
if File.directory?(file_path)
|
130
|
+
# Non-recursive directory upload
|
131
|
+
file_paths = Dir.glob(File.join(file_path, '*.*'))
|
132
|
+
logger.debug { "File Paths: #{file_paths}"}
|
133
|
+
file_paths.map { |fp| upload(args.merge(file_path: fp))}
|
134
|
+
return file_paths
|
135
|
+
end
|
136
|
+
logger.debug { "Preparing to upload '#{file_path}'" }
|
137
|
+
|
138
|
+
transfer_type = args[:transfer_type] || ''
|
139
|
+
storage_id = args[:storage_id]
|
140
|
+
vidispine_storage_config = vidispine_config['storages'][storage_id]
|
141
|
+
|
142
|
+
unless vidispine_storage_config && !vidispine_storage_config.empty?
|
143
|
+
raise "No configuration found for storage '#{storage_id}'"
|
144
|
+
end
|
145
|
+
|
146
|
+
should_import_file = args.fetch(:import_file, vidispine_storage_config.fetch('import', true))
|
147
|
+
|
148
|
+
should_preserve_path = args.fetch(:preserve_path, vidispine_storage_config.fetch('preserve_path', true))
|
149
|
+
|
150
|
+
destination_path = args[:destination_path] || vidispine_storage_config['destination_path'] || '/'
|
151
|
+
relative_path = should_preserve_path ? File.dirname(file_path) : nil
|
152
|
+
relative_path = File.expand_path(relative_path) if relative_path == '.'
|
153
|
+
|
154
|
+
target_path = relative_path ? File.join(destination_path, relative_path) : destination_path
|
155
|
+
target_path = target_path[0..-1] if target_path.start_with?('/') && !destination_path.start_with?('/')
|
156
|
+
|
157
|
+
|
158
|
+
# upload file
|
159
|
+
|
160
|
+
transfer_response = begin
|
161
|
+
aspera_config = vidispine_storage_config['aspera']
|
162
|
+
if (transfer_type.empty? || transfer_type == :aspera) && (aspera_config && !aspera_config.empty?)
|
163
|
+
client = Envoi::Mam::Agent::TransferClient::Aspera.new(agent: self)
|
164
|
+
response = client.upload(aspera_config, file_path, target_path)
|
165
|
+
end
|
166
|
+
|
167
|
+
s3_config = vidispine_storage_config['s3']
|
168
|
+
if !response && (transfer_type.empty? || transfer_type == :s3) && (s3_config && !s3_config.empty?)
|
169
|
+
_target_path = target_path
|
170
|
+
_target_path = File.expand_path(_target_path) if target_path == '.'
|
171
|
+
_target_path = File.join(_target_path, File.basename(file_path))
|
172
|
+
client = Envoi::Mam::Agent::TransferClient::S3.new(agent: self)
|
173
|
+
response = client.upload(s3_config, file_path, _target_path)
|
174
|
+
end
|
175
|
+
|
176
|
+
response
|
177
|
+
end
|
178
|
+
|
179
|
+
logger.warn { "No supported TransferClient configuration#{transfer_type && !transfer_type.empty? ? " for transfer type '#{transfer_type}' " : ''}found in storage configuration." } unless transfer_response != nil
|
180
|
+
|
181
|
+
_response = { transfer_response: transfer_response }
|
182
|
+
|
183
|
+
return _response unless should_import_file
|
184
|
+
|
185
|
+
item_id = args[:item_id]
|
186
|
+
shape_tag = args[:shape_tag] || default_vidispine_shape_tag
|
187
|
+
|
188
|
+
# attach file to item as shape
|
189
|
+
path_on_storage = File.join(target_path, File.basename(file_path))
|
190
|
+
file_create_response = api_client.storage_file_create storage_id: storage_id, path: path_on_storage, state: 'CLOSED'
|
191
|
+
file_id = file_create_response['id']
|
192
|
+
|
193
|
+
if item_id
|
194
|
+
item_shape_import_response = vs_api.item_shape_import item_id: item_id, tag: shape_tag, fileId: file_id
|
195
|
+
else
|
196
|
+
item_shape_import_response = vs_api.item_add_using_file_path storage_id: storage_id,
|
197
|
+
file_path: file_path,
|
198
|
+
file_id: file_id,
|
199
|
+
storage_path_map: { '/' => storage_id }
|
200
|
+
end
|
201
|
+
_response[:import_response] = item_shape_import_response
|
202
|
+
|
203
|
+
_response
|
204
|
+
end
|
205
|
+
|
206
|
+
# Agent
|
207
|
+
end
|
208
|
+
|
209
|
+
# Vidispine
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
module Envoi
|
2
|
+
|
3
|
+
module Mam
|
4
|
+
|
5
|
+
class Wiredrive
|
6
|
+
|
7
|
+
class Agent < Envoi::Mam::Agent
|
8
|
+
|
9
|
+
def after_initialize
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize_api_client(args = {})
|
14
|
+
@api_client = args[:api_client] || begin
|
15
|
+
client_args = {}
|
16
|
+
Ubiquity::Wiredrive::API::V3::Client.new(client_args)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def download(args = {})
|
21
|
+
|
22
|
+
presentation_invitation_token = args[:presentation_invitation_token]
|
23
|
+
if presentation_invitation_token
|
24
|
+
presentation_password = args[:presentation_password]
|
25
|
+
r = api_client.presentation_get_using_token(presentation_invitation_token, presentation_password)
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
# Downloads a file from a URI or file location and saves it to a local path
|
32
|
+
#
|
33
|
+
# @param [String] download_file_path The source path of the file being downloaded
|
34
|
+
# @param [String] destination_file_path The destination path for the file being downloaded
|
35
|
+
# @param [Boolean] overwrite Determines if the destination file will be overwritten if it is found to exist
|
36
|
+
#
|
37
|
+
# @return [Hash]
|
38
|
+
# * :download_file_path [String] The source path of the file being downloaded
|
39
|
+
# * :overwrite [Boolean] The value of the overwrite parameter when the method was called
|
40
|
+
# * :file_downloaded [Boolean] Indicates if the file was downloaded, will be false if overwrite was true and the file existed
|
41
|
+
# * :destination_file_existed [String|Boolean] The value will be 'unknown' if overwrite is true because the file exist check will not have been run inside of the method
|
42
|
+
# * :destination_file_path [String] The destination path for the file being downloaded
|
43
|
+
def download_file(download_file_path, destination_file_path, overwrite = false)
|
44
|
+
logger.debug { "Downloading '#{download_file_path}' -> '#{destination_file_path}' Overwrite: #{overwrite}" }
|
45
|
+
file_existed = 'unknown'
|
46
|
+
if overwrite or not (file_existed = File.exists?(destination_file_path))
|
47
|
+
File.open(destination_file_path, 'wb') { |tf|
|
48
|
+
open(download_file_path) { |sf| tf.write sf.read }
|
49
|
+
}
|
50
|
+
file_downloaded = true
|
51
|
+
else
|
52
|
+
file_downloaded = false
|
53
|
+
end
|
54
|
+
{ :download_file_path => download_file_path, :overwrite => overwrite, :file_downloaded => file_downloaded, :destination_file_existed => file_existed, :destination_file_path => destination_file_path }
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def presentation_assets_download(args = {}, options = {})
|
59
|
+
assets = args[:assets]
|
60
|
+
destination_path = args[:destination_path]
|
61
|
+
assets.each { |a| presentation_asset_download(a, destination_path, options) }
|
62
|
+
end
|
63
|
+
|
64
|
+
def presentation_asset_download(asset, destination_path, options = {})
|
65
|
+
destination_dir = destination_path
|
66
|
+
overwrite = options.fetch(:overwrite, false)
|
67
|
+
|
68
|
+
media_elements = asset['media']
|
69
|
+
# media_elements.concat asset['thumbnails']
|
70
|
+
media_elements.each do |media|
|
71
|
+
url = media['downloadUrl'] || media['url']
|
72
|
+
uri = URI(url)
|
73
|
+
file_name = CGI.unescape(File.basename(uri.path))
|
74
|
+
destination_file_path = File.join(destination_dir, file_name)
|
75
|
+
download_file(url, destination_file_path, overwrite)
|
76
|
+
end
|
77
|
+
|
78
|
+
thumbnails = asset['thumbnails']
|
79
|
+
thumbnails.each do |media|
|
80
|
+
url = media['downloadUrl'] || media['url']
|
81
|
+
uri = URI(url)
|
82
|
+
file_name = CGI.unescape(File.basename(uri.path)) + "_thumbnail_#{media['category']}.#{media['extension']}"
|
83
|
+
destination_file_path = File.join(destination_dir, file_name)
|
84
|
+
download_file(url, destination_file_path, overwrite)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
# @param [Object] presentation_invitation_token
|
90
|
+
# @param [Object] presentation_password
|
91
|
+
# @param [Object] options
|
92
|
+
# @option options [Boolean] :preserve_auth_token Determines if the api clients auth token is reset to the
|
93
|
+
# value it was before retrieving the presentation
|
94
|
+
# @return [Object]
|
95
|
+
def presentation_get_using_token(presentation_invitation_token, presentation_password = nil, options = {})
|
96
|
+
preserve_auth_token = options.fetch(:preserve_auth_token, true)
|
97
|
+
auth_token = api_client.presentation_authorize_get(token: presentation_invitation_token, password: presentation_password)
|
98
|
+
presentation_id = api_client.response['presentation']['id']
|
99
|
+
original_auth_token = api_client.auth_token
|
100
|
+
api_client.auth_token = auth_token
|
101
|
+
presentation = api_client.presentation_get(:id => presentation_id)
|
102
|
+
api_client.auth_token = original_auth_token if preserve_auth_token
|
103
|
+
presentation
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
def upload(args = {})
|
108
|
+
raise 'Upload method is not implemented.'
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|