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

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)



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

def app_status
  @app_status
end

#app_typeString



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

def app_type
  @app_type
end

#applicationSpaceship::Tunes::Application



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

def application
  @application
end

#can_beta_testBool



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

def can_beta_test
  @can_beta_test
end

#can_prepare_for_uploadBool



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



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

def can_reject_version
  @can_reject_version
end

#can_send_version_liveBool



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

def can_send_version_live
  @can_send_version_live
end


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

def copyright
  @copyright
end

#descriptionHash (readonly)



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

def description
  @description
end

#is_liveBool



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

def is_live
  @is_live
end

#keywordsHash (readonly)



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

def keywords
  @keywords
end

#languagesArray



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

def languages
  @languages
end

#large_app_iconSpaceship::Tunes::AppImage



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

def large_app_icon
  @large_app_icon
end

#marketing_urlHash (readonly)



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

def marketing_url
  @marketing_url
end

#platformString



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

def platform
  @platform
end

#raw_statusString



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

def raw_status
  @raw_status
end

#release_notesHash (readonly)



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

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



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

def review_demo_password
  @review_demo_password
end

#review_demo_userString



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

def review_demo_user
  @review_demo_user
end

#review_emailString



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

def review_email
  @review_email
end

#review_first_nameString

App Review Information



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

def review_first_name
  @review_first_name
end

#review_last_nameString



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

def review_last_name
  @review_last_name
end

#review_notesString



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

def review_notes
  @review_notes
end

#review_phone_numberString



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

def review_phone_number
  @review_phone_number
end

#screenshotsHash (readonly)



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

def screenshots
  @screenshots
end

#support_urlHash (readonly)



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

def support_url
  @support_url
end

#supports_apple_watchBool



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

def supports_apple_watch
  @supports_apple_watch
end

#trailersHash (readonly)



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

def trailers
  @trailers
end

#transit_app_fileSpaceship::Tunes::TransitAppFile

GeoJson



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

def transit_app_file
  @transit_app_file
end

#versionString



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

def version
  @version
end

#version_idInteger



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

def version_id
  @version_id
end

#watch_app_iconSpaceship::Tunes::AppImage



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.



151
152
153
154
155
156
# File 'lib/spaceship/tunes/app_version.rb', line 151

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

  return obj
end

.find(application, app_id, is_live) ⇒ Object



161
162
163
164
165
166
167
168
# File 'lib/spaceship/tunes/app_version.rb', line 161

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



204
205
206
207
208
209
210
211
212
# File 'lib/spaceship/tunes/app_version.rb', line 204

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

#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



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/spaceship/tunes/app_version.rb', line 182

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

#is_live?Bool

rubocop:disable Style/PredicateName



173
174
175
# File 'lib/spaceship/tunes/app_version.rb', line 173

def is_live?
  is_live
end

#save!Object

Push all changes that were made back to iTunes Connect



268
269
270
# File 'lib/spaceship/tunes/app_version.rb', line 268

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



217
218
219
220
221
222
# File 'lib/spaceship/tunes/app_version.rb', line 217

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



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

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…



438
439
440
441
442
443
444
445
446
447
448
# File 'lib/spaceship/tunes/app_version.rb', line 438

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/KrauseFx/deliver/blob/master/Reference.md



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/spaceship/tunes/app_version.rb', line 235

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



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

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



293
294
295
296
297
298
299
300
301
302
# File 'lib/spaceship/tunes/app_version.rb', line 293

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



340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/spaceship/tunes/app_version.rb', line 340

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



390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
# File 'lib/spaceship/tunes/app_version.rb', line 390

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



306
307
308
309
310
311
312
313
314
315
# File 'lib/spaceship/tunes/app_version.rb', line 306

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



273
274
275
276
277
# File 'lib/spaceship/tunes/app_version.rb', line 273

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