1 | <?php |
||
29 | class Vimeo extends AbstractService |
||
30 | { |
||
31 | // API version |
||
32 | const VERSION = '3.2'; |
||
33 | // API Header Accept |
||
34 | const HEADER_ACCEPT = 'application/vnd.vimeo.*+json;version=3.2'; |
||
35 | |||
36 | /** |
||
37 | * Scopes |
||
38 | * @see https://developer.vimeo.com/api/authentication#scope |
||
39 | */ |
||
40 | // View public videos |
||
41 | const SCOPE_PUBLIC = 'public'; |
||
42 | // View private videos |
||
43 | const SCOPE_PRIVATE = 'private'; |
||
44 | // View Vimeo On Demand purchase history |
||
45 | const SCOPE_PURCHASED = 'purchased'; |
||
46 | // Create new videos, groups, albums, etc. |
||
47 | const SCOPE_CREATE = 'create'; |
||
48 | // Edit videos, groups, albums, etc. |
||
49 | const SCOPE_EDIT = 'edit'; |
||
50 | // Delete videos, groups, albums, etc. |
||
51 | const SCOPE_DELETE = 'delete'; |
||
52 | // Interact with a video on behalf of a user, such as liking |
||
53 | // a video or adding it to your watch later queue |
||
54 | const SCOPE_INTERACT = 'interact'; |
||
55 | // Upload a video |
||
56 | const SCOPE_UPLOAD = 'upload'; |
||
57 | |||
58 | public function __construct( |
||
59 | CredentialsInterface $credentials, |
||
60 | ClientInterface $httpClient, |
||
61 | TokenStorageInterface $storage, |
||
62 | $scopes = array(), |
||
63 | UriInterface $baseApiUri = null |
||
64 | ) { |
||
65 | parent::__construct( |
||
66 | $credentials, |
||
67 | $httpClient, |
||
68 | $storage, |
||
69 | $scopes, |
||
70 | $baseApiUri, |
||
71 | true |
||
72 | ); |
||
73 | |||
74 | if (null === $baseApiUri) { |
||
75 | $this->baseApiUri = new Uri('https://api.vimeo.com/'); |
||
76 | } |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | public function getAuthorizationEndpoint() |
||
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | public function getAccessTokenEndpoint() |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | protected function getAuthorizationMethod() |
||
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | protected function parseAccessTokenResponse($responseBody) |
||
107 | { |
||
108 | $data = json_decode($responseBody, true); |
||
109 | |||
110 | if (null === $data || !is_array($data)) { |
||
111 | throw new TokenResponseException('Unable to parse response.'); |
||
112 | } elseif (isset($data['error_description'])) { |
||
113 | throw new TokenResponseException( |
||
114 | 'Error in retrieving token: "' . $data['error_description'] . '"' |
||
115 | ); |
||
116 | } elseif (isset($data['error'])) { |
||
117 | throw new TokenResponseException( |
||
118 | 'Error in retrieving token: "' . $data['error'] . '"' |
||
119 | ); |
||
120 | } |
||
121 | |||
122 | $token = new StdOAuth2Token(); |
||
123 | $token->setAccessToken($data['access_token']); |
||
124 | |||
125 | if (isset($data['expires_in'])) { |
||
126 | $token->setLifeTime($data['expires_in']); |
||
127 | unset($data['expires_in']); |
||
128 | } |
||
129 | if (isset($data['refresh_token'])) { |
||
130 | $token->setRefreshToken($data['refresh_token']); |
||
131 | unset($data['refresh_token']); |
||
132 | } |
||
133 | |||
134 | unset($data['access_token']); |
||
135 | |||
136 | $token->setExtraParams($data); |
||
137 | |||
138 | return $token; |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * {@inheritdoc} |
||
143 | */ |
||
144 | protected function getExtraOAuthHeaders() |
||
148 | |||
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | */ |
||
152 | protected function getExtraApiHeaders() |
||
156 | } |
||
157 |