Class: Spaceship::ConnectAPI::AppPreviewSet

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

Defined Under Namespace

Modules: PreviewType

Instance Attribute Summary collapse

Attributes included from Model

#id, #reverse_attr_map

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model

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

Instance Attribute Details

#app_previewsObject

Returns the value of attribute app_previews.



11
12
13
# File 'spaceship/lib/spaceship/connect_api/models/app_preview_set.rb', line 11

def app_previews
  @app_previews
end

#preview_typeObject

Returns the value of attribute preview_type.



9
10
11
# File 'spaceship/lib/spaceship/connect_api/models/app_preview_set.rb', line 9

def preview_type
  @preview_type
end

Class Method Details

.all(client: nil, app_store_version_localization_id: nil, filter: {}, includes: nil, limit: nil, sort: nil) ⇒ Object

API



65
66
67
68
69
# File 'spaceship/lib/spaceship/connect_api/models/app_preview_set.rb', line 65

def self.all(client: nil, app_store_version_localization_id: nil, filter: {}, includes: nil, limit: nil, sort: nil)
  client ||= Spaceship::ConnectAPI
  resp = client.get_app_preview_sets(app_store_version_localization_id: app_store_version_localization_id, filter: filter, includes: includes, limit: limit, sort: sort)
  return resp.to_models
end

.get(client: nil, app_preview_set_id: nil, includes: "appPreviews") ⇒ Object



71
72
73
74
# File 'spaceship/lib/spaceship/connect_api/models/app_preview_set.rb', line 71

def self.get(client: nil, app_preview_set_id: nil, includes: "appPreviews")
  client ||= Spaceship::ConnectAPI
  return client.get_app_preview_set(app_preview_set_id: app_preview_set_id, filter: nil, includes: includes, limit: nil, sort: nil).first
end

.preview_type_from_filename(name, preview_types = PreviewType::ALL) ⇒ Object



143
144
145
# File 'spaceship/lib/spaceship/connect_api/models/app_preview_set.rb', line 143

def self.preview_type_from_filename(name, preview_types = PreviewType::ALL)
  preview_types.find { |type| name.to_s.upcase.include?(type) }
end

.typeObject



57
58
59
# File 'spaceship/lib/spaceship/connect_api/models/app_preview_set.rb', line 57

def self.type
  return "appPreviewSets"
end

.validate_video_resolution(width, height, preview_type) ⇒ Object

Validate video resolution (portrait canonical sizes) for provided preview_type. Returns true if the resolution matches any accepted pair.



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
# File 'spaceship/lib/spaceship/connect_api/models/app_preview_set.rb', line 114

def self.validate_video_resolution(width, height, preview_type)
  return false unless width && height
  if width > height
    width, height = height, width
  end
  # for a list of valid resolutions, look for "Accepted resolutions" at https://developer.apple.com/help/app-store-connect/reference/app-information/app-preview-specifications
  # resolutions below are sorted by display inch from biggest to smallest (see top of the module)
  canonical = {
    # iPhone
    PreviewType::IPHONE_67 => [[886, 1920]],
    PreviewType::IPHONE_65 => [[886, 1920]],
    PreviewType::IPHONE_61 => [[886, 1920]],
    PreviewType::IPHONE_58 => [[886, 1920]],
    PreviewType::IPHONE_55 => [[1080, 1920]],
    PreviewType::IPHONE_47 => [[750, 1334]],
    PreviewType::IPHONE_40 => [[1080, 1920]],

    # iPad
    PreviewType::IPAD_PRO_3GEN_129 => [[1200, 1600]],
    PreviewType::IPAD_PRO_3GEN_11  => [[1200, 1600]],
    PreviewType::IPAD_PRO_129      => [[1200, 1600], [900, 1200]],
    PreviewType::IPAD_105          => [[1200, 1600]],
    PreviewType::IPAD_97           => [[900, 1200]],
  }

  pairs = canonical[preview_type] || []
  pairs.any? { |(canon_width, canon_height)| width == canon_width && height == canon_height }
end

Instance Method Details

#delete!(client: nil, filter: {}, includes: nil, limit: nil, sort: nil) ⇒ Object



76
77
78
79
# File 'spaceship/lib/spaceship/connect_api/models/app_preview_set.rb', line 76

def delete!(client: nil, filter: {}, includes: nil, limit: nil, sort: nil)
  client ||= Spaceship::ConnectAPI
  return client.delete_app_preview_set(app_preview_set_id: id)
end

#reorder_previews(client: nil, app_preview_ids: nil) ⇒ Object



105
106
107
108
109
110
# File 'spaceship/lib/spaceship/connect_api/models/app_preview_set.rb', line 105

def reorder_previews(client: nil, app_preview_ids: nil)
  client ||= Spaceship::ConnectAPI
  client.patch_app_preview_set_previews(app_preview_set_id: id, app_preview_ids: app_preview_ids)

  return client.get_app_preview_set(app_preview_set_id: id, includes: "appPreviews").first
end

#upload_preview(client: nil, path: nil, wait_for_processing: true, position: nil, frame_time_code: nil) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'spaceship/lib/spaceship/connect_api/models/app_preview_set.rb', line 81

def upload_preview(client: nil, path: nil, wait_for_processing: true, position: nil, frame_time_code: nil)
  client ||= Spaceship::ConnectAPI
  # Upload preview
  preview = Spaceship::ConnectAPI::AppPreview.create(client: client, app_preview_set_id: id, path: path, wait_for_processing: wait_for_processing, frame_time_code: frame_time_code)

  # Reposition (if specified)
  unless position.nil?
    # Get all app preview ids
    set = AppPreviewSet.get(app_preview_set_id: id)
    app_preview_ids = set.app_previews.map(&:id)

    # Remove new uploaded preview
    app_preview_ids.delete(preview.id)

    # Insert preview at specified position
    app_preview_ids = app_preview_ids.insert(position, preview.id).compact

    # Reorder previews
    reorder_previews(app_preview_ids: app_preview_ids)
  end

  return preview
end