/**
  * Get the top tags for an album on Last.fm, ordered by popularity.
  * 
  * @param string $artist the artist name
  * @param string $album the album name
  * @param string $mbid the musicbrainz id for the album
  * @param bool $autocorrect transform misspelled artist names into correct artist names
  */
 public function getTopTags($artist, $album, $mbid = null, $autocorrect = true)
 {
     $response = $this->call(array('method' => 'album.getTopTags', 'artist' => $artist, 'album' => $album, 'mbid' => $mbid, 'autocorrect' => $autocorrect));
     $tags = array();
     if (!empty($response->toptags->tag)) {
         foreach ($response->toptags->tag as $topTag) {
             $tag = LastfmModel\Tag::createFromResponse($topTag);
             $tags[$tag->getName()] = $tag;
         }
     }
     return $tags;
 }
 public function testCreateFromGetInfoResponse()
 {
     $mockResponse = $this->createMockResponse('MockTagGetInfoResponse');
     $tag = Tag::createFromResponse($mockResponse);
     $this->assertNotEmpty($tag->getName(), 'tag has empty name');
     $this->assertNotEmpty($tag->getUrl(), 'tag has empty url');
     $this->assertNotEmpty($tag->getReach(), 'tag has empty reach');
     $this->assertNotEmpty($tag->getTaggings(), 'tag has empty taggings');
     $this->assertNotEmpty($tag->getStreamable(), 'tag has empty streamable');
     $this->assertNotEmpty($tag->getPublished(), 'tag has empty published');
     $this->assertNotEmpty($tag->getSummary(), 'tag has empty summary');
     $this->assertNotEmpty($tag->getContent(), 'tag has empty content');
 }
 public static function createFromResponse(\SimpleXMLElement $response)
 {
     $artist = new Artist();
     $artist->setRawResponse($response->asXML());
     $artist->setName((string) $response->name);
     $artist->setMbid((string) $response->mbid);
     $artist->setUrl((string) $response->url);
     $images = array();
     if (!empty($response->image)) {
         foreach ($response->image as $image) {
             $imageAttributes = $image->attributes();
             if (!empty($imageAttributes->size)) {
                 $images[(string) $imageAttributes->size] = (string) $image;
             }
         }
     }
     $artist->setImages($images);
     $artist->setStreamable((int) $response->streamable);
     if (!empty($response->stats)) {
         $artist->setListeners((int) $response->stats->listeners);
         $artist->setPlayCount((int) $response->stats->playcount);
     } elseif (isset($response->listeners)) {
         $artist->setListeners((int) $response->listeners);
     }
     $similar = array();
     if (!empty($response->similar->artist)) {
         foreach ($response->similar->artist as $similarArtistXML) {
             $similarArtist = self::createFromResponse($similarArtistXML);
             if (!empty($similarArtist)) {
                 $similar[$similarArtist->getName()] = $similarArtist;
             }
         }
     }
     $artist->setSimilar($similar);
     $tags = array();
     if (!empty($response->tags->tag)) {
         foreach ($response->tags->tag as $tag) {
             $tags[] = Tag::createFromResponse($tag);
         }
     }
     $artist->setTags($tags);
     $bio = array();
     if (!empty($response->bio)) {
         $bio['published'] = (string) $response->bio->published;
         $bio['summary'] = (string) $response->bio->summary;
         $bio['content'] = (string) $response->bio->content;
     }
     $artist->setBio($bio);
     $artist->setWeight((int) $response->weight);
     return $artist;
 }
 /**
  * Search for a tag by name. Returns matches sorted by relevance.
  * 
  * @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 search($tag, $limit = null, $page = null)
 {
     $response = $this->call(array('method' => 'tag.search', 'tag' => $tag, 'limit' => $limit, 'page' => $page));
     $tags = array();
     if (!empty($response->results->tagmatches->tag)) {
         foreach ($response->results->tagmatches->tag as $responseTag) {
             $tags[] = LastfmModel\Tag::createFromResponse($responseTag);
         }
     }
     return $tags;
 }