1 | <?php |
||
5 | class Request |
||
6 | { |
||
7 | protected $method; |
||
8 | protected $apiKey; |
||
9 | protected $options; |
||
10 | protected $secure; |
||
11 | |||
12 | /** |
||
13 | * Methods that require Binary transfer |
||
14 | */ |
||
15 | protected $binaryMethods = [ |
||
16 | 'viddler.videos.setThumbnail' |
||
17 | ]; |
||
18 | |||
19 | /** |
||
20 | * Methods that require HTTPS |
||
21 | */ |
||
22 | protected $secureMethods = [ |
||
23 | 'viddler.users.auth', |
||
24 | 'viddler.users.register' |
||
25 | ]; |
||
26 | |||
27 | /** |
||
28 | * Methods that require POST |
||
29 | */ |
||
30 | protected $postMethods = [ |
||
31 | 'viddler.encoding.cancel', |
||
32 | 'viddler.encoding.encode', |
||
33 | 'viddler.encoding.setOptions', |
||
34 | 'viddler.encoding.setSettings', |
||
35 | 'viddler.logins.add', |
||
36 | 'viddler.logins.delete', |
||
37 | 'viddler.logins.update', |
||
38 | 'viddler.playlists.addVideo', |
||
39 | 'viddler.playlists.create', |
||
40 | 'viddler.playlists.delete', |
||
41 | 'viddler.playlists.moveVideo', |
||
42 | 'viddler.playlists.removeVideo', |
||
43 | 'viddler.playslists.setDetails', |
||
44 | 'viddler.resellers.removeSubaccount', |
||
45 | 'viddler.users.register', |
||
46 | 'viddler.users.setSettings', |
||
47 | 'viddler.users.setProfile', |
||
48 | 'viddler.users.setOptions', |
||
49 | 'viddler.users.setPlayerBranding', |
||
50 | 'viddler.videos.addClosedCaptioning', |
||
51 | 'viddler.videos.comments.add', |
||
52 | 'viddler.videos.comments.remove', |
||
53 | 'viddler.videos.delClosedCaptioning', |
||
54 | 'viddler.videos.delete', |
||
55 | 'viddler.videos.delFile', |
||
56 | 'viddler.videos.disableAds', |
||
57 | 'viddler.videos.enableAds', |
||
58 | 'viddler.videos.favorite', |
||
59 | 'viddler.videos.setClosedCaptioning', |
||
60 | 'viddler.videos.setDetails', |
||
61 | 'viddler.videos.setPermalink', |
||
62 | 'viddler.videos.setThumbnail', |
||
63 | ]; |
||
64 | |||
65 | /** |
||
66 | * A Mapping of what Exception to throw when Viddler returns a certain error code |
||
67 | */ |
||
68 | protected $exceptions = [ |
||
69 | "203" => Exceptions\ViddlerUploadingDisabledException::class, |
||
70 | "202" => Exceptions\ViddlerInvalidFormTypeException::class, |
||
71 | "200" => Exceptions\ViddlerSizeLimitExceededException::class, |
||
72 | "105" => Exceptions\ViddlerUsernameExistsException::class, |
||
73 | "104" => Exceptions\ViddlerTermsNotAcceptedException::class, |
||
74 | "103" => Exceptions\ViddlerInvalidPasswordException::class, |
||
75 | "102" => Exceptions\ViddlerAccountSuspendedException::class, |
||
76 | "101" => Exceptions\ViddlerForbiddenException::class, |
||
77 | "100" => Exceptions\ViddlerNotFoundException::class, |
||
78 | "8" => Exceptions\ViddlerInvalidApiKeyException::class, |
||
79 | "default" => Exceptions\ViddlerException::class |
||
80 | ]; |
||
81 | |||
82 | 15 | public function __construct($apiKey, $method, $options, $secure = false) |
|
89 | |||
90 | /** |
||
91 | * Constructs the Request requirements and then sends the Request returning the response |
||
92 | */ |
||
93 | 6 | public function execute() |
|
104 | |||
105 | /** |
||
106 | * Sends the actual curl request |
||
107 | */ |
||
108 | protected function sendRequest($url, $params) |
||
145 | |||
146 | /** |
||
147 | * Builds the query object from the options property |
||
148 | */ |
||
149 | 6 | protected function getParams() |
|
161 | |||
162 | /** |
||
163 | * Builds the URL for the request |
||
164 | */ |
||
165 | 6 | protected function getUrl($params) |
|
180 | |||
181 | /** |
||
182 | * Returns the binary arguments for the request |
||
183 | */ |
||
184 | 3 | protected function getBinaryArgs() |
|
201 | |||
202 | /** |
||
203 | * Throws an Exception if the response contains an error |
||
204 | */ |
||
205 | 6 | protected function checkResponseForErrors($response) |
|
229 | |||
230 | /** |
||
231 | * Checks if the method should be run as a POST |
||
232 | */ |
||
233 | 6 | protected function isPost() |
|
237 | |||
238 | /** |
||
239 | * Checks if the method is a binary method |
||
240 | */ |
||
241 | protected function isBinary() |
||
245 | |||
246 | /** |
||
247 | * Returns the correct protocol for the provided method |
||
248 | */ |
||
249 | 6 | protected function getProtocol() |
|
253 | } |
||
254 |