de.umass.lastfm
Class Caller

java.lang.Object
  extended by de.umass.lastfm.Caller

public class Caller
extends Object

The Caller class handles the low-level communication between the client and last.fm.
Direct usage of this class should be unnecessary since all method calls are available via the methods in the Artist, Album, User, etc. classes. If specialized calls which are not covered by the Java API are necessary this class may be used directly.
Supports the setting of a custom Proxy and a custom User-Agent HTTP header.

Author:
Janni Kovacs

Method Summary
 Result call(String method, Session session, Map<String,String> params)
           
 Result call(String method, Session session, String... params)
           
 Result call(String method, String apiKey, Map<String,String> params)
           
 Result call(String method, String apiKey, String... params)
           
 Cache getCache()
          Returns the current Cache.
static Caller getInstance()
          Returns the single instance of the Caller class.
 Result getLastResult()
          Returns the Result of the last operation, or null if no call operation has been performed yet.
 Proxy getProxy()
           
 String getUserAgent()
           
 boolean isDebugMode()
           
 HttpURLConnection openConnection(String url)
          Creates a new HttpURLConnection, sets the proxy, if available, and sets the User-Agent property.
 void setApiRootUrl(String apiRootUrl)
          Set api root url.
 void setCache(Cache cache)
          Sets the active Cache.
 void setDebugMode(boolean debugMode)
          Sets the debugMode property.
 void setProxy(Proxy proxy)
          Sets a Proxy instance this Caller will use for all upcoming HTTP requests.
 void setUserAgent(String userAgent)
          Sets a User Agent this Caller will use for all upcoming HTTP requests.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static Caller getInstance()
Returns the single instance of the Caller class.

Returns:
a Caller

setApiRootUrl

public void setApiRootUrl(String apiRootUrl)
Set api root url.

Parameters:
apiRootUrl - new api root url

setProxy

public void setProxy(Proxy proxy)
Sets a Proxy instance this Caller will use for all upcoming HTTP requests. May be null.

Parameters:
proxy - A Proxy or null.

setUserAgent

public void setUserAgent(String userAgent)
Sets a User Agent this Caller will use for all upcoming HTTP requests. For testing purposes use "tst". If you distribute your application use an identifiable User-Agent.

Parameters:
userAgent - a User-Agent string

setDebugMode

public void setDebugMode(boolean debugMode)
Sets the debugMode property. If debugMode is true all call() methods will print debug information and error messages on failure to stdout and stderr respectively.
Default is false. Set this to true while in development and for troubleshooting.

Parameters:
debugMode - true to enable debug mode

getCache

public Cache getCache()
Returns the current Cache.

Returns:
the Cache

setCache

public void setCache(Cache cache)
Sets the active Cache. May be null to disable caching.

Parameters:
cache - the new Cache or null

call

public Result call(String method,
                   String apiKey,
                   String... params)
            throws CallException
Throws:
CallException

call

public Result call(String method,
                   String apiKey,
                   Map<String,String> params)
            throws CallException
Throws:
CallException

call

public Result call(String method,
                   Session session,
                   String... params)

call

public Result call(String method,
                   Session session,
                   Map<String,String> params)

getLastResult

public Result getLastResult()
Returns the Result of the last operation, or null if no call operation has been performed yet.

Returns:
the last Result object

openConnection

public HttpURLConnection openConnection(String url)
                                 throws IOException
Creates a new HttpURLConnection, sets the proxy, if available, and sets the User-Agent property.

Parameters:
url - URL to connect to
Returns:
a new connection.
Throws:
IOException - if an I/O exception occurs.

getProxy

public Proxy getProxy()

getUserAgent

public String getUserAgent()

isDebugMode

public boolean isDebugMode()