Class: Spaceship::Tunes::Application

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

Instance Attribute Summary collapse

Attributes inherited from Base

#client, #raw_data

Getting information collapse

Modifying collapse

Builds collapse

Submit for Review collapse

release collapse

General collapse

Testers collapse

Promo codes collapse

Class 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_icon_preview_urlString

Returns The URL to a low resolution app icon of this app (340x340px). Might be nil.

Examples:

"https://is1-ssl.mzstatic.com/image/thumb/Purple7/v4/cd/a3/e2/cda3e2ac-4034-c6af-ee0c-3e4d9a0bafaa/pr_source.png/340x340bb-80.png"
nil

Returns:

  • (String)

    The URL to a low resolution app icon of this app (340x340px). Might be nil



35
36
37
# File 'lib/spaceship/tunes/application.rb', line 35

def app_icon_preview_url
  @app_icon_preview_url
end

#apple_idString

Returns The App identifier of this app, provided by iTunes Connect.

Examples:

"1013943394"

Returns:

  • (String)

    The App identifier of this app, provided by iTunes Connect



7
8
9
# File 'lib/spaceship/tunes/application.rb', line 7

def apple_id
  @apple_id
end

#bundle_idString

Returns The bundle_id (app identifier) of your app.

Examples:

"com.krausefx.app"

Returns:

  • (String)

    The bundle_id (app identifier) of your app



22
23
24
# File 'lib/spaceship/tunes/application.rb', line 22

def bundle_id
  @bundle_id
end

#issues_countInteger

Returns The number of issues provided by iTunes Connect.

Returns:

  • (Integer)

    The number of issues provided by iTunes Connect



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

def issues_count
  @issues_count
end

#last_modifiedString

Returns Last modified.

Returns:



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

def last_modified
  @last_modified
end

#nameString

Returns The name you provided for this app (in the default language).

Examples:

"Spaceship App"

Returns:

  • (String)

    The name you provided for this app (in the default language)



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

def name
  @name
end

#vendor_idString

Returns The Vendor ID provided by iTunes Connect.

Examples:

"1435592086"

Returns:

  • (String)

    The Vendor ID provided by iTunes Connect



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

def vendor_id
  @vendor_id
end

#version_setsArray

Returns An array of all versions sets.

Returns:

  • (Array)

    An array of all versions sets



38
39
40
# File 'lib/spaceship/tunes/application.rb', line 38

def version_sets
  @version_sets
end

Class Method Details

.allArray

Returns all apps available for this account

Returns:

  • (Array)

    Returns all apps available for this account



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

def all
  client.applications.map { |application| self.factory(application) }
end

.create!(name: nil, primary_language: nil, version: nil, sku: nil, bundle_id: nil, bundle_id_suffix: nil, company_name: nil, platform: nil) ⇒ Object

Creates a new application on iTunes Connect It cannot be changed after you create your first app.

Parameters:

  • name (String) (defaults to: nil)

    : The name of your app as it will appear on the App Store. This can’t be longer than 255 characters.

  • primary_language (String) (defaults to: nil)

    : If localized app information isn’t available in an App Store territory, the information from your primary language will be used instead.

  • version (String) (defaults to: nil)

    : The version number is shown on the App Store and should match the one you used in Xcode.

  • sku (String) (defaults to: nil)

    : A unique ID for your app that is not visible on the App Store.

  • bundle_id (String) (defaults to: nil)

    : The bundle ID must match the one you used in Xcode. It can’t be changed after you submit your first build.

  • company_name (String) (defaults to: nil)

    : The company name or developer name to display on the App Store for your apps.

  • platform (String) (defaults to: nil)

    : Platform one of (ios,osx) should it be an ios or an osx app



86
87
88
89
90
91
92
93
94
95
# File 'lib/spaceship/tunes/application.rb', line 86

def create!(name: nil, primary_language: nil, version: nil, sku: nil, bundle_id: nil, bundle_id_suffix: nil, company_name: nil, platform: nil)
  client.create_application!(name: name,
                 primary_language: primary_language,
                          version: version,
                              sku: sku,
                        bundle_id: bundle_id,
                        bundle_id_suffix: bundle_id_suffix,
                        company_name: company_name,
                            platform: platform)
end

.factory(attrs) ⇒ Object

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



53
54
55
# File 'lib/spaceship/tunes/application.rb', line 53

def factory(attrs)
  return self.new(attrs)
end

.find(identifier, mac: false) ⇒ Spaceship::Tunes::Application

Returns the application matching the parameter as either the App ID or the bundle identifier

Returns:



64
65
66
67
68
69
# File 'lib/spaceship/tunes/application.rb', line 64

def find(identifier, mac: false)
  all.find do |app|
    (app.apple_id == identifier.to_s || app.bundle_id == identifier) &&
      app.version_sets.any? { |v| (mac ? ["osx"] : ["ios", "appletvos"]).include?(v.platform) }
  end
end

Instance Method Details

#add_all_testers!Object

Add all testers (internal and external) to the current app list



360
361
362
363
# File 'lib/spaceship/tunes/application.rb', line 360

def add_all_testers!
  Tunes::Tester.external.add_all_to_app!(self.apple_id)
  Tunes::Tester.internal.add_all_to_app!(self.apple_id)
end

#add_external_tester!(email: nil, first_name: nil, last_name: nil) ⇒ Object

Add external tester to the current app list, if it doesn’t exist will be created

Parameters:

  • email (String) (defaults to: nil)

    (required): The email of the tester

  • first_name (String) (defaults to: nil)

    (optional): The first name of the tester (Ignored if user already exist)

  • last_name (String) (defaults to: nil)

    (optional): The last name of the tester (Ignored if user already exist)



393
394
395
396
397
398
399
400
# File 'lib/spaceship/tunes/application.rb', line 393

def add_external_tester!(email: nil, first_name: nil, last_name: nil)
  raise "Tester is already on #{self.name} betatesters" if find_external_tester(email)

  tester = Tunes::Tester.external.find(email) || Tunes::Tester.external.create!(email: email,
                                                                           first_name: first_name,
                                                                            last_name: last_name)
  tester.add_to_app!(self.apple_id)
end

#all_build_train_numbers(platform: nil) ⇒ Array

The numbers of all build trains that were uploaded

Returns:

  • (Array)

    An array of train version numbers



254
255
256
257
258
# File 'lib/spaceship/tunes/application.rb', line 254

def all_build_train_numbers(platform: nil)
  client.all_build_trains(app_id: self.apple_id, platform: platform).fetch("trains").collect do |current|
    current["versionString"]
  end
end

#all_builds_for_train(train: nil, platform: nil) ⇒ Object

Receive the build details for a specific build useful if the app is not listed in the TestFlight build list which might happen if you don’t use TestFlight This is used to receive dSYM files from Apple



264
265
266
267
268
269
# File 'lib/spaceship/tunes/application.rb', line 264

def all_builds_for_train(train: nil, platform: nil)
  client.all_builds_for_train(app_id: self.apple_id, train: train, platform: platform).fetch("items", []).collect do |attrs|
    attrs[:apple_id] = self.apple_id
    Tunes::Build.factory(attrs)
  end
end

#all_invalid_builds(platform: nil) ⇒ Array

Returns A list of binaries which are in the invalid state.

Returns:

  • (Array)

    A list of binaries which are in the invalid state



272
273
274
275
276
277
278
279
280
# File 'lib/spaceship/tunes/application.rb', line 272

def all_invalid_builds(platform: nil)
  builds = []

  self.build_trains(platform: platform).values.each do |train|
    builds.concat(train.invalid_builds)
  end

  return builds
end

#all_processing_builds(platform: nil) ⇒ Array

Returns This will return an array of all processing builds this include pre-processing or standard processing.

Returns:

  • (Array)

    This will return an array of all processing builds this include pre-processing or standard processing



284
285
286
287
288
289
290
291
292
# File 'lib/spaceship/tunes/application.rb', line 284

def all_processing_builds(platform: nil)
  builds = []

  self.build_trains(platform: platform).each do |version_number, train|
    builds.concat(train.processing_builds)
  end

  return builds
end

#build_trains(platform: nil) ⇒ Hash

TestFlight: A reference to all the build trains

Returns:

  • (Hash)

    a hash, the version number and platform being the key



248
249
250
# File 'lib/spaceship/tunes/application.rb', line 248

def build_trains(platform: nil)
  Tunes::BuildTrain.all(self, self.apple_id, platform: platform)
end

#builds(platform: nil) ⇒ Object

Get all builds that are already processed for all build trains You can either use the return value (array) or pass a block



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

def builds(platform: nil)
  all_builds = []
  self.build_trains(platform: platform).each do |version_number, train|
    train.builds.each do |build|
      yield(build) if block_given?
      all_builds << build unless block_given?
    end
  end
  all_builds
end

#cancel_all_testflight_submissions!Object

Cancels all ongoing TestFlight beta submission for this application



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

def cancel_all_testflight_submissions!
  self.builds do |build|
    begin
      build.cancel_beta_review!
    rescue
      # We really don't care about any errors here
    end
  end
  true
end

#create_submissionObject



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

def create_submission
  version = self.latest_version
  if version.nil?
    raise "Could not find a valid version to submit for review"
  end

  Spaceship::AppSubmission.create(self, version)
end

#create_version!(version_number, platform: nil) ⇒ Object

Create a new version of your app Since we have stored the outdated raw_data, we need to refresh this object otherwise ‘edit_version` will return nil



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

def create_version!(version_number, platform: nil)
  if edit_version(platform: platform)
    raise "Cannot create a new version for this app as there already is an `edit_version` available"
  end

  client.create_version!(apple_id, version_number, platform.nil? ? 'ios' : platform)

  # Future: implemented -reload method
end

#detailsObject



181
182
183
184
185
# File 'lib/spaceship/tunes/application.rb', line 181

def details
  attrs = client.app_details(apple_id)
  attrs[:application] = self
  Tunes::AppDetails.factory(attrs)
end

#edit_version(platform: nil) ⇒ Spaceship::AppVersion

Returns Receive the version that can fully be edited.

Returns:



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

def edit_version(platform: nil)
  Spaceship::AppVersion.find(self, self.apple_id, false, platform: platform)
end

#ensure_not_a_bundleObject

private to module



431
432
433
434
# File 'lib/spaceship/tunes/application.rb', line 431

def ensure_not_a_bundle
  # we only support applications
  raise "We do not support BUNDLE types right now" if self.type == 'BUNDLE'
end

#ensure_version!(version_number, platform: nil) ⇒ Bool

Will make sure the current edit_version matches the given version number This will either create a new version or change the version number from an existing version

Returns:

  • (Bool)

    Was something changed?



217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/spaceship/tunes/application.rb', line 217

def ensure_version!(version_number, platform: nil)
  if (e = edit_version(platform: platform))
    if e.version.to_s != version_number.to_s
      # Update an existing version
      e.version = version_number
      e.save!
      return true
    end
    return false
  else
    create_version!(version_number, platform: platform)
    return true
  end
end

#external_testersArray

Returns all external testers available for this app

Returns:

  • (Array)

    Returns all external testers available for this app



366
367
368
# File 'lib/spaceship/tunes/application.rb', line 366

def external_testers
  Tunes::Tester.external.all_by_app(self.apple_id)
end

#find_external_tester(identifier) ⇒ Spaceship::Tunes::Tester.external

Returns the external tester matching the parameter as either the Tester id or email

Parameters:

  • identifier (String)

    (required): Value used to filter the tester

Returns:

  • (Spaceship::Tunes::Tester.external)

    Returns the external tester matching the parameter as either the Tester id or email



378
379
380
# File 'lib/spaceship/tunes/application.rb', line 378

def find_external_tester(identifier)
  Tunes::Tester.external.find_by_app(self.apple_id, identifier)
end

#find_internal_tester(identifier) ⇒ Spaceship::Tunes::Tester.internal

Returns the internal tester matching the parameter as either the Tester id or email

Parameters:

  • identifier (String)

    (required): Value used to filter the tester

Returns:

  • (Spaceship::Tunes::Tester.internal)

    Returns the internal tester matching the parameter as either the Tester id or email



385
386
387
# File 'lib/spaceship/tunes/application.rb', line 385

def find_internal_tester(identifier)
  Tunes::Tester.internal.find_by_app(self.apple_id, identifier)
end

#internal_testersArray

Returns all internal testers available for this app

Returns:

  • (Array)

    Returns all internal testers available for this app



371
372
373
# File 'lib/spaceship/tunes/application.rb', line 371

def internal_testers
  Tunes::Tester.internal.all_by_app(self.apple_id)
end

#latest_version(platform: nil) ⇒ Spaceship::AppVersion

Returns This will return the ‘edit_version` if available and fallback to the `live_version`. Use this to just access the latest data.

Returns:

  • (Spaceship::AppVersion)

    This will return the ‘edit_version` if available and fallback to the `live_version`. Use this to just access the latest data



122
123
124
# File 'lib/spaceship/tunes/application.rb', line 122

def latest_version(platform: nil)
  edit_version(platform: platform) || live_version(platform: platform)
end

#live_version(platform: nil) ⇒ Spaceship::AppVersion

Returns Receive the version that is currently live on the App Store. You can’t modify all values there, so be careful.

Returns:

  • (Spaceship::AppVersion)

    Receive the version that is currently live on the App Store. You can’t modify all values there, so be careful.



111
112
113
# File 'lib/spaceship/tunes/application.rb', line 111

def live_version(platform: nil)
  Spaceship::AppVersion.find(self, self.apple_id, true, platform: platform)
end

#platformObject

kept for backward compatibility tries to guess the platform of the currently submitted apps note that as ITC now supports multiple app types, this might break if your app supports more than one



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

def platform
  if self.version_sets.nil?
    raise 'The application has no version sets and Spaceship does not know what to do here.'
  end

  if self.version_sets.length == 1
    version_sets[0].platform
  elsif self.platforms == %w(ios appletvos)
    'ios'
  end
  Spaceship::Tunes::AppVersionCommon.find_platform(raw_data['versionSets'])['platformString']
end

#platformsObject



144
145
146
147
148
149
150
# File 'lib/spaceship/tunes/application.rb', line 144

def platforms
  platforms = []
  version_sets.each do |version_set|
    platforms << version_set.platform
  end
  platforms
end

#price_tierObject

The current price tier



238
239
240
# File 'lib/spaceship/tunes/application.rb', line 238

def price_tier
  client.price_tier(self.apple_id)
end

#promocodesObject



416
417
418
419
420
421
# File 'lib/spaceship/tunes/application.rb', line 416

def promocodes
  data = client.app_promocodes(app_id: self.apple_id)
  data.map do |attrs|
    Tunes::AppVersionPromocodes.factory(attrs)
  end
end

#promocodes_historyObject



423
424
425
426
427
428
# File 'lib/spaceship/tunes/application.rb', line 423

def promocodes_history
  data = client.app_promocodes_history(app_id: self.apple_id)
  data.map do |attrs|
    Tunes::AppVersionGeneratedPromocodes.factory(attrs)
  end
end

#ratingsObject



138
139
140
141
142
# File 'lib/spaceship/tunes/application.rb', line 138

def ratings
  attrs = client.get_rating_summary(apple_id, platform)
  attrs[:application] = self
  Tunes::AppRatings.factory(attrs)
end

#release!Object



336
337
338
339
340
341
342
# File 'lib/spaceship/tunes/application.rb', line 336

def release!
  version = self.edit_version
  if version.nil?
    raise "Could not find a valid version to release"
  end
  version.release!
end

#remove_external_tester!(identifier) ⇒ Object

Remove external tester from the current app list that matching the parameter

as either the Tester id or email

Parameters:

  • identifier (String)

    (required): Value used to filter the tester



405
406
407
408
409
410
411
# File 'lib/spaceship/tunes/application.rb', line 405

def remove_external_tester!(identifier)
  tester = find_external_tester(identifier)

  raise "Tester is not on #{self.name} betatesters" unless tester

  tester.remove_from_app!(self.apple_id)
end

#resolution_centerHash

Returns Contains the reason for rejection. if everything is alright, the result will be ‘“sectionInfoKeys”=>[], “sectionWarningKeys”=>[], “replyConstraints”=>{“minLength”=>1, “maxLength”=>4000, “appNotes”=>“threads”=>[], “betaNotes”=>“threads”=>[], “appMessages”=>“threads”=>[]}`.

Returns:

  • (Hash)

    Contains the reason for rejection. if everything is alright, the result will be ‘“sectionInfoKeys”=>[], “sectionWarningKeys”=>[], “replyConstraints”=>{“minLength”=>1, “maxLength”=>4000, “appNotes”=>“threads”=>[], “betaNotes”=>“threads”=>[], “appMessages”=>“threads”=>[]}`



134
135
136
# File 'lib/spaceship/tunes/application.rb', line 134

def resolution_center
  client.get_resolution_center(apple_id, platform)
end

#setupObject



347
348
349
350
351
352
353
# File 'lib/spaceship/tunes/application.rb', line 347

def setup
  super
  @version_sets = (self.raw_data['versionSets'] || []).map do |attrs|
    attrs[:application] = self
    Tunes::VersionSet.factory(attrs)
  end
end

#typeObject



152
153
154
155
156
157
158
159
160
161
162
# File 'lib/spaceship/tunes/application.rb', line 152

def type
  if self.version_sets.nil?
    raise 'The application has no version sets and Spaceship does not know what to do here.'
  end

  if self.version_sets.length == 1
    version_sets[0].platform
  end
  platform = Spaceship::Tunes::AppVersionCommon.find_platform(raw_data['versionSets'])
  platform['type']
end

#update_price_tier!(price_tier) ⇒ Object

set the price tier. This method doesn’t require ‘save` to be called



233
234
235
# File 'lib/spaceship/tunes/application.rb', line 233

def update_price_tier!(price_tier)
  client.update_price_tier!(self.apple_id, price_tier)
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



127
128
129
# File 'lib/spaceship/tunes/application.rb', line 127

def url
  "https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/ra/ng/app/#{self.apple_id}"
end

#version_set_for_platform(platform) ⇒ Object



102
103
104
105
106
107
# File 'lib/spaceship/tunes/application.rb', line 102

def version_set_for_platform(platform)
  version_sets.each do |version_set|
    return version_set if version_set.platform == platform
  end
  nil
end

#versions_historyObject



187
188
189
190
191
192
193
194
# File 'lib/spaceship/tunes/application.rb', line 187

def versions_history
  ensure_not_a_bundle
  versions = client.versions_history(apple_id, platform)
  versions.map do |attrs|
    attrs[:application] = self
    Tunes::AppVersionHistory.factory(attrs)
  end
end