Class: Spaceship::FreePortalClient

Inherits:
PortalClient show all
Defined in:
lib/motion-provisioning/spaceship/free_portal_client.rb

Constant Summary collapse

XCODE_VERSION =
'9.2 (9C40b)'

Instance Method Summary collapse

Methods inherited from PortalClient

#distribution_certificates

Instance Method Details

#apps(mac: false) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/motion-provisioning/spaceship/free_portal_client.rb', line 91

def apps(mac: false)
  paging do |page_number|
    r = request_plist(:post, "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/#{platform_slug(mac)}/listAppIds.action?clientId=XABBG36SBA", {
      teamId: team_id,
      pageNumber: page_number,
      pageSize: page_size,
      sort: 'name=asc'
    })
    parse_response(r, 'appIds')
  end
end

#create_app!(type, name, bundle_id, mac: false, enable_services: {}) ⇒ Object



111
112
113
114
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
144
145
146
# File 'lib/motion-provisioning/spaceship/free_portal_client.rb', line 111

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',
                     # push: 'on',          # Not available to free teams
                     # inAppPurchase: 'on', # Not available to free teams
                     gameCenter: 'on'
                   }
                 when :wildcard
                   {
                     type: 'wildcard',
                   }
                 end

  params = {
    identifier: bundle_id,
    name: name,
    teamId: team_id
  }
  params.merge!(ident_params)

  enable_services.each do |k, v|
    params[v.service_id.to_sym] = v.value
  end

  ensure_csrf(Spaceship::App)

  r = request_plist(:post, "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/#{platform_slug(mac)}/addAppId.action?clientId=XABBG36SBA", params)
  parse_response(r, 'appId')
end

#create_development_certificate(csr, mac: false) ⇒ Object



156
157
158
159
160
161
162
163
164
165
# File 'lib/motion-provisioning/spaceship/free_portal_client.rb', line 156

def create_development_certificate(csr, mac: false)
  ensure_csrf(Spaceship::Certificate)

  r = request_plist(:post, "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/#{platform_slug(mac)}/submitDevelopmentCSR.action?clientId=XABBG36SBA&teamId=#{team_id}", {
    teamId: team_id,
    csrContent: csr
  })

  parse_response(r, 'certRequest')
end

#create_device!(device_name, device_id, mac: false) ⇒ Object



81
82
83
84
85
86
87
88
89
# File 'lib/motion-provisioning/spaceship/free_portal_client.rb', line 81

def create_device!(device_name, device_id, mac: false)
  r = request_plist(:post, "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/#{platform_slug(mac)}/addDevice.action", {
    teamId: team_id,
    deviceNumber: device_id,
    name: device_name
  })

  parse_response(r, 'device')
end

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



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/motion-provisioning/spaceship/free_portal_client.rb', line 45

def create_provisioning_profile!(name, distribution_method, app_id, certificate_ids, device_ids, mac: false, sub_platform: nil, template_name: nil)
  ensure_csrf(Spaceship::App)

  params = {
    teamId: team_id,
    appIdId: app_id,
  }

  r = request_plist(:post, "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/#{platform_slug(mac)}/downloadTeamProvisioningProfile.action", params)
  parse_response(r, 'provisioningProfile')
end

#details_for_app(app) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/motion-provisioning/spaceship/free_portal_client.rb', line 103

def details_for_app(app)
  r = request_plist(:post, "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/#{platform_slug(app.mac?)}/getAppIdDetail.action", {
    teamId: team_id,
    identifier: app.app_id
  })
  parse_response(r, 'appId')
end

#development_certificates(mac: false) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/motion-provisioning/spaceship/free_portal_client.rb', line 18

def development_certificates(mac: false)
  paging do |page_number|
    r = request(:post, "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/#{platform_slug(mac)}/listAllDevelopmentCerts.action?clientId=XABBG36SBA&teamId=#{team_id}", nil, {
      'X-Xcode-Version' => XCODE_VERSION # necessary in order to work with Xcode free team
    })
    parse_response(r, 'certificates')
  end
end

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



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/motion-provisioning/spaceship/free_portal_client.rb', line 68

def devices(mac: false, include_disabled: false)
  paging do |page_number|
    r = request_plist(:post, "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/#{platform_slug(mac)}/listDevices.action", {
      teamId: team_id,
      pageNumber: page_number,
      pageSize: page_size,
      sort: 'name=asc',
      includeRemovedDevices: include_disabled
    })
    parse_response(r, 'devices')
  end
end

#download_provisioning_profile(profile_id, mac: false) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/motion-provisioning/spaceship/free_portal_client.rb', line 57

def download_provisioning_profile(profile_id, mac: false)
  r = request_plist(:post, "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/#{platform_slug(mac)}/downloadProvisioningProfile.action", {
    teamId: team_id,
    provisioningProfileId: profile_id
  })
  a = parse_response(r, 'provisioningProfile')
  if a['encodedProfile']
    a['encodedProfile'].read
  end
end

#provisioning_profiles_via_xcode_api(mac: false) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/motion-provisioning/spaceship/free_portal_client.rb', line 27

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
    }
    r.headers['X-Xcode-Version'] = XCODE_VERSION # necessary in order to work with Xcode free team
  end

  result = parse_response(req, 'provisioningProfiles')

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

  result
end

#revoke_development_certificate(serial_number, mac: false) ⇒ Object



148
149
150
151
152
153
154
# File 'lib/motion-provisioning/spaceship/free_portal_client.rb', line 148

def revoke_development_certificate(serial_number, mac: false)
  r = request_plist(:post, "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/#{platform_slug(mac)}/revokeDevelopmentCert.action?clientId=XABBG36SBA", {
    teamId: team_id,
    serialNumber: serial_number,
  })
  parse_response(r, 'certRequests')
end

#teamsObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/motion-provisioning/spaceship/free_portal_client.rb', line 5

def teams
  return @teams if @teams
  req = request(:post, "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/listTeams.action", nil, {
    'X-Xcode-Version' => XCODE_VERSION # necessary in order to list Xcode free team
  })
  @teams = parse_response(req, 'teams').sort_by do |team|
    [
      team['name'],
      team['teamId']
    ]
  end
end