Class: Spaceship::Tunes::Application

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

Instance Attribute Summary collapse

Attributes inherited from Base

#client, #raw_data

Getting information collapse

Modifying collapse

in_app_purchases 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, factory, #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


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

def app_icon_preview_url
  @app_icon_preview_url
end

#apple_idString

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

Examples:

"1013943394"

Returns:

  • (String)

    The App identifier of this app, provided by App Store Connect


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

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


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

def bundle_id
  @bundle_id
end

#issues_countInteger

Returns The number of issues provided by App Store Connect.

Returns:

  • (Integer)

    The number of issues provided by App Store Connect


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

def issues_count
  @issues_count
end

#last_modifiedString

Returns Last modified.

Returns:


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

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)


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

def name
  @name
end

#vendor_idString

Returns The Vendor ID provided by App Store Connect.

Examples:

"1435592086"

Returns:

  • (String)

    The Vendor ID provided by App Store Connect


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

def vendor_id
  @vendor_id
end

#version_setsArray

Returns An array of all versions sets.

Returns:

  • (Array)

    An array of all versions sets


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

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


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

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

.available_bundle_ids(platform: nil) ⇒ Object


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

def available_bundle_ids(platform: nil)
  client.get_available_bundle_ids(platform: platform)
end

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

Creates a new application on App Store 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 (defaults to: nil)

    *DEPRECATED: Use `ensure_version!` method instead* (String): 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


94
95
96
97
98
99
100
101
102
103
104
# File 'spaceship/lib/spaceship/tunes/application.rb', line 94

def create!(name: nil, primary_language: nil, version: nil, sku: nil, bundle_id: nil, bundle_id_suffix: nil, company_name: nil, platform: nil, itunes_connect_users: nil)
  puts("The `version` parameter is deprecated. Use `ensure_version!` method instead") if version
  client.create_application!(name: name,
                 primary_language: primary_language,
                              sku: sku,
                        bundle_id: bundle_id,
                        bundle_id_suffix: bundle_id_suffix,
                        company_name: company_name,
                            platform: platform,
                            itunes_connect_users: itunes_connect_users)
end

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

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

Returns:


72
73
74
75
76
77
# File 'spaceship/lib/spaceship/tunes/application.rb', line 72

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

Instance Method Details

#all_build_train_numbers(platform: nil) ⇒ Array

The numbers of all build trains that were uploaded

Returns:

  • (Array)

    An array of train version numbers


306
307
308
# File 'spaceship/lib/spaceship/tunes/application.rb', line 306

def all_build_train_numbers(platform: nil)
  return self.build_trains(platform: platform || self.platform).versions
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


314
315
316
# File 'spaceship/lib/spaceship/tunes/application.rb', line 314

def all_builds_for_train(train: nil, platform: nil)
  return TestFlight::Build.builds_for_train(app_id: self.apple_id, platform: platform || self.platform, train_version: train)
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


320
321
322
# File 'spaceship/lib/spaceship/tunes/application.rb', line 320

def all_processing_builds(platform: nil)
  return TestFlight::Build.all_processing_builds(app_id: self.apple_id, platform: platform || self.platform)
end

#analyticsObject


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

def analytics
  if self.live_version.nil?
    raise 'Analytics are only available for live apps.'
  end

  attrs = {}
  attrs[:apple_id] = self.apple_id
  Spaceship::Tunes::AppAnalytics.factory(attrs)
end

#availabilityObject

The current availability.


280
281
282
# File 'spaceship/lib/spaceship/tunes/application.rb', line 280

def availability
  client.availability(self.apple_id)
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


300
301
302
# File 'spaceship/lib/spaceship/tunes/application.rb', line 300

def build_trains(platform: nil)
  TestFlight::BuildTrains.all(app_id: self.apple_id, platform: platform || self.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


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

def builds(platform: nil)
  all = TestFlight::Build.all(app_id: self.apple_id, platform: platform || self.platform)
  return all unless block_given?
  all.each { |build| yield(build) }
end

#cancel_all_testflight_submissions!Object

Cancels all ongoing TestFlight beta submission for this application


370
371
372
373
374
375
376
377
378
379
# File 'spaceship/lib/spaceship/tunes/application.rb', line 370

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_submission(platform: nil) ⇒ Object


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

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

  Spaceship::Tunes::AppSubmission.create(self, version, platform: platform)
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


226
227
228
229
230
231
232
233
234
# File 'spaceship/lib/spaceship/tunes/application.rb', line 226

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

#default_external_groupObject


408
409
410
# File 'spaceship/lib/spaceship/tunes/application.rb', line 408

def default_external_group
  TestFlight::Group.default_external_group(app_id: self.apple_id)
end

#detailsObject


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

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

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

Returns Receive the version that can fully be edited.

Returns:


129
130
131
# File 'spaceship/lib/spaceship/tunes/application.rb', line 129

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

#ensure_not_a_bundleObject

private to module


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

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?


240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'spaceship/lib/spaceship/tunes/application.rb', line 240

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

#in_app_purchasesObject

Get base In-App-Purchases object


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

def in_app_purchases
  attrs = {}
  attrs[:application] = self
  Tunes::IAP.factory(attrs)
end

#latest_version(platform: nil) ⇒ Spaceship::Tunes::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::Tunes::AppVersion)

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


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

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

#live_version(platform: nil) ⇒ Spaceship::Tunes::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::Tunes::AppVersion)

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


124
125
126
# File 'spaceship/lib/spaceship/tunes/application.rb', line 124

def live_version(platform: nil)
  Spaceship::Tunes::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


191
192
193
194
195
196
197
198
199
200
201
202
# File 'spaceship/lib/spaceship/tunes/application.rb', line 191

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


167
168
169
170
171
172
173
# File 'spaceship/lib/spaceship/tunes/application.rb', line 167

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

#price_tierObject

The current price tier


270
271
272
# File 'spaceship/lib/spaceship/tunes/application.rb', line 270

def price_tier
  client.price_tier(self.apple_id)
end

#promocodesObject


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

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

#promocodes_historyObject


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

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

#ratings(version_id: '', storefront: '') ⇒ Object


161
162
163
164
165
# File 'spaceship/lib/spaceship/tunes/application.rb', line 161

def ratings(version_id: '', storefront: '')
  attrs = client.get_ratings(apple_id, platform, version_id, storefront)
  attrs[:application] = self
  Tunes::AppRatings.new(attrs)
end

#reject_version_if_possible!Object


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

def reject_version_if_possible!
  can_reject = edit_version.can_reject_version
  if can_reject
    client.reject!(apple_id, edit_version.version_id)
  end

  return can_reject
end

#release!Object


385
386
387
388
389
390
391
# File 'spaceship/lib/spaceship/tunes/application.rb', line 385

def release!
  version = self.edit_version
  if version.nil?
    raise "Could not find a valid version to release"
  end
  version.release!
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”=>[]}`


157
158
159
# File 'spaceship/lib/spaceship/tunes/application.rb', line 157

def resolution_center
  client.get_resolution_center(apple_id, platform)
end

#setupObject


396
397
398
399
400
401
402
# File 'spaceship/lib/spaceship/tunes/application.rb', line 396

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

#tunes_all_build_trains(app_id: nil, platform: nil) ⇒ Object


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

def tunes_all_build_trains(app_id: nil, platform: nil)
  resp = client.all_build_trains(app_id: apple_id, platform: platform)
  trains = resp["trains"] or []
  trains.map do |attrs|
    attrs['application'] = self
    Tunes::BuildTrain.factory(attrs)
  end
end

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


333
334
335
336
337
338
339
340
# File 'spaceship/lib/spaceship/tunes/application.rb', line 333

def tunes_all_builds_for_train(train: nil, platform: nil)
  resp = client.all_builds_for_train(app_id: apple_id, train: train, platform: platform)
  items = resp["items"] or []
  items.map do |attrs|
    attrs['apple_id'] = apple_id
    Tunes::Build.factory(attrs)
  end
end

#tunes_build_details(train: nil, build_number: nil, platform: nil) ⇒ Object


342
343
344
345
346
# File 'spaceship/lib/spaceship/tunes/application.rb', line 342

def tunes_build_details(train: nil, build_number: nil, platform: nil)
  resp = client.build_details(app_id: apple_id, train: train, build_number: build_number, platform: platform)
  resp['apple_id'] = apple_id
  Tunes::BuildDetails.factory(resp)
end

#typeObject


175
176
177
178
179
180
181
182
183
184
185
# File 'spaceship/lib/spaceship/tunes/application.rb', line 175

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_availability!(availability) ⇒ Object

set the availability. This method doesn't require `save` to be called


275
276
277
# File 'spaceship/lib/spaceship/tunes/application.rb', line 275

def update_availability!(availability)
  client.update_availability!(self.apple_id, availability)
end

#update_price_tier!(price_tier) ⇒ Object

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


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

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


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

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

#version_set_for_platform(platform) ⇒ Object


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

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


210
211
212
213
214
215
216
217
# File 'spaceship/lib/spaceship/tunes/application.rb', line 210

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