## net.dontdrinkandroot.lastfm.api.ws
Class AbstractLastfmWebServices

    java.lang.Object
      net.dontdrinkandroot.lastfm.api.ws.AbstractLastfmWebServices

All Implemented Interfaces:
  LastfmWebServices

Direct Known Subclasses:
  DefaultLastfmWebServices

    public abstract class AbstractLastfmWebServices

extends java.lang.Object
implements LastfmWebServices

Field Summary
`protected org.slf4j.Logger` `logger` Our logger.

Constructor Summary
`AbstractLastfmWebServices(java.lang.String key, java.lang.String secret)` Set up the WebServices with the required components.
`AbstractLastfmWebServices(java.lang.String key, java.lang.String secret, Fetcher fetcher)`

Method Summary

`

`<T extends java.io.Serializable> T`

`

`execute(PostQuery<T> query)`
Execute an authenticated POST Query.

`

`<T extends java.io.Serializable> T`

`

`fetch(AuthenticatedGetQuery<T> query)`
Fetch an authenticated GET Query.

`

`<T extends java.io.Serializable> T`

`

`fetch(UnauthenticatedGetQuery<T> query)`
Fetch an unauthenticated GET Query.

`java.lang.String` `getApiKey()` Get the current api key.
`java.lang.String` `getApiSecret()` Get the current api secret.
`Fetcher` `getFetcher()` Get the current fetcher.
`protected abstract java.io.Serializable` `getFromCache(java.lang.String id)` Try to fetch the result from cache.
`protected abstract java.io.Serializable` `putToCache(java.lang.String id, java.io.Serializable result, long timeToLive)` Store result in cache.
`void` `setFetcher(Fetcher fetcher)` Sets the current fetcher.
`void` `setTimeToLive(java.util.Properties ttls)` You can specify how long the data of each method should be cached.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### logger

    protected final org.slf4j.Logger logger

  Our logger.

Constructor Detail

### AbstractLastfmWebServices

    public AbstractLastfmWebServices(java.lang.String key,
                                     java.lang.String secret)
                              throws javax.xml.parsers.ParserConfigurationException

  Set up the WebServices with the required components.

  Parameters:
    `key` - The last.fm API key, see http://www.last.fm/api/account
    `secret` - The last.fm API secret, see http://www.last.fm/api/account
    `cache` - The cache implementation
  Throws:
    `javax.xml.parsers.ParserConfigurationException`

### AbstractLastfmWebServices

    public AbstractLastfmWebServices(java.lang.String key,
                                     java.lang.String secret,
                                     Fetcher fetcher)

Method Detail

### fetch

    public final <T extends java.io.Serializable> T fetch(AuthenticatedGetQuery<T> query)
                                               throws LastfmWebServicesException

  Description copied from interface: `LastfmWebServices`
  Fetch an authenticated GET Query.

  Specified by:
    `fetch` in interface `LastfmWebServices`
  Type Parameters:
    `T` - The return type of the Query.
  Parameters:
    `query` - The query.
  Returns:
    The desired return object.
  Throws:
    `LastfmWebServicesException` - If fetching the Query fails.

### execute

    public final <T extends java.io.Serializable> T execute(PostQuery<T> query)
                                                 throws LastfmWebServicesException

  Description copied from interface: `LastfmWebServices`
  Execute an authenticated POST Query.

  Specified by:
    `execute` in interface `LastfmWebServices`
  Type Parameters:
    `T` - The return type of the query.
  Parameters:
    `query` - The query.
  Returns:
    The desired return object.
  Throws:
    `LastfmWebServicesException` - If executing the Query fails.

### fetch

    public final <T extends java.io.Serializable> T fetch(UnauthenticatedGetQuery<T> query)
                                               throws LastfmWebServicesException

  Description copied from interface: `LastfmWebServices`
  Fetch an unauthenticated GET Query.

  Specified by:
    `fetch` in interface `LastfmWebServices`
  Type Parameters:
    `T` - The return type of the query.
  Parameters:
    `query` - The query.
  Returns:
    The desired return object.
  Throws:
    `LastfmWebServicesException` - If fetching the Query fails.

### getApiSecret

    public final java.lang.String getApiSecret()

  Description copied from interface: `LastfmWebServices`
  Get the current api secret.

  Specified by:
    `getApiSecret` in interface `LastfmWebServices`
  Returns:
    The current api secret.

### getApiKey

    public final java.lang.String getApiKey()

  Description copied from interface: `LastfmWebServices`
  Get the current api key.

  Specified by:
    `getApiKey` in interface `LastfmWebServices`
  Returns:
    The current api key.

### getFetcher

    public Fetcher getFetcher()

  Description copied from interface: `LastfmWebServices`
  Get the current fetcher.

  Specified by:
    `getFetcher` in interface `LastfmWebServices`
  Returns:
    The `Fetcher` responsible for fetching the data.

### setFetcher

    public void setFetcher(Fetcher fetcher)

  Description copied from interface: `LastfmWebServices`
  Sets the current fetcher.

  Specified by:
    `setFetcher` in interface `LastfmWebServices`

### setTimeToLive

    public final void setTimeToLive(java.util.Properties ttls)

  You can specify how long the data of each method should be cached. Usually this defaults to the expiration header sent by last.fm. The properties must be organized as follows: The key is the package and method separated by a dot, the value is the time to live in milliseconds. E.g.:

       artist.getinfo = 2419200000

  A special entry is exception, this is used to cache exceptions.

  Parameters:
    `ttls` - Properties containing method time to lives.

### getFromCache

    protected abstract java.io.Serializable getFromCache(java.lang.String id)

  Try to fetch the result from cache.

  Type Parameters:
    `T` - Return type of the query.
  Parameters:
    `id` - Id to lookup.
  Returns:
    The entry if found or null.

### putToCache

    protected abstract java.io.Serializable putToCache(java.lang.String id,
                                                       java.io.Serializable result,
                                                       long timeToLive)

  Store result in cache.

  Type Parameters:
    `T` - Return type of the query.
  Parameters:
    `id` - The id to store the entry for.
    `result` - The query result.
    `timeToLive` - The time to live for the cache entry in milliseconds.
  Returns:
    The cached result or the original result on caching errors.

Copyright © 2012. All Rights Reserved.