Package org.jinstagram.auth.model

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


    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

     * 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

     * 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

     * 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

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

        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

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

        // 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());
                }
            }
        }

        response = request.send();

        return response;
    }
View Full Code Here

TOP

Related Classes of org.jinstagram.auth.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.