-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestingBotAPI.php
More file actions
223 lines (184 loc) · 6.71 KB
/
Copy pathTestingBotAPI.php
File metadata and controls
223 lines (184 loc) · 6.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
77
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
declare(strict_types=1);
namespace TestingBot;
use TestingBot\Http\HttpClientInterface;
use TestingBot\Http\Request;
/**
* Backward-compatible facade for the 1.x API surface.
*
* Every method from the 1.x client is preserved with the same name and
* signature; each delegates to the new resource-oriented {@see Client}. New
* code should prefer `TestingBot\Client` directly.
*
* BEHAVIOUR CHANGE IN 2.0: failed API calls now throw
* {@see \TestingBot\Exception\TestingBotExceptionInterface} instead of
* returning an array containing an `error` key. See CHANGELOG.md.
*
* @mixin Client
*/
class TestingBotAPI
{
private Client $client;
/**
* @param array<string, mixed> $options Forwarded to {@see Client}: `base_url`,
* `timeout`, `connect_timeout`,
* `ssl_verify`, `user_agent`.
*/
public function __construct($key, $secret, array $options = [], ?HttpClientInterface $httpClient = null)
{
$this->client = new Client((string) $key, (string) $secret, $options, $httpClient);
}
/**
* The underlying modern client, for access to resources not exposed as
* flat methods (screenshots, team management, codeless suites, …).
*/
public function client(): Client
{
return $this->client;
}
// -- Tests (jobs) --------------------------------------------------------
/** @param array<string, mixed> $details @return array<mixed> */
public function updateJob($sessionID, array $details)
{
return $this->client->tests()->update((string) $sessionID, $details);
}
/** @param array<string, mixed> $details @return array<mixed> */
public function getJob($sessionID, array $details = [])
{
return $this->client->tests()->get((string) $sessionID, $details);
}
/** @param array<string, mixed> $extraOptions @return array<mixed> */
public function getJobs($offset = 0, $count = 10, array $extraOptions = [])
{
return $this->client->tests()->list((int) $offset, (int) $count, $extraOptions);
}
/** @return array<mixed> */
public function deleteJob($sessionID)
{
return $this->client->tests()->delete((string) $sessionID);
}
/** @return array<mixed> */
public function stopJob($sessionID)
{
return $this->client->tests()->stop((string) $sessionID);
}
// -- Codeless (lab) tests ------------------------------------------------
/** @param array<string, mixed> $extras @return array<mixed> */
public function createLabTest($name, $baseUrl, $extras = [])
{
return $this->client->lab()->createTest(['name' => $name, 'url' => $baseUrl] + (array) $extras);
}
/**
* Replace a codeless test's steps.
*
* Sends the exact legacy `steps[][...]` body for byte-for-byte
* compatibility. New code should use `client()->lab()->setSteps()`, which
* URL-encodes step values.
*
* @param array<int, array{cmd?: string, locator?: string, value?: string}> $steps
* @return array<mixed>
*/
public function modifyLabTestSteps($labTestID, array $steps)
{
$processedSteps = [];
foreach (array_values($steps) as $i => $step) {
$processedSteps[] = 'steps[][order]=' . $i
. '&steps[][cmd]=' . ($step['cmd'] ?? '')
. '&steps[][locator]=' . ($step['locator'] ?? '')
. '&steps[][value]=' . ($step['value'] ?? '');
}
return $this->client->request(
new Request('POST', 'lab/' . $labTestID . '/steps', body: implode('&', $processedSteps)),
);
}
// -- Builds --------------------------------------------------------------
/** @return array<mixed> */
public function getBuilds($offset = 0, $count = 10)
{
return $this->client->builds()->list((int) $offset, (int) $count);
}
/** @return array<mixed> */
public function getBuild($buildID)
{
return $this->client->builds()->getTests((string) $buildID);
}
/** @return array<mixed> */
public function deleteBuild($buildID)
{
return $this->client->builds()->delete((string) $buildID);
}
// -- Tunnels -------------------------------------------------------------
/** @return array<mixed> */
public function getTunnels()
{
return $this->client->tunnels()->list();
}
/** @return array<mixed> */
public function deleteTunnel($tunnelID)
{
return $this->client->tunnels()->delete((int) $tunnelID);
}
// -- User ----------------------------------------------------------------
/** @return array<mixed> */
public function getUserInfo()
{
return $this->client->user()->get();
}
/** @param array<string, mixed> $details @return array<mixed> */
public function updateUserInfo(array $details)
{
return $this->client->user()->update($details);
}
// -- Browsers & devices --------------------------------------------------
/** @return array<mixed> */
public function getBrowsers()
{
return $this->client->browsers()->list();
}
/** @return array<mixed> */
public function getDevices()
{
return $this->client->devices()->list();
}
/** @return array<mixed> */
public function getAvailableDevices()
{
return $this->client->devices()->available();
}
/** @return array<mixed> */
public function getDevice($deviceID)
{
return $this->client->devices()->get((int) $deviceID);
}
// -- Storage -------------------------------------------------------------
/** @return array<mixed> */
public function uploadLocalFileToStorage($localFile)
{
return $this->client->storage()->uploadFile((string) $localFile);
}
/** @return array<mixed> */
public function uploadRemoteFileToStorage($remoteFileUrl)
{
return $this->client->storage()->uploadRemoteUrl((string) $remoteFileUrl);
}
/** @return array<mixed> */
public function getStorageFile($appUrl)
{
return $this->client->storage()->get((string) $appUrl);
}
/** @return array<mixed> */
public function getStorageFiles($offset = 0, $count = 10)
{
return $this->client->storage()->list((int) $offset, (int) $count);
}
/** @return array<mixed> */
public function deleteStorageFile($appUrl)
{
return $this->client->storage()->delete((string) $appUrl);
}
// -- Sharing -------------------------------------------------------------
public function getAuthenticationHash($identifier = null): string
{
return $this->client->getAuthenticationHash($identifier === null ? null : (string) $identifier);
}
}