Class: EnvoiImportUtility
- Inherits:
-
Object
- Object
- EnvoiImportUtility
- Defined in:
- lib/envoi/mam/agent/cli/commands/wiredrive.rb
Instance Attribute Summary collapse
-
#api_client ⇒ Object
Returns the value of attribute api_client.
-
#initial_args ⇒ Object
Returns the value of attribute initial_args.
Instance Method Summary collapse
- #after_initialize ⇒ Object
- #import_wiredrive_presentation_asset(asset, options = { }) ⇒ Object
-
#initialize(args = { }) ⇒ EnvoiImportUtility
constructor
A new instance of EnvoiImportUtility.
- #initialize_api_client(args = { }) ⇒ Object
Constructor Details
#initialize(args = { }) ⇒ EnvoiImportUtility
Returns a new instance of EnvoiImportUtility.
74 75 76 77 |
# File 'lib/envoi/mam/agent/cli/commands/wiredrive.rb', line 74 def initialize(args = { }) @initial_args = args initialize_api_client(args) end |
Instance Attribute Details
#api_client ⇒ Object
Returns the value of attribute api_client.
72 73 74 |
# File 'lib/envoi/mam/agent/cli/commands/wiredrive.rb', line 72 def api_client @api_client end |
#initial_args ⇒ Object
Returns the value of attribute initial_args.
72 73 74 |
# File 'lib/envoi/mam/agent/cli/commands/wiredrive.rb', line 72 def initial_args @initial_args end |
Instance Method Details
#after_initialize ⇒ Object
79 80 81 82 |
# File 'lib/envoi/mam/agent/cli/commands/wiredrive.rb', line 79 def after_initialize @default_original_storage_id = args[:default_original_storage_id] @default_thumbnail_storage_id = args[:default_thumbnail_storage_id] end |
#import_wiredrive_presentation_asset(asset, options = { }) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/envoi/mam/agent/cli/commands/wiredrive.rb', line 88 def import_wiredrive_presentation_asset(asset, = { }) title = asset['title'] || asset['label'] description = asset['description'] keywords = asset['keywords'] media_elements = asset['media'] media = media_elements.find { |me| me['type'] == 'original' } raise 'No original media found.' unless media url = media['url'] uri = URI(url) mime_type = media['mimeType'] size = media['fileSize'] url_path = uri.path.split('?').first filename = File.basename(url_path) original_storage_id = [:original_storage_id] || [:storage_id] || @default_original_storage_id create_args = { :name => title, :description => description, :file => { :mime => 'video/mp4', # mime_type, :path => url, :name => filename, :storage_key => url_path, :setting_id => original_storage_id, 'size' => size || 0 } } r = api_client.media_file_create(create_args) media_file_id = r['id'] raise 'No id found in response' unless media_file_id create_args = { 'media_file_id' => media_file_id, 'shape_type' => 'web', 'shape_label' => 'web', :mime => 'video/mp4', # mime_type, :path => url, :name => filename, :storage_key => url_path, :setting_id => original_storage_id, 'size' => size || 0 } r = api_client.media_file_file_add(create_args) video_thumb = asset['thumbnails'].find { |e| e['category'] == 'max' } if video_thumb thumbnail_storage_id = [:thumbnail_storage_id] || [:storage_id] || @default_thumbnail_storage_id video_thumb_url = video_thumb['url'] video_thumb_uri = URI(video_thumb_url) video_thumb_path = video_thumb_uri.path.split('?').first media_file_file_add_args = { 'media_file_id' => media_file_id, 'shape_type' => 'thumb', 'shape_label' => 'Thumbnail', 'name' => File.basename(video_thumb_path), 'mime' => 'image/jpeg', 'path' => video_thumb_url, 'size' => 0, 'setting_id' => thumbnail_storage_id, 'storage_key' => video_thumb_path } r = api_client.media_file_file_add(media_file_file_add_args) end end |