Class: Spaceship::Tunes::BuildTrain

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

Overview

Represents a build train of builds from iTunes Connect A build train is all builds for a given version number with different build numbers

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

#applicationSpaceship::Tunes::Application

Returns A reference to the application this train is for.

Returns:



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

def application
  @application
end

#buildsArray (readonly)

Returns An array of all builds that are inside this train (Spaceship::Tunes::Build).

Returns:

  • (Array)

    An array of all builds that are inside this train (Spaceship::Tunes::Build)



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

def builds
  @builds
end

#external_testing_enabledBool (readonly)

Returns Is external beta testing enabled for this train? Only one train can have enabled testing.

Returns:

  • (Bool)

    Is external beta testing enabled for this train? Only one train can have enabled testing.



20
21
22
# File 'lib/spaceship/tunes/build_train.rb', line 20

def external_testing_enabled
  @external_testing_enabled
end

#internal_testing_enabledBool (readonly)

Returns Is internal beta testing enabled for this train? Only one train can have enabled testing.

Returns:

  • (Bool)

    Is internal beta testing enabled for this train? Only one train can have enabled testing.



23
24
25
# File 'lib/spaceship/tunes/build_train.rb', line 23

def internal_testing_enabled
  @internal_testing_enabled
end

#platformString (readonly)

Returns Platform (e.g. “ios”).

Returns:

  • (String)

    Platform (e.g. “ios”)



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

def platform
  @platform
end

#processing_buildsArray (readonly)

Returns An array of all builds that are inside this train (Spaceship::Tunes::Build) I never got this to work to properly try and debug this.

Returns:

  • (Array)

    An array of all builds that are inside this train (Spaceship::Tunes::Build) I never got this to work to properly try and debug this



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

def processing_builds
  @processing_builds
end

#version_stringString (readonly)

Returns The version number of this train.

Returns:

  • (String)

    The version number of this train



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

def version_string
  @version_string
end

Class Method Details

.all(application, app_id) ⇒ Object

Parameters:



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/spaceship/tunes/build_train.rb', line 45

def all(application, app_id)
  trains = []
  trains += client.build_trains(app_id, 'internal')['trains']
  trains += client.build_trains(app_id, 'external')['trains']

  result = {}
  trains.each do |attrs|
    attrs.merge!(application: application)
    current = self.factory(attrs)
    result[current.version_string] = current
  end
  result
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.



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

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

Instance Method Details

#latest_buildSpaceship::Tunes::Build

Returns The latest build for this train, sorted by upload time.

Returns:



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

def latest_build
  @builds.max_by(&:upload_date)
end

#setupObject

Setup all the builds and processing builds



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/spaceship/tunes/build_train.rb', line 61

def setup
  super

  @builds = (self.raw_data['builds'] || []).collect do |attrs|
    attrs.merge!(build_train: self)
    Tunes::Build.factory(attrs)
  end

  @processing_builds = (self.raw_data['buildsInProcessing'] || []).collect do |attrs|
    attrs.merge!(build_train: self)
    Tunes::Build.factory(attrs)
  end
end

#update_testing_status!(new_value, testing_type, build = nil) ⇒ Object

Parameters:

  • internal (testing_type)

    or external



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/spaceship/tunes/build_train.rb', line 81

def update_testing_status!(new_value, testing_type, build = nil)
  data = client.build_trains(self.application.apple_id, testing_type)

  build ||= latest_build if testing_type == 'external'

  data['trains'].each do |train|
    train["#{testing_type}Testing"]['value'] = false
    train["#{testing_type}Testing"]['value'] = new_value if train['versionString'] == version_string

    # also update the builds
    train['builds'].each do |b|
      next if b["#{testing_type}Testing"].nil?
      next if build.nil?
      next if b["buildVersion"] != build.build_version
      b["#{testing_type}Testing"]['value'] = false
      b["#{testing_type}Testing"]['value'] = new_value if b['trainVersion'] == version_string
    end
  end

  result = client.update_build_trains!(application.apple_id, testing_type, data)
  self.internal_testing_enabled = new_value if testing_type == 'internal'
  self.external_testing_enabled = new_value if testing_type == 'external'

  result
end