Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Commit

Permalink
Added in the application controller and altered the execute command m…
Browse files Browse the repository at this point in the history
…ethod to accept parameters.
  • Loading branch information
nickbart committed Dec 28, 2012
1 parent e0693a9 commit 7cf84bb
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 2 deletions.
101 changes: 101 additions & 0 deletions Client/Controller/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

/**
* Plex Client Application Controller
*
* @category php-plex
* @package Plex_Client
* @subpackage Plex_Client_Controller
* @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
* @subpackage Plex_Client_Controller
* @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_Controller_Application extends Plex_Client_ControllerAbstract
{
/**
* Given a Plex server library item, this method plays the given item on
* the Plex client.
*
* @param Plex_Server_Library_ItemAbstract $item The item to be played.
* @param integer $viewOffset The point from which to play the item in
* milliseconds.
*
* @uses Plex_Server_Library::ENDPOINT_LIBRARY
* @uses Plex_Server_Library::ENDPOINT_METADATA
* @uses Plex_Server_Library_ItemAbstract::getRatingKey()
* @uses Plex_Client::getServer()
* @uses Plex_Server::getBaseUrl()
* @uses Plex_Client_ControllerAbstract::executeCommand()
*
* @return void
*/
public function playMedia(
Plex_Server_Library_ItemAbstract $item,
$viewOffset = NULL
)
{
$key = sprintf(
'/%s/%s/%d',
Plex_Server_Library::ENDPOINT_LIBRARY,
Plex_Server_Library::ENDPOINT_METADATA,
$item->getRatingKey()
);
$params = array(
'key' => $key,
'path' => sprintf(
'%s%s',
$this->getServer()->getBaseUrl(),
$key
)
);
if ($viewOffset) {
$params['viewOffset'] = $viewOffset;
}

$this->executeCommand($params);
}

/**
* Sets the volume to the given percentage level.
*
* @param integer $level The percentage level to which teh voume is to be
* set.
*
* @uses Plex_Client_ControllerAbstract::executeCommand()
*
* @return void
*/
public function setVolume($level)
{
$params = array(
'level' => $level
);

$this->executeCommand($params);
}
}
15 changes: 13 additions & 2 deletions Client/ControllerAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,28 @@ private function buildUrl($controller, $command)
* Using the calling class and function builds and calls the URL for the
* Plex client controller command.
*
* @param array $params An array of parameters that will be used to build an
* http query string.
*
* @uses Plex_MachineAbstract::getCallingFunction()
* @uses Plex_MachineAbstract::makeCall()
* @uses Plex_Client_ControllerAbstract::buildUrl()
*
* @return void
*/
protected function executeCommand()
protected function executeCommand($params = array())
{
$controller = strtolower(array_pop(explode('_', get_class($this))));
$command = $this->getCallingFunction();
$this->makeCall($this->buildUrl($controller, $command));
$url = $this->buildUrl($controller, $command);
if (count($params) > 0) {
$url = sprintf(
'%s?%s',
$url,
http_build_query($params)
);
}
$this->makeCall($url);
}

/**
Expand Down

0 comments on commit 7cf84bb

Please sign in to comment.