// Path: app/src/main/java/com/hhua/android/producthunt/services/ProductHunt20ServiceImpl.java
// public class ProductHunt20ServiceImpl extends OAuth20ServiceImpl {
// 
//     public ProductHunt20ServiceImpl(final DefaultApi20 api, final OAuthConfig config) {
//         super(api, config);
//     }
// 
// //    @Override
// //    protected <T extends AbstractRequest> T createAccessTokenRequest(final Verifier verifier, T request) {
// //        super.createAccessTokenRequest(verifier, request);
// //        if (!getConfig().hasGrantType()) {
// //            request.addParameter(OAuthConstants.GRANT_TYPE, "authorization_code");
// //        }
// //        return (T) request;
// //    }
// }


import com.hhua.android.producthunt.services.ProductHunt20ServiceImpl;
import org.scribe.builder.api.DefaultApi20;
import org.scribe.extractors.AccessTokenExtractor;
import org.scribe.extractors.JsonTokenExtractor;
import org.scribe.model.OAuthConfig;
import org.scribe.model.OAuthConstants;
import org.scribe.model.Verb;
import org.scribe.oauth.OAuthService;
import org.scribe.utils.OAuthEncoder;
import org.scribe.utils.Preconditions;
package com.hhua.android.producthunt.network;



public class ProductHuntApi extends DefaultApi20 {
    // Product Hunt API is using OAuth2 (Three legged)
    private static final String AUTHORIZE_URL = "https://api.producthunt.com/v1/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code&scope=public+private";
    private static final String ACCESS_TOKEN_URL = "https://api.producthunt.com/v1/oauth/token?grant_type=authorization_code";

    private static final String LOG_D = "PRODUCT_HUNT_API";

    @Override
    public Verb getAccessTokenVerb() {
        return Verb.POST;
    }

    @Override
    public String getAccessTokenEndpoint() {
        final String accessTokenEndpoint = ACCESS_TOKEN_URL;

        return accessTokenEndpoint;
    }

    @Override
    public String getAuthorizationUrl(final OAuthConfig config) {
        Preconditions.checkValidUrl(config.getCallback(),
                "Must provide a valid url as callback. Product Hunt does not support OOB");
        final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(
                config.getCallback())));
        if (config.hasScope()) {
            sb.append('&').append(OAuthConstants.SCOPE).append('=').append(OAuthEncoder.encode(config.getScope()));
        }

        return sb.toString();
    }

// Path: app/src/main/java/com/hhua/android/producthunt/services/ProductHunt20ServiceImpl.java
// public class ProductHunt20ServiceImpl extends OAuth20ServiceImpl {
// 
//     public ProductHunt20ServiceImpl(final DefaultApi20 api, final OAuthConfig config) {
//         super(api, config);
//     }
// 
// //    @Override
// //    protected <T extends AbstractRequest> T createAccessTokenRequest(final Verifier verifier, T request) {
// //        super.createAccessTokenRequest(verifier, request);
// //        if (!getConfig().hasGrantType()) {
// //            request.addParameter(OAuthConstants.GRANT_TYPE, "authorization_code");
// //        }
// //        return (T) request;
// //    }
// }


// Path: app/src/main/java/com/hhua/android/producthunt/network/ProductHuntApi.java
import com.hhua.android.producthunt.services.ProductHunt20ServiceImpl;
import org.scribe.builder.api.DefaultApi20;
import org.scribe.extractors.AccessTokenExtractor;
import org.scribe.extractors.JsonTokenExtractor;
import org.scribe.model.OAuthConfig;
import org.scribe.model.OAuthConstants;
import org.scribe.model.Verb;
import org.scribe.oauth.OAuthService;
import org.scribe.utils.OAuthEncoder;
import org.scribe.utils.Preconditions;

package com.hhua.android.producthunt.network;



public class ProductHuntApi extends DefaultApi20 {
    // Product Hunt API is using OAuth2 (Three legged)
    private static final String AUTHORIZE_URL = "https://api.producthunt.com/v1/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code&scope=public+private";
    private static final String ACCESS_TOKEN_URL = "https://api.producthunt.com/v1/oauth/token?grant_type=authorization_code";

    private static final String LOG_D = "PRODUCT_HUNT_API";

    @Override
    public Verb getAccessTokenVerb() {
        return Verb.POST;
    }

    @Override
    public String getAccessTokenEndpoint() {
        final String accessTokenEndpoint = ACCESS_TOKEN_URL;

        return accessTokenEndpoint;
    }

    @Override
    public String getAuthorizationUrl(final OAuthConfig config) {
        Preconditions.checkValidUrl(config.getCallback(),
                "Must provide a valid url as callback. Product Hunt does not support OOB");
        final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(
                config.getCallback())));
        if (config.hasScope()) {
            sb.append('&').append(OAuthConstants.SCOPE).append('=').append(OAuthEncoder.encode(config.getScope()));
        }

        return sb.toString();
    }

    @Override