get pins
This commit is contained in:
parent
85c6a8509a
commit
29e3563555
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
class PlexAuthenticator {
|
||||
// Product Name. Shown when loggin in
|
||||
private $plexProduct;
|
||||
// Client ID, this should be a UUID, we can randomly generate one
|
||||
private $clientID;
|
||||
// The token we get back
|
||||
private $token;
|
||||
|
||||
private $id;
|
||||
private $code;
|
||||
|
||||
public static function makeNewClient(String $productName){
|
||||
return new PlexAuthenticator($productName, uniqid());
|
||||
}
|
||||
|
||||
public static function makeNewClientWithId(String $productName, String $clientName){
|
||||
return new PlexAuthenticator($productName, $clientName);
|
||||
}
|
||||
|
||||
private function __construct(String $productName, String $clientName) {
|
||||
$this->clientID = $clientName;
|
||||
$this->plexProduct = $productName;
|
||||
}
|
||||
|
||||
private function getPins() {
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, "https://plex.tv/api/v2/pins");
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
$headers = array("Content-Type: application/x-www-form-urlencoded", "accept: application/json");
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
$data = "strong=true&X-Plex-Product=" . $this->plexProduct . "&X-Plex-Client-Identifier=" . $this->clientID;
|
||||
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
|
||||
$resp = curl_exec($curl);
|
||||
|
||||
$returnCode = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
if($returnCode != 201)
|
||||
return false;
|
||||
|
||||
return $resp;
|
||||
}
|
||||
|
||||
public function getURL(){
|
||||
|
||||
$pinJSON = $this->getPins();
|
||||
if(!$pinJSON){
|
||||
return false;
|
||||
}
|
||||
|
||||
$parsedPinJSON = json_decode($pinJSON,true);
|
||||
$this->id = parsedPinJSON["id"];
|
||||
$this->code = parsedPinJSON["code"];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
Reference in New Issue