// Path: rxuploader-sample/src/main/java/com/jagsaund/rxuploader/sample/config/Config.java
// public class Config {
//     public static final String HOST = "https://api.500px.com/";
// 
//     public static final HttpLoggingInterceptor.Level HTTP_LOG_LEVEL =
//             HttpLoggingInterceptor.Level.HEADERS;
// 
// 
//     public static final String REQUEST_TOKEN_URL = HOST + "v1/oauth/request_token";
//     public static final String ACCESS_TOKEN_URL = HOST + "v1/oauth/access_token";
//     public static final String AUTH_CALLBACK_URL = "";
// 
//     public static final String CONSUMER_KEY = "<INSERT YOUR 500PX CONSUMER KEY>";
//     public static final String CONSUMER_SECRET = "<INSERT YOUR 500PX CONSUMER SECRET>";
// 
//     public static final String X_AUTH_MODE = "client_auth";
//     public static final String X_AUTH_USERNAME = "<INSERT YOUR 500PX USERNAME>";
//     public static final String X_AUTH_PASSWORD = "<INSERT YOUR 500PX PASSWORD>";
// 
//     public static final String USERNAME = X_AUTH_USERNAME;
// }
// 
// Path: rxuploader-sample/src/main/java/com/jagsaund/rxuploader/sample/service/XOAuthProvider.java
// public class XOAuthProvider extends AbstractOAuthProvider {
// 
//     private transient OkHttpClient okHttpClient;
// 
//     public XOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl,
//                                String authorizationWebsiteUrl) {
//         super(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl);
//         this.okHttpClient = new OkHttpClient();
//     }
// 
//     public XOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl,
//                                String authorizationWebsiteUrl, OkHttpClient okHttpClient) {
//         super(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl);
//         this.okHttpClient = okHttpClient;
//     }
// 
//     public void setOkHttpClient(OkHttpClient okHttpClient) {
//         this.okHttpClient = okHttpClient;
//     }
// 
//     @Override
//     protected HttpRequest createRequest(String endpointUrl) throws Exception {
//         final Request.Builder builder =
//                 new Request.Builder()
//                         .url(endpointUrl)
//                         .post(Util.EMPTY_REQUEST);
//         if (endpointUrl.contains(Config.ACCESS_TOKEN_URL)) {
//             final MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
//             final String body =
//                     String.format("x_auth_mode=%s&x_auth_password=%s&x_auth_username=%s",
//                             Config.X_AUTH_MODE, Config.X_AUTH_PASSWORD, Config.X_AUTH_USERNAME);
//             builder.post(RequestBody.create(mediaType, body));
//         }
//         return new OkHttpRequestAdapter(builder.build());
//     }
// 
//     @Override
//     protected HttpResponse sendRequest(HttpRequest request) throws Exception {
//         Response response = okHttpClient.newCall((Request) request.unwrap()).execute();
//         return new OkHttpResponseAdapter(response);
//     }
// }


import android.app.Application;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.jagsaund.rxuploader.sample.config.Config;
import com.jagsaund.rxuploader.sample.service.XOAuthProvider;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import rx.Completable;
import rx.Observable;
import se.akerfeldt.okhttp.signpost.OkHttpOAuthConsumer;
import timber.log.Timber;

        final OkHttpOAuthConsumer consumer =
                new OkHttpOAuthConsumer(Config.CONSUMER_KEY, Config.CONSUMER_SECRET);

        final XOAuthProvider provider =
                new XOAuthProvider(Config.REQUEST_TOKEN_URL, Config.ACCESS_TOKEN_URL,
                        Config.AUTH_CALLBACK_URL, httpClient.build());

        return Observable.fromCallable(
                () -> provider.retrieveRequestToken(consumer, Config.AUTH_CALLBACK_URL))
                .flatMap(__ -> {
                    try {
                        provider.retrieveAccessToken(consumer, "");
                    } catch (@NonNull Exception e) {
                        Observable.error(e);
                    }
                    token = consumer.getToken();
                    secret = consumer.getTokenSecret();
                    return Observable.empty();
                })
                .toCompletable();
    }

    @Nullable
    public static String getToken() {
        return token;
    }

    @Nullable
    public static String getSecret() {
// Path: rxuploader-sample/src/main/java/com/jagsaund/rxuploader/sample/config/Config.java
// public class Config {
//     public static final String HOST = "https://api.500px.com/";
// 
//     public static final HttpLoggingInterceptor.Level HTTP_LOG_LEVEL =
//             HttpLoggingInterceptor.Level.HEADERS;
// 
// 
//     public static final String REQUEST_TOKEN_URL = HOST + "v1/oauth/request_token";
//     public static final String ACCESS_TOKEN_URL = HOST + "v1/oauth/access_token";
//     public static final String AUTH_CALLBACK_URL = "";
// 
//     public static final String CONSUMER_KEY = "<INSERT YOUR 500PX CONSUMER KEY>";
//     public static final String CONSUMER_SECRET = "<INSERT YOUR 500PX CONSUMER SECRET>";
// 
//     public static final String X_AUTH_MODE = "client_auth";
//     public static final String X_AUTH_USERNAME = "<INSERT YOUR 500PX USERNAME>";
//     public static final String X_AUTH_PASSWORD = "<INSERT YOUR 500PX PASSWORD>";
// 
//     public static final String USERNAME = X_AUTH_USERNAME;
// }
// 
// Path: rxuploader-sample/src/main/java/com/jagsaund/rxuploader/sample/service/XOAuthProvider.java
// public class XOAuthProvider extends AbstractOAuthProvider {
// 
//     private transient OkHttpClient okHttpClient;
// 
//     public XOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl,
//                                String authorizationWebsiteUrl) {
//         super(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl);
//         this.okHttpClient = new OkHttpClient();
//     }
// 
//     public XOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl,
//                                String authorizationWebsiteUrl, OkHttpClient okHttpClient) {
//         super(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl);
//         this.okHttpClient = okHttpClient;
//     }
// 
//     public void setOkHttpClient(OkHttpClient okHttpClient) {
//         this.okHttpClient = okHttpClient;
//     }
// 
//     @Override
//     protected HttpRequest createRequest(String endpointUrl) throws Exception {
//         final Request.Builder builder =
//                 new Request.Builder()
//                         .url(endpointUrl)
//                         .post(Util.EMPTY_REQUEST);
//         if (endpointUrl.contains(Config.ACCESS_TOKEN_URL)) {
//             final MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
//             final String body =
//                     String.format("x_auth_mode=%s&x_auth_password=%s&x_auth_username=%s",
//                             Config.X_AUTH_MODE, Config.X_AUTH_PASSWORD, Config.X_AUTH_USERNAME);
//             builder.post(RequestBody.create(mediaType, body));
//         }
//         return new OkHttpRequestAdapter(builder.build());
//     }
// 
//     @Override
//     protected HttpResponse sendRequest(HttpRequest request) throws Exception {
//         Response response = okHttpClient.newCall((Request) request.unwrap()).execute();
//         return new OkHttpResponseAdapter(response);
//     }
// }


// Path: rxuploader-sample/src/main/java/com/jagsaund/rxuploader/sample/SampleApplication.java
import android.app.Application;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.jagsaund.rxuploader.sample.config.Config;
import com.jagsaund.rxuploader.sample.service.XOAuthProvider;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import rx.Completable;
import rx.Observable;
import se.akerfeldt.okhttp.signpost.OkHttpOAuthConsumer;
import timber.log.Timber;


        final OkHttpOAuthConsumer consumer =
                new OkHttpOAuthConsumer(Config.CONSUMER_KEY, Config.CONSUMER_SECRET);

        final XOAuthProvider provider =
                new XOAuthProvider(Config.REQUEST_TOKEN_URL, Config.ACCESS_TOKEN_URL,
                        Config.AUTH_CALLBACK_URL, httpClient.build());

        return Observable.fromCallable(
                () -> provider.retrieveRequestToken(consumer, Config.AUTH_CALLBACK_URL))
                .flatMap(__ -> {
                    try {
                        provider.retrieveAccessToken(consumer, "");
                    } catch (@NonNull Exception e) {
                        Observable.error(e);
                    }
                    token = consumer.getToken();
                    secret = consumer.getTokenSecret();
                    return Observable.empty();
                })
                .toCompletable();
    }

    @Nullable
    public static String getToken() {
        return token;
    }

    @Nullable
    public static String getSecret() {
        return secret;