forked from nickbart/php-plex
-
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.
First set of files. This is just a bootstrap file and machine definit…
…ions. It won't do anything useful except allow you to register servers and clients.
- Loading branch information
Showing
7 changed files
with
767 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,199 @@ | ||
<?php | ||
|
||
/** | ||
* Plex Client | ||
* | ||
* @category php-plex | ||
* @package Plex_Client | ||
* @author <[email protected]> Nick Bartkowiak | ||
* @copyright (c) 2012 Nick Bartkowiak | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU Public Licence (GPLv3) | ||
* @version 0.0.1 | ||
* | ||
* This file is part of php-plex. | ||
* | ||
* php-plex is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* php-plex is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
/** | ||
* Represents a Plex client on the network. | ||
* | ||
* @category php-plex | ||
* @package Plex_Client | ||
* @author <[email protected]> Nick Bartkowiak | ||
* @copyright (c) 2012 Nick Bartkowiak | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU Public Licence (GPLv3) | ||
* @version 0.0.1 | ||
*/ | ||
class Plex_Client extends Plex_MachineAbstract | ||
{ | ||
/** | ||
* Plex client host as returned by Plex_Server::getClients(). | ||
* @var string | ||
*/ | ||
private $host; | ||
|
||
/** | ||
* Plex client machine identifier as returned by Plex_Server::getClients(). | ||
* @var string | ||
*/ | ||
private $machineIdentifier; | ||
|
||
/** | ||
* Version of Plex the client is running as returned by | ||
* Plex_Server::getClients(). | ||
* @var string | ||
*/ | ||
private $version; | ||
|
||
/** | ||
* The default port on which a Plex client listens. | ||
*/ | ||
const DEFAULT_PORT = 3000; | ||
|
||
/** | ||
* Sets up our Plex client using the minimum amount of data required to | ||
* interact. | ||
* | ||
* @param string $name The name of the Plex client. | ||
* @param string $address The IP address of the Plex client. | ||
* @param integer $port The port on which the Plex client is listening. | ||
* | ||
* @uses Plex_MachineAbstract::$name | ||
* @uses Plex_MachineAbstract::$address | ||
* @uses Plex_MachineAbstract::$port | ||
* @uses Plex_Client::DEFAULT_PORT | ||
* | ||
* @return void | ||
*/ | ||
public function __construct($name, $address, $port) | ||
{ | ||
$this->name = $name; | ||
$this->address = $address; | ||
$this->port = $port ? $port : self::DEFAULT_PORT; | ||
} | ||
|
||
/** | ||
* Returns the Plex client's name. | ||
* | ||
* @uses Plex_MachineAbstract::$name | ||
* | ||
* @return string The name of the Plex client. | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* Returns the Plex client's IP address. | ||
* | ||
* @uses Plex_MachineAbstract::$address | ||
* | ||
* @return string The IP address of the Plex client. | ||
*/ | ||
public function getAddress() | ||
{ | ||
return $this->address; | ||
} | ||
|
||
/** | ||
* Returns the port on which the Plex client listens. | ||
* | ||
* @uses Plex_MachineAbstract::$port | ||
* | ||
* @return integer The port on which the Plex client listens. | ||
*/ | ||
public function getPort() | ||
{ | ||
return $this->port; | ||
} | ||
|
||
/** | ||
* Returns the hostname of the Plex client. | ||
* | ||
* @uses Plex_Client::$host | ||
* | ||
* @return string The hostname of the Plex client. | ||
*/ | ||
public function getHost() | ||
{ | ||
return $this->host; | ||
} | ||
|
||
/** | ||
* Sets the hostname of the Plex client. | ||
* | ||
* @param string $host The hostname of the Plex client. | ||
* | ||
* @uses Plex_client::$host | ||
* | ||
* @return void | ||
*/ | ||
public function setHost($host) | ||
{ | ||
$this->host = $host; | ||
} | ||
|
||
/** | ||
* Returns the mac address of the Plex client. | ||
* | ||
* @uses Plex_Client::$machineIdentifier | ||
* | ||
* @return string The mac address of the Plex client. | ||
*/ | ||
public function getMachineIdentifier() | ||
{ | ||
return $this->machineIdentifier; | ||
} | ||
|
||
/** | ||
* Sets the mac address of the Plex client. | ||
* | ||
* @param string $machineIdentifier The macc address of the Plex client. | ||
* | ||
* @uses Plex_Client::$machineIdentifier | ||
* | ||
* @return void | ||
*/ | ||
public function setMachineIdentifier($machineIdentifier) | ||
{ | ||
$this->machineIdentifier = $machineIdentifier; | ||
} | ||
|
||
/** | ||
* Returns the version of the Plex software the Plex client is running. | ||
* | ||
* @uses Plex_Client::$version | ||
* | ||
* @return string The version of the Plex software the Plex client is | ||
* running. | ||
*/ | ||
public function getVersion() | ||
{ | ||
return $this->version; | ||
} | ||
|
||
/** | ||
* Sets the version of the Plex software the Plex client is running. | ||
* | ||
* @param string $version The version of the Plex software teh Plex client | ||
* is running. | ||
* | ||
* @uses Plex_Client::$version | ||
* | ||
* @return void | ||
*/ | ||
public function setVersion($version) | ||
{ | ||
$this->version = $version; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?php | ||
|
||
/** | ||
* Plex Machine | ||
* | ||
* @category php-plex | ||
* @package Plex_Machine | ||
* @author <[email protected]> Nick Bartkowiak | ||
* @copyright (c) 2012 Nick Bartkowiak | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU Public Licence (GPLv3) | ||
* @version 0.0.1 | ||
* | ||
* This file is part of php-plex. | ||
* | ||
* php-plex is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* php-plex is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
/** | ||
* Abstract base class containing methods and members for all Plex machines on | ||
* the network. This is used to define both Plex clients and servers. | ||
* | ||
* @category php-plex | ||
* @package Plex_Machine | ||
* @author <[email protected]> Nick Bartkowiak | ||
* @copyright (c) 2012 Nick Bartkowiak | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU Public Licence (GPLv3) | ||
* @version 0.0.1 | ||
*/ | ||
abstract class Plex_MachineAbstract implements Plex_MachineInterface | ||
{ | ||
/** | ||
* The name of the Plex machine on the network. | ||
* @var string | ||
*/ | ||
protected $name; | ||
|
||
/** | ||
* The IP address of the Plex machine on the network. | ||
* @var string | ||
*/ | ||
protected $address; | ||
|
||
/** | ||
* The port on which the Plex machine is listening. Typically 32400 for | ||
* servers and 3000 for clients. | ||
* @var integer | ||
*/ | ||
protected $port; | ||
|
||
/** | ||
* Returns the base URL, which will be standard for all requests made to the | ||
* Plex machine. | ||
* | ||
* @uses Plex_MachineAbstract::$address | ||
* @uses Plex_MachineAbstract::$port | ||
* | ||
* @return string The base URL, which will be standard for all requests made | ||
* to the Plex machine. | ||
*/ | ||
protected function getBaseUrl() | ||
{ | ||
return sprintf( | ||
'http://%s:%s', | ||
$this->address, | ||
$this->port | ||
); | ||
} | ||
|
||
/** | ||
* Typically the useful data returned by a Plex machine will containted in | ||
* XML attributes. This allows a set of XML nodes to be passed and all the | ||
* attribues extracted and returned as an associated array. | ||
* | ||
* @param SimpleXMLElement $xmlNodes An XML node to have its attributes | ||
* converted to a useful PHP array. | ||
* | ||
* @todo Make this recursive. | ||
* | ||
* @return array An associated array of XML attributes. | ||
*/ | ||
protected function xmlAttributesToArray($xmlNodes) | ||
{ | ||
$array = array(); | ||
$i= 0;; | ||
foreach($xmlNodes as $xmlNode) { | ||
foreach($xmlNode->attributes() as $key => $value) { | ||
// For abstraction, everything is casted to string. It is the | ||
// responsibility of the calling method to handle typing. | ||
$array[$i][$key] = (string) $value[0]; | ||
} | ||
$i++; | ||
} | ||
return $array; | ||
} | ||
|
||
/** | ||
* Utilizes php-curl to send a request to the passed URL and returns an XML | ||
* document reprentation of the returned content. | ||
* | ||
* @param string $url The URL to which the request is to be made. | ||
* | ||
* @return SimpleXMLElement An XML document from a Plex machine. | ||
*/ | ||
protected function makeCall($url) | ||
{ | ||
$ch = curl_init(); | ||
|
||
curl_setopt($ch, CURLOPT_URL, $url); | ||
curl_setopt($ch, CURLOPT_HEADER, FALSE); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | ||
|
||
$response = curl_exec($ch); | ||
|
||
curl_close($ch); | ||
|
||
return simplexml_load_string($response); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
/** | ||
* Plex Machine | ||
* | ||
* @category php-plex | ||
* @package Plex_Machine | ||
* @author <[email protected]> Nick Bartkowiak | ||
* @copyright (c) 2012 Nick Bartkowiak | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU Public Licence (GPLv3) | ||
* @version 0.0.1 | ||
* | ||
* This file is part of php-plex. | ||
* | ||
* php-plex is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* php-plex is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
/** | ||
* Interface that defines the structure of Plex machines. | ||
* | ||
* @category php-plex | ||
* @package Plex_Machine | ||
* @author <[email protected]> Nick Bartkowiak | ||
* @copyright (c) 2012 Nick Bartkowiak | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU Public Licence (GPLv3) | ||
* @version 0.0.1 | ||
*/ | ||
interface Plex_MachineInterface | ||
{ | ||
/** | ||
* Returns the name of the Plex machine. | ||
* | ||
* @return string The name of the Plex machine. | ||
*/ | ||
public function getName(); | ||
|
||
/** | ||
* Returns the IP address of the Plex machine. | ||
* | ||
* @return string The IP address of the Plex machine. | ||
*/ | ||
public function getAddress(); | ||
|
||
/** | ||
* Returns the port on which the Plex machine listens. | ||
* | ||
* @return integer The port on which the Plex machine listens. | ||
*/ | ||
public function getPort(); | ||
} |
Oops, something went wrong.