Class: Spaceship::TunesClient
- Inherits:
-
Client
- Object
- Client
- Spaceship::TunesClient
show all
- Defined in:
- lib/spaceship/tunes/tunes_client.rb
Defined Under Namespace
Classes: ITunesConnectError
Constant Summary
Constants inherited
from Client
Client::PROTOCOL_VERSION
Instance Attribute Summary
Attributes inherited from Client
#client, #cookie, #logger
-
#build_trains(app_id) ⇒ Object
-
#remove_testflight_build_from_review!(app_id: nil, train: nil, build_number: nil) ⇒ Object
-
#submit_testflight_build_for_review!(app_id: nil, train: nil, build_number: nil, changelog: nil, description: nil, feedback_email: nil, marketing_url: nil, first_name: nil, last_name: nil, review_email: nil, phone_number: nil, privacy_policy_url: nil, review_user_name: nil, review_password: nil, encryption: false) ⇒ Object
-
#update_build_trains!(app_id, data) ⇒ Object
Submit for Review
collapse
Methods inherited from Client
#UI, #initialize, login, #login, #page_size, #paging, #session?, #with_retry
Class Method Details
.hostname ⇒ Object
13
14
15
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 13
def self.hostname
"https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/"
end
|
Instance Method Details
#add_tester_to_app!(tester, app_id) ⇒ Object
412
413
414
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 412
def add_tester_to_app!(tester, app_id)
update_tester_from_app!(tester, app_id, true)
end
|
#app_version(app_id, is_live) ⇒ Object
191
192
193
194
195
196
197
198
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 191
def app_version(app_id, is_live)
raise "app_id is required" unless app_id
v_text = (is_live ? 'live' : nil)
r = request(:get, "ra/apps/version/#{app_id}", {v: v_text})
parse_response(r, 'data')
end
|
#applications ⇒ Object
132
133
134
135
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 132
def applications
r = request(:get, 'ra/apps/manageyourapps/summary')
parse_response(r, 'data')['summaries']
end
|
#build_trains(app_id) ⇒ Object
218
219
220
221
222
223
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 218
def build_trains(app_id)
raise "app_id is required" unless app_id
r = request(:get, "ra/apps/#{app_id}/trains/")
parse_response(r, 'data')
end
|
#create_application!(name: nil, primary_language: nil, version: nil, sku: nil, bundle_id: nil, bundle_id_suffix: nil, company_name: nil) ⇒ Object
Creates a new application on iTunes Connect
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 147
def create_application!(name: nil, primary_language: nil, version: nil, sku: nil, bundle_id: nil, bundle_id_suffix: nil, company_name: nil)
r = request(:get, 'ra/apps/create/?appType=ios')
data = parse_response(r, 'data')
data['versionString']['value'] = version
data['newApp']['name']['value'] = name
data['newApp']['bundleId']['value'] = bundle_id
data['newApp']['primaryLanguage']['value'] = primary_language || 'English'
data['newApp']['vendorId']['value'] = sku
data['newApp']['bundleIdSuffix']['value'] = bundle_id_suffix
data['companyName']['value'] = company_name if company_name
r = request(:post) do |req|
req.url 'ra/apps/create/?appType=ios'
req.body = data.to_json
req.['Content-Type'] = 'application/json'
end
data = parse_response(r, 'data')
handle_itc_response(data)
end
|
#create_tester!(tester: nil, email: nil, first_name: nil, last_name: nil) ⇒ Object
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 348
def create_tester!(tester: nil, email: nil, first_name: nil, last_name: nil)
url = tester.url[:create]
raise "Action not provided for this tester type." unless url
tester_data = {
emailAddress: {
value: email
},
firstName: {
value: first_name
},
lastName: {
value: last_name
},
testing: {
value: true
}
}
data = { testers: [tester_data] }
r = request(:post) do |req|
req.url url
req.body = data.to_json
req.['Content-Type'] = 'application/json'
end
data = parse_response(r, 'data')['testers']
handle_itc_response(data) || data[0]
end
|
#create_version!(app_id, version_number) ⇒ Object
172
173
174
175
176
177
178
179
180
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 172
def create_version!(app_id, version_number)
r = request(:post) do |req|
req.url "ra/apps/version/create/#{app_id}"
req.body = { version: version_number.to_s }.to_json
req.['Content-Type'] = 'application/json'
end
parse_response(r, 'data')
end
|
#delete_tester!(tester) ⇒ Object
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 379
def delete_tester!(tester)
url = tester.class.url[:delete]
raise "Action not provided for this tester type." unless url
data = [
{
emailAddress: {
value: tester.email
},
firstName: {
value: tester.first_name
},
lastName: {
value: tester.last_name
},
testing: {
value: false
},
userName: tester.email,
testerId: tester.tester_id
}
]
r = request(:post) do |req|
req.url url
req.body = data.to_json
req.['Content-Type'] = 'application/json'
end
data = parse_response(r, 'data')['testers']
handle_itc_response(data) || data[0]
end
|
#get_resolution_center(app_id) ⇒ Object
182
183
184
185
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 182
def get_resolution_center(app_id)
r = request(:get, "ra/apps/#{app_id}/resolutionCenter?v=latest")
parse_response(r, 'data')
end
|
#handle_itc_response(raw) ⇒ Object
78
79
80
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 78
def handle_itc_response(raw)
return unless raw
return unless raw.kind_of? Hash
data = raw['data'] || raw
if data.fetch('sectionErrorKeys', []).count == 0 and
data.fetch('sectionInfoKeys', []).count == 0 and
data.fetch('sectionWarningKeys', []).count == 0
logger.debug("Request was successful")
end
handle_response_hash = lambda do |hash|
errors = []
if hash.kind_of? Hash
hash.each do |key, value|
errors += handle_response_hash.call(value)
if key == 'errorKeys' and value.kind_of? Array and value.count > 0
errors += value
end
end
elsif hash.kind_of? Array
hash.each do |value|
errors += handle_response_hash.call(value)
end
end
return errors
end
errors = handle_response_hash.call(data)
errors += data.fetch('sectionErrorKeys') if data['sectionErrorKeys']
different_error = raw.fetch('messages', {}).fetch('error', nil)
errors << different_error if different_error
if errors.count > 0 raise ITunesConnectError.new, errors.join(' ')
end
puts data['sectionInfoKeys'] if data['sectionInfoKeys']
puts data['sectionWarningKeys'] if data['sectionWarningKeys']
return data
end
|
#login_url ⇒ Object
Fetches the latest login URL from iTunes Connect
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 18
def login_url
cache_path = "/tmp/spaceship_itc_login_url.txt"
begin
cached = File.read(cache_path)
rescue Errno::ENOENT
end
return cached if cached
host = "https://itunesconnect.apple.com"
begin
url = host + request(:get, self.class.hostname).body.match(%r{action="(/WebObjects/iTunesConnect.woa/wo/.*)"})[1]
raise "" unless url.length > 0
File.write(cache_path, url)
return url
rescue => ex
puts ex
raise "Could not fetch the login URL from iTunes Connect, the server might be down"
end
end
|
#remove_tester_from_app!(tester, app_id) ⇒ Object
416
417
418
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 416
def remove_tester_from_app!(tester, app_id)
update_tester_from_app!(tester, app_id, false)
end
|
#remove_testflight_build_from_review!(app_id: nil, train: nil, build_number: nil) ⇒ Object
237
238
239
240
241
242
243
244
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 237
def remove_testflight_build_from_review!(app_id: nil, train: nil, build_number: nil)
r = request(:post) do |req|
req.url "ra/apps/#{app_id}/trains/#{train}/builds/#{build_number}/reject"
req.body = {}.to_json
req.['Content-Type'] = 'application/json'
end
handle_itc_response(r.body)
end
|
#send_app_submission(app_id, data, stage) ⇒ Object
320
321
322
323
324
325
326
327
328
329
330
331
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 320
def send_app_submission(app_id, data, stage)
raise "app_id is required" unless app_id
r = request(:post) do |req|
req.url "ra/apps/#{app_id}/version/submit/#{stage}"
req.body = data.to_json
req.['Content-Type'] = 'application/json'
end
handle_itc_response(r.body)
parse_response(r, 'data')
end
|
#send_login_request(user, password) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 39
def send_login_request(user, password)
response = request(:post, login_url, {
theAccountName: user,
theAccountPW: password
})
if response['Set-Cookie'] =~ /myacinfo=(\w+);/
begin
re = response['Set-Cookie']
to_use = [
"myacinfo=" + re.match(/myacinfo=([^;]*)/)[1],
"woinst=" + re.match(/woinst=([^;]*)/)[1],
"itctx=" + re.match(/itctx=([^;]*)/)[1],
"wosid=" + re.match(/wosid=([^;]*)/)[1]
]
@cookie = to_use.join(';')
rescue
raise ITunesConnectError.new, [response.body, response['Set-Cookie']].join("\n")
end
return @client
else
if (response.body || "").include?("You have successfully signed out")
raise InvalidUserCredentialsError.new, "Invalid username and password combination. Used '#{user}' as the username."
else
info = [response.body, response['Set-Cookie']]
raise ITunesConnectError.new, info.join("\n")
end
end
end
|
#submit_testflight_build_for_review!(app_id: nil, train: nil, build_number: nil, changelog: nil, description: nil, feedback_email: nil, marketing_url: nil, first_name: nil, last_name: nil, review_email: nil, phone_number: nil, privacy_policy_url: nil, review_user_name: nil, review_password: nil, encryption: false) ⇒ Object
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 246
def submit_testflight_build_for_review!( app_id: nil,
train: nil,
build_number: nil,
changelog: nil,
description: nil,
feedback_email: nil,
marketing_url: nil,
first_name: nil,
last_name: nil,
review_email: nil,
phone_number: nil,
privacy_policy_url: nil,
review_user_name: nil,
review_password: nil,
encryption: false)
start_url = "ra/apps/#{app_id}/trains/#{train}/builds/#{build_number}/submit/start"
r = request(:get) do |req|
req.url start_url
req.['Content-Type'] = 'application/json'
end
handle_itc_response(r.body)
build_info = r.body['data']
build_info['testInfo']['details'].each do |current|
current['whatsNew']['value'] = changelog
current['description']['value'] = description
current['feedbackEmail']['value'] = feedback_email
current['marketingUrl']['value'] = marketing_url
current['privacyPolicyUrl']['value'] = privacy_policy_url
current['pageLanguageValue'] = current['language'] end
build_info['testInfo']['reviewFirstName']['value'] = first_name
build_info['testInfo']['reviewLastName']['value'] = last_name
build_info['testInfo']['reviewPhone']['value'] = phone_number
build_info['testInfo']['reviewEmail']['value'] = review_email
build_info['testInfo']['reviewUserName']['value'] = review_user_name
build_info['testInfo']['reviewPassword']['value'] = review_password
r = request(:post) do |req| req.url start_url
req.body = build_info.to_json
req.['Content-Type'] = 'application/json'
end
handle_itc_response(r.body)
encryption_info = r.body['data']
if encryption_info['exportComplianceRequired']
encryption_info['usesEncryption']['value'] = encryption
r = request(:post) do |req|
req.url "ra/apps/#{app_id}/trains/#{train}/builds/#{build_number}/submit/complete"
req.body = encryption_info.to_json
req.['Content-Type'] = 'application/json'
end
handle_itc_response(r.body)
end
end
|
#testers(tester) ⇒ Object
336
337
338
339
340
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 336
def testers(tester)
url = tester.url[:index]
r = request(:get, url)
parse_response(r, 'data')['testers']
end
|
#testers_by_app(tester, app_id) ⇒ Object
342
343
344
345
346
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 342
def testers_by_app(tester, app_id)
url = tester.url(app_id)[:index_by_app]
r = request(:get, url)
parse_response(r, 'data')['users']
end
|
#update_app_version!(app_id, is_live, data) ⇒ Object
200
201
202
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 200
def update_app_version!(app_id, is_live, data)
raise "app_id is required" unless app_id
v_text = (is_live ? 'live' : nil)
r = request(:post) do |req|
req.url "ra/apps/version/save/#{app_id}?v=#{v_text}"
req.body = data.to_json
req.['Content-Type'] = 'application/json'
end
handle_itc_response(r.body)
end
|
#update_build_trains!(app_id, data) ⇒ Object
225
226
227
228
229
230
231
232
233
234
235
|
# File 'lib/spaceship/tunes/tunes_client.rb', line 225
def update_build_trains!(app_id, data)
raise "app_id is required" unless app_id
r = request(:post) do |req|
req.url "ra/apps/#{app_id}/trains/"
req.body = data.to_json
req.['Content-Type'] = 'application/json'
end
handle_itc_response(r.body)
end
|