Class: Spaceship::ConnectAPI::AppPreview

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
spaceship/lib/spaceship/connect_api/models/app_preview.rb

Instance Attribute Summary collapse

Attributes included from Model

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model

#attr_mapping, included, #initialize, #to_json, #update_attributes

Instance Attribute Details

#asset_deliver_stateObject

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_nameObject

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_sizeObject

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_typeObject

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_codeObject

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_imageObject

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_checksumObject

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

#uploadObject

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_operationsObject

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_urlObject

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

Parameters:

  • app_preview_set_id (defaults to: nil)

    The AppPreviewSet id

  • path (defaults to: nil)

    The path of the file

  • frame_time_code (defaults to: nil)

    The time code for the preview still frame (ex: “00:00:07:01”)



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

.typeObject



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

Returns:

  • (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