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

Instance Attribute Summary collapse

Attributes inherited from Base

#client, #raw_data

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:



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

def app_status
  @app_status
end

#app_typeString

Returns The appType number of this version.

Returns:

  • (String)

    The appType number of this version



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

def app_type
  @app_type
end

#applicationSpaceship::Tunes::Application

Returns A reference to the application this version is for.

Returns:



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

def application
  @application
end

#can_beta_testBool

Returns:

  • (Bool)


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

def can_beta_test
  @can_beta_test
end

#can_prepare_for_uploadBool

Returns:

  • (Bool)


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

def can_prepare_for_upload
  @can_prepare_for_upload
end

#can_reject_versionBool

Returns:

  • (Bool)


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

def can_reject_version
  @can_reject_version
end

#can_send_version_liveBool

Returns:

  • (Bool)


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

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



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

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



97
98
99
# File 'lib/spaceship/tunes/app_version.rb', line 97

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?



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

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



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

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



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

def languages
  @languages
end

#large_app_iconSpaceship::Tunes::AppImage

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

Returns:



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

def large_app_icon
  @large_app_icon
end

#marketing_urlHash (readonly)

Returns A hash representing the keywords in all languages.

Returns:

  • (Hash)

    A hash representing the keywords in all languages



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

def marketing_url
  @marketing_url
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



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

def raw_status
  @raw_status
end

#release_notesHash (readonly)

Returns The changelog.

Returns:

  • (Hash)

    The changelog



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

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



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

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



81
82
83
# File 'lib/spaceship/tunes/app_version.rb', line 81

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



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

def review_demo_user
  @review_demo_user
end

#review_emailString

Returns App Review Information Email Address.

Returns:

  • (String)

    App Review Information Email Address



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

def review_email
  @review_email
end

#review_first_nameString

App Review Information

Returns:

  • (String)

    App Review Information First Name



66
67
68
# File 'lib/spaceship/tunes/app_version.rb', line 66

def review_first_name
  @review_first_name
end

#review_last_nameString

Returns App Review Information Last Name.

Returns:

  • (String)

    App Review Information Last Name



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

def review_last_name
  @review_last_name
end

#review_notesString

Returns App Review Information Notes.

Returns:

  • (String)

    App Review Information Notes



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

def review_notes
  @review_notes
end

#review_phone_numberString

Returns App Review Information Phone Number.

Returns:

  • (String)

    App Review Information Phone Number



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

def review_phone_number
  @review_phone_number
end

#screenshotsHash (readonly)

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

Returns:

  • (Hash)

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



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

def screenshots
  @screenshots
end

#support_urlHash (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 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?



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

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)



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

def trailers
  @trailers
end

#transit_app_fileSpaceship::Tunes::TransitAppFile

GeoJson

Returns:



60
61
62
# File 'lib/spaceship/tunes/app_version.rb', line 60

def transit_app_file
  @transit_app_file
end

#versionString

Returns The version number of this version.

Returns:

  • (String)

    The version number of this version



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

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



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

def version_id
  @version_id
end

#watch_app_iconSpaceship::Tunes::AppImage

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

Returns:



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

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.



146
147
148
149
150
151
# File 'lib/spaceship/tunes/app_version.rb', line 146

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

  return obj
end

.find(application, app_id, is_live) ⇒ Object

Parameters:



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

def find(application, app_id, is_live)
  attrs = client.app_version(app_id, is_live)
  return nil unless attrs
  attrs.merge!(application: application)
  attrs.merge!(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



207
208
209
210
211
212
213
214
215
# File 'lib/spaceship/tunes/app_version.rb', line 207

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.
    builds << Tunes::Build.factory(attrs)
  end
  return builds
end

#is_live?Bool

rubocop:disable Style/PredicateName

Returns:

  • (Bool)

    Is that version currently available in the App Store?



168
169
170
# File 'lib/spaceship/tunes/app_version.rb', line 168

def is_live?
  is_live
end

#save!Object

Push all changes that were made back to iTunes Connect



228
229
230
# File 'lib/spaceship/tunes/app_version.rb', line 228

def save!
  client.update_app_version!(application.apple_id, is_live?, 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



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

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



240
241
242
243
244
245
246
247
248
249
# File 'lib/spaceship/tunes/app_version.rb', line 240

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
  setup_screenshots
  setup_trailers
end

#unfold_languagesObject

Prefill name, keywords, etc…



398
399
400
401
402
403
404
405
406
407
408
# File 'lib/spaceship/tunes/app_version.rb', line 398

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

#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



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/spaceship/tunes/app_version.rb', line 279

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



253
254
255
256
257
258
259
260
261
262
# File 'lib/spaceship/tunes/app_version.rb', line 253

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



300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/spaceship/tunes/app_version.rb', line 300

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
        }
    }
    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



350
351
352
353
354
355
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 350

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}",
      "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



266
267
268
269
270
271
272
273
274
275
# File 'lib/spaceship/tunes/app_version.rb', line 266

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



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

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