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

General collapse

Testers 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


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

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"


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"


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

def bundle_id
  @bundle_id
end

#issues_countInteger



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

def issues_count
  @issues_count
end

#last_modifiedString



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

def last_modified
  @last_modified
end

#nameString

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

Examples:

"Spaceship App"


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

def name
  @name
end

#platformString

Returns the supported platform of this app.

Examples:

"ios"


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

def platform
  @platform
end

#vendor_idString

Returns The Vendor ID provided by iTunes Connect.

Examples:

"1435592086"


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

def vendor_id
  @vendor_id
end

Class Method Details

.allArray



61
62
63
# File 'lib/spaceship/tunes/application.rb', line 61

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) ⇒ Object

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



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

def create!(name: nil, primary_language: nil, version: nil, sku: nil, bundle_id: nil, bundle_id_suffix: nil, company_name: 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)
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.



56
57
58
# File 'lib/spaceship/tunes/application.rb', line 56

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

.find(identifier) ⇒ Spaceship::Tunes::Application



67
68
69
70
71
# File 'lib/spaceship/tunes/application.rb', line 67

def find(identifier)
  all.find do |app|
    (app.apple_id == identifier.to_s or app.bundle_id == identifier)
  end
end

Instance Method Details

#add_all_testers!Object

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



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

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



300
301
302
303
304
305
306
307
# File 'lib/spaceship/tunes/application.rb', line 300

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_processing_buildsArray



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

def all_processing_builds
  builds = self.pre_processing_builds

  self.build_trains.each do |version_number, train|
    train.processing_builds.each do |build|
      builds << build
    end
  end

  return builds
end

#build_trainsHash

A reference to all the build trains



184
185
186
# File 'lib/spaceship/tunes/application.rb', line 184

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

#buildsObject

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



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

def builds
  all_builds = []
  self.build_trains.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



245
246
247
248
249
250
251
252
253
254
# File 'lib/spaceship/tunes/application.rb', line 245

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



235
236
237
238
239
240
241
242
# File 'lib/spaceship/tunes/application.rb', line 235

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) ⇒ 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



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

def create_version!(version_number)
  if edit_version
    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)

  # Future: implemented -reload method
end

#detailsObject



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

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

#edit_versionSpaceship::AppVersion



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/spaceship/tunes/application.rb', line 114

def edit_version
  if raw_data['versions'].count == 1
    v = raw_data['versions'].last

    # this only applies for the initial version
    unless ['Prepare for Upload', 'Developer Rejected', 'Rejected', 'prepareForUpload'].include?(v['state'])
      return nil # only live version, user should create a new version
    end
  end

  Spaceship::AppVersion.find(self, self.apple_id, false)
end

#external_testersArray



273
274
275
# File 'lib/spaceship/tunes/application.rb', line 273

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

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



285
286
287
# File 'lib/spaceship/tunes/application.rb', line 285

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

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



292
293
294
# File 'lib/spaceship/tunes/application.rb', line 292

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

#internal_testersArray



278
279
280
# File 'lib/spaceship/tunes/application.rb', line 278

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

#latest_versionSpaceship::AppVersion



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

def latest_version
  edit_version || live_version
end

#live_versionSpaceship::AppVersion



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

def live_version
  if raw_data['versions'].count == 1
    v = raw_data['versions'].last
    if ['Prepare for Upload', 'prepareForUpload'].include?(v['state']) # this only applies for the initial version
      return nil
    end
  end

  Spaceship::AppVersion.find(self, self.apple_id, true)
end

#pre_processing_buildsArray



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

def pre_processing_builds
  data = client.build_trains(apple_id, 'internal') # we need to fetch all trains here to get the builds

  builds = data.fetch('processingBuilds', []).collect do |attrs|
    attrs.merge!(build_train: self)
    Tunes::ProcessingBuild.factory(attrs)
  end

  builds.delete_if { |a| a.state == "ITC.apps.betaProcessingStatus.InvalidBinary" }

  builds
end

#price_tierObject

The current price tier



174
175
176
# File 'lib/spaceship/tunes/application.rb', line 174

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


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

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



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

def resolution_center
  client.get_resolution_center(apple_id)
end

#setupObject



259
260
# File 'lib/spaceship/tunes/application.rb', line 259

def setup
end

#update_price_tier!(price_tier) ⇒ Object

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



169
170
171
# File 'lib/spaceship/tunes/application.rb', line 169

def update_price_tier!(price_tier)
  client.update_price_tier!(self.apple_id, price_tier)
end

#urlString



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

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