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 \InsightsConfig ;
13
+ use Algolia \AlgoliaSearch \ObjectSerializer ;
7
14
use Algolia \AlgoliaSearch \RetryStrategy \ApiWrapper ;
8
15
use Algolia \AlgoliaSearch \RetryStrategy \ApiWrapperInterface ;
9
16
use Algolia \AlgoliaSearch \RetryStrategy \ClusterHosts ;
@@ -30,8 +37,10 @@ class InsightsClient
30
37
* @param InsightsConfig $config
31
38
* @param ApiWrapperInterface $apiWrapper
32
39
*/
33
- public function __construct (ApiWrapperInterface $ apiWrapper , InsightsConfig $ config )
34
- {
40
+ public function __construct (
41
+ ApiWrapperInterface $ apiWrapper ,
42
+ InsightsConfig $ config
43
+ ) {
35
44
$ this ->config = $ config ;
36
45
37
46
$ this ->api = $ apiWrapper ;
@@ -47,7 +56,12 @@ public function __construct(ApiWrapperInterface $apiWrapper, InsightsConfig $con
47
56
public static function create ($ appId = null , $ apiKey = null , $ region = null )
48
57
{
49
58
$ allowedRegions = explode ('- ' , 'us-de ' );
50
- $ config = InsightsConfig::create ($ appId , $ apiKey , $ region , $ allowedRegions );
59
+ $ config = InsightsConfig::create (
60
+ $ appId ,
61
+ $ apiKey ,
62
+ $ region ,
63
+ $ allowedRegions
64
+ );
51
65
52
66
return static ::createWithConfig ($ config );
53
67
}
@@ -65,7 +79,9 @@ public static function createWithConfig(InsightsConfig $config)
65
79
// If a list of hosts was passed, we ignore the cache
66
80
$ clusterHosts = ClusterHosts::create ($ hosts );
67
81
} else {
68
- $ clusterHosts = ClusterHosts::create ('insights. ' .$ config ->getRegion ().'.algolia.io ' );
82
+ $ clusterHosts = ClusterHosts::create (
83
+ 'insights. ' . $ config ->getRegion () . '.algolia.io '
84
+ );
69
85
}
70
86
71
87
$ apiWrapper = new ApiWrapper (
@@ -118,14 +134,15 @@ public function del($path, $parameters = null)
118
134
119
135
// path params
120
136
if ($ path !== null ) {
121
- $ resourcePath = str_replace (
122
- '{path} ' ,
123
- $ path ,
124
- $ resourcePath
125
- );
137
+ $ resourcePath = str_replace ('{path} ' , $ path , $ resourcePath );
126
138
}
127
139
128
- return $ this ->sendRequest ('DELETE ' , $ resourcePath , $ queryParams , $ httpBody );
140
+ return $ this ->sendRequest (
141
+ 'DELETE ' ,
142
+ $ resourcePath ,
143
+ $ queryParams ,
144
+ $ httpBody
145
+ );
129
146
}
130
147
131
148
/**
@@ -161,14 +178,15 @@ public function get($path, $parameters = null)
161
178
162
179
// path params
163
180
if ($ path !== null ) {
164
- $ resourcePath = str_replace (
165
- '{path} ' ,
166
- $ path ,
167
- $ resourcePath
168
- );
181
+ $ resourcePath = str_replace ('{path} ' , $ path , $ resourcePath );
169
182
}
170
183
171
- return $ this ->sendRequest ('GET ' , $ resourcePath , $ queryParams , $ httpBody );
184
+ return $ this ->sendRequest (
185
+ 'GET ' ,
186
+ $ resourcePath ,
187
+ $ queryParams ,
188
+ $ httpBody
189
+ );
172
190
}
173
191
174
192
/**
@@ -205,34 +223,37 @@ public function post($path, $parameters = null, $body = null)
205
223
206
224
// path params
207
225
if ($ path !== null ) {
208
- $ resourcePath = str_replace (
209
- '{path} ' ,
210
- $ path ,
211
- $ resourcePath
212
- );
226
+ $ resourcePath = str_replace ('{path} ' , $ path , $ resourcePath );
213
227
}
214
228
215
229
if (isset ($ body )) {
216
230
$ httpBody = $ body ;
217
231
}
218
232
219
- return $ this ->sendRequest ('POST ' , $ resourcePath , $ queryParams , $ httpBody );
233
+ return $ this ->sendRequest (
234
+ 'POST ' ,
235
+ $ resourcePath ,
236
+ $ queryParams ,
237
+ $ httpBody
238
+ );
220
239
}
221
240
222
241
/**
223
242
* Pushes an array of events.
224
243
*
225
244
* @param array $insightEvents insightEvents (required)
226
245
* - $insightEvents['events'] => (array) Array of events sent. (required)
227
- *
228
246
* @see \Algolia\AlgoliaSearch\Model\Insights\InsightEvents
229
247
*
230
248
* @return array<string, mixed>|\Algolia\AlgoliaSearch\Model\Insights\PushEventsResponse
231
249
*/
232
250
public function pushEvents ($ insightEvents )
233
251
{
234
252
// verify the required parameter 'insightEvents' is set
235
- if ($ insightEvents === null || (is_array ($ insightEvents ) && count ($ insightEvents ) === 0 )) {
253
+ if (
254
+ $ insightEvents === null ||
255
+ (is_array ($ insightEvents ) && count ($ insightEvents ) === 0 )
256
+ ) {
236
257
throw new \InvalidArgumentException (
237
258
'Missing the required parameter $insightEvents when calling pushEvents '
238
259
);
@@ -246,7 +267,12 @@ public function pushEvents($insightEvents)
246
267
$ httpBody = $ insightEvents ;
247
268
}
248
269
249
- return $ this ->sendRequest ('POST ' , $ resourcePath , $ queryParams , $ httpBody );
270
+ return $ this ->sendRequest (
271
+ 'POST ' ,
272
+ $ resourcePath ,
273
+ $ queryParams ,
274
+ $ httpBody
275
+ );
250
276
}
251
277
252
278
/**
@@ -283,25 +309,30 @@ public function put($path, $parameters = null, $body = null)
283
309
284
310
// path params
285
311
if ($ path !== null ) {
286
- $ resourcePath = str_replace (
287
- '{path} ' ,
288
- $ path ,
289
- $ resourcePath
290
- );
312
+ $ resourcePath = str_replace ('{path} ' , $ path , $ resourcePath );
291
313
}
292
314
293
315
if (isset ($ body )) {
294
316
$ httpBody = $ body ;
295
317
}
296
318
297
- return $ this ->sendRequest ('PUT ' , $ resourcePath , $ queryParams , $ httpBody );
319
+ return $ this ->sendRequest (
320
+ 'PUT ' ,
321
+ $ resourcePath ,
322
+ $ queryParams ,
323
+ $ httpBody
324
+ );
298
325
}
299
326
300
- private function sendRequest ($ method , $ resourcePath , $ queryParams , $ httpBody )
301
- {
327
+ private function sendRequest (
328
+ $ method ,
329
+ $ resourcePath ,
330
+ $ queryParams ,
331
+ $ httpBody
332
+ ) {
302
333
$ query = \GuzzleHttp \Psr7 \Query::build ($ queryParams );
303
334
304
- if ($ method === 'GET ' ) {
335
+ if ($ method == 'GET ' ) {
305
336
$ request = $ this ->api ->read (
306
337
$ method ,
307
338
$ resourcePath . ($ query ? "? {$ query }" : '' )
0 commit comments