com.fitbit.api.client.http
Class HttpClient

java.lang.Object
  extended by com.fitbit.api.client.http.HttpClient
All Implemented Interfaces:
Serializable

public class HttpClient
extends Object
implements Serializable

A utility class to handle HTTP request/response.

Author:
Yusuke Yamamoto - yusuke at mac.com
See Also:
Serialized Form

Nested Class Summary
protected static class HttpClient.HttpMethod
           
 
Field Summary
static int CONFLICT
           
protected static org.apache.commons.logging.Log log
           
static int NOT_AUTHORIZED
           
 
Constructor Summary
HttpClient()
           
HttpClient(String userId, String password)
           
 
Method Summary
 Response delete(String url)
           
 Response delete(String url, boolean authenticated)
           
static String encodeParameters(PostParameter[] postParams)
           
 boolean equals(Object o)
           
 Response get(String url)
           
 Response get(String url, boolean authenticated)
           
 String getAccessTokenURL()
           
 String getAuthenticationRL()
           
 String getAuthorizationURL()
           
 int getConnectionTimeout()
           
 AccessToken getOAuthAccessToken(String token, String tokenSecret, String oauth_verifier)
           
 AccessToken getOAuthAccessToken(TempCredentials token)
           
 AccessToken getOAuthAccessToken(TempCredentials token, String pin)
           
 TempCredentials getOAuthRequestToken()
           
 TempCredentials getOauthRequestToken(String callback_url)
           
 String getPassword()
           
 String getProxyAuthPassword()
           
 String getProxyAuthUser()
           
 String getProxyHost()
           
 int getProxyPort()
           
 int getReadTimeout()
           
 String getRequestHeader(String name)
           
 String getRequestTokenURL()
           
 String getUserAgent()
           
 String getUserId()
           
 int hashCode()
           
protected  Response httpRequest(HttpClient.HttpMethod method, String url, PostParameter[] postParams, boolean authenticated)
           
 boolean isAuthenticationEnabled()
           
 Response post(String url)
           
 Response post(String url, boolean authenticated)
           
 Response post(String url, PostParameter[] postParameters)
           
 Response post(String url, PostParameter[] postParameters, boolean authenticated)
           
 void removeRequestHeader(String name)
           
 void setAccessTokenURL(String accessTokenURL)
           
 void setAuthorizationURL(String authorizationURL)
           
 void setConnectionTimeout(int connectionTimeout)
          Sets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced by this URLConnection.
 void setOAuthAccessToken(AccessToken token)
          Sets the authorized access token
 void setOAuthConsumer(String consumerKey, String consumerSecret)
          Sets the consumer key and consumer secret.
System property -DFitbit4j.oauth.consumerKey and -Dhttp.oauth.consumerSecret override this attribute.
 void setPassword(String password)
           
 void setProxyAuthPassword(String proxyAuthPassword)
          Sets proxy authentication password.
 void setProxyAuthUser(String proxyAuthUser)
          Sets proxy authentication user.
 void setProxyHost(String proxyHost)
          Sets proxy host.
 void setProxyPort(int proxyPort)
          Sets proxy port.
 void setReadTimeout(int readTimeout)
          Sets the read timeout to a specified timeout, in milliseconds.
 void setRequestHeader(String name, String value)
           
 void setRequestTokenURL(String requestTokenURL)
           
 void setRetryCount(int retryCount)
           
 void setRetryIntervalSecs(int retryIntervalSecs)
           
 void setUserAgent(String ua)
           
 void setUserId(String userId)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.apache.commons.logging.Log log

NOT_AUTHORIZED

public static final int NOT_AUTHORIZED
See Also:
Constant Field Values

CONFLICT

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

HttpClient

public HttpClient(String userId,
                  String password)

HttpClient

public HttpClient()
Method Detail

setUserId

public void setUserId(String userId)

setPassword

public void setPassword(String password)

getUserId

public String getUserId()

getPassword

public String getPassword()

isAuthenticationEnabled

public boolean isAuthenticationEnabled()

setOAuthConsumer

public void setOAuthConsumer(String consumerKey,
                             String consumerSecret)
Sets the consumer key and consumer secret.
System property -DFitbit4j.oauth.consumerKey and -Dhttp.oauth.consumerSecret override this attribute.

Parameters:
consumerKey - consumer key
consumerSecret - consumer secret

getOAuthRequestToken

public TempCredentials getOAuthRequestToken()
                                     throws FitbitAPIException
Returns:
request token
Throws:
FitbitAPIException

getOauthRequestToken

public TempCredentials getOauthRequestToken(String callback_url)
                                     throws FitbitAPIException
Parameters:
callback_url - callback url
Returns:
request token
Throws:
FitbitAPIException

getOAuthAccessToken

public AccessToken getOAuthAccessToken(TempCredentials token)
                                throws FitbitAPIException
Parameters:
token - request token
Returns:
access token
Throws:
FitbitAPIException

getOAuthAccessToken

public AccessToken getOAuthAccessToken(TempCredentials token,
                                       String pin)
                                throws FitbitAPIException
Parameters:
token - request token
Returns:
access token
Throws:
FitbitAPIException

getOAuthAccessToken

public AccessToken getOAuthAccessToken(String token,
                                       String tokenSecret,
                                       String oauth_verifier)
                                throws FitbitAPIException
Parameters:
token - request token
tokenSecret - request token secret
oauth_verifier - oauth_verifier or pin
Returns:
access token
Throws:
FitbitAPIException

setOAuthAccessToken

public void setOAuthAccessToken(AccessToken token)
Sets the authorized access token

Parameters:
token - authorized access token

setRequestTokenURL

public void setRequestTokenURL(String requestTokenURL)

getRequestTokenURL

public String getRequestTokenURL()

setAuthorizationURL

public void setAuthorizationURL(String authorizationURL)

getAuthorizationURL

public String getAuthorizationURL()

getAuthenticationRL

public String getAuthenticationRL()

setAccessTokenURL

public void setAccessTokenURL(String accessTokenURL)

getAccessTokenURL

public String getAccessTokenURL()

getProxyHost

public String getProxyHost()

setProxyHost

public void setProxyHost(String proxyHost)
Sets proxy host. System property -DFitbit4j.http.proxyHost or http.proxyHost overrides this attribute.

Parameters:
proxyHost -

getProxyPort

public int getProxyPort()

setProxyPort

public void setProxyPort(int proxyPort)
Sets proxy port. System property -DFitbit4j.http.proxyPort or -Dhttp.proxyPort overrides this attribute.

Parameters:
proxyPort -

getProxyAuthUser

public String getProxyAuthUser()

setProxyAuthUser

public void setProxyAuthUser(String proxyAuthUser)
Sets proxy authentication user. System property -DFitbit4j.http.proxyUser overrides this attribute.

Parameters:
proxyAuthUser -

getProxyAuthPassword

public String getProxyAuthPassword()

setProxyAuthPassword

public void setProxyAuthPassword(String proxyAuthPassword)
Sets proxy authentication password. System property -DFitbit4j.http.proxyPassword overrides this attribute.

Parameters:
proxyAuthPassword -

getConnectionTimeout

public int getConnectionTimeout()

setConnectionTimeout

public void setConnectionTimeout(int connectionTimeout)
Sets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced by this URLConnection. System property -DFitbit4j.http.connectionTimeout overrides this attribute.

Parameters:
connectionTimeout - - an int that specifies the connect timeout value in milliseconds

getReadTimeout

public int getReadTimeout()

setReadTimeout

public void setReadTimeout(int readTimeout)
Sets the read timeout to a specified timeout, in milliseconds. System property -DFitbit4j.http.readTimeout overrides this attribute.

Parameters:
readTimeout - - an int that specifies the timeout value to be used in milliseconds

setRetryCount

public void setRetryCount(int retryCount)

setUserAgent

public void setUserAgent(String ua)

getUserAgent

public String getUserAgent()

setRetryIntervalSecs

public void setRetryIntervalSecs(int retryIntervalSecs)

post

public Response post(String url,
                     PostParameter[] postParameters,
                     boolean authenticated)
              throws FitbitAPIException
Throws:
FitbitAPIException

post

public Response post(String url,
                     boolean authenticated)
              throws FitbitAPIException
Throws:
FitbitAPIException

post

public Response post(String url,
                     PostParameter[] postParameters)
              throws FitbitAPIException
Throws:
FitbitAPIException

post

public Response post(String url)
              throws FitbitAPIException
Throws:
FitbitAPIException

delete

public Response delete(String url)
                throws FitbitAPIException
Throws:
FitbitAPIException

delete

public Response delete(String url,
                       boolean authenticated)
                throws FitbitAPIException
Throws:
FitbitAPIException

get

public Response get(String url,
                    boolean authenticated)
             throws FitbitAPIException
Throws:
FitbitAPIException

get

public Response get(String url)
             throws FitbitAPIException
Throws:
FitbitAPIException

httpRequest

protected Response httpRequest(HttpClient.HttpMethod method,
                               String url,
                               PostParameter[] postParams,
                               boolean authenticated)
                        throws FitbitAPIException
Throws:
FitbitAPIException

encodeParameters

public static String encodeParameters(PostParameter[] postParams)

setRequestHeader

public void setRequestHeader(String name,
                             String value)

getRequestHeader

public String getRequestHeader(String name)

removeRequestHeader

public void removeRequestHeader(String name)

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 2012. All Rights Reserved.