Android Open Source - cheepcheep Http Client Factory






From Project

Back to project page cheepcheep.

License

The source code is released under:

Apache License

If you think the Android project cheepcheep listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.tarrio.cheepcheep.http;
//from   ww  w .  jav a  2 s.  co  m
import oauth.signpost.OAuthConsumer;
import oauth.signpost.OAuthProvider;
import oauth.signpost.basic.DefaultOAuthProvider;
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
import oauth.signpost.signature.SignatureMethod;

import org.apache.http.client.HttpClient;
import org.tarrio.cheepcheep.model.Preferences;

public class HttpClientFactory {

  /*
   * The OAuth consumer key and consumer secret are in the class
   * OAuthCredentials, which was not checked in.
   * 
   * To compile this project, register an application on Twitter and create a
   * class with that name in this same package, with this content:
   * 
   * <code>
   * package org.tarrio.cheepcheep.http;
   * 
   * class OAuthCredentials {
   *   static String CONSUMER_KEY = "contents of consumer key";
   *   static String CONSUMER_SECRET = "contents of consumer secret";
   * }
   * </code>
   */

  private static String REQUEST_TOKEN_URL = "https://api.twitter.com/oauth/request_token";
  private static String ACCESS_TOKEN_URL = "https://api.twitter.com/oauth/access_token";
  private static String AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize";

  private static HttpClient client;

  /**
   * Returns a HTTP client which can access Twitter using OAuth.
   * 
   * @param prefs
   *            the user's Preferences object.
   * @return an authenticating HTTP client.
   */
  public static HttpClient getClient(Preferences prefs) {
    if (client != null)
      return client;

    OAuthConsumer consumer = new CommonsHttpOAuthConsumer(
        OAuthCredentials.CONSUMER_KEY,
        OAuthCredentials.CONSUMER_SECRET, SignatureMethod.HMAC_SHA1);
    OAuthProvider provider = new DefaultOAuthProvider(consumer,
        REQUEST_TOKEN_URL, ACCESS_TOKEN_URL, AUTHORIZE_URL);

    if (!"".equals(prefs.getConsumerToken())) {
      consumer.setTokenWithSecret(prefs.getConsumerToken(), prefs
          .getConsumerSecret());
    }

    client = new OAuthHttpClient(consumer, provider);
    return client;
  }
}




Java Source Code List

org.tarrio.cheepcheep.Constants.java
org.tarrio.cheepcheep.HomeTimelineActivity.java
org.tarrio.cheepcheep.OAuthActivity.java
org.tarrio.cheepcheep.SingleTweetActivity.java
org.tarrio.cheepcheep.TweetListActions.java
org.tarrio.cheepcheep.TweetListAdapter.java
org.tarrio.cheepcheep.UserInfoActivity.java
org.tarrio.cheepcheep.dialog.CheepCheepDialog.java
org.tarrio.cheepcheep.dialog.ConfirmDeleteTweetDialog.java
org.tarrio.cheepcheep.dialog.NewTweetDialog.java
org.tarrio.cheepcheep.exceptions.AuthError.java
org.tarrio.cheepcheep.exceptions.CheepCheepException.java
org.tarrio.cheepcheep.exceptions.NetError.java
org.tarrio.cheepcheep.exceptions.ParseError.java
org.tarrio.cheepcheep.exceptions.TweetNotFoundError.java
org.tarrio.cheepcheep.exceptions.UserNotFoundError.java
org.tarrio.cheepcheep.http.HttpClientFactory.java
org.tarrio.cheepcheep.http.OAuthHttpClient.java
org.tarrio.cheepcheep.model.Preferences.java
org.tarrio.cheepcheep.model.Tweet.java
org.tarrio.cheepcheep.model.User.java
org.tarrio.cheepcheep.service.PreferencesProvider.java
org.tarrio.cheepcheep.service.TwitterJSONSerializer.java
org.tarrio.cheepcheep.service.TwitterService.java
org.tarrio.cheepcheep.service.TwitterStatusSaverService.java
org.tarrio.cheepcheep.task.AsyncTwitterTask.java
org.tarrio.cheepcheep.task.CreateNewTweetTask.java
org.tarrio.cheepcheep.task.DeleteTweetTask.java
org.tarrio.cheepcheep.task.FollowUnfollowUserTask.java
org.tarrio.cheepcheep.task.GetSingleTweetTask.java
org.tarrio.cheepcheep.task.GetUserInfoTask.java
org.tarrio.cheepcheep.task.TaskCallback.java
org.tarrio.cheepcheep.task.UpdateTweetsTask.java
org.tarrio.cheepcheep.task.VerifyCredentialsTask.java