1 | <?php |
||
17 | abstract class AbstractCoreApiClient implements LoggerAwareInterface |
||
18 | { |
||
19 | use LoggerAwareTrait; |
||
20 | |||
21 | /** |
||
22 | * @const string |
||
23 | */ |
||
24 | const OPT_VIDEO_MANAGER_ID = 'videoManagerId'; |
||
25 | |||
26 | /** |
||
27 | * @var ClientInterface The Guzzle HTTP client |
||
28 | */ |
||
29 | protected $httpClient; |
||
30 | |||
31 | /** |
||
32 | * @var Serializer The JMS Serializer instance |
||
33 | */ |
||
34 | protected $serializer; |
||
35 | |||
36 | /** |
||
37 | * ApiClient constructor. |
||
38 | * |
||
39 | * @param ClientInterface $httpClient |
||
40 | * @param Serializer $serializer |
||
41 | */ |
||
42 | 90 | public function __construct( |
|
49 | |||
50 | /** |
||
51 | * Perform the actual request in the implementation classes. |
||
52 | * |
||
53 | * @param string $method |
||
54 | * @param string $uri |
||
55 | * @param array $options |
||
56 | * |
||
57 | * @return mixed |
||
58 | */ |
||
59 | abstract protected function _doRequest($method, $uri, $options); |
||
60 | |||
61 | /** |
||
62 | * Make a request to the API and serialize the result according to our |
||
63 | * serialization strategy. |
||
64 | * |
||
65 | * @param string $method |
||
66 | * @param string $uri |
||
67 | * @param array $options |
||
68 | * |
||
69 | * @return object|ResponseInterface |
||
70 | */ |
||
71 | 48 | protected function makeRequest($method, $uri, $options) |
|
94 | |||
95 | /** |
||
96 | * Deserialize a response into an instance of it's associated class. |
||
97 | * |
||
98 | * @param string $data |
||
99 | * @param string $serialisationClass |
||
100 | * |
||
101 | * @return object |
||
102 | */ |
||
103 | 12 | protected function deserialize($data, $serialisationClass) |
|
107 | |||
108 | /** |
||
109 | * Helper method to build the JSON data array for making a request |
||
110 | * with ::makeRequest(). Optional parameters with empty or null value will be |
||
111 | * omitted from the return value. |
||
112 | * |
||
113 | * Examples: |
||
114 | * |
||
115 | * $this->buildJsonParameters(['title' => 'test'], ['description' => '', 'bla' => 'test']) |
||
116 | * |
||
117 | * Would result in: |
||
118 | * |
||
119 | * [ |
||
120 | * 'title' => 'test', |
||
121 | * 'bla' => 'test', |
||
122 | * ] |
||
123 | * |
||
124 | * @param array $required |
||
125 | * @param array $optional |
||
126 | * |
||
127 | * @return array |
||
128 | */ |
||
129 | 48 | protected function buildJsonParameters(array $required, array $optional) |
|
147 | } |
||
148 |