Source for file Library.php

Documentation is available at Library.php

  1. <?
  2.  
  3. /** Provides different methods to query user music library information.
  4.  *
  5.  * @package    php-lastfm-api
  6.  * @author  Felix Bruns <felixbruns@web.de>
  7.  * @version    1.0
  8.  */
  9. class Library {
  10.     /** Add an album to a user's last.fm library.
  11.      *
  12.      * @param    string    $artist        The artist that composed the album. (Required)
  13.      * @param    string    $album        The album name you wish to add. (Required)
  14.      * @param    Session    $session    A session obtained by {@link de.felixbruns.lastfm.Auth#getSession Auth::getSession} or {@link de.felixbruns.lastfm.Auth#getMobileSession Auth::getMobileSession}. (Required)
  15.      *
  16.      * @static
  17.      * @access    public
  18.      * @throws    Error
  19.      */
  20.     public static function addAlbum($artist$album$session){
  21.         CallerFactory::getDefaultCaller()->signedCall('library.addAlbum'array(
  22.             'artist' => $artist,
  23.             'album'  => $album
  24.         )$session'POST');
  25.     }
  26.  
  27.     /** Add an artist to a user's last.fm library.
  28.      *
  29.      * @param    string    $artist        The artist name you wish to add. (Required)
  30.      * @param    Session    $session    A session obtained by {@link de.felixbruns.lastfm.Auth#getSession Auth::getSession} or {@link de.felixbruns.lastfm.Auth#getMobileSession Auth::getMobileSession}. (Required)
  31.      *
  32.      * @static
  33.      * @access    public
  34.      * @throws    Error
  35.      */
  36.     public static function addArtist($artist$session){
  37.         CallerFactory::getDefaultCaller()->signedCall('library.addArtist'array(
  38.             'artist' => $artist
  39.         )$session'POST');
  40.     }
  41.  
  42.     /** Add a track to a user's last.fm library.
  43.      *
  44.      * @param    string    $artist        The artist that composed the track. (Required)
  45.      * @param    string    $track        The track name you wish to add. (Required)
  46.      * @param    Session    $session    A session obtained by {@link de.felixbruns.lastfm.Auth#getSession Auth::getSession} or {@link de.felixbruns.lastfm.Auth#getMobileSession Auth::getMobileSession}. (Required)
  47.      *
  48.      * @static
  49.      * @access    public
  50.      * @throws    Error
  51.      */
  52.     public static function addTrack($artist$track$session){
  53.         CallerFactory::getDefaultCaller()->signedCall('library.addTrack'array(
  54.             'artist' => $artist,
  55.             'track'  => $track
  56.         )$session'POST');
  57.     }
  58.  
  59.     /** A paginated list of all the albums in a user's library, with play counts and tag counts.
  60.      *
  61.      * @param    string    $user    The user whose library you want to fetch. (Required)
  62.      * @param    integer    $limit    Limit the amount of albums returned (maximum/default is 50). (Optional)
  63.      * @param    integer    $page    The page number you wish to scan to. (Optional)
  64.      * @return    PaginatedResult    A PaginatedResult object.
  65.      *
  66.      * @static
  67.      * @access    public
  68.      * @throws    Error
  69.      */
  70.     public static function getAlbums($user$limit null$page null){
  71.         $xml CallerFactory::getDefaultCaller()->call('library.getAlbums'array(
  72.             'user'  => $user,
  73.             'limit' => $limit,
  74.             'page'  => $page
  75.         ));
  76.  
  77.         $albums array();
  78.  
  79.         foreach($xml->children(as $album){
  80.             $albums[Album::fromSimpleXMLElement($album);
  81.         }
  82.  
  83.         $perPage Util::toInteger($xml['perPage']);
  84.  
  85.         return new PaginatedResult(
  86.             Util::toInteger($xml['totalPages']$perPage,
  87.             (Util::toInteger($xml['page']1$perPage,
  88.             $perPage,
  89.             $albums
  90.         );
  91.     }
  92.  
  93.     /** A paginated list of all the artists in a user's library, with play counts and tag counts.
  94.      *
  95.      * @param    string    $user    The user whose library you want to fetch. (Required)
  96.      * @param    integer    $limit    Limit the amount of artists returned (maximum/default is 50). (Optional)
  97.      * @param    integer    $page    The page number you wish to scan to. (Optional)
  98.      * @return    PaginatedResult    A PaginatedResult object.
  99.      *
  100.      * @static
  101.      * @access    public
  102.      * @throws    Error
  103.      */
  104.     public static function getArtists($user$limit null$page null){
  105.         $xml CallerFactory::getDefaultCaller()->call('library.getArtists'array(
  106.             'user'  => $user,
  107.             'limit' => $limit,
  108.             'page'  => $page
  109.         ));
  110.  
  111.         $artists array();
  112.  
  113.         foreach($xml->children(as $artist){
  114.             $artists[Artist::fromSimpleXMLElement($artist);
  115.         }
  116.  
  117.         $perPage Util::toInteger($xml['perPage']);
  118.  
  119.         return new PaginatedResult(
  120.             Util::toInteger($xml['totalPages']$perPage,
  121.             (Util::toInteger($xml['page']1$perPage,
  122.             $perPage,
  123.             $artists
  124.         );
  125.     }
  126.  
  127.     /** A paginated list of all the tracks in a user's library, with play counts and tag counts.
  128.      *
  129.      * @param    string    $user    The user whose library you want to fetch. (Required)
  130.      * @param    integer    $limit    Limit the amount of tracks returned (maximum/default is 50). (Optional)
  131.      * @param    integer    $page    The page number you wish to scan to. (Optional)
  132.      * @return    PaginatedResult    A PaginatedResult object.
  133.      *
  134.      * @static
  135.      * @access    public
  136.      * @throws    Error
  137.      */
  138.     public static function getTracks($user$limit$page){
  139.         $xml CallerFactory::getDefaultCaller()->call('library.getTracks'array(
  140.             'user'  => $user,
  141.             'limit' => $limit,
  142.             'page'  => $page
  143.         ));
  144.  
  145.         $tracks array();
  146.  
  147.         foreach($xml->children(as $track){
  148.             $tracks[Track::fromSimpleXMLElement($track);
  149.         }
  150.  
  151.         $perPage Util::toInteger($xml['perPage']);
  152.  
  153.         return new PaginatedResult(
  154.             Util::toInteger($xml['totalPages']$perPage,
  155.             (Util::toInteger($xml['page']1$perPage,
  156.             $perPage,
  157.             $tracks
  158.         );
  159.     }
  160. }
  161.  
  162. ?>

Documentation generated on Mon, 22 Dec 2008 16:57:38 +0100 by phpDocumentor 1.4.1