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

Commit

Permalink
Added in more type constants to the library base class. Added a littl…
Browse files Browse the repository at this point in the history
…e clean-up to the builUrl function to remove double slashes. Added in a method to turn a function name into an item type to help with polymorphic identification of items.
  • Loading branch information
nickbart committed Dec 24, 2012
1 parent 4400dbb commit 4eacf8f
Showing 1 changed file with 73 additions and 3 deletions.
76 changes: 73 additions & 3 deletions Server/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,14 @@ class Plex_Server_Library extends Plex_Server
const ENDPOINT_RECENTLY_ADDED = 'recentlyAdded';

/**
* URLl endpoint for a library's on deck items.
* URL endpoint for a library's on deck items.
*/
const ENDPOINT_ON_DECK = 'onDeck';

/**
* URL endpoint for single library items.
*/
const ENDPOINT_METADATA = 'metadata';

/**
* String that identifies a Plex library movie item type.
Expand All @@ -68,6 +73,16 @@ class Plex_Server_Library extends Plex_Server
*/
const TYPE_ARTIST = 'artist';

/**
* String that identifies a Plex library album item type.
*/
const TYPE_ALBUM = 'album';

/**
* String that identifies a Plex library track item type.
*/
const TYPE_TRACK = 'track';

/**
* String that identifies a Plex library photo item type.
*/
Expand All @@ -77,6 +92,11 @@ class Plex_Server_Library extends Plex_Server
* String that identifies a Plex library TV show item type.
*/
const TYPE_SHOW = 'show';

/**
* String that identifies a Plex library TV season item type.
*/
const TYPE_SEASON = 'season';

/**
* String that identifies a Plex library episode item type.
Expand All @@ -93,12 +113,23 @@ class Plex_Server_Library extends Plex_Server
*/
protected function buildUrl($endpoint)
{
$endpoint = sprintf(
'%s/%s',
self::ENDPOINT_LIBRARY,
$endpoint
);

// Some of the polymorphic methods leave double slashes, so here we
// simply clean them up.
$endpoint = str_replace('///', '/', $endpoint);
$endpoint = str_replace('//', '/', $endpoint);

$url = sprintf(
'%s/%s/%s',
'%s/%s',
$this->getBaseUrl(),
self::ENDPOINT_LIBRARY,
$endpoint
);

return $url;
}

Expand Down Expand Up @@ -127,6 +158,45 @@ protected function getItems($endpoint)
return $items;
}

/**
* Given a function name, uses that name to decide what Plex library item
* item type with whic the function is associated. This is useful when
* trying to polymorphically request items because we can use the calling
* function to abstractly identify what type of item with which we are
* dealing.
*
* @uses Plex_Server_Library::TYPE_MOVIE
* @uses Plex_Server_Library::TYPE_ARTIST
* @uses Plex_Server_Library::TYPE_ALBUM
* @uses Plex_Server_Library::TYPE_TRACK
* @uses Plex_Server_Library::TYPE_PHOTO
* @uses Plex_Server_Library::TYPE_SHOW
* @uses Plex_Server_Library::TYPE_SEASON
* @uses Plex_Server_Library::TYPE_EPISODE
*
* @return string The type of item with which the given function is
* associated.
*/
public function functionToType($function)
{
$availableTypes = array(
self::TYPE_MOVIE,
self::TYPE_ARTIST,
self::TYPE_ALBUM,
self::TYPE_TRACK,
self::TYPE_PHOTO,
self::TYPE_SHOW,
self::TYPE_SEASON,
self::TYPE_EPISODE
);

foreach ($availableTypes as $type) {
if (strpos(strtolower($function), $type) != FALSE) {
return $type;
}
}
}

/**
* Returns an array of user defined Plex library sections that can be used
* to interact with th eitems contained within.
Expand Down

0 comments on commit 4eacf8f

Please sign in to comment.