java.lang.Object | |
↳ | fm.audiobox.core.AudioBoxClient |
AudioBoxClient
is the main object of this library and allows you to perform requests and
operations on AudioBox.
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 com.google.api.client.auth.oauth2.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).
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | ACCOUNT_TOKENS | The key under which tokens are stored in the DataStore |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
AudioBoxClient(Configuration conf)
Instantiates a new Client.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
synchronized TokenResponse |
authorize(String username, String password, boolean relaunchExceptions)
Starts the authorization flow.
| ||||||||||
TokenResponse |
authorize(String username, String password)
Starts the authorization flow.
| ||||||||||
HttpResponse |
doDELETE(String path)
Performs
signed DELETE requests to the given path. | ||||||||||
HttpResponse |
doDELETE(String path, JsonObjectParser parser, HttpHeaders headers)
Performs
signed DELETE requests to the given path. | ||||||||||
HttpResponse |
doGET(String path)
Performs
signed GET requests and returns the response. | ||||||||||
HttpResponse |
doGET(String path, JsonObjectParser parser, HttpHeaders headers)
Performs
signed GET requests and returns the response. | ||||||||||
HttpResponse |
doPOST(String path, HttpContent data)
Performs
signed POST requests and returns the response. | ||||||||||
HttpResponse |
doPOST(String path)
Performs
signed POST requests and returns the response. | ||||||||||
HttpResponse |
doPOST(String path, HttpContent data, JsonObjectParser parser, HttpHeaders headers)
Performs
signed POST requests and returns the response. | ||||||||||
HttpResponse |
doPUT(String path, HttpContent data, JsonObjectParser parser, HttpHeaders headers)
Performs
signed PUT requests and returns the response. | ||||||||||
HttpResponse |
doPUT(String path, HttpContent data)
Performs
signed PUT requests and returns the response. | ||||||||||
HttpResponse |
doRequest(String method, String path, HttpContent data, JsonObjectParser parser, HttpHeaders headers)
Executes the configured request by calling AudioBox API services.
| ||||||||||
synchronized HttpResponse |
doRequestToChannel(String method, String path, HttpContent data, JsonObjectParser parser, Configuration.Channels channel, HttpHeaders headers)
Executes the configured request by calling AudioBox API services.
| ||||||||||
Configuration |
getConf()
Gets the global client configuration.
| ||||||||||
HttpHeaders |
getDefaultHeaders()
Gets global request headers
| ||||||||||
Notifications |
getNotifications()
Gets user's notifications.
| ||||||||||
Playlist |
getPlaylist(String token)
Gets the token-specified playlist.
| ||||||||||
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(File file, NetworkProgressListener listener)
Builds a new
Upload ready to start. | ||||||||||
Upload |
newUpload(File file)
Builds a new
Upload ready to start. | ||||||||||
String |
remoteDaemonIp()
This methods returns the
remote ip address of AudioBox Desktop application |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
The key under which tokens are stored in the DataStore
Instantiates a new Client.
conf | the conf |
---|
ConfigurationException | the configuration exception |
---|---|
IOException | if any problem occurs with the configured data store factory |
Starts the authorization flow.
Given a username and a password if the request succeed this method will store the grant token for future requests and return the response.username | the username |
---|---|
password | the password |
relaunchExceptions | whether or not relaunch possible exceptions. |
AuthorizationException | in case the authorization fails. |
---|---|
IOException | if any connection or configured data store problems occurs. |
Starts the authorization flow.
Given a username and a password if the request succeed this method will store the grant token for future requests and return the response.username | the username |
---|---|
password | the password |
AuthorizationException | in case the authorization fails. |
---|---|
IOException | if any connection or configured data store problems occurs. |
Performs 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. |
---|---|
IOException | if any connection problem occurs. |
Performs signed
DELETE requests to the given path.
path | the AudioBox API path where to make the request to. |
---|---|
parser | the com.google.api.client.json.JsonObjectParser to use to parse the response. |
headers | additional request headers |
AudioBoxException | if any of the remote error exception is detected. |
---|---|
IOException | if any connection problem occurs. |
Performs 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. |
---|---|
IOException | if any connection problem occurs. |
Performs signed
GET requests and returns the response.
path | the AudioBox API path where to make the request to. |
---|---|
parser | the com.google.api.client.json.JsonObjectParser to use to parse the response. |
headers | additional request headers |
AudioBoxException | if any of the remote error exception is detected. |
---|---|
IOException | if any connection problem occurs. |
Performs 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 request |
AudioBoxException | if any of the remote error exception is detected. |
---|---|
IOException | if any connection problem occurs. |
Performs 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. |
---|---|
IOException | if any connection problem occurs. |
Performs 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 request |
parser | the com.google.api.client.json.JsonObjectParser to use to parse the response. |
headers | additional request headers |
AudioBoxException | if any of the remote error exception is detected. |
---|---|
IOException | if any connection problem occurs. |
Performs 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 request |
parser | the com.google.api.client.json.JsonObjectParser to use to parse the response. |
headers | additional request headers |
AudioBoxException | if any of the remote error exception is detected. |
---|---|
IOException | if any connection problem occurs. |
Performs 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 request |
AudioBoxException | if any of the remote error exception is detected. |
---|---|
IOException | if any connection problem occurs. |
Executes the configured request by calling AudioBox API services.
method | the method to use |
---|---|
path | the AudioBox API path where to make the request to. |
data | the data to send with the request |
parser | the parser to use for the resulting object |
headers | additional request headers |
AudioBoxException | if any of the remote error exception is detected. |
---|---|
IOException | if any connection problem occurs. |
Executes the configured request by calling AudioBox API services.
method | the method to use |
---|---|
path | the AudioBox API path where to make the request to. |
data | the data to send with the request |
parser | the parser to use for the resulting object |
channel | the Channel to query |
headers | additional request headers |
AudioBoxException | if any of the remote error exception is detected. |
---|---|
IOException | if any connection problem occurs. |
Gets global request headers
Gets user's notifications.
notifications
AudioBoxException | if any of the remote error exception is detected. |
---|---|
IOException | if any connection problem occurs. |
Gets the token-specified playlist.
Triggers Smart Playlist compilation if the requested playlist is a SmartPlaylist.
NOTE: this method will always perform a request against AudioBox servers, for this reason be
smart and try to apply some sort of cache strategy.
token | the token of the playlist to get. |
---|
playlist
AudioBoxException | if any of the remote error exception is detected. |
---|---|
IOException | if any connection problem occurs. |
Gets user's playlists.
playlists
AudioBoxException | if any of the remote error exception is detected. |
---|---|
IOException | if any connection problem occurs. |
Returns information about the authorized user.
NOTE: this method always performs a request, use it wisely
user
AudioBoxException | if any of the remote error exception is detected. |
---|---|
IOException | if any connection problem occurs. |
This method returns 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. |
---|---|
IOException | if any connection problem occurs. |
Builds a new Upload
ready to start.
file | the file to upload on AudioBox |
---|---|
listener | the NetworkProgressListener for progress monitoring |
Builds a new Upload
ready to start.
You can still set a listener with setListener(fm.audiobox.core.net.NetworkProgressListener)
file | the file to upload on AudioBox |
---|
This methods returns the remote ip address
of AudioBox Desktop application
remote ip address
AudioBoxException | if any of the remote error exception is detected. |
---|---|
IOException | if any connection problem occurs. |