This repository has been archived by the owner on Jun 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
14 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,7 @@ | |
* @author <[email protected]> Nick Bartkowiak | ||
* @copyright (c) 2013 Nick Bartkowiak | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU Public Licence (GPLv3) | ||
* @version 0.0.2.5 | ||
* @version 0.0.2.6 | ||
*/ | ||
class Plex | ||
{ | ||
|
@@ -206,12 +206,16 @@ public function getClient($clientName) | |
/** | ||
* Returns the token of the sesion plex | ||
* | ||
* @author <[email protected]> José Erick Carreón | ||
* | ||
* @param string $username The username of the Plex server account. | ||
* @param string $password The password of the Plex server account. | ||
* | ||
* @uses Plex::$registerServers() | ||
* | ||
* @return string The token Plex account. | ||
* | ||
* @throws Plex_Exception_Server() Server token not obtained. | ||
*/ | ||
public function getToken($username, $password) { | ||
$host = "https://plex.tv/users/sign_in.json"; | ||
|
@@ -230,8 +234,14 @@ public function getToken($username, $password) { | |
curl_setopt($process, CURLOPT_POST, 1); | ||
curl_setopt($process, CURLOPT_RETURNTRANSFER, true); | ||
$data = curl_exec($process); | ||
$curlError = curl_error($process); | ||
$json = json_decode($data, true); | ||
return $json['user']['authentication_token']; | ||
if ($data === FALSE) { | ||
throw new Plex_Exception_Machine( | ||
'CURL_ERROR', | ||
array(curl_errno($data), curl_error($data)) | ||
); | ||
} | ||
curl_close($process); | ||
|
||
return json_decode($data, true)['user']['authentication_token']; | ||
} | ||
} |