Package de.umass.lastfm
Class Caller
- java.lang.Object
-
- de.umass.lastfm.Caller
-
public class Caller extends java.lang.ObjectTheCallerclass 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 theArtist,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 customProxyand a customUser-AgentHTTP header.- Author:
- Janni Kovacs
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Resultcall(java.lang.String method, Session session, java.lang.String... params)Resultcall(java.lang.String method, Session session, java.util.Map<java.lang.String,java.lang.String> params)Resultcall(java.lang.String method, java.lang.String apiKey, java.lang.String... params)Resultcall(java.lang.String method, java.lang.String apiKey, java.util.Map<java.lang.String,java.lang.String> params)CachegetCache()Returns the currentCache.static CallergetInstance()Returns the single instance of theCallerclass.ResultgetLastResult()Returns theResultof the last operation, ornullif no call operation has been performed yet.java.net.ProxygetProxy()java.lang.StringgetUserAgent()booleanisDebugMode()java.net.HttpURLConnectionopenConnection(java.lang.String url)Creates a newHttpURLConnection, sets the proxy, if available, and sets the User-Agent property.voidsetApiRootUrl(java.lang.String apiRootUrl)Set api root url.voidsetCache(Cache cache)Sets the activeCache.voidsetDebugMode(boolean debugMode)Sets thedebugModeproperty.voidsetProxy(java.net.Proxy proxy)Sets aProxyinstance this Caller will use for all upcoming HTTP requests.voidsetUserAgent(java.lang.String userAgent)Sets a User Agent this Caller will use for all upcoming HTTP requests.
-
-
-
Method Detail
-
getInstance
public static Caller getInstance()
Returns the single instance of theCallerclass.- Returns:
- a
Caller
-
setApiRootUrl
public void setApiRootUrl(java.lang.String apiRootUrl)
Set api root url.- Parameters:
apiRootUrl- new api root url
-
setProxy
public void setProxy(java.net.Proxy proxy)
Sets aProxyinstance this Caller will use for all upcoming HTTP requests. May benull.- Parameters:
proxy- AProxyornull.
-
setUserAgent
public void setUserAgent(java.lang.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 thedebugModeproperty. IfdebugModeistrueall call() methods will print debug information and error messages on failure to stdout and stderr respectively.
Default isfalse. Set this totruewhile in development and for troubleshooting.- Parameters:
debugMode-trueto enable debug mode
-
setCache
public void setCache(Cache cache)
Sets the activeCache. May benullto disable caching.- Parameters:
cache- the new Cache ornull
-
call
public Result call(java.lang.String method, java.lang.String apiKey, java.lang.String... params) throws CallException
- Throws:
CallException
-
call
public Result call(java.lang.String method, java.lang.String apiKey, java.util.Map<java.lang.String,java.lang.String> params) throws CallException
- Throws:
CallException
-
call
public Result call(java.lang.String method, Session session, java.util.Map<java.lang.String,java.lang.String> params)
-
getLastResult
public Result getLastResult()
Returns theResultof the last operation, ornullif no call operation has been performed yet.- Returns:
- the last Result object
-
openConnection
public java.net.HttpURLConnection openConnection(java.lang.String url) throws java.io.IOExceptionCreates a newHttpURLConnection, sets the proxy, if available, and sets the User-Agent property.- Parameters:
url- URL to connect to- Returns:
- a new connection.
- Throws:
java.io.IOException- if an I/O exception occurs.
-
getProxy
public java.net.Proxy getProxy()
-
getUserAgent
public java.lang.String getUserAgent()
-
isDebugMode
public boolean isDebugMode()
-
-