Class: Spaceship::ConnectAPI::AppPreview
- Inherits:
-
Object
- Object
- Spaceship::ConnectAPI::AppPreview
- Includes:
- Model
- Defined in:
- spaceship/lib/spaceship/connect_api/models/app_preview.rb
Instance Attribute Summary collapse
-
#asset_deliver_state ⇒ Object
Returns the value of attribute asset_deliver_state.
-
#file_name ⇒ Object
Returns the value of attribute file_name.
-
#file_size ⇒ Object
Returns the value of attribute file_size.
-
#mime_type ⇒ Object
Returns the value of attribute mime_type.
-
#preview_frame_time_code ⇒ Object
Returns the value of attribute preview_frame_time_code.
-
#preview_image ⇒ Object
Returns the value of attribute preview_image.
-
#source_file_checksum ⇒ Object
Returns the value of attribute source_file_checksum.
-
#upload ⇒ Object
Returns the value of attribute upload.
-
#upload_operations ⇒ Object
Returns the value of attribute upload_operations.
-
#video_url ⇒ Object
Returns the value of attribute video_url.
Attributes included from Model
Class Method Summary collapse
-
.create(app_preview_set_id: nil, path: nil, frame_time_code: nil) ⇒ Object
Creates an AppPreview in an AppPreviewSet Setting the optional frame_time_code will force polling until video is done processing.
-
.get(app_preview_id: nil) ⇒ Object
API.
- .type ⇒ Object
Instance Method Summary collapse
- #complete? ⇒ Boolean
- #delete!(filter: {}, includes: nil, limit: nil, sort: nil) ⇒ Object
- #update(attributes: nil) ⇒ Object
Methods included from Model
#attr_mapping, included, #initialize, #to_json, #update_attributes
Instance Attribute Details
#asset_deliver_state ⇒ Object
Returns the value of attribute asset_deliver_state.
20 21 22 |
# File 'spaceship/lib/spaceship/connect_api/models/app_preview.rb', line 20 def asset_deliver_state @asset_deliver_state end |
#file_name ⇒ Object
Returns the value of attribute file_name.
13 14 15 |
# File 'spaceship/lib/spaceship/connect_api/models/app_preview.rb', line 13 def file_name @file_name end |
#file_size ⇒ Object
Returns the value of attribute file_size.
12 13 14 |
# File 'spaceship/lib/spaceship/connect_api/models/app_preview.rb', line 12 def file_size @file_size end |
#mime_type ⇒ Object
Returns the value of attribute mime_type.
16 17 18 |
# File 'spaceship/lib/spaceship/connect_api/models/app_preview.rb', line 16 def mime_type @mime_type end |
#preview_frame_time_code ⇒ Object
Returns the value of attribute preview_frame_time_code.
15 16 17 |
# File 'spaceship/lib/spaceship/connect_api/models/app_preview.rb', line 15 def preview_frame_time_code @preview_frame_time_code end |
#preview_image ⇒ Object
Returns the value of attribute preview_image.
18 19 20 |
# File 'spaceship/lib/spaceship/connect_api/models/app_preview.rb', line 18 def preview_image @preview_image end |
#source_file_checksum ⇒ Object
Returns the value of attribute source_file_checksum.
14 15 16 |
# File 'spaceship/lib/spaceship/connect_api/models/app_preview.rb', line 14 def source_file_checksum @source_file_checksum end |
#upload ⇒ Object
Returns the value of attribute upload.
21 22 23 |
# File 'spaceship/lib/spaceship/connect_api/models/app_preview.rb', line 21 def upload @upload end |
#upload_operations ⇒ Object
Returns the value of attribute upload_operations.
19 20 21 |
# File 'spaceship/lib/spaceship/connect_api/models/app_preview.rb', line 19 def upload_operations @upload_operations end |
#video_url ⇒ Object
Returns the value of attribute video_url.
17 18 19 |
# File 'spaceship/lib/spaceship/connect_api/models/app_preview.rb', line 17 def video_url @video_url end |
Class Method Details
.create(app_preview_set_id: nil, path: nil, frame_time_code: nil) ⇒ Object
Creates an AppPreview in an AppPreviewSet Setting the optional frame_time_code will force polling until video is done processing
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 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 |
# File 'spaceship/lib/spaceship/connect_api/models/app_preview.rb', line 57 def self.create(app_preview_set_id: nil, path: nil, frame_time_code: nil) require 'faraday' filename = File.basename(path) filesize = File.size(path) bytes = File.binread(path) post_attributes = { fileSize: filesize, fileName: filename } # Create placeholder preview = Spaceship::ConnectAPI.post_app_preview( app_preview_set_id: app_preview_set_id, attributes: post_attributes ).to_models.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 = Spaceship::ConnectAPI.patch_app_preview( app_preview_id: preview.id, attributes: patch_attributes ).to_models.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(app_preview_id: preview.id) raise error unless preview.complete? end # Poll for video processing completion to set still frame time unless frame_time_code.nil? 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(app_preview_id: preview.id) end end preview end |
.get(app_preview_id: nil) ⇒ Object
API
48 49 50 |
# File 'spaceship/lib/spaceship/connect_api/models/app_preview.rb', line 48 def self.get(app_preview_id: nil) Spaceship::ConnectAPI.get_app_preview(app_preview_id: app_preview_id).first end |
.type ⇒ Object
36 37 38 |
# File 'spaceship/lib/spaceship/connect_api/models/app_preview.rb', line 36 def self.type return "appPreviews" end |
Instance Method Details
#complete? ⇒ Boolean
40 41 42 |
# File 'spaceship/lib/spaceship/connect_api/models/app_preview.rb', line 40 def complete? (asset_delivery_state || {})["state"] == "COMPLETE" end |
#delete!(filter: {}, includes: nil, limit: nil, sort: nil) ⇒ Object
124 125 126 |
# File 'spaceship/lib/spaceship/connect_api/models/app_preview.rb', line 124 def delete!(filter: {}, includes: nil, limit: nil, sort: nil) Spaceship::ConnectAPI.delete_app_preview(app_preview_id: id) end |
#update(attributes: nil) ⇒ Object
120 121 122 |
# File 'spaceship/lib/spaceship/connect_api/models/app_preview.rb', line 120 def update(attributes: nil) Spaceship::ConnectAPI.patch_app_preview(app_preview_id: id, attributes: attributes) end |