lu.thinds.android
Class RestService

java.lang.Object
  extended by lu.thinds.android.RestService

public class RestService
extends java.lang.Object

This is an Android Service to provide REST functionality outside of the Application thread.


Field Summary
static int GET
           
static int POST
           
 
Constructor Summary
RestService(Handler mHandler, Context mContext, java.lang.String url)
          Class constructor, requiring a handler (to receive a result), a context (to launch the service), and a url (to specify where to make the request).
 
Method Summary
 void addHeader(java.lang.String name, java.lang.String value)
          Appends a header to the URL supplied by the constructor
 void addParam(java.lang.String name, java.lang.String value)
          Appends a parameter to the URL supplied by the constructor.
 void execute(int method)
          Executes the current URL as a REST request in an IntentService.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GET

public static final int GET
See Also:
Constant Field Values

POST

public static final int POST
See Also:
Constant Field Values
Constructor Detail

RestService

public RestService(Handler mHandler,
                   Context mContext,
                   java.lang.String url)
Class constructor, requiring a handler (to receive a result), a context (to launch the service), and a url (to specify where to make the request).

In this implementation, name is written as a simple string and value as a UTF-8 Url Encoded Value.

Parameters:
mHandler - The handler used to receive a response. Response is given to the msg object accessed in an Overridden handleMessage.
mContext - The context used to execute the service. Suggested to use getApplicationContext() to prevent leaks.
url - The url on which to execute the request.
Method Detail

addParam

public void addParam(java.lang.String name,
                     java.lang.String value)
Appends a parameter to the URL supplied by the constructor.

In this implementation, name is written as a simple string and value as a UTF-8 Url Encoded Value.

Parameters:
name - The name associated with the name/value pair for the url argument
value - The value associated with the name/value pair for the url argument

addHeader

public void addHeader(java.lang.String name,
                      java.lang.String value)
Appends a header to the URL supplied by the constructor

Parameters:
name - The name associated with the name/value pair for the url header
value - The value associated with the name/value pair for the url header

execute

public void execute(int method)
Executes the current URL as a REST request in an IntentService. The method argument specifies the HTTP Verb to use. Must use either RestService.GET or RestService.POST

The return string will be provided in the HandleMessage method of the handler provided by the constructor. It will be present as the object field of the incoming message.

Parameters:
method - The type of HTTP request to make. Can be either RestService.GET or RestService.POST