Class: Spaceship::Tunes::AppVersion

Inherits:
TunesBase show all
Defined in:
lib/spaceship/tunes/app_version.rb

Overview

Represents an editable version of an iTunes Connect Application This can either be the live or the edit version retrieved via the app rubocop:disable Metrics/ClassLength

Promo codes collapse

Instance Attribute Summary collapse

Attributes inherited from Base

#client, #raw_data

Promo codes collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TunesBase

client

Methods inherited from Base

attr_accessor, attr_mapping, #attributes, attributes, #initialize, #inspect, mapping_module, method_missing, set_client, #to_s

Constructor Details

This class inherits a constructor from Spaceship::Base

Instance Attribute Details

#app_statusSpaceship::Tunes::AppStatus (readonly)

Returns What’s the current status of this app e.g. Waiting for Review, Ready for Sale, …

Returns:



25
26
27
# File 'lib/spaceship/tunes/app_version.rb', line 25

def app_status
  @app_status
end

#app_typeString

Returns The appType number of this version.

Returns:

  • (String)

    The appType number of this version



21
22
23
# File 'lib/spaceship/tunes/app_version.rb', line 21

def app_type
  @app_type
end

#applicationSpaceship::Tunes::Application

Returns A reference to the application this version is for.

Returns:



9
10
11
# File 'lib/spaceship/tunes/app_version.rb', line 9

def application
  @application
end

#can_beta_testBool

Returns:

  • (Bool)


46
47
48
# File 'lib/spaceship/tunes/app_version.rb', line 46

def can_beta_test
  @can_beta_test
end

#can_prepare_for_uploadBool

Returns:

  • (Bool)


37
38
39
# File 'lib/spaceship/tunes/app_version.rb', line 37

def can_prepare_for_upload
  @can_prepare_for_upload
end

#can_reject_versionBool

Returns:

  • (Bool)


34
35
36
# File 'lib/spaceship/tunes/app_version.rb', line 34

def can_reject_version
  @can_reject_version
end

#can_send_version_liveBool

Returns:

  • (Bool)


40
41
42
# File 'lib/spaceship/tunes/app_version.rb', line 40

def can_send_version_live
  @can_send_version_live
end

Returns The copyright information of this app.

Returns:

  • (String)

    The copyright information of this app



18
19
20
# File 'lib/spaceship/tunes/app_version.rb', line 18

def copyright
  @copyright
end

#descriptionHash (readonly)

Returns A hash representing the description in all languages.

Returns:

  • (Hash)

    A hash representing the description in all languages



106
107
108
# File 'lib/spaceship/tunes/app_version.rb', line 106

def description
  @description
end

#is_liveBool

Returns Is that the version that’s currently available in the App Store?.

Returns:

  • (Bool)

    Is that the version that’s currently available in the App Store?



28
29
30
# File 'lib/spaceship/tunes/app_version.rb', line 28

def is_live
  @is_live
end

#keywordsHash (readonly)

Returns A hash representing the keywords in all languages.

Returns:

  • (Hash)

    A hash representing the keywords in all languages



103
104
105
# File 'lib/spaceship/tunes/app_version.rb', line 103

def keywords
  @keywords
end

#languagesArray

Returns Raw access the all available languages. You shouldn’t use it probably.

Returns:

  • (Array)

    Raw access the all available languages. You shouldn’t use it probably



100
101
102
# File 'lib/spaceship/tunes/app_version.rb', line 100

def languages
  @languages
end

#large_app_iconSpaceship::Tunes::AppImage

Returns the structure containing information about the large app icon (1024x1024).

Returns:



52
53
54
# File 'lib/spaceship/tunes/app_version.rb', line 52

def large_app_icon
  @large_app_icon
end

#marketing_urlHash (readonly)

Returns A hash representing the marketing url in all languages.

Returns:

  • (Hash)

    A hash representing the marketing url in all languages



115
116
117
# File 'lib/spaceship/tunes/app_version.rb', line 115

def marketing_url
  @marketing_url
end

#platformString

Returns The platform value of this version.

Returns:

  • (String)

    The platform value of this version.



12
13
14
# File 'lib/spaceship/tunes/app_version.rb', line 12

def platform
  @platform
end

#raw_statusString

Returns App Status (e.g. ‘readyForSale’). You should use ‘app_status` instead.

Returns:

  • (String)

    App Status (e.g. ‘readyForSale’). You should use ‘app_status` instead



31
32
33
# File 'lib/spaceship/tunes/app_version.rb', line 31

def raw_status
  @raw_status
end

#release_notesHash (readonly)

Returns The changelog.

Returns:

  • (Hash)

    The changelog



109
110
111
# File 'lib/spaceship/tunes/app_version.rb', line 109

def release_notes
  @release_notes
end

#release_on_approvalObject

These methods takes care of properly parsing values that are not returned in the right format, e.g. boolean as string



43
44
45
# File 'lib/spaceship/tunes/app_version.rb', line 43

def release_on_approval
  @release_on_approval
end

#review_demo_passwordString

Returns App Review Information Demo Account Password.

Returns:

  • (String)

    App Review Information Demo Account Password



90
91
92
# File 'lib/spaceship/tunes/app_version.rb', line 90

def review_demo_password
  @review_demo_password
end

#review_demo_userString

Returns App Review Information Demo Account User Name.

Returns:

  • (String)

    App Review Information Demo Account User Name



87
88
89
# File 'lib/spaceship/tunes/app_version.rb', line 87

def review_demo_user
  @review_demo_user
end

#review_emailString

Returns App Review Information Email Address.

Returns:

  • (String)

    App Review Information Email Address



79
80
81
# File 'lib/spaceship/tunes/app_version.rb', line 79

def review_email
  @review_email
end

#review_first_nameString

App Review Information

Returns:

  • (String)

    App Review Information First Name



70
71
72
# File 'lib/spaceship/tunes/app_version.rb', line 70

def review_first_name
  @review_first_name
end

#review_last_nameString

Returns App Review Information Last Name.

Returns:

  • (String)

    App Review Information Last Name



73
74
75
# File 'lib/spaceship/tunes/app_version.rb', line 73

def review_last_name
  @review_last_name
end

#review_notesString

Returns App Review Information Notes.

Returns:

  • (String)

    App Review Information Notes



93
94
95
# File 'lib/spaceship/tunes/app_version.rb', line 93

def review_notes
  @review_notes
end

#review_phone_numberString

Returns App Review Information Phone Number.

Returns:

  • (String)

    App Review Information Phone Number



76
77
78
# File 'lib/spaceship/tunes/app_version.rb', line 76

def review_phone_number
  @review_phone_number
end

#review_user_neededBoolean (readonly)

Returns The checkbox that indiciates if a demo account is needed. Is set automatically depending on if a user and pass are set.

Returns:

  • (Boolean)

    The checkbox that indiciates if a demo account is needed. Is set automatically depending on if a user and pass are set



84
85
86
# File 'lib/spaceship/tunes/app_version.rb', line 84

def review_user_needed
  @review_user_needed
end

#screenshotsHash (readonly)

Returns Represents the screenshots of this app version (read-only).

Returns:

  • (Hash)

    Represents the screenshots of this app version (read-only)



118
119
120
# File 'lib/spaceship/tunes/app_version.rb', line 118

def screenshots
  @screenshots
end

#support_urlHash (readonly)

Returns A hash representing the support url in all languages.

Returns:

  • (Hash)

    A hash representing the support url in all languages



112
113
114
# File 'lib/spaceship/tunes/app_version.rb', line 112

def support_url
  @support_url
end

#supports_apple_watchBool

Returns Does the binary contain a watch binary?.

Returns:

  • (Bool)

    Does the binary contain a watch binary?



49
50
51
# File 'lib/spaceship/tunes/app_version.rb', line 49

def supports_apple_watch
  @supports_apple_watch
end

#trailersHash (readonly)

Returns Represents the trailers of this app version (read-only).

Returns:

  • (Hash)

    Represents the trailers of this app version (read-only)



121
122
123
# File 'lib/spaceship/tunes/app_version.rb', line 121

def trailers
  @trailers
end

#transit_app_fileSpaceship::Tunes::TransitAppFile

GeoJson

Returns:



64
65
66
# File 'lib/spaceship/tunes/app_version.rb', line 64

def transit_app_file
  @transit_app_file
end

#versionString

Returns The version number of this version.

Returns:

  • (String)

    The version number of this version



15
16
17
# File 'lib/spaceship/tunes/app_version.rb', line 15

def version
  @version
end

#version_idInteger

Returns a unqiue ID for this version generated by iTunes Connect.

Returns:

  • (Integer)

    a unqiue ID for this version generated by iTunes Connect



58
59
60
# File 'lib/spaceship/tunes/app_version.rb', line 58

def version_id
  @version_id
end

#watch_app_iconSpaceship::Tunes::AppImage

Returns the structure containing information about the large watch icon (1024x1024).

Returns:



55
56
57
# File 'lib/spaceship/tunes/app_version.rb', line 55

def watch_app_icon
  @watch_app_icon
end

Class Method Details

.factory(attrs) ⇒ Object

Create a new object based on a hash. This is used to create a new object based on the server response.



157
158
159
160
161
162
# File 'lib/spaceship/tunes/app_version.rb', line 157

def factory(attrs)
  obj = self.new(attrs)
  obj.unfold_languages

  return obj
end

.find(application, app_id, is_live) ⇒ Object

Parameters:



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/spaceship/tunes/app_version.rb', line 167

def find(application, app_id, is_live)
  # we only support applications
  platform = Spaceship::Tunes::AppVersionCommon.find_platform(application.raw_data['versionSets'])
  raise "We do not support BUNDLE types right now" if platform['type'] == 'BUNDLE'

  # too bad the "id" field is empty, it forces us to make more requests to the server
  # these could also be cached
  attrs = client.app_version(app_id, is_live)
  return nil unless attrs

  attrs[:application] = application
  attrs[:is_live] = is_live

  return self.factory(attrs)
end

Instance Method Details

#candidate_buildsObject

Returns an array of all builds that can be sent to review



219
220
221
222
223
224
225
226
227
228
# File 'lib/spaceship/tunes/app_version.rb', line 219

def candidate_builds
  res = client.candidate_builds(self.application.apple_id, self.version_id)
  builds = []
  res.each do |attrs|
    next unless attrs["type"] == "BUILD" # I don't know if it can be something else.
    attrs[:apple_id] = self.application.apple_id
    builds << Tunes::Build.factory(attrs)
  end
  return builds
end

#create_languages(languages) ⇒ Object

Call this method to make sure the given languages are available for this app You should call this method before accessing the name, description and other localized values This will create the new language if it’s not available yet and do nothing if everything’s there Important: Due to a bug you have to fetch the ‘edit_version` again, as it doesn’t get refreshed immediately



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/spaceship/tunes/app_version.rb', line 197

def create_languages(languages)
  languages = [languages] if languages.kind_of?(String)
  raise "Please pass an array" unless languages.kind_of? Array

  copy_from = self.languages.find { |a| a['language'] == 'en-US' } || self.languages.first

  languages.each do |language|
    # First, see if it's already available
    found = self.languages.find do |local|
      local['language'] == language
    end
    next if found

    new_language = copy_from.clone
    new_language['language'] = language

    self.languages << new_language
  end
  nil
end

#generate_promocodes!(quantity) ⇒ Object



483
484
485
486
487
488
489
490
# File 'lib/spaceship/tunes/app_version.rb', line 483

def generate_promocodes!(quantity)
  data = client.generate_app_version_promocodes!(
    app_id: self.application.apple_id,
    version_id: self.version_id,
    quantity: quantity
  )
  Tunes::AppVersionGeneratedPromocodes.factory(data)
end

#is_live?Bool

Returns Is that version currently available in the App Store?.

Returns:

  • (Bool)

    Is that version currently available in the App Store?



185
186
187
# File 'lib/spaceship/tunes/app_version.rb', line 185

def is_live?
  is_live
end

#release!Object



476
477
478
# File 'lib/spaceship/tunes/app_version.rb', line 476

def release!
  client.release!(self.application.apple_id, self.version_id)
end

#save!Object

Push all changes that were made back to iTunes Connect



284
285
286
# File 'lib/spaceship/tunes/app_version.rb', line 284

def save!
  client.update_app_version!(application.apple_id, self.version_id, raw_data)
end

#select_build(build) ⇒ Object

Select a build to be submitted for Review. You have to pass a build you got from - candidate_builds Don’t forget to call save! after calling this method



233
234
235
236
237
238
# File 'lib/spaceship/tunes/app_version.rb', line 233

def select_build(build)
  raw_data.set(['preReleaseBuildVersionString', 'value'], build.build_version)
  raw_data.set(['preReleaseBuildTrainVersionString'], build.train_version)
  raw_data.set(['preReleaseBuildUploadDate'], build.upload_date)
  true
end

#setupObject

Private methods



296
297
298
299
300
301
302
303
304
305
# File 'lib/spaceship/tunes/app_version.rb', line 296

def setup
  # Properly parse the AppStatus
  status = raw_data['status']
  @app_status = Tunes::AppStatus.get_from_string(status)
  setup_large_app_icon
  setup_watch_app_icon
  setup_transit_app_file if supports_app_transit?
  setup_screenshots
  setup_trailers
end

#unfold_languagesObject

Prefill name, keywords, etc…



464
465
466
467
468
469
470
471
472
473
474
# File 'lib/spaceship/tunes/app_version.rb', line 464

def unfold_languages
  {
    keywords: :keywords,
    description: :description,
    supportURL: :support_url,
    marketingURL: :marketing_url,
    releaseNotes: :release_notes
  }.each do |json, attribute|
    instance_variable_set("@#{attribute}".to_sym, LanguageItem.new(json, languages))
  end
end

#update_rating(hash) ⇒ Object

Set the age restriction rating Call it like this: v.update_rating(

'CARTOON_FANTASY_VIOLENCE' => 0,
'MATURE_SUGGESTIVE' => 2,
'UNRESTRICTED_WEB_ACCESS' => 0,
'GAMBLING_CONTESTS' => 0

)

Available Values github.com/fastlane/fastlane/blob/master/deliver/Reference.md



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/spaceship/tunes/app_version.rb', line 251

def update_rating(hash)
  raise "Must be a hash" unless hash.kind_of?(Hash)

  hash.each do |key, value|
    to_edit = self.raw_data['ratings']['nonBooleanDescriptors'].find do |current|
      current['name'].include?(key)
    end

    if to_edit
      to_set = "NONE" if value == 0
      to_set = "INFREQUENT_MILD" if value == 1
      to_set = "FREQUENT_INTENSE" if value == 2
      raise "Invalid value '#{value}' for '#{key}', must be 0-2" unless to_set
      to_edit['level'] = "ITC.apps.ratings.level.#{to_set}"
    else
      # Maybe it's a boolean descriptor?
      to_edit = self.raw_data['ratings']['booleanDescriptors'].find do |current|
        current['name'].include?(key)
      end

      if to_edit
        to_set = "NO"
        to_set = "YES" if value.to_i > 0
        to_edit['level'] = "ITC.apps.ratings.level.#{to_set}"
      else
        raise "Could not find option '#{key}' in the list of available options"
      end
    end
  end
  true
end

#upload_geojson!(geojson_path) ⇒ Object

Uploads or removes the transit app file

Parameters:

  • icon_path (String)

    : The path to the geojson file. Use nil to remove it



335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/spaceship/tunes/app_version.rb', line 335

def upload_geojson!(geojson_path)
  unless geojson_path
    raw_data["transitAppFile"]["value"] = nil
    @transit_app_file = nil
    return
  end
  upload_file = UploadFile.from_path geojson_path
  geojson_data = client.upload_geojson(self, upload_file)

  @transit_app_file = Tunes::TransitAppFile.factory({}) if @transit_app_file.nil?
  @transit_app_file .url = nil # response.headers['Location']
  @transit_app_file.asset_token = geojson_data["token"]
  @transit_app_file.name = upload_file.file_name
  @transit_app_file.time_stamp = Time.now.to_i * 1000 # works without but...
end

#upload_large_icon!(icon_path) ⇒ Object

Uploads or removes the large icon

Parameters:

  • icon_path (String)

    : The path to the icon. Use nil to remove it



309
310
311
312
313
314
315
316
317
318
# File 'lib/spaceship/tunes/app_version.rb', line 309

def upload_large_icon!(icon_path)
  unless icon_path
    @large_app_icon.reset!
    return
  end
  upload_image = UploadFile.from_path icon_path
  image_data = client.upload_large_icon(self, upload_image)

  @large_app_icon.reset!({ asset_token: image_data['token'], original_file_name: upload_image.file_name })
end

#upload_screenshot!(screenshot_path, sort_order, language, device) ⇒ Object

Uploads or removes a screenshot

Parameters:

  • icon_path (String)

    : The path to the screenshot. Use nil to remove it

  • sort_order (Fixnum)

    : The sort_order, from 1 to 5

  • language (String)

    : The language for this screenshot

  • device (string)

    : The device for this screenshot



356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/spaceship/tunes/app_version.rb', line 356

def upload_screenshot!(screenshot_path, sort_order, language, device)
  raise "sort_order must be positive" unless sort_order > 0
  raise "sort_order must not be > 5" if sort_order > 5
  # this will also check both language and device parameters
  device_lang_screenshots = screenshots_data_for_language_and_device(language, device)["value"]

  existing_sort_orders = device_lang_screenshots.map { |s| s["value"]["sortOrder"] }
  if screenshot_path # adding / replacing
    upload_file = UploadFile.from_path screenshot_path
    screenshot_data = client.upload_screenshot(self, upload_file, device)

    new_screenshot = {
        "value" => {
            "assetToken" => screenshot_data["token"],
            "sortOrder" => sort_order,
            "url" => nil,
            "thumbNailUrl" => nil,
            "originalFileName" => upload_file.file_name
        }
    }

    # We disable "scaling" for this device type / language combination
    # We only set this, if we actually successfully uploaded a new screenshot
    # for this device / language combination
    # if this value is not set, iTC will fallback to another device type for screenshots
    language_details = raw_data_details.find { |d| d["language"] == language }["displayFamilies"]["value"]
    device_language_details = language_details.find { |display_family| display_family['name'] == device }
    device_language_details["scaled"]["value"] = false

    if existing_sort_orders.include?(sort_order) # replace
      device_lang_screenshots[existing_sort_orders.index(sort_order)] = new_screenshot
    else # add
      device_lang_screenshots << new_screenshot
    end
  else # removing
    raise "cannot remove screenshot with non existing sort_order" unless existing_sort_orders.include?(sort_order)
    device_lang_screenshots.delete_at(existing_sort_orders.index(sort_order))
  end
  setup_screenshots
end

#upload_trailer!(trailer_path, language, device, timestamp = "05.00", preview_image_path = nil) ⇒ Object

Uploads, removes a trailer video or change its preview image

A preview image for the video is required by ITC and is usually automatically extracted by your browser. This method will either automatically extract it from the video (using ‘ffmpeg) or allow you to specify it using preview_image_path. If the preview image is specified, ffmpeg` will ot be used. The image resolution will be checked against expectations (which might be different from the trailer resolution.

It is recommended to extract the preview image using the spaceship related tools in order to ensure the appropriate format and resolution are used.

Note: if the video is already set, the trailer_path is only used to grab the preview screenshot. Note: to extract its resolution and a screenshot preview, the ‘ffmpeg` tool will be used

Parameters:

  • icon_path (String)

    : The path to the screenshot. Use nil to remove it

  • sort_order (Fixnum)

    : The sort_order, from 1 to 5

  • language (String)

    : The language for this screenshot

  • device (String)

    : The device for this screenshot

  • timestamp (String) (defaults to: "05.00")

    : The optional timestamp of the screenshot to grab



416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/spaceship/tunes/app_version.rb', line 416

def upload_trailer!(trailer_path, language, device, timestamp = "05.00", preview_image_path = nil)
  raise "No app trailer supported for iphone35" if device == 'iphone35'

  device_lang_trailer = trailer_data_for_language_and_device(language, device)
  if trailer_path # adding / replacing trailer / replacing preview
    raise "Invalid timestamp #{timestamp}" if (timestamp =~ /^[0-9][0-9].[0-9][0-9]$/).nil?

    if preview_image_path
      check_preview_screenshot_resolution(preview_image_path, device)
      video_preview_path = preview_image_path
    else
      # IDEA: optimization, we could avoid fetching the screenshot if the timestamp hasn't changed
      video_preview_resolution = video_preview_resolution_for(device, trailer_path)
      video_preview_path = Utilities.grab_video_preview(trailer_path, timestamp, video_preview_resolution)
    end
    video_preview_file = UploadFile.from_path video_preview_path
    video_preview_data = client.upload_trailer_preview(self, video_preview_file)

    trailer = device_lang_trailer["value"]
    if trailer.nil? # add trailer
      upload_file = UploadFile.from_path trailer_path
      trailer_data = client.upload_trailer(self, upload_file)
      trailer_data = trailer_data['responses'][0]
      trailer = {
          "videoAssetToken" => trailer_data["token"],
          "descriptionXML" => trailer_data["descriptionDoc"],
          "contentType" => upload_file.content_type
      }
      device_lang_trailer["value"] = trailer
    end
    # add / update preview
    # different format required
    ts = "00:00:#{timestamp}"
    ts[8] = ':'

    trailer.merge!({
      "pictureAssetToken" => video_preview_data["token"],
      "previewFrameTimeCode" => ts.to_s,
      "isPortrait" => Utilities.portrait?(video_preview_path)
    })
  else # removing trailer
    raise "cannot remove non existing trailer" if device_lang_trailer["value"].nil?
    device_lang_trailer["value"] = nil
  end
  setup_trailers
end

#upload_watch_icon!(icon_path) ⇒ Object

Uploads or removes the watch icon

Parameters:

  • icon_path (String)

    : The path to the icon. Use nil to remove it



322
323
324
325
326
327
328
329
330
331
# File 'lib/spaceship/tunes/app_version.rb', line 322

def upload_watch_icon!(icon_path)
  unless icon_path
    @watch_app_icon.reset!
    return
  end
  upload_image = UploadFile.from_path icon_path
  image_data = client.upload_watch_icon(self, upload_image)

  @watch_app_icon.reset!({ asset_token: image_data["token"], original_file_name: upload_image.file_name })
end

#urlString

Returns An URL to this specific resource. You can enter this URL into your browser.

Returns:

  • (String)

    An URL to this specific resource. You can enter this URL into your browser



289
290
291
292
293
# File 'lib/spaceship/tunes/app_version.rb', line 289

def url
  url = "https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/ra/ng/app/#{application.apple_id}/ios/versioninfo/"
  url += "deliverable" if self.is_live?
  return url
end