class Spaceship::ConnectAPI::AppPreview
Attributes
asset_delivery_state[RW]
file_name[RW]
file_size[RW]
mime_type[RW]
preview_frame_time_code[RW]
preview_image[RW]
source_file_checksum[RW]
upload[RW]
upload_operations[RW]
video_url[RW]
Public Class Methods
create(client: nil, app_preview_set_id: nil, path: nil, wait_for_processing: true, frame_time_code: nil)
click to toggle source
Creates an AppPreview
in an AppPreviewSet
Setting the optional frame_time_code will force polling until video is done processing @param app_preview_set_id The AppPreviewSet
id @param path The path of the file @param frame_time_code The time code for the preview still frame (ex: “00:00:07:01”)
# File spaceship/lib/spaceship/connect_api/models/app_preview.rb, line 58 def self.create(client: nil, app_preview_set_id: nil, path: nil, wait_for_processing: true, frame_time_code: nil) client ||= Spaceship::ConnectAPI require 'faraday' filename = File.basename(path) filesize = File.size(path) bytes = File.binread(path) post_attributes = { fileSize: filesize, fileName: filename } # Create placeholder preview = client.post_app_preview( app_preview_set_id: app_preview_set_id, attributes: post_attributes ).first # Upload the file upload_operations = preview.upload_operations Spaceship::ConnectAPI::FileUploader.upload(upload_operations, bytes) # Update file uploading complete patch_attributes = { uploaded: true, sourceFileChecksum: Digest::MD5.hexdigest(bytes) } begin preview = client.patch_app_preview( app_preview_id: preview.id, attributes: patch_attributes ).first rescue => error puts("Failed to patch app preview. Update may have gone through so verifying") if Spaceship::Globals.verbose? preview = Spaceship::ConnectAPI::AppPreview.get(client: client, app_preview_id: preview.id) raise error unless preview.complete? end # Poll for video processing completion to set still frame time wait_for_processing = true unless frame_time_code.nil? if wait_for_processing loop do unless preview.video_url.nil? puts("Preview processing complete!") if Spaceship::Globals.verbose? preview = preview.update(attributes: { previewFrameTimeCode: frame_time_code }) puts("Updated preview frame time code!") if Spaceship::Globals.verbose? break end sleep_time = 30 puts("Waiting #{sleep_time} seconds before checking status of processing...") if Spaceship::Globals.verbose? sleep(sleep_time) preview = Spaceship::ConnectAPI::AppPreview.get(client: client, app_preview_id: preview.id) end end preview end
get(client: nil, app_preview_id: nil)
click to toggle source
API
# File spaceship/lib/spaceship/connect_api/models/app_preview.rb, line 48 def self.get(client: nil, app_preview_id: nil) client ||= Spaceship::ConnectAPI client.get_app_preview(app_preview_id: app_preview_id).first end
type()
click to toggle source
# File spaceship/lib/spaceship/connect_api/models/app_preview.rb, line 36 def self.type return "appPreviews" end
Public Instance Methods
complete?()
click to toggle source
# File spaceship/lib/spaceship/connect_api/models/app_preview.rb, line 40 def complete? (asset_delivery_state || {})["state"] == "COMPLETE" end
delete!(client: nil, filter: {}, includes: nil, limit: nil, sort: nil)
click to toggle source
# File spaceship/lib/spaceship/connect_api/models/app_preview.rb, line 129 def delete!(client: nil, filter: {}, includes: nil, limit: nil, sort: nil) client ||= Spaceship::ConnectAPI client.delete_app_preview(app_preview_id: id) end
update(client: nil, attributes: nil)
click to toggle source
# File spaceship/lib/spaceship/connect_api/models/app_preview.rb, line 123 def update(client: nil, attributes: nil) client ||= Spaceship::ConnectAPI attributes = reverse_attr_mapping(attributes) client.patch_app_preview(app_preview_id: id, attributes: attributes).first end