78
78
* @author <[email protected] > Nick Bartkowiak
79
79
* @copyright (c) 2013 Nick Bartkowiak
80
80
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU Public Licence (GPLv3)
81
- * @version 0.0.2.5
81
+ * @version 0.0.2.6
82
82
*/
83
83
class Plex
84
84
{
@@ -206,12 +206,16 @@ public function getClient($clientName)
206
206
/**
207
207
* Returns the token of the sesion plex
208
208
*
209
+ * @author <[email protected] > José Erick Carreón
210
+ *
209
211
* @param string $username The username of the Plex server account.
210
212
* @param string $password The password of the Plex server account.
211
213
*
212
214
* @uses Plex::$registerServers()
213
215
*
214
216
* @return string The token Plex account.
217
+ *
218
+ * @throws Plex_Exception_Server() Server token not obtained.
215
219
*/
216
220
public function getToken ($ username , $ password ) {
217
221
$ host = "https://plex.tv/users/sign_in.json " ;
@@ -230,8 +234,14 @@ public function getToken($username, $password) {
230
234
curl_setopt ($ process , CURLOPT_POST , 1 );
231
235
curl_setopt ($ process , CURLOPT_RETURNTRANSFER , true );
232
236
$ data = curl_exec ($ process );
233
- $ curlError = curl_error ($ process );
234
- $ json = json_decode ($ data , true );
235
- return $ json ['user ' ]['authentication_token ' ];
237
+ if ($ data === FALSE ) {
238
+ throw new Plex_Exception_Machine (
239
+ 'CURL_ERROR ' ,
240
+ array (curl_errno ($ data ), curl_error ($ data ))
241
+ );
242
+ }
243
+ curl_close ($ process );
244
+
245
+ return json_decode ($ data , true )['user ' ]['authentication_token ' ];
236
246
}
237
247
}
0 commit comments