Package org.scribe.model

Examples of org.scribe.model.OAuthRequest


    public YelpSearchResults searchMultiple(String searchTerm, String city) {

        // Execute a signed call to the Yelp service.
        OAuthService service = new ServiceBuilder().provider(YelpApi2.class).apiKey(CONSUMER_KEY).apiSecret(CONSUMER_SECRET).build();
        Token accessToken = new Token(TOKEN, TOKEN_SECRET);
        OAuthRequest request = new OAuthRequest(Verb.GET, "http://api.yelp.com/v2/search");

        request.addQuerystringParameter("location", city);
        //request.addQuerystringParameter("category", "restaurants");
        request.addQuerystringParameter("term", searchTerm);
        request.addQuerystringParameter("limit", "20");

        service.signRequest(accessToken, request);
        Response response = request.send();
        String rawData = response.getBody();

        YelpSearchResults mYelpSearchResult = null;

        try {
View Full Code Here


  protected ResponseType get(String endPoint) {
    return get(endPoint, null, null);
  }

  protected ResponseType get(String endPoint, Date modifiedAfter, Map<String,String> params) {
    OAuthRequest request = new OAuthRequest(Verb.GET, BASE_URL + endPoint);
    if (modifiedAfter != null) {
      request.addHeader("If-Modified-Since", utcFormatter.format(modifiedAfter));
    }
    if (params != null) {
      for (Map.Entry<String,String> param : params.entrySet()) {
        request.addQuerystringParameter(param.getKey(), param.getValue());
      }
    }
    service.signRequest(token, request);
    Response response = request.send();
    if (response.getCode() != 200) {
      ApiException exception = null;
      try {
        exception = unmarshallResponse(response, ApiException.class);
      } catch (Exception e) { 
View Full Code Here

    }
    return unmarshallResponse(response, ResponseType.class);
  }

  protected ResponseType put(String endPoint, Object object) {
    OAuthRequest request = new OAuthRequest(Verb.PUT, BASE_URL + endPoint);
    String contents = marshallRequest(object);
    request.addPayload(contents);
    service.signRequest(token, request);
    Response response = request.send();
    if (response.getCode() != 200) {
      ApiException exception = unmarshallResponse(response, ApiException.class);
      throw new XeroApiException(response.getCode(), "Error number "
          + exception.getErrorNumber() + ". " + exception.getMessage());       
    }
View Full Code Here

    @Override
    protected OAuthPrincipal<LinkedinAccessTokenContext> getOAuthPrincipal(HttpServletRequest request, HttpServletResponse response, InteractionState<LinkedinAccessTokenContext> interactionState) {
        LinkedinAccessTokenContext accessTokenContext = interactionState.getAccessTokenContext();

        OAuthRequest oauthRequest = new OAuthRequest(Verb.GET, URL_CURRENT_PROFILE_USER);
        accessTokenContext.oauthService.signRequest(accessTokenContext.accessToken, oauthRequest);
        Response oauthResponse = oauthRequest.send();
        String body = oauthResponse.getBody();

        try {
            JSONObject json = new JSONObject(body);
            String id = json.getString("id");
View Full Code Here

     * @param token
     * @param secret
     * @return
     */
    public String get(String url, String token, String secret) {
        OAuthRequest request = new OAuthRequest(Verb.GET, url);
        service.signRequest(new Token(token, secret), request); // the access token from step 4
        Response response = request.send();
        if (response.isSuccessful()) {
            return response.getBody();
        } else {
            return null;
        }
View Full Code Here

    }

    public void postMessage(TwitterOAuthAccount account, String message) {
        try {
            String url = "http://api.twitter.com/1/statuses/update.json";
            OAuthRequest request = new OAuthRequest(Verb.POST, url);
            request.addQuerystringParameter("status", message);
            post(request, account.token, account.secret);
        } catch (Exception e) {
            throw new UnexpectedException(e);
        }
    }
View Full Code Here

        }
    }

    public void verifyCredentials(TwitterOAuthAccount account) {
        String url = "http://api.twitter.com/1/account/verify_credentials.json";
        OAuthRequest request = new OAuthRequest(Verb.GET, url);
        post(request, account.token, account.secret);
    }
View Full Code Here

        this.apiUrl = apiUrl;
        this.apiAccessToken = apiAccessToken;
    }
   
    private String send(Verb verb, String params) throws Exception {
        OAuthRequest request = new OAuthRequest(verb, apiUrl + ((params != null) ? params : ""));
        request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, apiAccessToken);
        Response response = request.send();
        if (response.isSuccessful()) {                   
            return response.getBody();
        } else {
            throw new Exception(String.format("Failed to poll %s. Got response code %s and body: %s", getApiUrl(), response.getCode(), response.getBody()));
        }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  public Token getAccessToken(Token requestToken, Verifier verifier)
  {
    OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
    request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
    //request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
    request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
    request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
    //Adding grant_type parameter manually
    //Hard-coded the values for now until scribe comes up with an update
    request.addHeader("Content-Type", "application/x-www-form-urlencoded");
    request.addBodyParameter("grant_type", "authorization_code");  
    if(config.hasScope()) request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope());   
    Response response = request.send();
    return api.getAccessTokenExtractor().extract(response.getBody());
  }
View Full Code Here

  protected ResponseType get(String endPoint) {
    return get(endPoint, null, null);
  }

  protected ResponseType get(String endPoint, Date modifiedAfter, Map<String,String> params) {
    OAuthRequest request = new OAuthRequest(Verb.GET, BASE_URL + endPoint);
    if (modifiedAfter != null) {
      request.addHeader("If-Modified-Since", utcFormatter.format(modifiedAfter));
    }
    if (params != null) {
      for (Map.Entry<String,String> param : params.entrySet()) {
        request.addQuerystringParameter(param.getKey(), param.getValue());
      }
    }
    service.signRequest(token, request);
    Response response = request.send();
    if (response.getCode() != 200) {
      ApiException exception = unmarshallResponse(response, ApiException.class);
      throw new XeroApiException(response.getCode() + " response: Error number "
          + exception.getErrorNumber() + ". " + exception.getMessage());       
    }
View Full Code Here

TOP

Related Classes of org.scribe.model.OAuthRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.