// Path: soundcloud-api/src/main/java/com/jlubecki/soundcloud/webapi/android/SoundCloudAPI.java
// public class SoundCloudAPI {
// 
//     public static final String SOUNDCLOUD_API_ENDPOINT = "https://api.soundcloud.com/";
// 
//     private final SoundCloudService service;
// 
//     private final String clientId;
//     private String token;
// 
//     /**
//      * Creates a {@link SoundCloudService}. Serializes with JSON.
//      *
//      * @param clientId Client ID provided by SoundCloud.
//      */
//     public SoundCloudAPI(String clientId) {
//         this.clientId = clientId;
// 
//         Gson gson = new GsonBuilder()
//                 .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
//                 .registerTypeAdapter(Date.class, new DateTypeAdapter())
//                 .create();
// 
//         OkHttpClient client = new OkHttpClient.Builder()
//                 .addInterceptor(new SoundCloudInterceptor())
//                 .build();
// 
//         Retrofit adapter = new Retrofit.Builder()
//                 .client(client)
//                 .baseUrl(SOUNDCLOUD_API_ENDPOINT)
//                 .addConverterFactory(GsonConverterFactory.create(gson))
//                 .build();
// 
//         service = adapter.create(SoundCloudService.class);
//     }
// 
//     /**
//      * Gives access to a {@link SoundCloudService}.
//      *
//      * @return The {@link SoundCloudService} created by this {@link SoundCloudAPI}.
//      */
//     public SoundCloudService getService() {
//         return service;
//     }
// 
//     /**
//      * Sets the auth token needed by the service in order to make authenticated requests.
//      *
//      * @param token The OAuth token to use for authenticated requests.
//      */
//     public void setToken(String token) {
//         this.token = token;
//     }
// 
//     private class SoundCloudInterceptor implements Interceptor {
//         @Override
//         public Response intercept(Interceptor.Chain chain) throws IOException {
// 
//             Request request = chain.request();
// 
//             HttpUrl.Builder urlBuilder = request.url().newBuilder();
// 
//             urlBuilder.addEncodedQueryParameter("client_id", clientId);
//             if (token != null) {
//                 urlBuilder.addEncodedQueryParameter("oauth_token", token);
//             }
// 
//             Request newRequest = request.newBuilder()
//                     .url(urlBuilder.build())
//                     .build();
// 
//             return chain.proceed(newRequest);
//         }
//     }
// }
// 
// Path: soundcloud-api/src/main/java/com/jlubecki/soundcloud/webapi/android/auth/models/AuthenticationResponse.java
// public class AuthenticationResponse {
// 
//     public String access_token;
// 
//     public String scope;
// 
//     public String error;
// 
//     /**
//      * Helper method to determine authentication response type.
//      *
//      * @return The type of the authentication response.
//      */
//     public ResponseType getType() {
//         if (access_token != null) {
//             return ResponseType.TOKEN;
//         }
// 
//         if (error != null) {
//             return ResponseType.ERROR;
//         }
// 
//         return ResponseType.UNKNOWN;
//     }
// 
//     public enum ResponseType {
//         TOKEN,
//         ERROR,
//         UNKNOWN
//     }
// 
//     @Override
//     public String toString() {
//         return "AuthenticationResponse{" +
//                 "access_token='" + access_token + '\'' +
//                 ", scope='" + scope + '\'' +
//                 ", error='" + error + '\'' +
//                 '}';
//     }
// }


import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import com.jlubecki.soundcloud.webapi.android.SoundCloudAPI;
import com.jlubecki.soundcloud.webapi.android.auth.models.AuthenticationResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
    }

    /**
     * Retrofit interface built solely to authenticate SoundCloud.
     */
    public interface AuthService {

        /**
         * Asynchronously obtains an OAuth Token.
         *
         * @param authMap An {@link Map} defining form-urlencoded auth parameters.
         * @return the call that can be run to access the API resource.
         */
        @FormUrlEncoded
        @POST("oauth2/token")
        Call<AuthenticationResponse> authorize(@FieldMap Map<String, String> authMap);
    }

    /**
     * Gets the Auth Service so a user can call
     * {@link AuthService#authorize(Map)}.
     *
     * @return An instance of a {@link AuthService}.
     */
    public final AuthService getAuthService() {
        if (service == null) {
            OkHttpClient client =
                    new OkHttpClient.Builder().addInterceptor(new AuthInterceptor()).build();

            Retrofit adapter = new Retrofit.Builder()
// Path: soundcloud-api/src/main/java/com/jlubecki/soundcloud/webapi/android/SoundCloudAPI.java
// public class SoundCloudAPI {
// 
//     public static final String SOUNDCLOUD_API_ENDPOINT = "https://api.soundcloud.com/";
// 
//     private final SoundCloudService service;
// 
//     private final String clientId;
//     private String token;
// 
//     /**
//      * Creates a {@link SoundCloudService}. Serializes with JSON.
//      *
//      * @param clientId Client ID provided by SoundCloud.
//      */
//     public SoundCloudAPI(String clientId) {
//         this.clientId = clientId;
// 
//         Gson gson = new GsonBuilder()
//                 .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
//                 .registerTypeAdapter(Date.class, new DateTypeAdapter())
//                 .create();
// 
//         OkHttpClient client = new OkHttpClient.Builder()
//                 .addInterceptor(new SoundCloudInterceptor())
//                 .build();
// 
//         Retrofit adapter = new Retrofit.Builder()
//                 .client(client)
//                 .baseUrl(SOUNDCLOUD_API_ENDPOINT)
//                 .addConverterFactory(GsonConverterFactory.create(gson))
//                 .build();
// 
//         service = adapter.create(SoundCloudService.class);
//     }
// 
//     /**
//      * Gives access to a {@link SoundCloudService}.
//      *
//      * @return The {@link SoundCloudService} created by this {@link SoundCloudAPI}.
//      */
//     public SoundCloudService getService() {
//         return service;
//     }
// 
//     /**
//      * Sets the auth token needed by the service in order to make authenticated requests.
//      *
//      * @param token The OAuth token to use for authenticated requests.
//      */
//     public void setToken(String token) {
//         this.token = token;
//     }
// 
//     private class SoundCloudInterceptor implements Interceptor {
//         @Override
//         public Response intercept(Interceptor.Chain chain) throws IOException {
// 
//             Request request = chain.request();
// 
//             HttpUrl.Builder urlBuilder = request.url().newBuilder();
// 
//             urlBuilder.addEncodedQueryParameter("client_id", clientId);
//             if (token != null) {
//                 urlBuilder.addEncodedQueryParameter("oauth_token", token);
//             }
// 
//             Request newRequest = request.newBuilder()
//                     .url(urlBuilder.build())
//                     .build();
// 
//             return chain.proceed(newRequest);
//         }
//     }
// }
// 
// Path: soundcloud-api/src/main/java/com/jlubecki/soundcloud/webapi/android/auth/models/AuthenticationResponse.java
// public class AuthenticationResponse {
// 
//     public String access_token;
// 
//     public String scope;
// 
//     public String error;
// 
//     /**
//      * Helper method to determine authentication response type.
//      *
//      * @return The type of the authentication response.
//      */
//     public ResponseType getType() {
//         if (access_token != null) {
//             return ResponseType.TOKEN;
//         }
// 
//         if (error != null) {
//             return ResponseType.ERROR;
//         }
// 
//         return ResponseType.UNKNOWN;
//     }
// 
//     public enum ResponseType {
//         TOKEN,
//         ERROR,
//         UNKNOWN
//     }
// 
//     @Override
//     public String toString() {
//         return "AuthenticationResponse{" +
//                 "access_token='" + access_token + '\'' +
//                 ", scope='" + scope + '\'' +
//                 ", error='" + error + '\'' +
//                 '}';
//     }
// }


// Path: soundcloud-api/src/main/java/com/jlubecki/soundcloud/webapi/android/auth/SoundCloudAuthenticator.java
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import com.jlubecki.soundcloud.webapi.android.SoundCloudAPI;
import com.jlubecki.soundcloud.webapi.android.auth.models.AuthenticationResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;

    }

    /**
     * Retrofit interface built solely to authenticate SoundCloud.
     */
    public interface AuthService {

        /**
         * Asynchronously obtains an OAuth Token.
         *
         * @param authMap An {@link Map} defining form-urlencoded auth parameters.
         * @return the call that can be run to access the API resource.
         */
        @FormUrlEncoded
        @POST("oauth2/token")
        Call<AuthenticationResponse> authorize(@FieldMap Map<String, String> authMap);
    }

    /**
     * Gets the Auth Service so a user can call
     * {@link AuthService#authorize(Map)}.
     *
     * @return An instance of a {@link AuthService}.
     */
    public final AuthService getAuthService() {
        if (service == null) {
            OkHttpClient client =
                    new OkHttpClient.Builder().addInterceptor(new AuthInterceptor()).build();

            Retrofit adapter = new Retrofit.Builder()
                    .baseUrl(SoundCloudAPI.SOUNDCLOUD_API_ENDPOINT)