/**
  * Get the top albums tagged by this tag, ordered by tag count.
  * 
  * @param string $tag the tag name
  * @param int $limit the number of results to fetch per page. Defaults to 50
  * @param int $page the page number to fetch. Defaults to first page
  */
 public function getTopAlbums($tag, $limit = null, $page = null)
 {
     $response = $this->call(array('method' => 'tag.getTopAlbums', 'tag' => $tag, 'limit' => $limit, 'page' => $page));
     $albums = array();
     if (!empty($response->topalbums->album)) {
         foreach ($response->topalbums->album as $album) {
             $albums[(int) $album->attributes()->rank] = LastfmModel\Album::createFromResponse($album);
         }
     }
     return $albums;
 }
 public function testCreateFromResponse()
 {
     $mockResponse = $this->createMockResponse('MockAlbumResponse');
     $album = Album::createFromResponse($mockResponse);
     $this->assertInstanceOf('BinaryThinking\\LastfmBundle\\Lastfm\\Model\\Album', $album, 'object created is not an instance of Album');
     $this->assertNotEmpty($album->getId(), 'empty album id');
     $this->assertNotEmpty($album->getName(), 'empty album name');
     $this->assertNotEmpty($album->getArtist(), 'empty album artist');
     $this->assertNotEmpty($album->getUrl(), 'empty album url');
     $this->assertNotEmpty($album->getMbid(), 'empty album mbid');
     $this->assertNotEmpty($album->getReleaseDate(), 'empty album release date');
     $this->assertNotEmpty($album->getListeners(), 'empty album listeners');
     $this->assertNotEmpty($album->getPlayCount(), 'empty album play count');
     $this->assertNotEmpty($album->getImages(), 'empty album images');
     $this->assertNotEmpty($album->getStreamable(), 'empty album streamable');
     $this->assertNotEmpty($album->getTopTags(), 'empty album top tags');
     $this->assertNotEmpty($album->getTracks(), 'empty album tracks');
 }
 /**
  * Search for an album by name. Returns album matches sorted by relevance.
  * 
  * @param string $album the album name
  * @param int $limit the number of results to fetch per page. Defaults to 30.
  * @param int $page the page number to fetch. Defaults to first page.
  */
 public function search($album, $limit = null, $page = null)
 {
     $response = $this->call(array('method' => 'album.search', 'album' => $album, 'limit' => $limit, 'page' => $page));
     $albums = array();
     if (!empty($response->results->albummatches->album)) {
         foreach ($response->results->albummatches->album as $albumMatch) {
             $album = LastfmModel\Album::createFromResponse($albumMatch);
             $albums[$album->getId()] = $album;
         }
     }
     return $albums;
 }
 /**
  * Get the top albums for an artist on Last.fm, ordered by popularity.
  * 
  * @param string $artist the artist name
  * @param string $mbid the musicbrainz id for the artist
  * @param int $limit the number of results to fetch per page. Defaults to 50
  * @param int $page the page number to fetch. Defaults to first page
  * @param bool $autocorrect transform misspelled artist names into correct artist names
  */
 public function getTopAlbums($artist, $mbid = null, $limit = null, $page = null, $autocorrect = true)
 {
     $response = $this->call(array('method' => 'artist.getTopAlbums', 'artist' => $artist, 'mbid' => $mbid, 'autocorrect' => $autocorrect, 'limit' => $limit, 'page' => $page));
     $albums = array();
     if (!empty($response->topalbums->album)) {
         foreach ($response->topalbums->album as $topAlbum) {
             $topAlbumAttributes = $topAlbum->attributes();
             $topAlbum = LastfmModel\Album::createFromResponse($topAlbum);
             $albums[(int) $topAlbumAttributes->rank] = $topAlbum;
         }
     }
     return $albums;
 }