Class: Spaceship::PortalClient

Inherits:
Client
  • Object
show all
Defined in:
lib/spaceship/portal/portal_client.rb

Constant Summary

Constants inherited from Client

Client::PROTOCOL_VERSION

Instance Attribute Summary

Attributes inherited from Client

#client, #cookie, #logger

Init and Login collapse

Apps collapse

Devices collapse

Certificates collapse

Provisioning Profiles collapse

Methods inherited from Client

#UI, #initialize, login, #login, #page_size, #paging, #session?

Constructor Details

This class inherits a constructor from Spaceship::Client

Class Method Details

.hostnameObject



8
9
10
# File 'lib/spaceship/portal/portal_client.rb', line 8

def self.hostname
  "https://developer.apple.com/services-account/#{PROTOCOL_VERSION}/"
end

Instance Method Details

#api_keyObject

Fetches the latest API Key from the Apple Dev Portal



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/spaceship/portal/portal_client.rb', line 13

def api_key
  cache_path = "/tmp/spaceship_api_key.txt"
  begin
    cached = File.read(cache_path) 
  rescue Errno::ENOENT
  end
  return cached if cached

  landing_url = "https://developer.apple.com/membercenter/index.action"
  logger.info("GET: " + landing_url)
  headers = @client.get(landing_url).headers
  results = headers['location'].match(/.*appIdKey=(\h+)/)
  if results.length > 1
    api_key = results[1]
    File.write(cache_path, api_key)
    return api_key
  else
    raise "Could not find latest API Key from the Dev Portal"
  end
end

#appsObject



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/spaceship/portal/portal_client.rb', line 95

def apps
  paging do |page_number|
    r = request(:post, 'account/ios/identifiers/listAppIds.action', {
      teamId: team_id,
      pageNumber: page_number,
      pageSize: page_size,
      sort: 'name=asc'
    })
    parse_response(r, 'appIds')
  end
end

#certificates(types) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/spaceship/portal/portal_client.rb', line 186

def certificates(types)
  paging do |page_number|
    r = request(:post, 'account/ios/certificate/listCertRequests.action', {
      teamId: team_id,
      types: types.join(','),
      pageNumber: page_number,
      pageSize: page_size,
      sort: 'certRequestStatusCode=asc'
    })
    parse_response(r, 'certRequests')
  end
end

#create_app!(type, name, bundle_id) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/spaceship/portal/portal_client.rb', line 115

def create_app!(type, name, bundle_id)
  ident_params = case type.to_sym
  when :explicit
    {
      type: 'explicit',
      explicitIdentifier: bundle_id,
      appIdentifierString: bundle_id,
      push: 'on',
      inAppPurchase: 'on',
      gameCenter: 'on'
    }
  when :wildcard
    {
      type: 'wildcard',
      wildcardIdentifier: bundle_id,
      appIdentifierString: bundle_id
    }
  end

  params = {
    appIdName: name,
    teamId: team_id
  }

  params.merge!(ident_params)

  r = request(:post, 'account/ios/identifiers/addAppId.action', params)
  parse_response(r, 'appId')
end

#create_certificate!(type, csr, app_id = nil) ⇒ Object



199
200
201
202
203
204
205
206
207
# File 'lib/spaceship/portal/portal_client.rb', line 199

def create_certificate!(type, csr, app_id = nil)
  r = request(:post, 'account/ios/certificate/submitCertificateRequest.action', {
    teamId: team_id,
    type: type,
    csrContent: csr,
    appIdId: app_id  #optional
  })
  parse_response(r, 'certRequest')
end

#create_device!(device_name, device_id) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/spaceship/portal/portal_client.rb', line 169

def create_device!(device_name, device_id)
  r = request(:post) do |r|
    r.url "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/ios/addDevice.action"
    r.params = {
      teamId: team_id,
      deviceNumber: device_id,
      name: device_name
    }
  end

  parse_response(r, 'device')
end

#create_provisioning_profile!(name, distribution_method, app_id, certificate_ids, device_ids) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
# File 'lib/spaceship/portal/portal_client.rb', line 246

def create_provisioning_profile!(name, distribution_method, app_id, certificate_ids, device_ids)
  r = request(:post, 'account/ios/profile/createProvisioningProfile.action', {
    teamId: team_id,
    provisioningProfileName: name,
    appIdId: app_id,
    distributionType: distribution_method,
    certificateIds: certificate_ids,
    deviceIds: device_ids
  })
  parse_response(r, 'provisioningProfile')
end

#delete_app!(app_id) ⇒ Object



145
146
147
148
149
150
151
# File 'lib/spaceship/portal/portal_client.rb', line 145

def delete_app!(app_id)
  r = request(:post, 'account/ios/identifiers/deleteAppId.action', {
    teamId: team_id,
    appIdId: app_id
  })
  parse_response(r)
end

#delete_provisioning_profile!(profile_id) ⇒ Object



266
267
268
269
270
271
272
# File 'lib/spaceship/portal/portal_client.rb', line 266

def delete_provisioning_profile!(profile_id)
  r = request(:post, 'account/ios/profile/deleteProvisioningProfile.action', {
    teamId: team_id,
    provisioningProfileId: profile_id
  })
  parse_response(r)
end

#details_for_app(app) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/spaceship/portal/portal_client.rb', line 107

def details_for_app(app)
  r = request(:post, 'account/ios/identifiers/getAppIdDetail.action', {
    teamId: team_id,
    appIdId: app.app_id
  })
  parse_response(r, 'appId')
end

#devicesObject



157
158
159
160
161
162
163
164
165
166
167
# File 'lib/spaceship/portal/portal_client.rb', line 157

def devices
  paging do |page_number|
    r = request(:post, 'account/ios/device/listDevices.action', {
      teamId: team_id,
      pageNumber: page_number,
      pageSize: page_size,
      sort: 'name=asc'
    })
    parse_response(r, 'devices')
  end
end

#download_certificate(certificate_id, type) ⇒ Object



209
210
211
212
213
214
215
216
217
218
# File 'lib/spaceship/portal/portal_client.rb', line 209

def download_certificate(certificate_id, type)
  {type: type, certificate_id: certificate_id}.each { |k, v| raise "#{k} must not be nil" if v.nil? }

  r = request(:post, 'https://developer.apple.com/account/ios/certificate/certificateContentDownload.action', {
    teamId: team_id,
    displayId: certificate_id,
    type: type
  })
  parse_response(r)
end

#download_provisioning_profile(profile_id) ⇒ Object



258
259
260
261
262
263
264
# File 'lib/spaceship/portal/portal_client.rb', line 258

def download_provisioning_profile(profile_id)
  r = request(:get, 'https://developer.apple.com/account/ios/profile/profileContentDownload.action', {
    teamId: team_id,
    displayId: profile_id
  })
  parse_response(r)
end

#in_house?Boolean

Is the current session from an Enterprise In House account?

Returns:

  • (Boolean)


85
86
87
88
# File 'lib/spaceship/portal/portal_client.rb', line 85

def in_house?
  return @in_house unless @in_house.nil?
  @in_house = (team_information['type'] == 'In-House')
end

#provisioning_profilesObject



233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/spaceship/portal/portal_client.rb', line 233

def provisioning_profiles
  r = request(:post) do |r|
    r.url "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/ios/listProvisioningProfiles.action"
    r.params = {
      teamId: team_id,
      includeInactiveProfiles: true,
      onlyCountLists: true,
    }
  end

  parse_response(r, 'provisioningProfiles')
end

#repair_provisioning_profile!(profile_id, name, distribution_method, app_id, certificate_ids, device_ids) ⇒ Object



274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/spaceship/portal/portal_client.rb', line 274

def repair_provisioning_profile!(profile_id, name, distribution_method, app_id, certificate_ids, device_ids)
  r = request(:post, 'account/ios/profile/regenProvisioningProfile.action', {
    teamId: team_id,
    provisioningProfileId: profile_id,
    provisioningProfileName: name,
    appIdId: app_id,
    distributionType: distribution_method,
    certificateIds: certificate_ids.first, # we are most of the times only allowed to pass one
    deviceIds: device_ids
  })

  parse_response(r, 'provisioningProfile')
end

#revoke_certificate!(certificate_id, type) ⇒ Object



220
221
222
223
224
225
226
227
# File 'lib/spaceship/portal/portal_client.rb', line 220

def revoke_certificate!(certificate_id, type)
  r = request(:post, 'account/ios/certificate/revokeCertificate.action', {
    teamId: team_id,
    certificateId: certificate_id,
    type: type
  })
  parse_response(r, 'certRequests')
end

#select_teamObject

Shows a team selection for the user in the terminal. This should not be called on CI systems



68
69
70
# File 'lib/spaceship/portal/portal_client.rb', line 68

def select_team
  @current_team_id = self.UI.select_team
end

#send_login_request(user, password) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/spaceship/portal/portal_client.rb', line 34

def (user, password)
  response = request(:post, "https://idmsa.apple.com/IDMSWebAuth/authenticate", {
    appleId: user,
    accountPassword: password,
    appIdKey: api_key
  })

  if response['Set-Cookie'] =~ /myacinfo=(\w+);/
    @cookie = "myacinfo=#{$1};"
    return @client
  else
    # User Credentials are wrong
    raise InvalidUserCredentialsError.new(response)
  end
end

#team_idString

Returns The currently selected Team ID.

Returns:

  • (String)

    The currently selected Team ID



57
58
59
60
61
62
63
64
# File 'lib/spaceship/portal/portal_client.rb', line 57

def team_id
  return @current_team_id if @current_team_id

  if teams.count > 1
    puts "The current user is in #{teams.count} teams. Pass a team ID or call `select_team` to choose a team. Using the first one for now."
  end
  @current_team_id ||= teams[0]['teamId']
end

#team_id=(team_id) ⇒ Object

Set a new team ID which will be used from now on



73
74
75
# File 'lib/spaceship/portal/portal_client.rb', line 73

def team_id=(team_id)
  @current_team_id = team_id
end

#team_informationHash

Returns Fetches all information of the currently used team.

Returns:

  • (Hash)

    Fetches all information of the currently used team



78
79
80
81
82
# File 'lib/spaceship/portal/portal_client.rb', line 78

def team_information
  teams.find do |t|
    t['teamId'] == team_id
  end
end

#teamsArray

Returns A list of all available teams.

Returns:

  • (Array)

    A list of all available teams



51
52
53
54
# File 'lib/spaceship/portal/portal_client.rb', line 51

def teams
  r = request(:post, 'account/listTeams.action')
  parse_response(r, 'teams')
end