com.betfair.games
Class ApiAdapter

java.lang.Object
  extended by org.apache.commons.httpclient.HttpClient
      extended by com.betfair.games.ApiAdapter
Direct Known Subclasses:
ApiClient

public class ApiAdapter
extends org.apache.commons.httpclient.HttpClient

The Java ApiAdapter is a subclass of HttpClient. It is designed to connect to the Betfair Exchange Games API. It provides a simple GET and POST methods to wrap the communication. The ApiAdapter also handles the XML used. the GET and POST method only returns Objects thats are instances of class from the betfair.games.api.v1 package (a JAXB compiled set of classes build from the gamex API schema XSD.

Version:
1.0.1
Author:
M Larsson

Constructor Summary
ApiAdapter(ApiApplication app)
          Constructs a new ApiAdapter to be used in a specified application.
 
Method Summary
static java.lang.String createAgentInstanceID(java.lang.String gamexAPIAgent)
          Static method to be used where a Agent Instance has to be created as it is specified in the Betfair Gamex API documentation.
 betfair.games.api.v1.Api get()
          When the get method is called without parameters it returns the root element (the API service list) by sending a GET request using the base URL for the API Server as specified by the application.
 java.lang.Object get(java.lang.String url)
          Returns an Object object that is an instance of the responseType Class, as defined by the API XML.
 java.lang.String getParam(java.lang.String name)
          Returns the value of the parameter with the specified name, or null if this map contains no mapping for the name.
 java.lang.String getVersion()
          Returns version information for the ApiAdapter.
 java.lang.Object post(java.lang.String url, java.lang.Object bodyobject)
          Returns an Object object that is an instance of the responseType Class, as defined by the API XML.
 void putParam(java.lang.String name, java.lang.String value)
          Adds a parameter to the query string sent to the Api server when using the get() or post() methods of the adapter.
 
Methods inherited from class org.apache.commons.httpclient.HttpClient
executeMethod, executeMethod, executeMethod, getHost, getHostConfiguration, getHttpConnectionManager, getParams, getPort, getState, isStrictMode, setConnectionTimeout, setHostConfiguration, setHttpConnectionFactoryTimeout, setHttpConnectionManager, setParams, setState, setStrictMode, setTimeout
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ApiAdapter

public ApiAdapter(ApiApplication app)
           throws ApiAdapterException
Constructs a new ApiAdapter to be used in a specified application. The constructor initiates the HttpClient by calling the parent constructor. It reads required user data and application data from the application. It gets the application instance ID from the registry (or sets it). It creates JAXB unmarshaller/marshaller objects and verifies the JAXB instance against the schema on the API server.

Parameters:
app - The application using the ApiAdapter. The ApiApplication is forced to provide the adapter with user and application data as specified by the ApiApplication interface.
Throws:
ApiAdapterException - if the construction of the ApiAdapter fails.
Method Detail

putParam

public void putParam(java.lang.String name,
                     java.lang.String value)
Adds a parameter to the query string sent to the Api server when using the get() or post() methods of the adapter.

Parameters:
name - name of query parameter with which the specified value is to be associated
value - query parameter value to be associated with the specified name

getParam

public java.lang.String getParam(java.lang.String name)
Returns the value of the parameter with the specified name, or null if this map contains no mapping for the name.

Parameters:
name - name of the query parameter whose associated value is to be returned
Returns:
the value of the query parameter with the specified name, or null if this map contains no mapping for the key

get

public betfair.games.api.v1.Api get()
                             throws ApiAdapterException
When the get method is called without parameters it returns the root element (the API service list) by sending a GET request using the base URL for the API Server as specified by the application.

Returns:
instance of the class Api
Throws:
ApiAdapterException - if there is an error when trying to retrieve the list of API services.

get

public java.lang.Object get(java.lang.String url)
                     throws ApiAdapterException
Returns an Object object that is an instance of the responseType Class, as defined by the API XML. The returned object must be cast before it can be used.

Parameters:
url - api server url to be called
Returns:
an Object object that is an instance of the responseType Class
Throws:
ApiAdapterException - if anything fails in the process of requesting the XML and create instances using the JAXB classes.

post

public java.lang.Object post(java.lang.String url,
                             java.lang.Object bodyobject)
                      throws ApiAdapterException
Returns an Object object that is an instance of the responseType Class, as defined by the API XML. The returned object must be cast before it can be used.

Parameters:
url - api server url to be called
Returns:
an Object object that is an instance of the responseType Class
Throws:
ApiAdapterException - if anything fails in the process of requesting the XML and create instances using the JAXB classes.

createAgentInstanceID

public static java.lang.String createAgentInstanceID(java.lang.String gamexAPIAgent)
Static method to be used where a Agent Instance has to be created as it is specified in the Betfair Gamex API documentation.

Parameters:
gamexAPIAgent - the unique name and version of the application
Returns:
gamexAPIAgentInstance, a unique 32 digit hexadecimal string

getVersion

public java.lang.String getVersion()
Returns version information for the ApiAdapter.

Returns:
version number as a test string