1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ApiVideo\Client\Api; |
4
|
|
|
|
5
|
|
|
use ApiVideo\Client\Buzz\OAuthBrowser; |
6
|
|
|
use ApiVideo\Client\Model\Account as AccountModel; |
7
|
|
|
use ApiVideo\Client\Model\Analytic\PlayerSession; |
8
|
|
|
use ApiVideo\Client\Model\Caption; |
9
|
|
|
use ApiVideo\Client\Model\Chapter; |
10
|
|
|
use ApiVideo\Client\Model\Live; |
11
|
|
|
use ApiVideo\Client\Model\Player; |
12
|
|
|
use ApiVideo\Client\Model\Video; |
13
|
|
|
use Buzz\Message\MessageInterface; |
14
|
|
|
use Buzz\Message\Response; |
15
|
|
|
|
16
|
|
|
abstract class BaseApi |
17
|
|
|
{ |
18
|
|
|
/** @var array */ |
19
|
|
|
private $lastError; |
20
|
|
|
|
21
|
|
|
/** @var OAuthBrowser */ |
22
|
|
|
protected $browser; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param OAuthBrowser $browser |
26
|
|
|
*/ |
27
|
|
|
public function __construct(OAuthBrowser $browser) |
28
|
|
|
{ |
29
|
|
|
$this->browser = $browser; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function getLastError() |
33
|
|
|
{ |
34
|
|
|
return $this->lastError; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getBrowser() |
38
|
|
|
{ |
39
|
|
|
return $this->browser; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
protected function registerLastError(Response $response) |
43
|
|
|
{ |
44
|
|
|
$this->lastError = array( |
45
|
|
|
'status' => $response->getStatusCode(), |
46
|
|
|
'message' => json_decode($response->getContent(), true), |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param MessageInterface $message |
52
|
|
|
* @return Caption|Chapter|Player|Video|Live|PlayerSession|AccountModel |
53
|
|
|
*/ |
54
|
|
|
protected function unmarshal(MessageInterface $message) |
55
|
|
|
{ |
56
|
|
|
return $this->cast(json_decode($message->getContent(), true)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param array $collection |
61
|
|
|
* @return Caption[]|Chapter[]|Players[]|Video[]|Live[]|PlayerSession[] |
62
|
|
|
*/ |
63
|
|
|
protected function castAll(array $collection) |
64
|
|
|
{ |
65
|
|
|
return array_map(array($this, 'cast'), $collection); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
abstract protected function cast(array $data); |
69
|
|
|
} |
70
|
|
|
|