public class Caller extends Object
Caller
class handles the low-level communication between the client and last.fm.Artist
, Album
, User
, etc. classes.
If specialized calls which are not covered by the Java API are necessary this class may be used directly.Proxy
and a custom User-Agent
HTTP header.Modifier and Type | Field and Description |
---|---|
private String |
apiRootUrl |
private de.umass.lastfm.cache.Cache |
cache |
private boolean |
debugMode |
private static String |
DEFAULT_API_ROOT |
private static Caller |
instance |
private Result |
lastResult |
private Logger |
log |
private static String |
PARAM_API_KEY |
private static String |
PARAM_METHOD |
private Proxy |
proxy |
static boolean |
tomDebug_ |
private String |
userAgent |
Modifier | Constructor and Description |
---|---|
private |
Caller() |
Modifier and Type | Method and Description |
---|---|
private String |
buildPostBody(String method,
Map<String,String> params,
String... strings) |
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) |
private Result |
call(String method,
String apiKey,
Map<String,String> params,
Session session)
Performs the web-service call.
|
Result |
call(String method,
String apiKey,
String... params) |
private Result |
createResultFromInputStream(InputStream inputStream) |
private String |
createSignature(Map<String,String> params,
String secret) |
de.umass.lastfm.cache.Cache |
getCache()
Returns the current
Cache . |
private InputStream |
getInputStreamFromConnection(HttpURLConnection connection) |
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. |
Logger |
getLogger() |
Proxy |
getProxy() |
private InputStream |
getStreamFromCache(String cacheEntryName) |
String |
getUserAgent() |
boolean |
isDebugMode()
Deprecated.
Use the Logger instead
|
private DocumentBuilder |
newDocumentBuilder() |
HttpURLConnection |
openConnection(String url)
Creates a new
HttpURLConnection , sets the proxy, if available, and sets the User-Agent property. |
private HttpURLConnection |
openPostConnection(String method,
Map<String,String> params) |
void |
setApiRootUrl(String apiRootUrl)
Set api root url.
|
void |
setCache(de.umass.lastfm.cache.Cache cache)
Sets the active
Cache . |
void |
setDebugMode(boolean debugMode)
Deprecated.
Use the Logger instead
|
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.
|
public static boolean tomDebug_
private static final String PARAM_API_KEY
private static final String PARAM_METHOD
private static final String DEFAULT_API_ROOT
private String apiRootUrl
private boolean debugMode
private de.umass.lastfm.cache.Cache cache
private Result lastResult
private Caller()
public static Caller getInstance()
Caller
class.Caller
public void setApiRootUrl(String apiRootUrl)
apiRootUrl
- new api root urlpublic void setProxy(Proxy proxy)
Proxy
instance this Caller will use for all upcoming HTTP requests. May be null
.proxy
- A Proxy
or null
.public void setUserAgent(String userAgent)
userAgent
- a User-Agent stringpublic String getUserAgent()
public de.umass.lastfm.cache.Cache getCache()
Cache
.public void setCache(de.umass.lastfm.cache.Cache cache)
Cache
. May be null
to disable caching.cache
- the new Cache or null
public void setDebugMode(boolean debugMode)
debugMode
property. If debugMode
is true
all call() methods
will print debug information and error messages on failure to stdout and stderr respectively.false
. Set this to true
while in development and for troubleshooting.debugMode
- true
to enable debug modegetLogger()
public boolean isDebugMode()
getLogger()
public Result getLastResult()
Result
of the last operation, or null
if no call operation has been
performed yet.public Result call(String method, String apiKey, String... params) throws CallException
CallException
public Result call(String method, String apiKey, Map<String,String> params) throws CallException
CallException
private Result call(String method, String apiKey, Map<String,String> params, Session session)
session
parameter is non-null
then an
authenticated call is made. If it's null
then an unauthenticated call is made.apiKey
parameter is always required, even when a valid session is passed to this method.method
- The method to callapiKey
- A Last.fm API keyparams
- Parameterssession
- A Session instance or null
private InputStream getStreamFromCache(String cacheEntryName)
public HttpURLConnection openConnection(String url) throws IOException
HttpURLConnection
, sets the proxy, if available, and sets the User-Agent property.url
- URL to connect toIOException
- if an I/O exception occurs.private HttpURLConnection openPostConnection(String method, Map<String,String> params) throws IOException
IOException
private InputStream getInputStreamFromConnection(HttpURLConnection connection) throws IOException
IOException
private Result createResultFromInputStream(InputStream inputStream) throws SAXException, IOException
SAXException
IOException
private DocumentBuilder newDocumentBuilder()
private String buildPostBody(String method, Map<String,String> params, String... strings)
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses