2
2
3
3
namespace Algolia \AlgoliaSearch \Api ;
4
4
5
+ use GuzzleHttp \Exception \RequestException ;
6
+ use GuzzleHttp \Exception \ConnectException ;
7
+ use GuzzleHttp \Psr7 \MultipartStream ;
8
+ use GuzzleHttp \RequestOptions ;
9
+ use GuzzleHttp \Utils ;
5
10
use Algolia \AlgoliaSearch \Algolia ;
11
+ use Algolia \AlgoliaSearch \ApiException ;
6
12
use Algolia \AlgoliaSearch \Configuration \AbtestingConfig ;
7
13
use Algolia \AlgoliaSearch \ObjectSerializer ;
8
14
use Algolia \AlgoliaSearch \RetryStrategy \ApiWrapper ;
@@ -31,8 +37,10 @@ class AbtestingClient
31
37
* @param AbtestingConfig $config
32
38
* @param ApiWrapperInterface $apiWrapper
33
39
*/
34
- public function __construct (ApiWrapperInterface $ apiWrapper , AbtestingConfig $ config )
35
- {
40
+ public function __construct (
41
+ ApiWrapperInterface $ apiWrapper ,
42
+ AbtestingConfig $ config
43
+ ) {
36
44
$ this ->config = $ config ;
37
45
38
46
$ this ->api = $ apiWrapper ;
@@ -48,7 +56,12 @@ public function __construct(ApiWrapperInterface $apiWrapper, AbtestingConfig $co
48
56
public static function create ($ appId = null , $ apiKey = null , $ region = null )
49
57
{
50
58
$ allowedRegions = explode ('- ' , 'us-de ' );
51
- $ config = AbtestingConfig::create ($ appId , $ apiKey , $ region , $ allowedRegions );
59
+ $ config = AbtestingConfig::create (
60
+ $ appId ,
61
+ $ apiKey ,
62
+ $ region ,
63
+ $ allowedRegions
64
+ );
52
65
53
66
return static ::createWithConfig ($ config );
54
67
}
@@ -66,7 +79,9 @@ public static function createWithConfig(AbtestingConfig $config)
66
79
// If a list of hosts was passed, we ignore the cache
67
80
$ clusterHosts = ClusterHosts::create ($ hosts );
68
81
} else {
69
- $ clusterHosts = ClusterHosts::create ('analytics. ' .$ config ->getRegion ().'.algolia.com ' );
82
+ $ clusterHosts = ClusterHosts::create (
83
+ 'analytics. ' . $ config ->getRegion () . '.algolia.com '
84
+ );
70
85
}
71
86
72
87
$ apiWrapper = new ApiWrapper (
@@ -93,15 +108,17 @@ public function getClientConfig()
93
108
* - $addABTestsRequest['name'] => (string) A/B test name. (required)
94
109
* - $addABTestsRequest['variant'] => (array) List of 2 variants for the A/B test. (required)
95
110
* - $addABTestsRequest['endAt'] => (string) End date for the A/B test expressed as YYYY-MM-DDThh:mm:ssZ. (required)
96
- *
97
111
* @see \Algolia\AlgoliaSearch\Model\Abtesting\AddABTestsRequest
98
112
*
99
113
* @return array<string, mixed>|\Algolia\AlgoliaSearch\Model\Abtesting\ABTestResponse
100
114
*/
101
115
public function addABTests ($ addABTestsRequest )
102
116
{
103
117
// verify the required parameter 'addABTestsRequest' is set
104
- if ($ addABTestsRequest === null || (is_array ($ addABTestsRequest ) && count ($ addABTestsRequest ) === 0 )) {
118
+ if (
119
+ $ addABTestsRequest === null ||
120
+ (is_array ($ addABTestsRequest ) && count ($ addABTestsRequest ) === 0 )
121
+ ) {
105
122
throw new \InvalidArgumentException (
106
123
'Missing the required parameter $addABTestsRequest when calling addABTests '
107
124
);
@@ -115,7 +132,12 @@ public function addABTests($addABTestsRequest)
115
132
$ httpBody = $ addABTestsRequest ;
116
133
}
117
134
118
- return $ this ->sendRequest ('POST ' , $ resourcePath , $ queryParams , $ httpBody );
135
+ return $ this ->sendRequest (
136
+ 'POST ' ,
137
+ $ resourcePath ,
138
+ $ queryParams ,
139
+ $ httpBody
140
+ );
119
141
}
120
142
121
143
/**
@@ -151,14 +173,15 @@ public function del($path, $parameters = null)
151
173
152
174
// path params
153
175
if ($ path !== null ) {
154
- $ resourcePath = str_replace (
155
- '{path} ' ,
156
- $ path ,
157
- $ resourcePath
158
- );
176
+ $ resourcePath = str_replace ('{path} ' , $ path , $ resourcePath );
159
177
}
160
178
161
- return $ this ->sendRequest ('DELETE ' , $ resourcePath , $ queryParams , $ httpBody );
179
+ return $ this ->sendRequest (
180
+ 'DELETE ' ,
181
+ $ resourcePath ,
182
+ $ queryParams ,
183
+ $ httpBody
184
+ );
162
185
}
163
186
164
187
/**
@@ -190,7 +213,12 @@ public function deleteABTest($id)
190
213
);
191
214
}
192
215
193
- return $ this ->sendRequest ('DELETE ' , $ resourcePath , $ queryParams , $ httpBody );
216
+ return $ this ->sendRequest (
217
+ 'DELETE ' ,
218
+ $ resourcePath ,
219
+ $ queryParams ,
220
+ $ httpBody
221
+ );
194
222
}
195
223
196
224
/**
@@ -226,14 +254,15 @@ public function get($path, $parameters = null)
226
254
227
255
// path params
228
256
if ($ path !== null ) {
229
- $ resourcePath = str_replace (
230
- '{path} ' ,
231
- $ path ,
232
- $ resourcePath
233
- );
257
+ $ resourcePath = str_replace ('{path} ' , $ path , $ resourcePath );
234
258
}
235
259
236
- return $ this ->sendRequest ('GET ' , $ resourcePath , $ queryParams , $ httpBody );
260
+ return $ this ->sendRequest (
261
+ 'GET ' ,
262
+ $ resourcePath ,
263
+ $ queryParams ,
264
+ $ httpBody
265
+ );
237
266
}
238
267
239
268
/**
@@ -265,7 +294,12 @@ public function getABTest($id)
265
294
);
266
295
}
267
296
268
- return $ this ->sendRequest ('GET ' , $ resourcePath , $ queryParams , $ httpBody );
297
+ return $ this ->sendRequest (
298
+ 'GET ' ,
299
+ $ resourcePath ,
300
+ $ queryParams ,
301
+ $ httpBody
302
+ );
269
303
}
270
304
271
305
/**
@@ -302,7 +336,12 @@ public function listABTests($offset = 0, $limit = 10)
302
336
}
303
337
}
304
338
305
- return $ this ->sendRequest ('GET ' , $ resourcePath , $ queryParams , $ httpBody );
339
+ return $ this ->sendRequest (
340
+ 'GET ' ,
341
+ $ resourcePath ,
342
+ $ queryParams ,
343
+ $ httpBody
344
+ );
306
345
}
307
346
308
347
/**
@@ -339,18 +378,19 @@ public function post($path, $parameters = null, $body = null)
339
378
340
379
// path params
341
380
if ($ path !== null ) {
342
- $ resourcePath = str_replace (
343
- '{path} ' ,
344
- $ path ,
345
- $ resourcePath
346
- );
381
+ $ resourcePath = str_replace ('{path} ' , $ path , $ resourcePath );
347
382
}
348
383
349
384
if (isset ($ body )) {
350
385
$ httpBody = $ body ;
351
386
}
352
387
353
- return $ this ->sendRequest ('POST ' , $ resourcePath , $ queryParams , $ httpBody );
388
+ return $ this ->sendRequest (
389
+ 'POST ' ,
390
+ $ resourcePath ,
391
+ $ queryParams ,
392
+ $ httpBody
393
+ );
354
394
}
355
395
356
396
/**
@@ -387,18 +427,19 @@ public function put($path, $parameters = null, $body = null)
387
427
388
428
// path params
389
429
if ($ path !== null ) {
390
- $ resourcePath = str_replace (
391
- '{path} ' ,
392
- $ path ,
393
- $ resourcePath
394
- );
430
+ $ resourcePath = str_replace ('{path} ' , $ path , $ resourcePath );
395
431
}
396
432
397
433
if (isset ($ body )) {
398
434
$ httpBody = $ body ;
399
435
}
400
436
401
- return $ this ->sendRequest ('PUT ' , $ resourcePath , $ queryParams , $ httpBody );
437
+ return $ this ->sendRequest (
438
+ 'PUT ' ,
439
+ $ resourcePath ,
440
+ $ queryParams ,
441
+ $ httpBody
442
+ );
402
443
}
403
444
404
445
/**
@@ -430,14 +471,23 @@ public function stopABTest($id)
430
471
);
431
472
}
432
473
433
- return $ this ->sendRequest ('POST ' , $ resourcePath , $ queryParams , $ httpBody );
474
+ return $ this ->sendRequest (
475
+ 'POST ' ,
476
+ $ resourcePath ,
477
+ $ queryParams ,
478
+ $ httpBody
479
+ );
434
480
}
435
481
436
- private function sendRequest ($ method , $ resourcePath , $ queryParams , $ httpBody )
437
- {
482
+ private function sendRequest (
483
+ $ method ,
484
+ $ resourcePath ,
485
+ $ queryParams ,
486
+ $ httpBody
487
+ ) {
438
488
$ query = \GuzzleHttp \Psr7 \Query::build ($ queryParams );
439
489
440
- if ($ method === 'GET ' ) {
490
+ if ($ method == 'GET ' ) {
441
491
$ request = $ this ->api ->read (
442
492
$ method ,
443
493
$ resourcePath . ($ query ? "? {$ query }" : '' )
0 commit comments