Examples of OAuthRequest


Examples of org.apache.shindig.gadgets.oauth.OAuthRequest

  // Yes, this is really allowed by the HTTP spec and supported by real servers.
  public HttpResponse sendGetWithBody(String target, String type, byte[] body) {
    HttpRequest request = new HttpRequest(Uri.parse(target));
    request.setOAuthArguments(recallState());
    OAuthRequest dest = createRequest();
    if (type != null) {
      request.setHeader("Content-Type", type);
    }
    request.setPostBody(body);
    request.setSecurityToken(securityToken);
    HttpResponse response = dest.fetch(request);
    saveState(response);
    return response;
  }
View Full Code Here

Examples of org.apache.shindig.gadgets.oauth.OAuthRequest

   * Send an OAuth POST request to the given URL.
   */
  public HttpResponse sendFormPost(String target, String body) throws Exception {
    HttpRequest request = new HttpRequest(Uri.parse(target));
    request.setOAuthArguments(recallState());
    OAuthRequest dest = createRequest();
    request.setMethod("POST");
    request.setPostBody(CharsetUtil.getUtf8Bytes(body));
    request.setHeader("content-type", "application/x-www-form-urlencoded");
    request.setSecurityToken(securityToken);
    HttpResponse response = dest.fetch(request);
    saveState(response);
    return response;
  }
View Full Code Here

Examples of org.apache.shindig.gadgets.oauth.OAuthRequest

   * Send an OAuth POST with binary data in the binary.
   */
  public HttpResponse sendRawPost(String target, String type, byte[] body) throws Exception {
    HttpRequest request = new HttpRequest(Uri.parse(target));
    request.setOAuthArguments(recallState());
    OAuthRequest dest = createRequest();
    request.setMethod("POST");
    if (type != null) {
      request.setHeader("Content-Type", type);
    }
    request.setPostBody(body);
    request.setSecurityToken(securityToken);
    HttpResponse response = dest.fetch(request);
    saveState(response);
    return response;
  }
View Full Code Here

Examples of org.jinstagram.auth.model.OAuthRequest

   * @return Response object.
   */
  protected Response getApiResponse(Verbs verb, String methodName, Map<String, String> params) throws IOException {
    Response response;
    String apiResourceUrl = config.getApiURL() + methodName;
    OAuthRequest request = new OAuthRequest(verb, apiResourceUrl);

    request.setConnectTimeout(config.getConnectionTimeoutMills(), TimeUnit.MILLISECONDS);
    request.setReadTimeout(config.getReadTimeoutMills(), TimeUnit.MILLISECONDS);
   
        if (enforceSignatrue != null) {
            request.addHeader(EnforceSignedHeaderUtils.ENFORCE_SIGNED_HEADER, enforceSignatrue);
        }
   
   
    // Additional parameters in url
    if (params != null) {
      for (Map.Entry<String, String> entry : params.entrySet()) {
        if (verb == Verbs.GET) {
          request.addQuerystringParameter(entry.getKey(), entry.getValue());
        }
        else {
          request.addBodyParameter(entry.getKey(), entry.getValue());
        }
      }
    }

    // Add the AccessToken to the Request Url
    if ((verb == Verbs.GET) || (verb == Verbs.DELETE)) {
      if (accessToken == null) {
          request.addQuerystringParameter(OAuthConstants.CLIENT_ID, clientId);
      } else {
          request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
      }
    }
    else {
        if (accessToken == null) {
            request.addBodyParameter(OAuthConstants.CLIENT_ID, clientId);
        } else {
            request.addBodyParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
        }
    }

    response = request.send();

    return response;
  }
View Full Code Here

Examples of org.jinstagram.auth.model.OAuthRequest

    if(callback == null){
      callback = "";
    }
    Preconditions.checkEmptyString(callback, "You must provide a callback url");

        final OAuthRequest request = prepareOAuthRequest(Verbs.POST);
    request.addBodyParameter(Constants.ASPECT, "media");
   
    for(Map.Entry<String, String> entry: this.params.entrySet()){
      request.addBodyParameter(entry.getKey(), entry.getValue());
    }

        try {
            final Response response = request.send();
            return getSubscriptionResponse(response.getBody());
        } catch (IOException e) {
            throw new InstagramException("Failed to create subscription", e);
        }
  }
View Full Code Here

Examples of org.jinstagram.auth.model.OAuthRequest

     * Deletes a subscription with the specified identifier.
     *
     * @param id the id of the subscription to remove
     */
    public SubscriptionResponse deleteSubscription(String id) throws InstagramException {
        final OAuthRequest request = prepareOAuthRequest(Verbs.DELETE);
        request.addQuerystringParameter("id", id);

        try {
            final Response response = request.send();
            return getSubscriptionResponse(response.getBody());
        } catch (IOException e) {
            throw new InstagramException("Failed to delete subscription with id ["+id+"]", e);
        }
    }
View Full Code Here

Examples of org.jinstagram.auth.model.OAuthRequest

     * Deletes all the known subscription.
     *
     * @return the response of this request, holding mainly the code
     */
  public SubscriptionResponse deleteAllSubscription() throws InstagramException {
        final OAuthRequest request = prepareOAuthRequest(Verbs.DELETE);
    request.addQuerystringParameter(Constants.SUBSCRIPTION_TYPE, "all");

        try {
            final Response response = request.send();
            return getSubscriptionResponse(response.getBody());
        } catch (IOException e) {
            throw new InstagramException("Failed to delete all subscriptions", e);
        }
  }
View Full Code Here

Examples of org.jinstagram.auth.model.OAuthRequest

     * Returns the currently active subscription.
     *
     * @return the active subscription
     */
  public SubscriptionsListResponse getSubscriptionList() throws InstagramException {
    final OAuthRequest request = prepareOAuthRequest(Verbs.GET);

        try {
            final Response response = request.send();
            return getSubscriptionsListResponse(response.getBody());
        } catch (IOException e) {
            throw new InstagramException("Failed to get subscription list", e);
        }
  }
View Full Code Here

Examples of org.jinstagram.auth.model.OAuthRequest

  /**
   * {@inheritDoc}
   */
  public Token getAccessToken(Token requestToken, Verifier verifier) {
    OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(),
        api.getAccessTokenEndpoint());

    // Add the oauth parameter in the body
    request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
    request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
    request.addBodyParameter("grant_type", "authorization_code");
    request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
    request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());

    if (config.hasScope()) {
      request.addBodyParameter(OAuthConstants.SCOPE, config.getScope());
    }

    if (config.getDisplay() != null) {
      request.addBodyParameter(OAuthConstants.DISPLAY, config.getDisplay());
    }

        Response response;
        try {
            response = request.send();
        } catch (IOException e) {
            throw new OAuthException("Could not get access token", e);
        }

    return api.getAccessTokenExtractor().extract(response.getBody());
View Full Code Here

Examples of org.jinstagram.auth.model.OAuthRequest

        Preconditions.checkEmptyString(clientId, "You must provide a clientId key");
 
        String clientSecret = params.get(Constants.CLIENT_SECRET);
        Preconditions.checkEmptyString(clientSecret, "You must provide a clientSecret");

        final OAuthRequest request = new OAuthRequest(verb, Constants.SUBSCRIPTION_ENDPOINT);
        // Add the oauth parameter in the body
        request.addQuerystringParameter(Constants.CLIENT_ID, clientId);
        request.addQuerystringParameter(Constants.CLIENT_SECRET, clientSecret);

        return request;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.