public class AudioBoxClient
extends java.lang.Object
AudioBoxClient is the main object of this library and allows you to perform requests and
operations on AudioBox.
AudioBox let developers access to API in order to build any kind of modern applications,
libraries and integrations on top of the platform.
Configuration config = new Configuration()
.setApiKey( "[Your Consumer Key]" )
.setApiSecret( "[Your Consumer Secret]" );
Through the Configuration object you can configure many aspects
of the library behaviors; some are trivial such as application name, version, etc. and
other are more complex such as HttpTransport or JSON parser.
This library does not offer a data store for credentials storage out of the box. You should provide
an implementation of the CredentialDataStore.
config.setCredentialDataStore( new MyCredentialDataStore() );
To comply with OAuth standard you also have to provide a CredentialRefreshListener
in order to keep tokens up to date.
config.setCredentialRefreshListener( new MyCredentialRefreshListener() );
Since this library wants to be as much agnostic as possible regarding the HTTP client and
the JSON parser libraries you should set them at this moment by choosing amongst:
config
.setHttpTransport( new NetHttpTransport() )
.setJsonFactory( new JacksonFactory() );
This is the basic configuration and once the setup is completed you can create your
Client, authorize the application and start performing any kind of operation supported
by AudioBox API through it:
Client client = new Client( config );
client.authorize( "username", "password" );
List<Playlist> playlists = client.getPlaylists();
...
NOTE: authorize(String, String) is only needed once
to get and store the OAuth2 grant token; password is never (and it never should be) stored.
NOTE: grant tokens may expires at any time. A request against AudioBox with
an expired token will result in an
AuthorizationException.
Your application should be ready to trap it in order to present a new login form.
NOTE: most of the methods of this library performs requests against
AudioBox services. In order to avoid too many requests is highly recommended to implement
some sort of caching system (memory or persisted).
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ACCOUNT_TOKENS
The key under which tokens are stored in the DataStore
|
| Constructor and Description |
|---|
AudioBoxClient(Configuration conf)
Instantiates a new Client.
|
| Modifier and Type | Method and Description |
|---|---|
com.google.api.client.auth.oauth2.TokenResponse |
authorize(java.lang.String username,
java.lang.String password)
Starts the authorization flow.
|
com.google.api.client.auth.oauth2.TokenResponse |
authorize(java.lang.String username,
java.lang.String password,
boolean relaunchExceptions)
Starts the authorization flow.
|
com.google.api.client.http.HttpResponse |
doDELETE(java.lang.String path)
Performs
signed DELETE requests to the given path. |
com.google.api.client.http.HttpResponse |
doDELETE(java.lang.String path,
com.google.api.client.json.JsonObjectParser parser,
com.google.api.client.http.HttpHeaders headers)
Performs
signed DELETE requests to the given path. |
com.google.api.client.http.HttpResponse |
doGET(java.lang.String path)
Performs
signed GET requests and returns the response. |
com.google.api.client.http.HttpResponse |
doGET(java.lang.String path,
com.google.api.client.json.JsonObjectParser parser,
com.google.api.client.http.HttpHeaders headers)
Performs
signed GET requests and returns the response. |
com.google.api.client.http.HttpResponse |
doPOST(java.lang.String path)
Performs
signed POST requests and returns the response. |
com.google.api.client.http.HttpResponse |
doPOST(java.lang.String path,
com.google.api.client.http.HttpContent data)
Performs
signed POST requests and returns the response. |
com.google.api.client.http.HttpResponse |
doPOST(java.lang.String path,
com.google.api.client.http.HttpContent data,
com.google.api.client.json.JsonObjectParser parser,
com.google.api.client.http.HttpHeaders headers)
Performs
signed POST requests and returns the response. |
com.google.api.client.http.HttpResponse |
doPUT(java.lang.String path,
com.google.api.client.http.HttpContent data)
Performs
signed PUT requests and returns the response. |
com.google.api.client.http.HttpResponse |
doPUT(java.lang.String path,
com.google.api.client.http.HttpContent data,
com.google.api.client.json.JsonObjectParser parser,
com.google.api.client.http.HttpHeaders headers)
Performs
signed PUT requests and returns the response. |
com.google.api.client.http.HttpResponse |
doRequest(java.lang.String method,
java.lang.String path,
com.google.api.client.http.HttpContent data,
com.google.api.client.json.JsonObjectParser parser,
com.google.api.client.http.HttpHeaders headers)
Executes the configured request by calling AudioBox API services.
|
com.google.api.client.http.HttpResponse |
doRequestToChannel(java.lang.String method,
java.lang.String path,
com.google.api.client.http.HttpContent data,
com.google.api.client.json.JsonObjectParser parser,
Configuration.Channels channel,
com.google.api.client.http.HttpHeaders headers)
Executes the configured request by calling AudioBox API services.
|
Configuration |
getConf()
Gets the global client configuration.
|
com.google.api.client.http.HttpHeaders |
getDefaultHeaders()
Gets global request headers
|
Notifications |
getNotifications()
Gets user's notifications.
|
Playlist |
getPlaylist(java.lang.String token)
Gets the token-specified playlist.
|
java.util.List<Playlist> |
getPlaylists()
Gets user's playlists.
|
User |
getUser()
Returns information about the authorized user.
|
boolean |
isDaemonRunning()
This method returns
true if AudioBox Desktop application is active on any computer. |
Upload |
newUpload(java.io.File file)
Builds a new
Upload ready to start. |
Upload |
newUpload(java.io.File file,
NetworkProgressListener listener)
Builds a new
Upload ready to start. |
java.lang.String |
remoteDaemonIp()
This methods returns the
remote ip address of AudioBox Desktop application |
public static final java.lang.String ACCOUNT_TOKENS
public AudioBoxClient(Configuration conf) throws ConfigurationException, java.io.IOException
conf - the confConfigurationException - the configuration exceptionjava.io.IOException - if any problem occurs with the configured data store factorypublic Configuration getConf()
public com.google.api.client.http.HttpHeaders getDefaultHeaders()
public com.google.api.client.auth.oauth2.TokenResponse authorize(java.lang.String username,
java.lang.String password)
throws java.io.IOException
username - the usernamepassword - the passwordAuthorizationException - in case the authorization fails.java.io.IOException - if any connection or configured data store problems occurs.public com.google.api.client.auth.oauth2.TokenResponse authorize(java.lang.String username,
java.lang.String password,
boolean relaunchExceptions)
throws java.io.IOException
username - the usernamepassword - the passwordrelaunchExceptions - whether or not relaunch possible exceptions.AuthorizationException - in case the authorization fails.java.io.IOException - if any connection or configured data store problems occurs.public boolean isDaemonRunning()
throws java.io.IOException
true if AudioBox Desktop application is active on any computer.true if AudioBox Desktop application is active on any computer. false if notAudioBoxException - if any of the remote error exception is detected.java.io.IOException - if any connection problem occurs.AudioBoxExceptionpublic java.lang.String remoteDaemonIp()
throws java.io.IOException
remote ip address of AudioBox Desktop applicationremote ip addressAudioBoxException - if any of the remote error exception is detected.java.io.IOException - if any connection problem occurs.AudioBoxExceptionpublic User getUser() throws java.io.IOException
userAudioBoxException - if any of the remote error exception is detected.java.io.IOException - if any connection problem occurs.AudioBoxExceptionpublic java.util.List<Playlist> getPlaylists() throws java.io.IOException
List of playlistsAudioBoxException - if any of the remote error exception is detected.java.io.IOException - if any connection problem occurs.AudioBoxExceptionpublic Playlist getPlaylist(java.lang.String token) throws java.io.IOException
token - the token of the playlist to get.playlistAudioBoxException - if any of the remote error exception is detected.java.io.IOException - if any connection problem occurs.AudioBoxExceptionpublic Notifications getNotifications() throws java.io.IOException
notificationsAudioBoxException - if any of the remote error exception is detected.java.io.IOException - if any connection problem occurs.AudioBoxExceptionpublic Upload newUpload(java.io.File file)
Upload ready to start.
You can still set a listener with Upload.setListener(fm.audiobox.core.net.NetworkProgressListener)
file - the file to upload on AudioBoxUpload ready to Upload.start()public Upload newUpload(java.io.File file, NetworkProgressListener listener)
Upload ready to start.file - the file to upload on AudioBoxlistener - the NetworkProgressListener for progress monitoringUpload ready to Upload.start()public com.google.api.client.http.HttpResponse doGET(java.lang.String path)
throws java.io.IOException
signed GET requests and returns the response.path - the AudioBox API path where to make the request to.AudioBoxException - if any of the remote error exception is detected.java.io.IOException - if any connection problem occurs.AudioBoxExceptionpublic com.google.api.client.http.HttpResponse doGET(java.lang.String path,
com.google.api.client.json.JsonObjectParser parser,
com.google.api.client.http.HttpHeaders headers)
throws java.io.IOException
signed GET requests and returns the response.path - the AudioBox API path where to make the request to.parser - the JsonObjectParser to use to parse the response.headers - additional request headersAudioBoxException - if any of the remote error exception is detected.java.io.IOException - if any connection problem occurs.AudioBoxExceptionpublic com.google.api.client.http.HttpResponse doPUT(java.lang.String path,
com.google.api.client.http.HttpContent data)
throws java.io.IOException
signed PUT requests and returns the response.path - the AudioBox API path where to make the request to.data - the data to send with the requestAudioBoxException - if any of the remote error exception is detected.java.io.IOException - if any connection problem occurs.AudioBoxExceptionpublic com.google.api.client.http.HttpResponse doPUT(java.lang.String path,
com.google.api.client.http.HttpContent data,
com.google.api.client.json.JsonObjectParser parser,
com.google.api.client.http.HttpHeaders headers)
throws java.io.IOException
signed PUT requests and returns the response.path - the AudioBox API path where to make the request to.data - the data to send with the requestparser - the JsonObjectParser to use to parse the response.headers - additional request headersAudioBoxException - if any of the remote error exception is detected.java.io.IOException - if any connection problem occurs.AudioBoxExceptionpublic com.google.api.client.http.HttpResponse doDELETE(java.lang.String path)
throws java.io.IOException
signed DELETE requests to the given path.path - the AudioBox API path where to make the request to.AudioBoxException - if any of the remote error exception is detected.java.io.IOException - if any connection problem occurs.AudioBoxExceptionpublic com.google.api.client.http.HttpResponse doDELETE(java.lang.String path,
com.google.api.client.json.JsonObjectParser parser,
com.google.api.client.http.HttpHeaders headers)
throws java.io.IOException
signed DELETE requests to the given path.path - the AudioBox API path where to make the request to.parser - the JsonObjectParser to use to parse the response.headers - additional request headersAudioBoxException - if any of the remote error exception is detected.java.io.IOException - if any connection problem occurs.AudioBoxExceptionpublic com.google.api.client.http.HttpResponse doPOST(java.lang.String path)
throws java.io.IOException
signed POST requests and returns the response.path - the AudioBox API path where to make the request to.AudioBoxException - if any of the remote error exception is detected.java.io.IOException - if any connection problem occurs.AudioBoxExceptionpublic com.google.api.client.http.HttpResponse doPOST(java.lang.String path,
com.google.api.client.http.HttpContent data)
throws java.io.IOException
signed POST requests and returns the response.path - the AudioBox API path where to make the request to.data - the data to send with the requestAudioBoxException - if any of the remote error exception is detected.java.io.IOException - if any connection problem occurs.AudioBoxExceptionpublic com.google.api.client.http.HttpResponse doPOST(java.lang.String path,
com.google.api.client.http.HttpContent data,
com.google.api.client.json.JsonObjectParser parser,
com.google.api.client.http.HttpHeaders headers)
throws java.io.IOException
signed POST requests and returns the response.path - the AudioBox API path where to make the request to.data - the data to send with the requestparser - the JsonObjectParser to use to parse the response.headers - additional request headersAudioBoxException - if any of the remote error exception is detected.java.io.IOException - if any connection problem occurs.AudioBoxExceptionpublic com.google.api.client.http.HttpResponse doRequest(java.lang.String method,
java.lang.String path,
com.google.api.client.http.HttpContent data,
com.google.api.client.json.JsonObjectParser parser,
com.google.api.client.http.HttpHeaders headers)
throws java.io.IOException
method - the method to usepath - the AudioBox API path where to make the request to.data - the data to send with the requestparser - the parser to use for the resulting objectheaders - additional request headersAudioBoxException - if any of the remote error exception is detected.java.io.IOException - if any connection problem occurs.AudioBoxExceptionpublic com.google.api.client.http.HttpResponse doRequestToChannel(java.lang.String method,
java.lang.String path,
com.google.api.client.http.HttpContent data,
com.google.api.client.json.JsonObjectParser parser,
Configuration.Channels channel,
com.google.api.client.http.HttpHeaders headers)
throws java.io.IOException
method - the method to usepath - the AudioBox API path where to make the request to.data - the data to send with the requestparser - the parser to use for the resulting objectchannel - the Channel to queryheaders - additional request headersAudioBoxException - if any of the remote error exception is detected.java.io.IOException - if any connection problem occurs.AudioBoxException