Class: Spaceship::TestFlight::Group

Inherits:
Base
  • Object
show all
Defined in:
spaceship/lib/spaceship/test_flight/group.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#client, #raw_data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

client, inherited, #to_json

Methods inherited from Base

attr_accessor, attr_mapping, #attributes, attributes, factory, #initialize, #inspect, mapping_module, method_missing, set_client, #setup, #to_s

Constructor Details

This class inherits a constructor from Spaceship::Base

Instance Attribute Details

#app_idObject

Returns the value of attribute app_id


14
15
16
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 14

def app_id
  @app_id
end

#createdObject

Returns the value of attribute created


12
13
14
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 12

def created
  @created
end

#idObject

Returns the value of attribute id


6
7
8
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 6

def id
  @id
end

#is_activeObject

Returns the value of attribute is_active


11
12
13
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 11

def is_active
  @is_active
end

#is_default_external_groupObject

Returns the value of attribute is_default_external_group


8
9
10
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 8

def is_default_external_group
  @is_default_external_group
end

#is_internal_groupObject

Returns the value of attribute is_internal_group


9
10
11
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 9

def is_internal_group
  @is_internal_group
end

#nameObject

Returns the value of attribute name


7
8
9
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 7

def name
  @name
end

#provider_idObject

Returns the value of attribute provider_id


10
11
12
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 10

def provider_id
  @provider_id
end

Class Method Details

.add_tester_to_groups!(tester: nil, app: nil, groups: nil) ⇒ Object


88
89
90
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 88

def self.add_tester_to_groups!(tester: nil, app: nil, groups: nil)
  self.perform_for_groups_in_app(app: app, groups: groups) { |group| group.add_tester!(tester) }
end

.all(app_id: nil) ⇒ Object


39
40
41
42
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 39

def self.all(app_id: nil)
  groups = client.get_groups(app_id: app_id)
  groups.map { |g| self.new(g) }
end

.create!(app_id: nil, group_name: nil) ⇒ Object


27
28
29
30
31
32
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 27

def self.create!(app_id: nil, group_name: nil)
  group = self.find(app_id: app_id, group_name: group_name)
  return group unless group.nil?
  data = client.create_group_for_app(app_id: app_id, group_name: group_name)
  self.new(data)
end

.default_external_group(app_id: nil) ⇒ Object


49
50
51
52
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 49

def self.default_external_group(app_id: nil)
  groups = self.all(app_id: app_id)
  groups.find(&:default_external_group?)
end

.delete!(app_id: nil, group_name: nil) ⇒ Object


34
35
36
37
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 34

def self.delete!(app_id: nil, group_name: nil)
  group = self.find(app_id: app_id, group_name: group_name)
  client.delete_group_for_app(app_id: app_id, group_id: group.id)
end

.filter_groups(app_id: nil, &block) ⇒ Object


54
55
56
57
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 54

def self.filter_groups(app_id: nil, &block)
  groups = self.all(app_id: app_id)
  groups.select(&block)
end

.find(app_id: nil, group_name: nil) ⇒ Object


44
45
46
47
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 44

def self.find(app_id: nil, group_name: nil)
  groups = self.all(app_id: app_id)
  groups.find { |g| g.name == group_name }
end

.internal_group(app_id: nil) ⇒ Object


59
60
61
62
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 59

def self.internal_group(app_id: nil)
  groups = self.all(app_id: app_id)
  groups.find(&:internal_group?)
end

.perform_for_groups_in_app(app: nil, groups: nil, &block) ⇒ Object


113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 113

def self.perform_for_groups_in_app(app: nil, groups: nil, &block)
  if groups.nil?
    default_external_group = app.default_external_group
    if default_external_group.nil?
      raise "The app #{app.name} does not have a default external group. Please make sure to pass group names to the `:groups` option."
    end
    test_flight_groups = [default_external_group]
  else
    test_flight_groups = self.filter_groups(app_id: app.apple_id) do |group|
      groups.include?(group.name)
    end

    raise "There are no groups available matching the names passed to the `:groups` option." if test_flight_groups.empty?
  end

  test_flight_groups.each(&block)
end

.remove_tester_from_groups!(tester: nil, app: nil, groups: nil) ⇒ Object


92
93
94
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 92

def self.remove_tester_from_groups!(tester: nil, app: nil, groups: nil)
  self.perform_for_groups_in_app(app: app, groups: groups) { |group| group.remove_tester!(tester) }
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)

104
105
106
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 104

def active?
  is_active
end

#add_tester!(tester) ⇒ Object

First we need to add the tester to the app It's ok if the tester already exists, we just have to do this… don't ask This will enable testing for the tester for a given app, as just creating the tester on an account-level is not enough to add the tester to a group. If this isn't done the next request would fail. This is a bug we reported to the App Store Connect team, as it also happens on the App Store Connect UI on 18. April 2017


69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 69

def add_tester!(tester)
  # This post request creates an account-level tester and then makes it available to the app, or just makes
  # it available to the app if it already exists
  client.create_app_level_tester(app_id: self.app_id,
                             first_name: tester.first_name,
                              last_name: tester.last_name,
                                  email: tester.email)
  # This put request adds the tester to the group
  client.post_tester_to_group(group_id: self.id,
                                 email: tester.email,
                            first_name: tester.first_name,
                             last_name: tester.last_name,
                                app_id: self.app_id)
end

#buildsObject


108
109
110
111
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 108

def builds
  builds = client.builds_for_group(app_id: self.app_id, group_id: self.id)
  builds.map { |b| Spaceship::TestFlight::Build.new(b) }
end

#default_external_group?Boolean

Returns:

  • (Boolean)

96
97
98
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 96

def default_external_group?
  is_default_external_group
end

#internal_group?Boolean

Returns:

  • (Boolean)

100
101
102
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 100

def internal_group?
  is_internal_group
end

#remove_tester!(tester) ⇒ Object


84
85
86
# File 'spaceship/lib/spaceship/test_flight/group.rb', line 84

def remove_tester!(tester)
  client.delete_tester_from_group(group_id: self.id, tester_id: tester.tester_id, app_id: self.app_id)
end