winterwell.jtwitter
Interface Twitter.IHttpClient

All Known Implementing Classes:
OAuthScribeClient, OAuthSignpostClient, URLConnectionHttpClient
Enclosing class:
Twitter

public static interface Twitter.IHttpClient

Interface for an http client - e.g. allows for OAuth to be used instead. The standard version is OAuthSignpostClient.

If creating your own version, please provide support for throwing the right subclass of TwitterException - see URLConnectionHttpClient.processError(java.net.HttpURLConnection) for example code.


Method Summary
 boolean canAuthenticate()
          Whether this client is setup to do authentication when contacting the Twitter server.
 java.net.HttpURLConnection connect(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> vars, boolean authenticate)
          Lower-level GET method.
 Twitter.IHttpClient copy()
           
 java.lang.String getHeader(java.lang.String headerName)
          Fetch a header from the last http request.
 java.lang.String getPage(java.lang.String uri, java.util.Map<java.lang.String,java.lang.String> vars, boolean authenticate)
          Send an HTTP GET request and return the response body.
 RateLimit getRateLimit(Twitter.KRequestType reqType)
           
 java.lang.String post(java.lang.String uri, java.util.Map<java.lang.String,java.lang.String> vars, boolean authenticate)
          Send an HTTP POST request and return the response body.
 java.net.HttpURLConnection post2_connect(java.lang.String uri, java.util.Map<java.lang.String,java.lang.String> vars)
          Lower-level POST method.
 void setTimeout(int millisecs)
          Set the timeout for a single get/post request.
 

Method Detail

canAuthenticate

boolean canAuthenticate()
Whether this client is setup to do authentication when contacting the Twitter server. Note: This is a fast method that does not call the server, so it does not check whether the access token or password is valid. See {Twitter#isValidLogin()} or Twitter_Account.verifyCredentials() if you need to check a login.


connect

java.net.HttpURLConnection connect(java.lang.String url,
                                   java.util.Map<java.lang.String,java.lang.String> vars,
                                   boolean authenticate)
                                   throws java.io.IOException
Lower-level GET method.

Parameters:
url -
vars -
authenticate -
Returns:
Throws:
java.io.IOException

copy

Twitter.IHttpClient copy()
Returns:
a copy of this client. The copy can share structure, but it MUST be safe for passing to a new thread to be used in parallel with the original.

getHeader

java.lang.String getHeader(java.lang.String headerName)
Fetch a header from the last http request. This is inherently NOT thread safe. Headers from error messages should (probably) be cached.

Parameters:
headerName -
Returns:
header value, or null if unset

getPage

java.lang.String getPage(java.lang.String uri,
                         java.util.Map<java.lang.String,java.lang.String> vars,
                         boolean authenticate)
                         throws TwitterException
Send an HTTP GET request and return the response body. Note that this will change all line breaks into system line breaks!

Parameters:
uri - The uri to fetch
vars - get arguments to add to the uri
authenticate - If true, use authentication. The authentication method used depends on the implementation (basic-auth, OAuth). It is an error to use true if no authentication details have been set.
Throws:
TwitterException - for a variety of reasons
TwitterException.E404 - for resource-does-not-exist errors

getRateLimit

RateLimit getRateLimit(Twitter.KRequestType reqType)
See Also:
This is where the Twitter method is implemented.

post

java.lang.String post(java.lang.String uri,
                      java.util.Map<java.lang.String,java.lang.String> vars,
                      boolean authenticate)
                      throws TwitterException
Send an HTTP POST request and return the response body.

Parameters:
uri - The uri to post to.
vars - The form variables to send. These are URL encoded before sending.
authenticate - If true, send user authentication
Returns:
The response from the server.
Throws:
TwitterException - for a variety of reasons
TwitterException.E404 - for resource-does-not-exist errors

post2_connect

java.net.HttpURLConnection post2_connect(java.lang.String uri,
                                         java.util.Map<java.lang.String,java.lang.String> vars)
                                         throws java.lang.Exception
Lower-level POST method.

Parameters:
uri -
vars -
Returns:
a freshly opened authorised connection
Throws:
TwitterException
java.lang.Exception

setTimeout

void setTimeout(int millisecs)
Set the timeout for a single get/post request. This is an optional method - implementations can ignore it!

Parameters:
millisecs -