Class: Spaceship::TestFlight::Client
- Inherits:
-
Client
- Object
- Client
- Spaceship::TestFlight::Client
show all
- Defined in:
- spaceship/lib/spaceship/test_flight/client.rb
Constant Summary
Constants inherited
from Client
Client::AppleTimeoutError, Client::BasicPreferredInfoError, Client::InsufficientPermissions, Client::InternalServerError, Client::InvalidUserCredentialsError, Client::NoUserCredentialsError, Client::PROTOCOL_VERSION, 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
Build trains API
collapse
-
#create_app_level_tester(app_id: nil, first_name: nil, last_name: nil, email: nil) ⇒ Object
-
#delete_tester_from_app(app_id: nil, tester_id: nil) ⇒ Object
-
#delete_tester_from_group(group_id: nil, tester_id: nil, app_id: nil) ⇒ Object
-
#post_tester_to_group(app_id: nil, email: nil, first_name: nil, last_name: nil, group_id: nil) ⇒ Object
-
#resend_invite_to_external_tester(app_id: nil, tester_id: nil) ⇒ Object
-
#search_for_tester_in_app(app_id: nil, text: nil) ⇒ Object
-
#testers_for_app(app_id: nil) ⇒ Object
Class Method Summary
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, #team_id, #team_id=, #team_information, #teams, #update_request_headers, #user_details_data, #with_retry
Class Method Details
.hostname ⇒ Object
Spaceship HTTP client for the testflight API.
This client is solely responsible for the making HTTP requests and parsing their responses. Parameters should be either named parameters, or for large request data bodies, pass in anything that can resond to ‘to_json`.
Each request method should validate the required parameters. A required parameter is one that would result in 400-range response if it is not supplied. Each request method should make only one request. For more high-level logic, put code in the data models.
17
18
19
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 17
def self.hostname
'https://itunesconnect.apple.com/testflight/v2/'
end
|
Instance Method Details
#add_group_to_build(app_id: nil, group_id: nil, build_id: nil) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 118
def add_group_to_build(app_id: nil, group_id: nil, build_id: nil)
assert_required_params(__method__, binding)
body = {
'groupId' => group_id,
'buildId' => build_id
}
response = request(:put) do |req|
req.url("providers/#{team_id}/apps/#{app_id}/groups/#{group_id}/builds/#{build_id}")
req.body = body.to_json
req.['Content-Type'] = 'application/json'
end
handle_response(response)
end
|
#create_app_level_tester(app_id: nil, first_name: nil, last_name: nil, email: nil) ⇒ Object
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 213
def create_app_level_tester(app_id: nil, first_name: nil, last_name: nil, email: nil)
assert_required_params(__method__, binding)
url = "providers/#{team_id}/apps/#{app_id}/testers"
response = request(:post) do |req|
req.url(url)
req.body = {
"email" => email,
"firstName" => first_name,
"lastName" => last_name
}.to_json
req.['Content-Type'] = 'application/json'
end
handle_response(response)
end
|
#create_group_for_app(app_id: nil, group_name: nil) ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 104
def create_group_for_app(app_id: nil, group_name: nil)
assert_required_params(__method__, binding)
body = {
'name' => group_name
}
response = request(:post) do |req|
req.url("providers/#{team_id}/apps/#{app_id}/groups")
req.body = body.to_json
req.['Content-Type'] = 'application/json'
end
handle_response(response)
end
|
#delete_tester_from_app(app_id: nil, tester_id: nil) ⇒ Object
191
192
193
194
195
196
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 191
def delete_tester_from_app(app_id: nil, tester_id: nil)
assert_required_params(__method__, binding)
url = "providers/#{team_id}/apps/#{app_id}/testers/#{tester_id}"
response = request(:delete, url)
handle_response(response)
end
|
#delete_tester_from_group(group_id: nil, tester_id: nil, app_id: nil) ⇒ Object
246
247
248
249
250
251
252
253
254
255
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 246
def delete_tester_from_group(group_id: nil, tester_id: nil, app_id: nil)
assert_required_params(__method__, binding)
url = "providers/#{team_id}/apps/#{app_id}/groups/#{group_id}/testers/#{tester_id}"
response = request(:delete) do |req|
req.url(url)
req.['Content-Type'] = 'application/json'
end
handle_response(response)
end
|
#expire_build(app_id: nil, build_id: nil, build: nil) ⇒ Object
75
76
77
78
79
80
81
82
83
84
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 75
def expire_build(app_id: nil, build_id: nil, build: nil)
assert_required_params(__method__, binding)
response = request(:post) do |req|
req.url("providers/#{team_id}/apps/#{app_id}/builds/#{build_id}/expire")
req.body = build.to_json
req.['Content-Type'] = 'application/json'
end
handle_response(response)
end
|
#get_app_test_info(app_id: nil) ⇒ Object
261
262
263
264
265
266
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 261
def get_app_test_info(app_id: nil)
assert_required_params(__method__, binding)
response = request(:get, "providers/#{team_id}/apps/#{app_id}/testInfo")
handle_response(response)
end
|
#get_build(app_id: nil, build_id: nil) ⇒ Object
46
47
48
49
50
51
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 46
def get_build(app_id: nil, build_id: nil)
assert_required_params(__method__, binding)
response = request(:get, "providers/#{team_id}/apps/#{app_id}/builds/#{build_id}")
handle_response(response)
end
|
#get_build_trains(app_id: nil, platform: "ios") ⇒ Object
Returns an array of all available build trains (not the builds they include)
26
27
28
29
30
31
32
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 26
def get_build_trains(app_id: nil, platform: "ios")
assert_required_params(__method__, binding)
response = request(:get, "providers/#{team_id}/apps/#{app_id}/platforms/#{platform}/trains")
handle_response(response)
end
|
#get_builds_for_train(app_id: nil, platform: "ios", train_version: nil, retry_count: 3) ⇒ Object
34
35
36
37
38
39
40
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 34
def get_builds_for_train(app_id: nil, platform: "ios", train_version: nil, retry_count: 3)
assert_required_params(__method__, binding)
with_retry(retry_count) do
response = request(:get, "providers/#{team_id}/apps/#{app_id}/platforms/#{platform}/trains/#{train_version}/builds", nil, {}, true)
handle_response(response)
end
end
|
#get_groups(app_id: nil) ⇒ Object
Returns a list of available testing groups e.g.
{"b6f65dbd-c845-4d91-bc39-0b661d608970" => "Boarding",
"70402368-9deb-409f-9a26-bb3f215dfee3" => "Automatic"}
94
95
96
97
98
99
100
101
102
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 94
def get_groups(app_id: nil)
@cached_groups = {} unless @cached_groups
return @cached_groups[app_id] if @cached_groups[app_id]
assert_required_params(__method__, binding)
response = request(:get, "/testflight/v2/providers/#{provider_id}/apps/#{app_id}/groups")
@cached_groups[app_id] = handle_response(response)
end
|
#post_for_testflight_review(app_id: nil, build_id: nil, build: nil) ⇒ Object
64
65
66
67
68
69
70
71
72
73
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 64
def post_for_testflight_review(app_id: nil, build_id: nil, build: nil)
assert_required_params(__method__, binding)
response = request(:post) do |req|
req.url("providers/#{team_id}/apps/#{app_id}/builds/#{build_id}/review")
req.body = build.to_json
req.['Content-Type'] = 'application/json'
end
handle_response(response)
end
|
#post_tester_to_group(app_id: nil, email: nil, first_name: nil, last_name: nil, group_id: nil) ⇒ Object
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 228
def post_tester_to_group(app_id: nil, email: nil, first_name: nil, last_name: nil, group_id: nil)
assert_required_params(__method__, binding)
url = "providers/#{team_id}/apps/#{app_id}/groups/#{group_id}/testers"
response = request(:post) do |req|
req.url(url)
req.body = [{
"email" => email,
"firstName" => first_name,
"lastName" => last_name
}].to_json
req.['Content-Type'] = 'application/json'
end
handle_response(response)
end
|
#put_app_test_info(app_id: nil, app_test_info: nil) ⇒ Object
268
269
270
271
272
273
274
275
276
277
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 268
def put_app_test_info(app_id: nil, app_test_info: nil)
assert_required_params(__method__, binding)
response = request(:put) do |req|
req.url("providers/#{team_id}/apps/#{app_id}/testInfo")
req.body = app_test_info.to_json
req.['Content-Type'] = 'application/json'
end
handle_response(response)
end
|
#put_build(app_id: nil, build_id: nil, build: nil) ⇒ Object
53
54
55
56
57
58
59
60
61
62
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 53
def put_build(app_id: nil, build_id: nil, build: nil)
assert_required_params(__method__, binding)
response = request(:put) do |req|
req.url("providers/#{team_id}/apps/#{app_id}/builds/#{build_id}")
req.body = build.to_json
req.['Content-Type'] = 'application/json'
end
handle_response(response)
end
|
#resend_invite_to_external_tester(app_id: nil, tester_id: nil) ⇒ Object
206
207
208
209
210
211
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 206
def resend_invite_to_external_tester(app_id: nil, tester_id: nil)
assert_required_params(__method__, binding)
url = "/testflight/v1/invites/#{app_id}/resend?testerId=#{tester_id}"
response = request(:post, url)
handle_response(response)
end
|
#search_for_tester_in_app(app_id: nil, text: nil) ⇒ Object
198
199
200
201
202
203
204
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 198
def search_for_tester_in_app(app_id: nil, text: nil)
assert_required_params(__method__, binding)
text = CGI.escape(text)
url = "providers/#{team_id}/apps/#{app_id}/testers?order=asc&search=#{text}&sort=status"
response = request(:get, url)
handle_response(response)
end
|
#testers(tester) ⇒ Object
136
137
138
139
140
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 136
def testers(tester)
url = tester.url[:index]
r = request(:get, url)
parse_response(r, 'data')['users']
end
|
#testers_by_app(tester, app_id, group_id: nil) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 142
def testers_by_app(tester, app_id, group_id: nil)
if group_id.nil?
group_ids = get_groups(app_id: app_id).map do |group|
group['id']
end
end
group_ids ||= [group_id]
testers = []
group_ids.each do |json_group_id|
url = tester.url(app_id, provider_id, json_group_id)[:index_by_app]
r = request(:get, url)
testers += parse_response(r, 'data')['users']
end
testers
end
|
#testers_for_app(app_id: nil) ⇒ Object
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
# File 'spaceship/lib/spaceship/test_flight/client.rb', line 164
def testers_for_app(app_id: nil)
assert_required_params(__method__, binding)
page_size = 40 resulting_array = []
initial_url = "providers/#{team_id}/apps/#{app_id}/testers?limit=#{page_size}&sort=email&order=asc"
response = request(:get, initial_url)
link_from_response = proc do |r|
(l = r.['link']) && (m = l.match(/<(.*)>/)) && m.captures.first
end
next_link = link_from_response.call(response)
result = Array(handle_response(response))
resulting_array += result
return resulting_array if result.count == 0
until next_link.nil?
response = request(:get, next_link)
result = Array(handle_response(response))
next_link = link_from_response.call(response)
break if result.count == 0
resulting_array += result
end
return resulting_array.uniq
end
|