Class: Spaceship::ConnectAPI::AppScreenshot
- Inherits:
-
Object
- Object
- Spaceship::ConnectAPI::AppScreenshot
- Includes:
- Model
- Defined in:
- spaceship/lib/spaceship/connect_api/models/app_screenshot.rb
Instance Attribute Summary collapse
-
#asset_delivery_state ⇒ Object
Returns the value of attribute asset_delivery_state.
-
#asset_token ⇒ Object
Returns the value of attribute asset_token.
-
#asset_type ⇒ Object
Returns the value of attribute asset_type.
-
#file_name ⇒ Object
Returns the value of attribute file_name.
-
#image_asset ⇒ Object
Returns the value of attribute image_asset.
-
#source_file_checksum ⇒ Object
Returns the value of attribute source_file_checksum.
-
#upload_operations ⇒ Object
Returns the value of attribute upload_operations.
-
#uploaded ⇒ Object
Returns the value of attribute uploaded.
Attributes included from Model
Class Method Summary collapse
-
.create(app_screenshot_set_id: nil, path: nil, wait_for_processing: true) ⇒ Object
API.
- .type ⇒ Object
Instance Method Summary collapse
- #complete? ⇒ Boolean
- #delete!(filter: {}, includes: nil, limit: nil, sort: nil) ⇒ Object
- #error? ⇒ Boolean
- #error_messages ⇒ Object
-
#image_asset_url(width: nil, height: nil, type: "png") ⇒ Object
This does not download the source image (exact image that was uploaded) This downloads a modified version.
Methods included from Model
#attr_mapping, included, #initialize, #to_json, #update_attributes
Instance Attribute Details
#asset_delivery_state ⇒ Object
Returns the value of attribute asset_delivery_state.
18 19 20 |
# File 'spaceship/lib/spaceship/connect_api/models/app_screenshot.rb', line 18 def asset_delivery_state @asset_delivery_state end |
#asset_token ⇒ Object
Returns the value of attribute asset_token.
15 16 17 |
# File 'spaceship/lib/spaceship/connect_api/models/app_screenshot.rb', line 15 def asset_token @asset_token end |
#asset_type ⇒ Object
Returns the value of attribute asset_type.
16 17 18 |
# File 'spaceship/lib/spaceship/connect_api/models/app_screenshot.rb', line 16 def asset_type @asset_type end |
#file_name ⇒ Object
Returns the value of attribute file_name.
12 13 14 |
# File 'spaceship/lib/spaceship/connect_api/models/app_screenshot.rb', line 12 def file_name @file_name end |
#image_asset ⇒ Object
Returns the value of attribute image_asset.
14 15 16 |
# File 'spaceship/lib/spaceship/connect_api/models/app_screenshot.rb', line 14 def image_asset @image_asset end |
#source_file_checksum ⇒ Object
Returns the value of attribute source_file_checksum.
13 14 15 |
# File 'spaceship/lib/spaceship/connect_api/models/app_screenshot.rb', line 13 def source_file_checksum @source_file_checksum end |
#upload_operations ⇒ Object
Returns the value of attribute upload_operations.
17 18 19 |
# File 'spaceship/lib/spaceship/connect_api/models/app_screenshot.rb', line 17 def upload_operations @upload_operations end |
#uploaded ⇒ Object
Returns the value of attribute uploaded.
19 20 21 |
# File 'spaceship/lib/spaceship/connect_api/models/app_screenshot.rb', line 19 def uploaded @uploaded end |
Class Method Details
.create(app_screenshot_set_id: nil, path: nil, wait_for_processing: true) ⇒ Object
API
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'spaceship/lib/spaceship/connect_api/models/app_screenshot.rb', line 75 def self.create(app_screenshot_set_id: nil, path: nil, wait_for_processing: true) require 'faraday' filename = File.basename(path) filesize = File.size(path) bytes = File.binread(path) post_attributes = { fileSize: filesize, fileName: filename } # Create placeholder screenshot = Spaceship::ConnectAPI.post_app_screenshot( app_screenshot_set_id: app_screenshot_set_id, attributes: post_attributes ).first # Upload the file upload_operations = screenshot.upload_operations Spaceship::ConnectAPI::FileUploader.upload(upload_operations, bytes) # Update file uploading complete patch_attributes = { uploaded: true, sourceFileChecksum: Digest::MD5.hexdigest(bytes) } # Patch screenshot that file upload is complete # Catch error if patch retries due to 504. Origal patch # may go through by return response as 504. begin screenshot = Spaceship::ConnectAPI.patch_app_screenshot( app_screenshot_id: screenshot.id, attributes: patch_attributes ).first rescue => error puts("Failed to patch app screenshot. Update may have gone through so verifying") if Spaceship::Globals.verbose? screenshot = Spaceship::ConnectAPI.get_app_screenshot(app_screenshot_id: screenshot.id).first raise error unless screenshot.complete? end # Wait for processing if wait_for_processing loop do if screenshot.complete? puts("Screenshot processing complete!") if Spaceship::Globals.verbose? break elsif screenshot.error? = ["Error processing screenshot '#{screenshot.file_name}'"] + screenshot. raise .join(". ") end # Poll every 2 seconds sleep_time = 2 puts("Waiting #{sleep_time} seconds before checking status of processing...") if Spaceship::Globals.verbose? sleep(sleep_time) screenshot = Spaceship::ConnectAPI.get_app_screenshot(app_screenshot_id: screenshot.id).first end end return screenshot end |
.type ⇒ Object
32 33 34 |
# File 'spaceship/lib/spaceship/connect_api/models/app_screenshot.rb', line 32 def self.type return "appScreenshots" end |
Instance Method Details
#complete? ⇒ Boolean
36 37 38 |
# File 'spaceship/lib/spaceship/connect_api/models/app_screenshot.rb', line 36 def complete? (asset_delivery_state || {})["state"] == "COMPLETE" end |
#delete!(filter: {}, includes: nil, limit: nil, sort: nil) ⇒ Object
141 142 143 |
# File 'spaceship/lib/spaceship/connect_api/models/app_screenshot.rb', line 141 def delete!(filter: {}, includes: nil, limit: nil, sort: nil) Spaceship::ConnectAPI.delete_app_screenshot(app_screenshot_id: id) end |
#error? ⇒ Boolean
40 41 42 |
# File 'spaceship/lib/spaceship/connect_api/models/app_screenshot.rb', line 40 def error? (asset_delivery_state || {})["state"] == "FAILED" end |
#error_messages ⇒ Object
44 45 46 47 48 49 |
# File 'spaceship/lib/spaceship/connect_api/models/app_screenshot.rb', line 44 def errors = (asset_delivery_state || {})["errors"] (errors || []).map do |error| [error["code"], error["description"]].compact.join(" - ") end end |
#image_asset_url(width: nil, height: nil, type: "png") ⇒ Object
This does not download the source image (exact image that was uploaded) This downloads a modified version. This image won’t have the same checksums as source_file_checksum.
There is an open radar for allowing downloading of source file. openradar.appspot.com/radar?id=4980344105205760
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'spaceship/lib/spaceship/connect_api/models/app_screenshot.rb', line 57 def image_asset_url(width: nil, height: nil, type: "png") return nil if image_asset.nil? template_url = image_asset["templateUrl"] width ||= image_asset["width"] height ||= image_asset["height"] return template_url .gsub("{w}", width.to_s) .gsub("{h}", height.to_s) .gsub("{f}", type) end |