import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
@ -18,7 +18,7 @@
|
||||
* @subpackage Audioscrobbler
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Audioscrobbler.php 9094 2008-03-30 18:36:55Z thomas $
|
||||
* @version $Id: Audioscrobbler.php 14809 2009-04-09 19:01:40Z beberlei $
|
||||
*/
|
||||
|
||||
|
||||
@ -53,22 +53,6 @@ class Zend_Service_Audioscrobbler
|
||||
*/
|
||||
protected $_params;
|
||||
|
||||
/**
|
||||
* Flag if we're doing testing or not
|
||||
*
|
||||
* @var boolean
|
||||
* @access protected
|
||||
*/
|
||||
protected $_testing;
|
||||
|
||||
/**
|
||||
* Http response used for testing purposes
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $_testingResponse;
|
||||
|
||||
/**
|
||||
* Holds error information (e.g., for handling simplexml_load_string() warnings)
|
||||
*
|
||||
@ -78,33 +62,50 @@ class Zend_Service_Audioscrobbler
|
||||
protected $_error = null;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
/////////////////// CORE METHODS ///////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Sets up character encoding, instantiates the HTTP client, and assigns the web service version
|
||||
* and testing parameters (if provided).
|
||||
*
|
||||
* @param boolean $testing
|
||||
* @param string $testingResponse
|
||||
* @return void
|
||||
* Sets up character encoding, instantiates the HTTP client, and assigns the web service version.
|
||||
*/
|
||||
public function __construct($testing = false, $testingResponse = null)
|
||||
public function __construct()
|
||||
{
|
||||
$this->set('version', '1.0');
|
||||
|
||||
iconv_set_encoding('output_encoding', 'UTF-8');
|
||||
iconv_set_encoding('input_encoding', 'UTF-8');
|
||||
iconv_set_encoding('internal_encoding', 'UTF-8');
|
||||
|
||||
$this->_client = new Zend_Http_Client();
|
||||
|
||||
$this->_testing = (boolean) $testing;
|
||||
$this->_testingResponse = (string) $testingResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Http Client
|
||||
*
|
||||
* @param Zend_Http_Client $client
|
||||
*/
|
||||
public function setHttpClient(Zend_Http_Client $client)
|
||||
{
|
||||
$this->_client = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current http client.
|
||||
*
|
||||
* @return Zend_Http_Client
|
||||
*/
|
||||
public function getHttpClient()
|
||||
{
|
||||
if($this->_client == null) {
|
||||
$this->lazyLoadHttpClient();
|
||||
}
|
||||
return $this->_client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazy load Http Client if none is instantiated yet.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function lazyLoadHttpClient()
|
||||
{
|
||||
$this->_client = new Zend_Http_Client();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a field value, or false if the named field does not exist
|
||||
@ -151,24 +152,12 @@ class Zend_Service_Audioscrobbler
|
||||
$params = (string) $params;
|
||||
|
||||
if ($params === '') {
|
||||
$this->_client->setUri("http://ws.audioscrobbler.com{$service}");
|
||||
$this->getHttpClient()->setUri("http://ws.audioscrobbler.com{$service}");
|
||||
} else {
|
||||
$this->_client->setUri("http://ws.audioscrobbler.com{$service}?{$params}");
|
||||
$this->getHttpClient()->setUri("http://ws.audioscrobbler.com{$service}?{$params}");
|
||||
}
|
||||
|
||||
if ($this->_testing) {
|
||||
/**
|
||||
* @see Zend_Http_Client_Adapter_Test
|
||||
*/
|
||||
require_once 'Zend/Http/Client/Adapter/Test.php';
|
||||
$adapter = new Zend_Http_Client_Adapter_Test();
|
||||
|
||||
$this->_client->setConfig(array('adapter' => $adapter));
|
||||
|
||||
$adapter->setResponse($this->_testingResponse);
|
||||
}
|
||||
|
||||
$response = $this->_client->request();
|
||||
$response = $this->getHttpClient()->request();
|
||||
$responseBody = $response->getBody();
|
||||
|
||||
if (preg_match('/No such path/', $responseBody)) {
|
||||
@ -210,12 +199,9 @@ class Zend_Service_Audioscrobbler
|
||||
return $simpleXmlElementResponse;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
/////////////////////// USER ///////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Utility function to get Audioscrobbler profile information (eg: Name, Gender)
|
||||
*
|
||||
* @return array containing information
|
||||
*/
|
||||
public function userGetProfileInformation()
|
||||
@ -226,6 +212,7 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function get this user's 50 most played artists
|
||||
*
|
||||
* @return array containing info
|
||||
*/
|
||||
public function userGetTopArtists()
|
||||
@ -236,7 +223,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function to get this user's 50 most played albums
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetTopAlbums()
|
||||
{
|
||||
@ -256,7 +244,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function to get this user's 50 most used tags
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetTopTags()
|
||||
{
|
||||
@ -266,8 +255,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns the user's top tags used most used on a specific artist
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetTopTagsForArtist()
|
||||
{
|
||||
@ -278,8 +267,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns this user's top tags for an album
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetTopTagsForAlbum()
|
||||
{
|
||||
@ -290,8 +279,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns this user's top tags for a track
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetTopTagsForTrack()
|
||||
{
|
||||
@ -302,7 +291,7 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that retrieves this user's list of friends
|
||||
* @return SimpleXML object containing result set
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetFriends()
|
||||
{
|
||||
@ -312,8 +301,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of people with similar listening preferences to this user
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetNeighbours()
|
||||
{
|
||||
@ -323,8 +312,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of the 10 most recent tracks played by this user
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetRecentTracks()
|
||||
{
|
||||
@ -334,8 +323,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of the 10 tracks most recently banned by this user
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetRecentBannedTracks()
|
||||
{
|
||||
@ -345,8 +334,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of the 10 tracks most recently loved by this user
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetRecentLovedTracks()
|
||||
{
|
||||
@ -356,9 +345,10 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of dates of available weekly charts for a this user
|
||||
* Should actually be named userGetWeeklyChartDateList() but we have to follow audioscrobbler's naming
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* Should actually be named userGetWeeklyChartDateList() but we have to follow audioscrobbler's naming
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetWeeklyChartList()
|
||||
{
|
||||
@ -369,10 +359,10 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns weekly album chart data for this user
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @param integer $from optional UNIX timestamp for start of date range
|
||||
* @param integer $to optional UNIX timestamp for end of date range
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetWeeklyAlbumChart($from = NULL, $to = NULL)
|
||||
{
|
||||
@ -390,10 +380,10 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns weekly artist chart data for this user
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @param integer $from optional UNIX timestamp for start of date range
|
||||
* @param integer $to optional UNIX timestamp for end of date range
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetWeeklyArtistChart($from = NULL, $to = NULL)
|
||||
{
|
||||
@ -411,10 +401,10 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns weekly track chart data for this user
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @param integer $from optional UNIX timestamp for start of date range
|
||||
* @param integer $to optional UNIX timestamp for end of date range
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetWeeklyTrackChart($from = NULL, $to = NULL)
|
||||
{
|
||||
@ -431,20 +421,10 @@ class Zend_Service_Audioscrobbler
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
/////////////////////// ARTIST /////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Public functions for retrieveing artist-specific information
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of artists similiar to this artist
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function artistGetRelatedArtists()
|
||||
{
|
||||
@ -454,8 +434,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of this artist's top listeners
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function artistGetTopFans()
|
||||
{
|
||||
@ -465,8 +445,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of this artist's top-rated tracks
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function artistGetTopTracks()
|
||||
{
|
||||
@ -476,8 +456,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of this artist's top-rated albums
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function artistGetTopAlbums()
|
||||
{
|
||||
@ -487,8 +467,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of this artist's top-rated tags
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function artistGetTopTags()
|
||||
{
|
||||
@ -496,70 +476,103 @@ class Zend_Service_Audioscrobbler
|
||||
return $this->_getInfo($service);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
/////////////////////// ALBUM //////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Get information about an album
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function albumGetInfo()
|
||||
{
|
||||
$service = "/{$this->get('version')}/album/{$this->get('artist')}/{$this->get('album')}/info.xml";
|
||||
return $this->_getInfo($service);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
/////////////////////// TRACKS //////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Get top fans of the current track.
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function trackGetTopFans()
|
||||
{
|
||||
$service = "/{$this->get('version')}/track/{$this->get('artist')}/{$this->get('track')}/fans.xml";
|
||||
return $this->_getInfo($service);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top tags of the current track.
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function trackGetTopTags()
|
||||
{
|
||||
$service = "/{$this->get('version')}/track/{$this->get('artist')}/{$this->get('track')}/toptags.xml";
|
||||
return $this->_getInfo($service);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
/////////////////////// TAGS //////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Get Top Tags.
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function tagGetTopTags()
|
||||
{
|
||||
$service = "/{$this->get('version')}/tag/toptags.xml";
|
||||
return $this->_getInfo($service);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top albums by current tag.
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function tagGetTopAlbums()
|
||||
{
|
||||
$service = "/{$this->get('version')}/tag/{$this->get('tag')}/topalbums.xml";
|
||||
return $this->_getInfo($service);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top artists by current tag.
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function tagGetTopArtists()
|
||||
{
|
||||
$service = "/{$this->get('version')}/tag/{$this->get('tag')}/topartists.xml";
|
||||
return $this->_getInfo($service);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Top Tracks by currently set tag.
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function tagGetTopTracks()
|
||||
{
|
||||
$service = "/{$this->get('version')}/tag/{$this->get('tag')}/toptracks.xml";
|
||||
return $this->_getInfo($service);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
/////////////////////// GROUPS //////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Get weekly chart list by current set group.
|
||||
*
|
||||
* @see set()
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function groupGetWeeklyChartList()
|
||||
{
|
||||
$service = "/{$this->get('version')}/group/{$this->get('group')}/weeklychartlist.xml";
|
||||
return $this->_getInfo($service);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve weekly Artist Charts
|
||||
*
|
||||
* @param int $from
|
||||
* @param int $to
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function groupGetWeeklyArtistChartList($from = NULL, $to = NULL)
|
||||
{
|
||||
|
||||
@ -575,6 +588,13 @@ class Zend_Service_Audioscrobbler
|
||||
return $this->_getInfo($service, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Weekly Track Charts
|
||||
*
|
||||
* @param int $from
|
||||
* @param int $to
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function groupGetWeeklyTrackChartList($from = NULL, $to = NULL)
|
||||
{
|
||||
if ($from != NULL && $to != NULL) {
|
||||
@ -589,6 +609,13 @@ class Zend_Service_Audioscrobbler
|
||||
return $this->_getInfo($service, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Weekly album charts.
|
||||
*
|
||||
* @param int $from
|
||||
* @param int $to
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function groupGetWeeklyAlbumChartList($from = NULL, $to = NULL)
|
||||
{
|
||||
if ($from != NULL && $to != NULL) {
|
||||
@ -623,4 +650,32 @@ class Zend_Service_Audioscrobbler
|
||||
'errcontext' => $errcontext
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call Intercept for set($name, $field)
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return Zend_Service_Audioscrobbler
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
if(substr($method, 0, 3) !== "set") {
|
||||
require_once "Zend/Service/Exception.php";
|
||||
throw new Zend_Service_Exception(
|
||||
"Method ".$method." does not exist in class Zend_Service_Audioscrobbler."
|
||||
);
|
||||
}
|
||||
$field = strtolower(substr($method, 3));
|
||||
|
||||
if(!is_array($args) || count($args) != 1) {
|
||||
require_once "Zend/Service/Exception.php";
|
||||
throw new Zend_Service_Exception(
|
||||
"A value is required for setting a parameter field."
|
||||
);
|
||||
}
|
||||
$this->set($field, $args[0]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user