21
21
22
22
use GuzzleHttp \Client ;
23
23
use GuzzleHttp \ClientInterface ;
24
+ use GuzzleHttp \Exception \ConnectException ;
24
25
use GuzzleHttp \Exception \RequestException ;
25
26
use GuzzleHttp \Psr7 \MultipartStream ;
26
27
use GuzzleHttp \Psr7 \Request ;
@@ -61,6 +62,13 @@ final class ThingApi
61
62
*/
62
63
private $ hostIndex ;
63
64
65
+ /** @var string[] */
66
+ public const contentTypes = [
67
+ 'getInfo ' => [
68
+ 'application/json ' ,
69
+ ],
70
+ ];
71
+
64
72
/**
65
73
* @param ClientInterface $client
66
74
* @param Configuration $config
@@ -109,14 +117,15 @@ public function getConfig(): Configuration
109
117
*
110
118
* Get thing info
111
119
*
112
- * @param string $id id (required)
120
+ * @param string $id id (required)
121
+ * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
113
122
*
114
123
* @throws \InvalidArgumentException
115
124
* @throws \Sigwin\RedditClient\ApiException on non-2xx response
116
125
*/
117
- public function getInfo ($ id ): \Sigwin \RedditClient \Model \ListingEnvelope
126
+ public function getInfo ($ id, string $ contentType = self ::contentTypes[ ' getInfo ' ][ 0 ] ): \Sigwin \RedditClient \Model \ListingEnvelope
118
127
{
119
- [$ response ] = $ this ->getInfoWithHttpInfo ($ id );
128
+ [$ response ] = $ this ->getInfoWithHttpInfo ($ id, $ contentType );
120
129
121
130
return $ response ;
122
131
}
@@ -126,23 +135,26 @@ public function getInfo($id): \Sigwin\RedditClient\Model\ListingEnvelope
126
135
*
127
136
* Get thing info
128
137
*
129
- * @param string $id (required)
138
+ * @param string $id (required)
139
+ * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
130
140
*
131
141
* @return array of \Sigwin\RedditClient\Model\ListingEnvelope, HTTP status code, HTTP response headers (array of strings)
132
142
*
133
143
* @throws \InvalidArgumentException
134
144
* @throws \Sigwin\RedditClient\ApiException on non-2xx response
135
145
*/
136
- public function getInfoWithHttpInfo ($ id ): array
146
+ public function getInfoWithHttpInfo ($ id, string $ contentType = self ::contentTypes[ ' getInfo ' ][ 0 ] ): array
137
147
{
138
- $ request = $ this ->getInfoRequest ($ id );
148
+ $ request = $ this ->getInfoRequest ($ id, $ contentType );
139
149
140
150
try {
141
151
$ options = $ this ->createHttpClientOption ();
142
152
try {
143
153
$ response = $ this ->client ->send ($ request , $ options );
144
154
} catch (RequestException $ e ) {
145
155
throw new ApiException ("[ {$ e ->getCode ()}] {$ e ->getMessage ()}" , (int ) $ e ->getCode (), $ e ->getResponse () ? $ e ->getResponse ()->getHeaders () : null , $ e ->getResponse () ? (string ) $ e ->getResponse ()->getBody () : null );
156
+ } catch (ConnectException $ e ) {
157
+ throw new ApiException ("[ {$ e ->getCode ()}] {$ e ->getMessage ()}" , (int ) $ e ->getCode (), null , null );
146
158
}
147
159
148
160
$ statusCode = $ response ->getStatusCode ();
@@ -157,6 +169,9 @@ public function getInfoWithHttpInfo($id): array
157
169
$ content = $ response ->getBody (); // stream goes to serializer
158
170
} else {
159
171
$ content = (string ) $ response ->getBody ();
172
+ if ('\Sigwin\RedditClient\Model\ListingEnvelope ' !== 'string ' ) {
173
+ $ content = json_decode ($ content );
174
+ }
160
175
}
161
176
162
177
return [
@@ -171,6 +186,9 @@ public function getInfoWithHttpInfo($id): array
171
186
$ content = $ response ->getBody (); // stream goes to serializer
172
187
} else {
173
188
$ content = (string ) $ response ->getBody ();
189
+ if ($ returnType !== 'string ' ) {
190
+ $ content = json_decode ($ content );
191
+ }
174
192
}
175
193
176
194
return [
@@ -198,13 +216,14 @@ public function getInfoWithHttpInfo($id): array
198
216
*
199
217
* Get thing info
200
218
*
201
- * @param string $id (required)
219
+ * @param string $id (required)
220
+ * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
202
221
*
203
222
* @throws \InvalidArgumentException
204
223
*/
205
- public function getInfoAsync ($ id ): \GuzzleHttp \Promise \PromiseInterface
224
+ public function getInfoAsync ($ id, string $ contentType = self ::contentTypes[ ' getInfo ' ][ 0 ] ): \GuzzleHttp \Promise \PromiseInterface
206
225
{
207
- return $ this ->getInfoAsyncWithHttpInfo ($ id )
226
+ return $ this ->getInfoAsyncWithHttpInfo ($ id, $ contentType )
208
227
->then (
209
228
static function ($ response ) {
210
229
return $ response [0 ];
@@ -218,14 +237,15 @@ static function ($response) {
218
237
*
219
238
* Get thing info
220
239
*
221
- * @param string $id (required)
240
+ * @param string $id (required)
241
+ * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
222
242
*
223
243
* @throws \InvalidArgumentException
224
244
*/
225
- public function getInfoAsyncWithHttpInfo ($ id ): \GuzzleHttp \Promise \PromiseInterface
245
+ public function getInfoAsyncWithHttpInfo ($ id, string $ contentType = self ::contentTypes[ ' getInfo ' ][ 0 ] ): \GuzzleHttp \Promise \PromiseInterface
226
246
{
227
247
$ returnType = '\Sigwin\RedditClient\Model\ListingEnvelope ' ;
228
- $ request = $ this ->getInfoRequest ($ id );
248
+ $ request = $ this ->getInfoRequest ($ id, $ contentType );
229
249
230
250
return $ this ->client
231
251
->sendAsync ($ request , $ this ->createHttpClientOption ())
@@ -235,6 +255,9 @@ static function ($response) use ($returnType) {
235
255
$ content = $ response ->getBody (); // stream goes to serializer
236
256
} else {
237
257
$ content = (string ) $ response ->getBody ();
258
+ if ($ returnType !== 'string ' ) {
259
+ $ content = json_decode ($ content );
260
+ }
238
261
}
239
262
240
263
return [
@@ -255,11 +278,12 @@ static function ($exception): void {
255
278
/**
256
279
* Create request for operation 'getInfo'.
257
280
*
258
- * @param string $id (required)
281
+ * @param string $id (required)
282
+ * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getInfo'] to see the possible values for this operation
259
283
*
260
284
* @throws \InvalidArgumentException
261
285
*/
262
- public function getInfoRequest ($ id ): Request
286
+ public function getInfoRequest ($ id, string $ contentType = self ::contentTypes[ ' getInfo ' ][ 0 ] ): Request
263
287
{
264
288
// verify the required parameter 'id' is set
265
289
if ($ id === null || (\is_array ($ id ) && \count ($ id ) === 0 )) {
@@ -274,23 +298,20 @@ public function getInfoRequest($id): Request
274
298
$ multipart = false ;
275
299
276
300
// query params
277
- if (\is_array ($ id )) {
278
- $ id = ObjectSerializer::serializeCollection ($ id , '' , true );
279
- }
280
- if ($ id !== null ) {
281
- $ queryParams ['id ' ] = $ id ;
282
- }
283
-
284
- if ($ multipart ) {
285
- $ headers = $ this ->headerSelector ->selectHeadersForMultipart (
286
- ['application/json ' ]
287
- );
288
- } else {
289
- $ headers = $ this ->headerSelector ->selectHeaders (
290
- ['application/json ' ],
291
- []
292
- );
293
- }
301
+ $ queryParams = array_merge ($ queryParams , ObjectSerializer::toQueryValue (
302
+ $ id ,
303
+ 'id ' , // param base name
304
+ 'string ' , // openApiType
305
+ '' , // style
306
+ false , // explode
307
+ true // required
308
+ ) ?? []);
309
+
310
+ $ headers = $ this ->headerSelector ->selectHeaders (
311
+ ['application/json ' ],
312
+ $ contentType ,
313
+ $ multipart
314
+ );
294
315
295
316
// for model (json/xml)
296
317
if (\count ($ formParams ) > 0 ) {
@@ -307,16 +328,17 @@ public function getInfoRequest($id): Request
307
328
}
308
329
// for HTTP post (form)
309
330
$ httpBody = new MultipartStream ($ multipartContents );
310
- } elseif ($ headers ['Content-Type ' ] === 'application/json ' ) {
311
- $ httpBody = \GuzzleHttp \json_encode ($ formParams );
331
+ } elseif (mb_stripos ($ headers ['Content-Type ' ], 'application/json ' ) !== false ) {
332
+ // if Content-Type contains "application/json", json_encode the form parameters
333
+ $ httpBody = \GuzzleHttp \Utils::jsonEncode ($ formParams );
312
334
} else {
313
335
// for HTTP post (form)
314
- $ httpBody = \ GuzzleHttp \ Psr7 \build_query ($ formParams );
336
+ $ httpBody = ObjectSerializer:: buildQuery ($ formParams );
315
337
}
316
338
}
317
339
318
340
// this endpoint requires OAuth (access token)
319
- if ($ this ->config ->getAccessToken () !== null ) {
341
+ if (! empty ( $ this ->config ->getAccessToken ()) ) {
320
342
$ headers ['Authorization ' ] = 'Bearer ' .$ this ->config ->getAccessToken ();
321
343
}
322
344
@@ -331,11 +353,12 @@ public function getInfoRequest($id): Request
331
353
$ headers
332
354
);
333
355
334
- $ query = \GuzzleHttp \Psr7 \build_query ($ queryParams );
356
+ $ operationHost = $ this ->config ->getHost ();
357
+ $ query = ObjectSerializer::buildQuery ($ queryParams );
335
358
336
359
return new Request (
337
360
'GET ' ,
338
- $ this -> config -> getHost () .$ resourcePath .($ query ? "? {$ query }" : '' ),
361
+ $ operationHost .$ resourcePath .($ query ? "? {$ query }" : '' ),
339
362
$ headers ,
340
363
$ httpBody
341
364
);
0 commit comments