示例#1
0
 /**
  * Creates a Last.fm playlist.
  *
  * @param title A title for the playlist
  * @param description A description for the playlist
  * @param session A Session instance
  * @return the result of the operation
  */
 public static Playlist create(String title, String description, Session session) {
   Result result =
       Caller.getInstance()
           .call("playlist.create", session, "title", title, "description", description);
   if (!result.isSuccessful()) return null;
   return ResponseBuilder.buildItem(
       result.getContentElement().getChild("playlist"), Playlist.class);
 }
 /**
  * Gets a list of a user's playlists on Last.fm. Note that this method only fetches metadata
  * regarding the user's playlists. If you want to retrieve the list of tracks in a playlist use
  * {@link Playlist#fetch(String, String) Playlist.fetch()}.
  *
  * @param user The last.fm username to fetch the playlists of.
  * @param apiKey A Last.fm API key.
  * @return a list of Playlists
  */
 public static Collection<Playlist> getPlaylists(String user, String apiKey) {
   Result result = Caller.getInstance().call("user.getPlaylists", apiKey, "user", user);
   if (!result.isSuccessful()) return Collections.emptyList();
   Collection<Playlist> playlists = new ArrayList<Playlist>();
   for (DomElement element : result.getContentElement().getChildren("playlist")) {
     playlists.add(Playlist.playlistFromElement(element));
   }
   return playlists;
 }
示例#3
0
文件: Geo.java 项目: junwuwei/jSona
 /**
  * Get a list of valid countries and {@link de.umass.lastfm.Geo.Metro}s for use in the other
  * webservices.
  *
  * @param country Optionally restrict the results to those Metros from a particular country, as
  *     defined by the ISO 3166-1 country names standard
  * @param apiKey A Last.fm API key
  * @return a List of {@link de.umass.lastfm.Geo.Metro}s
  */
 public static Collection<Metro> getMetros(String country, String apiKey) {
   Map<String, String> params = new HashMap<String, String>();
   MapUtilities.nullSafePut(params, "country", country);
   Result result = Caller.getInstance().call("geo.getMetros", apiKey, params);
   if (!result.isSuccessful()) return Collections.emptyList();
   Collection<DomElement> children = result.getContentElement().getChildren("metro");
   Collection<Metro> metros = new ArrayList<Metro>(children.size());
   for (DomElement child : children) {
     metros.add(new Metro(child.getChildText("name"), child.getChildText("country")));
   }
   return metros;
 }