|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MovingImage\Client\VMPro\ApiClient; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\Message\Response; |
|
6
|
|
|
use MovingImage\Client\VMPro\ApiClient; |
|
7
|
|
|
use MovingImage\Client\VMPro\Interfaces\ApiClientInterface; |
|
8
|
|
|
use GuzzleHttp\Message\ResponseInterface; |
|
9
|
|
|
use MovingImage\Client\VMPro\Exception; |
|
10
|
|
|
use GuzzleHttp\Stream\Stream; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class Guzzle5ApiClient. |
|
14
|
|
|
* |
|
15
|
|
|
* @author Ruben Knol <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
class Guzzle5ApiClient extends ApiClient implements ApiClientInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Guzzle5 Client implementation for making HTTP requests with |
|
21
|
|
|
* the appropriate options. |
|
22
|
|
|
* |
|
23
|
|
|
* @param string $method |
|
24
|
|
|
* @param string $uri |
|
25
|
|
|
* @param array $options |
|
26
|
|
|
* |
|
27
|
|
|
* @return \GuzzleHttp\Message\ResponseInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
protected function _doRequest($method, $uri, $options) |
|
30
|
|
|
{ |
|
31
|
|
|
// For Guzzle5 we cannot have any options that are not pre-defined, |
|
32
|
|
|
// so instead we put it in the config array |
|
33
|
|
|
$options['config'][self::OPT_VIDEO_MANAGER_ID] = $options[self::OPT_VIDEO_MANAGER_ID]; |
|
34
|
|
|
unset($options[self::OPT_VIDEO_MANAGER_ID]); |
|
35
|
|
|
|
|
36
|
|
|
$request = $this->httpClient->createRequest($method, $uri, $options); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
return $this->httpClient->send($request); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritdoc} |
|
43
|
|
|
* |
|
44
|
|
|
* @param ResponseInterface $response |
|
45
|
|
|
* |
|
46
|
|
|
* @return string |
|
47
|
|
|
*/ |
|
48
|
|
View Code Duplication |
protected function serializeResponse($response) |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
|
|
/** @var ResponseInterface $response */ |
|
51
|
|
|
$serialized = serialize([ |
|
52
|
|
|
$response->getStatusCode(), |
|
53
|
|
|
$response->getHeaders(), |
|
54
|
|
|
$response->getBody()->getContents(), |
|
55
|
|
|
]); |
|
56
|
|
|
|
|
57
|
|
|
//subsequent calls need to access the stream from the beginning |
|
58
|
|
|
$response->getBody()->seek(0); |
|
59
|
|
|
|
|
60
|
|
|
return $serialized; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Unserializes the serialized response into a ResponseInterface instance. |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $serialized |
|
67
|
|
|
* |
|
68
|
|
|
* @return ResponseInterface |
|
69
|
|
|
* |
|
70
|
|
|
* @throws Exception |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function unserializeResponse($serialized) |
|
73
|
|
|
{ |
|
74
|
|
|
$array = unserialize($serialized); |
|
75
|
|
|
if (!is_array($array) || count($array) !== 3) { |
|
76
|
|
|
throw new Exception(sprintf('Error unserializing response: %s', $serialized)); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return new Response($array[0], $array[1], Stream::factory($array[2])); |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.