com.feedhenry.sdk
Class FH

java.lang.Object
  extended by com.feedhenry.sdk.FH

public class FH
extends java.lang.Object

The FH class provides static methods to initialize the library, create new instance of all the API request objects and configure global settings.


Field Summary
static java.lang.String APP_APIKEY_KEY
           
static java.lang.String APP_CONNECTION_TAG_KEY
           
static java.lang.String APP_HOST_KEY
           
static java.lang.String APP_ID_KEY
           
static java.lang.String APP_MODE_KEY
           
static java.lang.String APP_PROJECT_KEY
           
static int LOG_LEVEL_DEBUG
           
static int LOG_LEVEL_ERROR
           
static int LOG_LEVEL_INFO
           
static int LOG_LEVEL_NONE
           
static int LOG_LEVEL_VERBOSE
           
static int LOG_LEVEL_WARNING
           
static java.lang.String USER_AGENT_TEMP
           
static java.lang.String VERSION
           
 
Method Summary
static FHActRequest buildActRequest(java.lang.String pRemoteAction, JSONObject pParams)
          Deprecated. 
static FHAuthRequest buildAuthRequest()
          Build an instance of FHAuthRequest object to perform authentication request.
static FHAuthRequest buildAuthRequest(java.lang.String pPolicyId)
          Build an instance of FHAuthRequest object to perform authentication request and set the auth policy id
static FHAuthRequest buildAuthRequest(java.lang.String pPolicyId, java.lang.String pUserName, java.lang.String pPassword)
          Build an instance of FHAuthRequest object to perform authentication request and set the auth policy id, user name and passowrd
static FHCloudRequest buildCloudRequest(java.lang.String pPath, java.lang.String pMethod, org.apache.http.Header[] pHeaders, JSONObject pParams)
          Build an instance of FHCloudRequest object to call cloud APIs
static void cloud(java.lang.String pPath, java.lang.String pMethod, org.apache.http.Header[] pHeaders, JSONObject pParams, FHActCallback pCallback)
          Call cloud APIs asynchronously.
static java.lang.String getCloudHost()
          Get the cloud host after app finish initialising
static JSONObject getDefaultParams()
          Get the default params for customised HTTP Requests.
static org.apache.http.Header[] getDefaultParamsAsHeaders(org.apache.http.Header[] pHeaders)
          Similar to getDefaultParams, but return HTTP headers instead
static int getLogLevel()
          Get the current log level for the FH library
static java.lang.String getUserAgent()
          Get the customized user-agent string for the SDK
static void init(android.content.Context pContext, FHActCallback pCallback)
          Initialize the application.
static boolean isOnline()
           
static boolean isReady()
          Check if FH is ready
static void setLogLevel(int pLogLevel)
          Set the log level for the library.
static void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

APP_HOST_KEY

public static final java.lang.String APP_HOST_KEY
See Also:
Constant Field Values

APP_PROJECT_KEY

public static final java.lang.String APP_PROJECT_KEY
See Also:
Constant Field Values

APP_CONNECTION_TAG_KEY

public static final java.lang.String APP_CONNECTION_TAG_KEY
See Also:
Constant Field Values

APP_ID_KEY

public static final java.lang.String APP_ID_KEY
See Also:
Constant Field Values

APP_APIKEY_KEY

public static final java.lang.String APP_APIKEY_KEY
See Also:
Constant Field Values

APP_MODE_KEY

public static final java.lang.String APP_MODE_KEY
See Also:
Constant Field Values

LOG_LEVEL_VERBOSE

public static final int LOG_LEVEL_VERBOSE
See Also:
Constant Field Values

LOG_LEVEL_DEBUG

public static final int LOG_LEVEL_DEBUG
See Also:
Constant Field Values

LOG_LEVEL_INFO

public static final int LOG_LEVEL_INFO
See Also:
Constant Field Values

LOG_LEVEL_WARNING

public static final int LOG_LEVEL_WARNING
See Also:
Constant Field Values

LOG_LEVEL_ERROR

public static final int LOG_LEVEL_ERROR
See Also:
Constant Field Values

LOG_LEVEL_NONE

public static final int LOG_LEVEL_NONE
See Also:
Constant Field Values

USER_AGENT_TEMP

public static final java.lang.String USER_AGENT_TEMP
See Also:
Constant Field Values

VERSION

public static final java.lang.String VERSION
See Also:
Constant Field Values
Method Detail

init

public static void init(android.content.Context pContext,
                        FHActCallback pCallback)
Initialize the application. This must be called before the application can use the FH library. The initialization process happens in a background thread so that the UI thread won't be blocked. If you need to call other FH API methods, you need to make sure they are called after the init finishes. The best way to do it is to provide a FHActCallback instance and implement the success method. The callback functions are invoked on the main UI thread. For example, in your main activity class's onCreate method, you can do this
 FH.init(this, new FHActCallback() {
    public void success(FHResponse pRes) {
      //pRes will be null for init call if it succeeds, don't use it to access response data
      FHActRequest request = FH.buildActRequest("readData", new JSONObject());
      request.executeAsync(new FHActCallback(){
        public void success(FHResponse pResp){
          //process response data
        }
        
        public void fail(FHResponse pResp){
          //process error data
        }
      })
    }
     
    public void fail(FHResponse pRes) {
      Log.e("FHInit", pRes.getErrorMessage(), pRes.getError());
    }
  });
 

Parameters:
pContext - your application's context
pCallback - the callback function to be executed after the initialization is finished

isOnline

public static boolean isOnline()

stop

public static void stop()

isReady

public static boolean isReady()
Check if FH is ready

Returns:
A boolean value to indicate if FH finishes initialization

buildActRequest

@Deprecated
public static FHActRequest buildActRequest(java.lang.String pRemoteAction,
                                                      JSONObject pParams)
                                    throws FHNotReadyException
Deprecated. 

Throws:
FHNotReadyException

buildAuthRequest

public static FHAuthRequest buildAuthRequest()
                                      throws FHNotReadyException
Build an instance of FHAuthRequest object to perform authentication request.

Returns:
an instance of FHAuthRequest
Throws:
FHNotReadyException

buildAuthRequest

public static FHAuthRequest buildAuthRequest(java.lang.String pPolicyId)
                                      throws FHNotReadyException
Build an instance of FHAuthRequest object to perform authentication request and set the auth policy id

Parameters:
pPolicyId - the auth policy id used by this auth request
Returns:
an instance of FHAuthRequest
Throws:
FHNotReadyException

buildAuthRequest

public static FHAuthRequest buildAuthRequest(java.lang.String pPolicyId,
                                             java.lang.String pUserName,
                                             java.lang.String pPassword)
                                      throws FHNotReadyException
Build an instance of FHAuthRequest object to perform authentication request and set the auth policy id, user name and passowrd

Parameters:
pPolicyId - the auth policy id used by this auth request
pUserName - the required user name for the auth request
pPassword - the required password for the auth request
Returns:
an instance of FHAuthRequest
Throws:
FHNotReadyException

buildCloudRequest

public static FHCloudRequest buildCloudRequest(java.lang.String pPath,
                                               java.lang.String pMethod,
                                               org.apache.http.Header[] pHeaders,
                                               JSONObject pParams)
                                        throws java.lang.Exception
Build an instance of FHCloudRequest object to call cloud APIs

Parameters:
pPath - the path of the cloud API
pMethod - currently supports GET, POST, PUT and DELETE
pHeaders - headers need to be set, can be null
pParams - the request params, can be null
Returns:
an instance of FHCloudRequest
Throws:
java.lang.Exception

getCloudHost

public static java.lang.String getCloudHost()
                                     throws FHNotReadyException
Get the cloud host after app finish initialising

Returns:
the cloud host of the app
Throws:
FHNotReadyException

getDefaultParams

public static JSONObject getDefaultParams()
                                   throws java.lang.Exception
Get the default params for customised HTTP Requests. Those params will be required to enable app analytics on the FH platform. You can either add the params to your request body as a JSONObject with the key "__fh", or use the getDefaultParamsAsHeaders method to add them as HTTP request headers.

Returns:
a JSONObject contains the default params
Throws:
java.lang.Exception

getDefaultParamsAsHeaders

public static org.apache.http.Header[] getDefaultParamsAsHeaders(org.apache.http.Header[] pHeaders)
                                                          throws java.lang.Exception
Similar to getDefaultParams, but return HTTP headers instead

Parameters:
pHeaders - existing headers
Returns:
new headers by combining existing headers and default headers
Throws:
java.lang.Exception

cloud

public static void cloud(java.lang.String pPath,
                         java.lang.String pMethod,
                         org.apache.http.Header[] pHeaders,
                         JSONObject pParams,
                         FHActCallback pCallback)
                  throws java.lang.Exception
Call cloud APIs asynchronously.

Parameters:
pPath - the path to the cloud API
pMethod - currently supports GET, POST, PUT and DELETE
pHeaders - headers need to be set, can be null
pParams - the request params, can be null. Will be converted to query strings depending on the HTTP method
pCallback - the callback to be executed when the cloud call is finished
Throws:
java.lang.Exception

setLogLevel

public static void setLogLevel(int pLogLevel)
Set the log level for the library. The default level is LOG_LEVEL_ERROR. Please make sure this is set to LOG_LEVEL_ERROR or LOG_LEVEL_NONE before releasing the application. The log level can be one of

Parameters:
pLogLevel - The level of logging for the FH library

getLogLevel

public static int getLogLevel()
Get the current log level for the FH library

Returns:
The current log level

getUserAgent

public static java.lang.String getUserAgent()
Get the customized user-agent string for the SDK

Returns:
customized user-agent string