Package org.scribe.model

Examples of org.scribe.model.Response


   * @return <tt>String</tt> body of API response
   */
  private String sendRequestAndGetResponse(OAuthRequest request) {
    System.out.println("Querying " + request.getCompleteUrl() + " ...");
    this.service.signRequest(this.accessToken, request);
    Response response = request.send();
    return response.getBody();
  }
View Full Code Here


        //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 {
            mYelpSearchResult = new Gson().fromJson(rawData, YelpSearchResults.class);
View Full Code Here

  private int rateLimitTotal = 0;
  private int rateLimitRemaining = 0;

  public TKResponse(Request req)
  {
    Response response = req.send();
    String limitUsed = response.getHeader("X-RateLimit-Used");
    String limitExpire = response.getHeader("X-RateLimit-Expire");
    String limitTotal = response.getHeader("X-RateLimit-Limit");
    String limitRemain = response.getHeader("X-RateLimit-Remaining");
    if (limitUsed != null)
    {
      rateLimitUsed = Integer.parseInt(limitUsed);
    }
    if (limitExpire != null)
    {
      rateLimitExpire = Long.parseLong(limitExpire);
    }
    if (limitTotal != null)
    {
      rateLimitTotal = Integer.parseInt(limitTotal);
    }
    if (limitRemain != null)
    {
      rateLimitRemaining = Integer.parseInt(limitRemain);
    }
    this.response = response.getBody();
  }
View Full Code Here

      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) { 
      }
      if (exception == null) {
        throw new XeroApiException(response.getCode());
      } else {
        throw new XeroApiException(response.getCode(), "Error number "
            + exception.getErrorNumber() + ". " + exception.getMessage());       
      }
    }
    return unmarshallResponse(response, ResponseType.class);
  }
View Full Code Here

  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());       
    }
    return unmarshallResponse(response, ResponseType.class);
  }
View Full Code Here

    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");
            String firstName = json.getString("firstName");
View Full Code Here

     * @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

    }

    protected Response post(OAuthRequest request, String token, String secret) {
        Token accessToken = new Token(token, secret);
        getService().signRequest(accessToken, request);
        Response response = request.send();
        if (response.getCode() != Http.StatusCode.OK) {
            throw new OAuthProviderException(response.getCode(), response.getBody(), provider);
        }

        return response;
    }
View Full Code Here

    }
   
    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

    //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

TOP

Related Classes of org.scribe.model.Response

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.