Class: Envoi::Mam::Wiredrive::Agent
- Inherits:
-
Agent
- Object
- Agent
- Envoi::Mam::Wiredrive::Agent
show all
- Defined in:
- lib/envoi/mam/wiredrive/agent.rb
Constant Summary
Constants inherited
from Agent
Agent::VERSION
Instance Attribute Summary
Attributes inherited from Agent
#api_client, #config, #initial_args, #logger
Instance Method Summary
collapse
Methods inherited from Agent
#dry_run?, #initialize, #initialize_logger, load_config_and_init, load_config_from_file, load_config_from_service, load_from_config_file, load_from_config_service, #notify, #run_operation, #shell_execute
Instance Method Details
#after_initialize ⇒ Object
9
10
11
|
# File 'lib/envoi/mam/wiredrive/agent.rb', line 9
def after_initialize
end
|
#download(args = {}) ⇒ Object
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/envoi/mam/wiredrive/agent.rb', line 20
def download(args = {})
presentation_invitation_token = args[:presentation_invitation_token]
if presentation_invitation_token
presentation_password = args[:presentation_password]
r = api_client.presentation_get_using_token(presentation_invitation_token, presentation_password)
end
end
|
#download_file(download_file_path, destination_file_path, overwrite = false) ⇒ Hash
Downloads a file from a URI or file location and saves it to a local path
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/envoi/mam/wiredrive/agent.rb', line 43
def download_file(download_file_path, destination_file_path, overwrite = false)
logger.debug { "Downloading '#{download_file_path}' -> '#{destination_file_path}' Overwrite: #{overwrite}" }
file_existed = 'unknown'
if overwrite or not (file_existed = File.exists?(destination_file_path))
File.open(destination_file_path, 'wb') { |tf|
open(download_file_path) { |sf| tf.write sf.read }
}
file_downloaded = true
else
file_downloaded = false
end
{ :download_file_path => download_file_path, :overwrite => overwrite, :file_downloaded => file_downloaded, :destination_file_existed => file_existed, :destination_file_path => destination_file_path }
end
|
#initialize_api_client(args = {}) ⇒ Object
13
14
15
16
17
18
|
# File 'lib/envoi/mam/wiredrive/agent.rb', line 13
def initialize_api_client(args = {})
@api_client = args[:api_client] || begin
client_args = {}
Ubiquity::Wiredrive::API::V3::Client.new(client_args)
end
end
|
#presentation_asset_download(asset, destination_path, options = {}) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/envoi/mam/wiredrive/agent.rb', line 64
def presentation_asset_download(asset, destination_path, options = {})
destination_dir = destination_path
overwrite = options.fetch(:overwrite, false)
media_elements = asset['media']
media_elements.each do |media|
url = media['downloadUrl'] || media['url']
uri = URI(url)
file_name = CGI.unescape(File.basename(uri.path))
destination_file_path = File.join(destination_dir, file_name)
download_file(url, destination_file_path, overwrite)
end
thumbnails = asset['thumbnails']
thumbnails.each do |media|
url = media['downloadUrl'] || media['url']
uri = URI(url)
file_name = CGI.unescape(File.basename(uri.path)) + "_thumbnail_#{media['category']}.#{media['extension']}"
destination_file_path = File.join(destination_dir, file_name)
download_file(url, destination_file_path, overwrite)
end
end
|
#presentation_assets_download(args = {}, options = {}) ⇒ Object
58
59
60
61
62
|
# File 'lib/envoi/mam/wiredrive/agent.rb', line 58
def presentation_assets_download(args = {}, options = {})
assets = args[:assets]
destination_path = args[:destination_path]
assets.each { |a| presentation_asset_download(a, destination_path, options) }
end
|
#presentation_get_using_token(presentation_invitation_token, presentation_password = nil, options = {}) ⇒ Object
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/envoi/mam/wiredrive/agent.rb', line 95
def presentation_get_using_token(presentation_invitation_token, presentation_password = nil, options = {})
preserve_auth_token = options.fetch(:preserve_auth_token, true)
auth_token = api_client.presentation_authorize_get(token: presentation_invitation_token, password: presentation_password)
presentation_id = api_client.response['presentation']['id']
original_auth_token = api_client.auth_token
api_client.auth_token = auth_token
presentation = api_client.presentation_get(:id => presentation_id)
api_client.auth_token = original_auth_token if preserve_auth_token
presentation
end
|
#upload(args = {}) ⇒ Object
107
108
109
|
# File 'lib/envoi/mam/wiredrive/agent.rb', line 107
def upload(args = {})
raise 'Upload method is not implemented.'
end
|