class Envoi::Mam::Wiredrive::Agent
Public Instance Methods
after_initialize()
click to toggle source
# File lib/envoi/mam/wiredrive/agent.rb, line 9 def after_initialize end
download(args = {})
click to toggle source
# 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)
click to toggle source
Downloads a file from a URI or file location and saves it to a local path
@param [String] download_file_path The source path of the file being downloaded @param [String] destination_file_path The destination path for the file being downloaded @param [Boolean] overwrite Determines if the destination file will be overwritten if it is found to exist
@return [Hash]
* :download_file_path [String] The source path of the file being downloaded * :overwrite [Boolean] The value of the overwrite parameter when the method was called * :file_downloaded [Boolean] Indicates if the file was downloaded, will be false if overwrite was true and the file existed * :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 * :destination_file_path [String] The destination path for the file being downloaded
# 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 = {})
click to toggle source
# 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 = {})
click to toggle source
# 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.concat asset['thumbnails'] 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 = {})
click to toggle source
# 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 = {})
click to toggle source
@param [Object] presentation_invitation_token @param [Object] presentation_password @param [Object] options @option options [Boolean] :preserve_auth_token Determines if the api clients auth token is reset to the
value it was before retrieving the presentation
@return [Object]
# 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 = {})
click to toggle source
# File lib/envoi/mam/wiredrive/agent.rb, line 107 def upload(args = {}) raise 'Upload method is not implemented.' end