|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Rutube PHP API Client package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Rutube |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Rutube\Transports; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Низкоуровневое обращение к API |
|
16
|
|
|
* |
|
17
|
|
|
* @package Rutube\Transports |
|
18
|
|
|
*/ |
|
19
|
|
|
class DefaultTransport extends Transport |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @param string $username |
|
23
|
|
|
* @param string $password |
|
24
|
|
|
* @return $this |
|
25
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
26
|
|
|
*/ |
|
27
|
|
|
public function authorize($username, $password) |
|
28
|
|
|
{ |
|
29
|
|
|
$response = $this->call( |
|
30
|
|
|
'POST', |
|
31
|
|
|
'api/accounts/token_auth/', |
|
32
|
|
|
array('username' => $username, 'password' => $password) |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
$this->token = $response->token; |
|
36
|
|
|
|
|
37
|
|
|
return $this; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param array $query |
|
42
|
|
|
* @return mixed |
|
43
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
44
|
|
|
*/ |
|
45
|
|
|
public function loadVideoPerson(array $query) |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->call('GET', 'api/video/person/', array(), $query); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param int $id |
|
52
|
|
|
* @param array $query |
|
53
|
|
|
* @return mixed |
|
54
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
55
|
|
|
*/ |
|
56
|
|
|
public function loadVideoPersonById($id, array $query) |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->call('GET', 'api/video/person/' . $id . '/', array(), $query); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return mixed |
|
63
|
|
|
* @param array $query |
|
64
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
65
|
|
|
*/ |
|
66
|
|
|
public function loadTags(array $query) |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->call('GET', 'api/tags/', array(), $query); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param int $id |
|
73
|
|
|
* @param array $query |
|
74
|
|
|
* @return mixed |
|
75
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
76
|
|
|
*/ |
|
77
|
|
|
public function loadVideoTags($id, array $query) |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->call('GET', 'api/tags/video/' . $id . '/', array(), $query); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param array $query |
|
84
|
|
|
* @return mixed |
|
85
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
86
|
|
|
*/ |
|
87
|
|
|
public function loadMetainfoTv(array $query) |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->call('GET', 'api/metainfo/tv/', array(), $query); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param string $id |
|
94
|
|
|
* @return mixed |
|
95
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
96
|
|
|
*/ |
|
97
|
|
|
public function loadMetainfoTvContentTypes($id) |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->call('GET', 'api/metainfo/tv/' . $id . '/contenttvstype/'); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param string $id |
|
105
|
|
|
* @return mixed |
|
106
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
107
|
|
|
*/ |
|
108
|
|
|
public function loadMetainfoTvSeasons($id) |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->call('GET', 'api/metainfo/tv/' . $id . '/season/'); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @param string $id |
|
115
|
|
|
* @param array $query |
|
116
|
|
|
* @return mixed |
|
117
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
118
|
|
|
*/ |
|
119
|
|
|
public function loadMetainfoTvVideos($id, array $query) |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->call('GET', 'api/metainfo/tv/' . $id . '/video/', array(), $query); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @param string $id |
|
126
|
|
|
* @param array $query |
|
127
|
|
|
* @return mixed |
|
128
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
129
|
|
|
*/ |
|
130
|
|
|
public function loadMetainfoTvLastEpisode($id, $query) |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->call('GET', 'api/metainfo/tv/' . $id . '/last_episode/', array(), $query); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @param string $id |
|
137
|
|
|
* @return mixed |
|
138
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
139
|
|
|
*/ |
|
140
|
|
|
public function loadMetainfoContenttvs($id) |
|
141
|
|
|
{ |
|
142
|
|
|
return $this->call('GET', 'api/metainfo/contenttvs/' . $id . '/'); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @param string $id |
|
147
|
|
|
* @param array $query |
|
148
|
|
|
* @return mixed |
|
149
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
150
|
|
|
*/ |
|
151
|
|
|
public function getVideoPlayOptions($id, array $query) |
|
152
|
|
|
{ |
|
153
|
|
|
return $this->call('GET', 'api/play/options/' . $id . '/', array(), $query); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @param array $params |
|
158
|
|
|
* @return mixed |
|
159
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
160
|
|
|
*/ |
|
161
|
|
|
public function uploadVideo(array $params) |
|
162
|
|
|
{ |
|
163
|
|
|
return $this->call('POST', 'api/video/', $params); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @param string $id |
|
168
|
|
|
* @return bool |
|
169
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
170
|
|
|
*/ |
|
171
|
|
|
public function deleteVideo($id) |
|
172
|
|
|
{ |
|
173
|
|
|
return $this->call('DELETE', 'api/video/' . $id, array(), array(), array(), true) == 204; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @param string $id |
|
178
|
|
|
* @param array $params |
|
179
|
|
|
* @return mixed |
|
180
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
181
|
|
|
*/ |
|
182
|
|
|
public function putVideo($id, $params) |
|
183
|
|
|
{ |
|
184
|
|
|
return $this->call('PUT', 'api/video/' . $id . '/', $params); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @param string $id |
|
189
|
|
|
* @return mixed |
|
190
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
191
|
|
|
*/ |
|
192
|
|
|
public function getVideo($id) |
|
193
|
|
|
{ |
|
194
|
|
|
return $this->call('GET', 'api/video/' . $id . '/'); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* @param string $id |
|
199
|
|
|
* @param array $params |
|
200
|
|
|
* @return mixed |
|
201
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
202
|
|
|
*/ |
|
203
|
|
|
public function patchVideo($id, $params) |
|
204
|
|
|
{ |
|
205
|
|
|
return $this->call('PATCH', 'api/video/' . $id, $params); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* @param string $id |
|
210
|
|
|
* @param array $file |
|
211
|
|
|
* @return mixed |
|
212
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
213
|
|
|
*/ |
|
214
|
|
|
public function addThumb($id, array $file) |
|
215
|
|
|
{ |
|
216
|
|
|
return $this->call('POST', 'api/video/' . $id . '/thumbnail/', array(), array(), $file); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @param array $params |
|
221
|
|
|
* @return mixed |
|
222
|
|
|
* @throws \Rutube\Exceptions\ConnectionErrorException |
|
223
|
|
|
*/ |
|
224
|
|
|
public function publication($params) |
|
225
|
|
|
{ |
|
226
|
|
|
return $this->call('POST', 'api/video/publication/', $params); |
|
227
|
|
|
} |
|
228
|
|
|
} |
|
229
|
|
|
|