com.googlecode.jinahya.twitter.xauth
Class Client

java.lang.Object
  extended by com.googlecode.jinahya.twitter.xauth.Client
All Implemented Interfaces:
Authenticator, Requester

public abstract class Client
extends Object
implements Authenticator, Requester

Author:
Jin Kwon

Constructor Summary
Client(String consumerKey, String consumerSecret)
          Creates a new instance.
 
Method Summary
protected  String authorize(String method, String url, Vector<String> parameters, String token, String tokenSecret)
           
 InputStream GET(String url, Hashtable<String,String> parameters, boolean authorize)
          Requests HTTP GET resource.
 String getScreenName()
          Returns current user's screen name.
 String getUserId()
          Returns current user's id.
 boolean isSignedIn()
          Checks whether currently signed in or not.
 InputStream POST(String url, Hashtable<String,String> parameters, boolean authorize)
          Requests HTTP POST resource.
 InputStream request(String method, String url, Hashtable<String,String> parameters)
           
 InputStream request(String method, String url, Hashtable<String,String> parameters, boolean authorize)
           
 InputStream request(String method, String url, Vector<String> parameters, boolean authorize)
           
protected  String sign(String method, String url, Vector<String> parameters, String tokenSecret)
           
 void signIn(String username, String password)
          Signs in with given user credentials.
 void signOut()
          Signs out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.googlecode.jinahya.twitter.xauth.Authenticator
authenticate
 
Methods inherited from interface com.googlecode.jinahya.twitter.xauth.Requester
request
 

Constructor Detail

Client

public Client(String consumerKey,
              String consumerSecret)
Creates a new instance.

Parameters:
consumerKey - consumer key
consumerSecret - consumer secret
Method Detail

signIn

public void signIn(String username,
                   String password)
            throws Exception
Signs in with given user credentials.

Parameters:
username - username
password - password
Throws:
Exception - if an error occurs.

GET

public InputStream GET(String url,
                       Hashtable<String,String> parameters,
                       boolean authorize)
                throws Exception
Requests HTTP GET resource.

Parameters:
url - normalized request URL
parameters - request parameters
authorize - authorize flag
Returns:
resource stream
Throws:
Exception - if an I/O error occurs.

POST

public InputStream POST(String url,
                        Hashtable<String,String> parameters,
                        boolean authorize)
                 throws Exception
Requests HTTP POST resource.

Parameters:
url - normalized request URL
parameters - request parameters
authorize - authorize flag
Returns:
resource stream
Throws:
Exception - if any error occurs.

request

public InputStream request(String method,
                           String url,
                           Hashtable<String,String> parameters)
                    throws Exception
Parameters:
method -
url -
parameters -
Returns:
Throws:
Exception

request

public InputStream request(String method,
                           String url,
                           Hashtable<String,String> parameters,
                           boolean authorize)
                    throws Exception
Parameters:
method - request method
url - normalized resource url
parameters -
authorize - flag for authentication requirement
Returns:
resource stream
Throws:
Exception - if an error occurs.

request

public InputStream request(String method,
                           String url,
                           Vector<String> parameters,
                           boolean authorize)
                    throws Exception
Parameters:
method - request method
url - normalized resource URL
parameters - parameters
authorize - flag for authentication requirement
Returns:
resource stream
Throws:
Exception - if an error occurs

signOut

public void signOut()
Signs out.


getUserId

public String getUserId()
Returns current user's id. An IllegalStateException will be thrown if this client is not signed in.

Returns:
current user's id

getScreenName

public String getScreenName()
Returns current user's screen name. An IllegalStateException will be thrown if this client is not signed in.

Returns:
current user's screen name

isSignedIn

public boolean isSignedIn()
Checks whether currently signed in or not.

Returns:
signed in status

authorize

protected String authorize(String method,
                           String url,
                           Vector<String> parameters,
                           String token,
                           String tokenSecret)
                    throws Exception
Parameters:
method - request method
url - normalized resource url
parameters - parameters
token - access token
tokenSecret - token secret
Returns:
OAuth Authorization header value
Throws:
Exception - if an error occurs

sign

protected String sign(String method,
                      String url,
                      Vector<String> parameters,
                      String tokenSecret)
               throws Exception
Parameters:
method - HTTP method
url - normalized request URL
parameters - OAuth parameters
tokenSecret - token secret
Returns:
signature
Throws:
Exception - if an error occurs


Copyright © 2011. All Rights Reserved.