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