Class: Spaceship::PortalClient

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

Overview

rubocop:disable Metrics/ClassLength

Init and Login collapse

PROTOCOL_VERSION =
Spaceship::Client::PROTOCOL_VERSION

Constants inherited from Client

Client::AppleTimeoutError, Client::BasicPreferredInfoError, Client::InsufficientPermissions, Client::InternalServerError, Client::InvalidUserCredentialsError, Client::NoUserCredentialsError, Client::ProgramLicenseAgreementUpdated, Client::USER_AGENT, Client::UnauthorizedAccessError, Client::UnexpectedResponse

Instance Attribute Summary

Attributes inherited from Client

#available_providers, #client, #csrf_tokens, #logger, #provider, #user, #user_email

Init and Login collapse

Apps collapse

Passbook collapse

Website Push collapse

Merchant collapse

App Groups collapse

Team collapse

Devices collapse

Certificates collapse

Provisioning Profiles collapse

Keys collapse

Methods inherited from Client

#UI, client_with_authorization_from, #cookie, #detect_most_common_errors_and_raise_exceptions, #fastlane_user_dir, #fetch_olympus_session, #handle_two_factor, #handle_two_step, #initialize, #itc_service_key, #load_session_from_env, #load_session_from_file, login, #login, #page_size, #paging, #parse_response, #persistent_cookie_path, #raise_insuffient_permission_error!, #request, #select_device, #send_shared_login_request, spaceship_session_env, #store_cookie, #store_session, #update_request_headers, #user_details_data, #with_retry

Constructor Details

This class inherits a constructor from Spaceship::Client

Class Method Details

.hostnameObject



22
23
24
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 22

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

Instance Method Details

#app_groupsObject



343
344
345
346
347
348
349
350
351
352
353
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 343

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

#apps(mac: false) ⇒ Object



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

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

#associate_groups_with_app(app, groups) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 136

def associate_groups_with_app(app, groups)
  ensure_csrf(Spaceship::Portal::AppGroup)

  request(:post, 'account/ios/identifiers/assignApplicationGroupToAppId.action', {
    teamId: team_id,
    appIdId: app.app_id,
    displayId: app.app_id,
    applicationGroups: groups.map(&:app_group_id)
  })

  details_for_app(app)
end

#associate_merchants_with_app(app, merchants, mac) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 149

def associate_merchants_with_app(app, merchants, mac)
  ensure_csrf(Spaceship::Portal::Merchant)

  request(:post, "account/#{platform_slug(mac)}/identifiers/assignOMCToAppId.action", {
    teamId: team_id,
    appIdId: app.app_id,
    omcIds: merchants.map(&:merchant_id)
  })

  details_for_app(app)
end

#certificates(types, mac: false) ⇒ Object



512
513
514
515
516
517
518
519
520
521
522
523
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 512

def certificates(types, mac: false)
  paging do |page_number|
    r = request(:post, "account/#{platform_slug(mac)}/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, mac: false, enable_services: {}) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 173

def create_app!(type, name, bundle_id, mac: false, enable_services: {})
  # We moved the ensure_csrf to the top of this method
  # as we got some users with issues around creating new apps
  # https://github.com/fastlane/fastlane/issues/5813
  ensure_csrf(Spaceship::Portal::App)

  ident_params = case type.to_sym
                 when :explicit
                   {
                     type: 'explicit',
                     identifier: bundle_id,
                     push: 'on',
                     inAppPurchase: 'on',
                     gameCenter: 'on'
                   }
                 when :wildcard
                   {
                     type: 'wildcard',
                     identifier: bundle_id
                   }
                 end

  params = {
    name: valid_name_for(name),
    teamId: team_id
  }
  params.merge!(ident_params)
  enable_services.each do |k, v|
    params[v.service_id.to_sym] = v.value
  end
  r = request(:post, "account/#{platform_slug(mac)}/identifiers/addAppId.action", params)
  parse_response(r, 'appId')
end

#create_app_group!(name, group_id) ⇒ Object



355
356
357
358
359
360
361
362
363
364
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 355

def create_app_group!(name, group_id)
  ensure_csrf(Spaceship::Portal::AppGroup)

  r = request(:post, 'account/ios/identifiers/addApplicationGroup.action', {
    name: valid_name_for(name),
    identifier: group_id,
    teamId: team_id
  })
  parse_response(r, 'applicationGroup')
end

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



525
526
527
528
529
530
531
532
533
534
535
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 525

def create_certificate!(type, csr, app_id = nil, mac = false)
  ensure_csrf(Spaceship::Portal::Certificate)

  r = request(:post, "account/#{platform_slug(mac)}/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, mac: false) ⇒ Object



478
479
480
481
482
483
484
485
486
487
488
489
490
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 478

def create_device!(device_name, device_id, mac: false)
  ensure_csrf(Spaceship::Portal::Device)

  req = request(:post, "account/#{platform_slug(mac)}/device/addDevices.action", {
    teamId: team_id,
    deviceClasses: mac ? 'mac' : 'iphone',
    deviceNumbers: device_id,
    deviceNames: device_name,
    register: 'single'
  })

  parse_response(req, 'devices').first
end

#create_key!(name: nil, service_configs: nil) ⇒ Object



716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 716

def create_key!(name: nil, service_configs: nil)
  params = {
    name: name,
    serviceConfigurations: service_configs,
    teamId: team_id
  }

  response = request(:post, 'account/auth/key/create') do |req|
    req.headers['Content-Type'] = 'application/json'
    req.body = params.to_json
  end

  # response contains a list of keys with 1 item
  parse_response(response, 'keys').first
end

#create_merchant!(name, bundle_id, mac: false) ⇒ Object



318
319
320
321
322
323
324
325
326
327
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 318

def create_merchant!(name, bundle_id, mac: false)
  ensure_csrf(Spaceship::Portal::Merchant)

  r = request(:post, "account/#{platform_slug(mac)}/identifiers/addOMC.action", {
      name: name,
      identifier: bundle_id,
      teamId: team_id
  })
  parse_response(r, 'omcId')
end

#create_passbook!(name, bundle_id) ⇒ Object



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

def create_passbook!(name, bundle_id)
  ensure_csrf(Spaceship::Portal::Passbook)

  r = request(:post, "account/ios/identifiers/addPassTypeId.action", {
      name: name,
      identifier: bundle_id,
      teamId: team_id
  })
  parse_response(r, 'passTypeId')
end

#create_provisioning_profile!(name, distribution_method, app_id, certificate_ids, device_ids, mac: false, sub_platform: nil, template_name: nil) ⇒ Object



617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 617

def create_provisioning_profile!(name, distribution_method, app_id, certificate_ids, device_ids, mac: false, sub_platform: nil, template_name: nil)
  ensure_csrf(Spaceship::Portal::ProvisioningProfile) do
    fetch_csrf_token_for_provisioning
  end

  params = {
    teamId: team_id,
    provisioningProfileName: name,
    appIdId: app_id,
    distributionType: distribution_method,
    certificateIds: certificate_ids,
    deviceIds: device_ids
  }
  params[:subPlatform] = sub_platform if sub_platform

  # if `template_name` is nil, Default entitlements will be used
  params[:template] = template_name if template_name

  r = request(:post, "account/#{platform_slug(mac)}/profile/createProvisioningProfile.action", params)
  parse_response(r, 'provisioningProfile')
end

#create_website_push!(name, bundle_id, mac: false) ⇒ Object



281
282
283
284
285
286
287
288
289
290
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 281

def create_website_push!(name, bundle_id, mac: false)
  ensure_csrf(Spaceship::Portal::WebsitePush)

  r = request(:post, "account/#{platform_slug(mac)}/identifiers/addWebsitePushId.action", {
      name: name,
      identifier: bundle_id,
      teamId: team_id
  })
  parse_response(r, 'websitePushId')
end

#delete_app!(app_id, mac: false) ⇒ Object



207
208
209
210
211
212
213
214
215
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 207

def delete_app!(app_id, mac: false)
  ensure_csrf(Spaceship::Portal::App)

  r = request(:post, "account/#{platform_slug(mac)}/identifiers/deleteAppId.action", {
    teamId: team_id,
    appIdId: app_id
  })
  parse_response(r)
end

#delete_app_group!(app_group_id) ⇒ Object



366
367
368
369
370
371
372
373
374
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 366

def delete_app_group!(app_group_id)
  ensure_csrf(Spaceship::Portal::AppGroup)

  r = request(:post, 'account/ios/identifiers/deleteApplicationGroup.action', {
    teamId: team_id,
    applicationGroup: app_group_id
  })
  parse_response(r)
end

#delete_merchant!(merchant_id, mac: false) ⇒ Object



329
330
331
332
333
334
335
336
337
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 329

def delete_merchant!(merchant_id, mac: false)
  ensure_csrf(Spaceship::Portal::Merchant)

  r = request(:post, "account/#{platform_slug(mac)}/identifiers/deleteOMC.action", {
      teamId: team_id,
      omcId: merchant_id
  })
  parse_response(r)
end

#delete_passbook!(passbook_id) ⇒ Object



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

def delete_passbook!(passbook_id)
  ensure_csrf(Spaceship::Portal::Passbook)

  r = request(:post, "account/ios/identifiers/deletePassTypeId.action", {
      teamId: team_id,
      passTypeId: passbook_id
  })
  parse_response(r)
end

#delete_provisioning_profile!(profile_id, mac: false) ⇒ Object



656
657
658
659
660
661
662
663
664
665
666
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 656

def delete_provisioning_profile!(profile_id, mac: false)
  ensure_csrf(Spaceship::Portal::ProvisioningProfile) do
    fetch_csrf_token_for_provisioning
  end

  r = request(:post, "account/#{platform_slug(mac)}/profile/deleteProvisioningProfile.action", {
    teamId: team_id,
    provisioningProfileId: profile_id
  })
  parse_response(r)
end

#delete_website_push!(website_id, mac: false) ⇒ Object



292
293
294
295
296
297
298
299
300
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 292

def delete_website_push!(website_id, mac: false)
  ensure_csrf(Spaceship::Portal::WebsitePush)

  r = request(:post, "account/#{platform_slug(mac)}/identifiers/deleteWebsitePushId.action", {
      teamId: team_id,
      websitePushId: website_id
  })
  parse_response(r)
end

#details_for_app(app) ⇒ Object



115
116
117
118
119
120
121
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 115

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

#devices(mac: false, include_disabled: false) ⇒ Object



447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 447

def devices(mac: false, include_disabled: false)
  paging do |page_number|
    r = request(:post, "account/#{platform_slug(mac)}/device/listDevices.action", {
      teamId: team_id,
      pageNumber: page_number,
      pageSize: page_size,
      sort: 'name=asc',
      includeRemovedDevices: include_disabled
    })
    result = parse_response(r, 'devices')

    csrf_cache[Spaceship::Portal::Device] = self.csrf_tokens

    result
  end
end

#devices_by_class(device_class, include_disabled: false) ⇒ Object



464
465
466
467
468
469
470
471
472
473
474
475
476
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 464

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

#disable_device!(device_id, device_udid, mac: false) ⇒ Object



492
493
494
495
496
497
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 492

def disable_device!(device_id, device_udid, mac: false)
  request(:post, "https://developer.apple.com/services-account/#{PROTOCOL_VERSION}/account/#{platform_slug(mac)}/device/deleteDevice.action", {
    teamId: team_id,
    deviceId: device_id
  })
end

#download_certificate(certificate_id, type, mac: false) ⇒ Object



537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 537

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

  r = request(:get, "account/#{platform_slug(mac)}/certificate/downloadCertificateContent.action", {
    teamId: team_id,
    certificateId: certificate_id,
    type: type
  })
  a = parse_response(r)
  if r.success? && a.include?("Apple Inc")
    return a
  else
    raise UnexpectedResponse.new, "Couldn't download certificate, got this instead: #{a}"
  end
end

#download_key(id: nil) ⇒ Object



711
712
713
714
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 711

def download_key(id: nil)
  response = request(:get, 'account/auth/key/download', { teamId: team_id, keyId: id })
  parse_response(response)
end

#download_provisioning_profile(profile_id, mac: false) ⇒ Object



639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 639

def download_provisioning_profile(profile_id, mac: false)
  ensure_csrf(Spaceship::Portal::ProvisioningProfile) do
    fetch_csrf_token_for_provisioning
  end

  r = request(:get, "account/#{platform_slug(mac)}/profile/downloadProfileContent", {
    teamId: team_id,
    provisioningProfileId: profile_id
  })
  a = parse_response(r)
  if r.success? && a.include?("DOCTYPE plist PUBLIC")
    return a
  else
    raise UnexpectedResponse.new, "Couldn't download provisioning profile, got this instead: #{a}"
  end
end

#enable_device!(device_id, device_udid, mac: false) ⇒ Object



499
500
501
502
503
504
505
506
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 499

def enable_device!(device_id, device_udid, mac: false)
  req = request(:post, "https://developer.apple.com/services-account/#{PROTOCOL_VERSION}/account/#{platform_slug(mac)}/device/enableDevice.action", {
      teamId: team_id,
      displayId: device_id,
      deviceNumber: device_udid
  })
  parse_response(req, 'device')
end

#get_key(id: nil) ⇒ Object



705
706
707
708
709
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 705

def get_key(id: nil)
  response = request(:post, 'account/auth/key/get', { teamId: team_id, keyId: id })
  # response contains a list of keys with 1 item
  parse_response(response, 'keys').first
end

#in_house?Boolean

Is the current session from an Enterprise In House account?

Returns:

  • (Boolean)


85
86
87
88
# File 'spaceship/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

#list_keysObject



693
694
695
696
697
698
699
700
701
702
703
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 693

def list_keys
  paging do |page_number|
    response = request(:post, 'account/auth/key/list', {
      teamId: team_id,
      pageNumber: page_number,
      pageSize: page_size,
      sort: 'name=asc'
    })
    parse_response(response, 'keys')
  end
end

#merchants(mac: false) ⇒ Object



306
307
308
309
310
311
312
313
314
315
316
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 306

def merchants(mac: false)
  paging do |page_number|
    r = request(:post, "account/#{platform_slug(mac)}/identifiers/listOMCs.action", {
        teamId: team_id,
        pageNumber: page_number,
        pageSize: page_size,
        sort: 'name=asc'
    })
    parse_response(r, 'identifierList')
  end
end

#passbooksObject



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

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

#provisioning_profile_details(provisioning_profile_id: nil, mac: false) ⇒ Object



609
610
611
612
613
614
615
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 609

def provisioning_profile_details(provisioning_profile_id: nil, mac: false)
  r = request(:post, "account/#{platform_slug(mac)}/profile/getProvisioningProfile.action", {
    teamId: team_id,
    provisioningProfileId: provisioning_profile_id
  })
  parse_response(r, 'provisioningProfile')
end

#provisioning_profiles(mac: false) ⇒ Object



568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 568

def provisioning_profiles(mac: false)
  paging do |page_number|
    req = request(:post, "account/#{platform_slug(mac)}/profile/listProvisioningProfiles.action", {
      teamId: team_id,
      pageNumber: page_number,
      pageSize: page_size,
      sort: 'name=asc',
      includeInactiveProfiles: true,
      onlyCountLists: true
    })

    result = parse_response(req, 'provisioningProfiles')

    csrf_cache[Spaceship::Portal::ProvisioningProfile] = self.csrf_tokens

    result
  end
end

#provisioning_profiles_via_xcode_api(mac: false) ⇒ Object

this endpoint is used by Xcode to fetch provisioning profiles. The response is an xml plist but has the added benefit of containing the appId of each provisioning profile.

Use this method over ‘provisioning_profiles` if possible because no secondary API calls are necessary to populate the ProvisioningProfile data model.



592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 592

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

  result = parse_response(req, 'provisioningProfiles')

  csrf_cache[Spaceship::Portal::ProvisioningProfile] = self.csrf_tokens

  result
end

#repair_provisioning_profile!(profile_id, name, distribution_method, app_id, certificate_ids, device_ids, mac: false, sub_platform: nil, template_name: nil) ⇒ Object



668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 668

def repair_provisioning_profile!(profile_id, name, distribution_method, app_id, certificate_ids, device_ids, mac: false, sub_platform: nil, template_name: nil)
  fetch_csrf_token_for_provisioning

  params = {
      teamId: team_id,
      provisioningProfileId: profile_id,
      provisioningProfileName: name,
      appIdId: app_id,
      distributionType: distribution_method,
      certificateIds: certificate_ids.join(','),
      deviceIds: device_ids
  }
  params[:subPlatform] = sub_platform if sub_platform
  # if `template_name` is nil, Default entitlements will be used
  params[:template] = template_name if template_name

  r = request(:post, "account/#{platform_slug(mac)}/profile/regenProvisioningProfile.action", params)

  parse_response(r, 'provisioningProfile')
end

#revoke_certificate!(certificate_id, type, mac: false) ⇒ Object



553
554
555
556
557
558
559
560
561
562
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 553

def revoke_certificate!(certificate_id, type, mac: false)
  ensure_csrf(Spaceship::Portal::Certificate)

  r = request(:post, "account/#{platform_slug(mac)}/certificate/revokeCertificate.action", {
    teamId: team_id,
    certificateId: certificate_id,
    type: type
  })
  parse_response(r, 'certRequests')
end

#revoke_key!(id: nil) ⇒ Object



732
733
734
735
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 732

def revoke_key!(id: nil)
  response = request(:post, 'account/auth/key/revoke', { teamId: team_id, keyId: id })
  parse_response(response)
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 'spaceship/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



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 26

def (user, password)
  response = (user, password)
  return response if self.cookie.include?("myacinfo")

  # When the user has 2 step enabled, we might have to call this method again
  # This only occurs when the user doesn't have a team on iTunes Connect
  # For 2 step verification we use the iTunes Connect back-end
  # which is enough to get the DES... cookie, however we don't get a valid
  # myacinfo cookie at that point. That means, after getting the DES... cookie
  # we have to send the login request again. This will then get us a valid myacinfo
  # cookie, additionally to the DES... cookie
  return (user, password)
end

#team_idString

Returns The currently selected Team ID.

Returns:

  • (String)

    The currently selected Team ID



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

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

  if teams.count == 0
    raise "User '#{user}' does not have access to any teams with an active membership"
  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 'spaceship/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 'spaceship/lib/spaceship/portal/portal_client.rb', line 78

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

#team_invite(email, role) ⇒ Object



428
429
430
431
432
433
434
435
436
437
438
439
440
441
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 428

def team_invite(email, role)
  ensure_csrf(Spaceship::Portal::Persons)
  response = request(:post) do |req|
    req.url("/services-account/#{PROTOCOL_VERSION}/account/sendInvites")
    req.body = {
      invites: [
        { recipientEmail: email, recipientRole: role }
      ],
      teamId: team_id
    }.to_json
    req.headers['Content-Type'] = 'application/json'
  end
  parse_response(response)
end

#team_invitedObject



390
391
392
393
394
395
396
397
398
399
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 390

def team_invited
  response = request(:post) do |req|
    req.url("/services-account/#{PROTOCOL_VERSION}/account/getInvites")
    req.body = {
      teamId: team_id
    }.to_json
    req.headers['Content-Type'] = 'application/json'
  end
  parse_response(response)
end

#team_membersObject



379
380
381
382
383
384
385
386
387
388
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 379

def team_members
  response = request(:post) do |req|
    req.url("/services-account/#{PROTOCOL_VERSION}/account/getTeamMembers")
    req.body = {
      teamId: team_id
    }.to_json
    req.headers['Content-Type'] = 'application/json'
  end
  parse_response(response)
end

#team_remove_member!(team_member_id) ⇒ Object



415
416
417
418
419
420
421
422
423
424
425
426
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 415

def team_remove_member!(team_member_id)
  ensure_csrf(Spaceship::Portal::Persons)
  response = request(:post) do |req|
    req.url("/services-account/#{PROTOCOL_VERSION}/account/removeTeamMembers")
    req.body = {
      teamId: team_id,
      teamMemberIds: [team_member_id]
    }.to_json
    req.headers['Content-Type'] = 'application/json'
  end
  parse_response(response)
end

#team_set_role(team_member_id, role) ⇒ Object



401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 401

def team_set_role(team_member_id, role)
  ensure_csrf(Spaceship::Portal::Persons)
  response = request(:post) do |req|
    req.url("/services-account/#{PROTOCOL_VERSION}/account/setTeamMemberRoles")
    req.body = {
      teamId: team_id,
      role: role,
      teamMemberIds: [team_member_id]
    }.to_json
    req.headers['Content-Type'] = 'application/json'
  end
  parse_response(response)
end

#teamsArray

Returns A list of all available teams.

Returns:

  • (Array)

    A list of all available teams



41
42
43
44
45
46
47
48
49
50
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 41

def teams
  return @teams if @teams
  req = request(:post, "account/listTeams.action")
  @teams = parse_response(req, 'teams').sort_by do |team|
    [
      team['name'],
      team['teamId']
    ]
  end
end

#update_app_name!(app_id, name, mac: false) ⇒ Object



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

def update_app_name!(app_id, name, mac: false)
  ensure_csrf(Spaceship::Portal::App)

  r = request(:post, "account/#{platform_slug(mac)}/identifiers/updateAppIdName.action", {
    teamId: team_id,
    appIdId: app_id,
    name: valid_name_for(name)
  })
  parse_response(r, 'appId')
end

#update_service_for_app(app, service) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 123

def update_service_for_app(app, service)
  ensure_csrf(Spaceship::Portal::App)

  request(:post, service.service_uri, {
    teamId: team_id,
    displayId: app.app_id,
    featureType: service.service_id,
    featureValue: service.value
  })

  details_for_app(app)
end

#valid_name_for(input) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 161

def valid_name_for(input)
  latinized = input.to_slug.transliterate
  latinized = latinized.gsub(/[^0-9A-Za-z\d\s]/, '') # remove non-valid characters
  # Check if the input string was modified, since it might be empty now
  # (if it only contained non-latin symbols) or the duplicate of another app
  if latinized != input
    latinized << " "
    latinized << Digest::MD5.hexdigest(input)
  end
  latinized
end

#website_push(mac: false) ⇒ Object



269
270
271
272
273
274
275
276
277
278
279
# File 'spaceship/lib/spaceship/portal/portal_client.rb', line 269

def website_push(mac: false)
  paging do |page_number|
    r = request(:post, "account/#{platform_slug(mac)}/identifiers/listWebsitePushIds.action", {
        teamId: team_id,
        pageNumber: page_number,
        pageSize: page_size,
        sort: 'name=asc'
    })
    parse_response(r, 'websitePushIdList')
  end
end