public abstract class AbstractLastfmWebServices extends Object implements LastfmWebServices
| Modifier and Type | Field and Description |
|---|---|
protected org.slf4j.Logger |
logger
Our logger.
|
| Constructor and Description |
|---|
AbstractLastfmWebServices(String key,
String secret)
Set up the WebServices with the required components.
|
AbstractLastfmWebServices(String key,
String secret,
Fetcher fetcher) |
| Modifier and Type | Method and Description |
|---|---|
<T extends Serializable> |
execute(PostQuery<T> query)
Execute an authenticated POST Query.
|
<T extends Serializable> |
fetch(AuthenticatedGetQuery<T> query)
Fetch an authenticated GET Query.
|
<T extends Serializable> |
fetch(UnauthenticatedGetQuery<T> query)
Fetch an unauthenticated GET Query.
|
String |
getApiKey()
Get the current api key.
|
String |
getApiSecret()
Get the current api secret.
|
Fetcher |
getFetcher()
Get the current fetcher.
|
protected abstract Serializable |
getFromCache(Map<String,String> parameters)
Try to fetch the result from cache.
|
protected abstract Serializable |
putToCache(Map<String,String> parameters,
Serializable result,
long timeToLive)
Store result in cache.
|
void |
setFetcher(Fetcher fetcher)
Sets the current fetcher.
|
void |
setTimeToLive(Properties ttls)
You can specify how long the data of each method should be cached.
|
public AbstractLastfmWebServices(String key, String secret) throws ParserConfigurationException
key - The last.fm API key, see http://www.last.fm/api/accountsecret - The last.fm API secret, see http://www.last.fm/api/accountcache - The cache implementationParserConfigurationExceptionpublic final <T extends Serializable> T fetch(AuthenticatedGetQuery<T> query) throws LastfmWebServicesException
LastfmWebServicesfetch in interface LastfmWebServicesT - The return type of the Query.query - The query.LastfmWebServicesException - If fetching the Query fails.public final <T extends Serializable> T execute(PostQuery<T> query) throws LastfmWebServicesException
LastfmWebServicesexecute in interface LastfmWebServicesT - The return type of the query.query - The query.LastfmWebServicesException - If executing the Query fails.public final <T extends Serializable> T fetch(UnauthenticatedGetQuery<T> query) throws LastfmWebServicesException
LastfmWebServicesfetch in interface LastfmWebServicesT - The return type of the query.query - The query.LastfmWebServicesException - If fetching the Query fails.public final String getApiSecret()
LastfmWebServicesgetApiSecret in interface LastfmWebServicespublic final String getApiKey()
LastfmWebServicesgetApiKey in interface LastfmWebServicespublic Fetcher getFetcher()
LastfmWebServicesgetFetcher in interface LastfmWebServicesFetcher responsible for fetching the data.public void setFetcher(Fetcher fetcher)
LastfmWebServicessetFetcher in interface LastfmWebServicespublic final void setTimeToLive(Properties ttls)
artist.getinfo = 2419200000A special entry is exception, this is used to cache exceptions.
ttls - Properties containing method time to lives.protected abstract Serializable getFromCache(Map<String,String> parameters)
T - Return type of the query.parameters - The parameters of the request.protected abstract Serializable putToCache(Map<String,String> parameters, Serializable result, long timeToLive)
T - Return type of the query.parameters - The parameters of the request.result - The query result.timeToLive - The time to live for the cache entry in milliseconds.Copyright © 2012. All Rights Reserved.