// Path: app/src/main/java/com/etiennelawlor/loop/models/AccessToken.java
// public class AccessToken {
// 
//     // region Fields
//     private String tokenType;
//     private String accessToken;
//     // endregion
// 
//     // region Constructors
//     public AccessToken(String tokenType, String accessToken) {
//         this.tokenType = tokenType;
//         this.accessToken = accessToken;
//     }
//     // endregion
// 
//     // region Getters
//     public String getTokenType() {
//         // OAuth requires uppercase Authorization HTTP header value for token type
//         if ( ! Character.isUpperCase(tokenType.charAt(0))) {
//             tokenType = Character.toString(tokenType.charAt(0)).toUpperCase() + tokenType.substring(1);
//         }
// 
//         return tokenType;
//     }
// 
//     public String getAccessToken() {
//         return accessToken;
//     }
//     // endregion
// }
// 
// Path: app/src/main/java/com/etiennelawlor/loop/utilities/RequestUtility.java
// public class RequestUtility {
// 
//     public static Request addQueryParams(Request originalRequest, Map<String, String> queryParamsMap){
//         HttpUrl originalHttpUrl = originalRequest.url();
//         HttpUrl.Builder httpUrlBuilder = originalHttpUrl.newBuilder();
// 
//         for (Map.Entry<String, String> entry : queryParamsMap.entrySet()) {
//             String key = entry.getKey();
//             String value = entry.getValue();
//             httpUrlBuilder.addQueryParameter(key, value);
//         }
// 
//         HttpUrl httpUrl = httpUrlBuilder.build();
//         Request.Builder requestBuilder = originalRequest.newBuilder()
//                 .url(httpUrl);
// 
//         return requestBuilder.build();
//     }
// 
//     public static Request updateHeaders(Request originalRequest, Map<String, String> headersMap){
//         Request.Builder requestBuilder = originalRequest.newBuilder();
// 
//         for (Map.Entry<String, String> entry : headersMap.entrySet()) {
//             String key = entry.getKey();
//             String value = entry.getValue();
//             requestBuilder.header(key, value);
//         }
// 
//         return requestBuilder.build();
//     }
// }


import com.etiennelawlor.loop.models.AccessToken;
import com.etiennelawlor.loop.utilities.RequestUtility;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
package com.etiennelawlor.loop.network.interceptors;




/**
 * Created by etiennelawlor on 12/5/16.
 */

public class AuthorizedNetworkInterceptor implements Interceptor {

    // region Member Variables
    private AccessToken accessToken;
    // endregion

    // region Constructors
    public AuthorizedNetworkInterceptor(AccessToken accessToken) {
        this.accessToken = accessToken;
    }
    // endregion

    @Override
    public Response intercept(Chain chain) throws IOException {
        if (chain != null) {
            Request originalRequest = chain.request();

            if (accessToken != null) {
                Map<String, String> headersMap = new HashMap<>();
                headersMap.put("Authorization", String.format("%s %s", accessToken.getTokenType(), accessToken.getAccessToken()));
                headersMap.put("Accept", "application/vnd.vimeo.*+json; version=3.2");
                Request modifiedRequest = RequestUtility.updateHeaders(originalRequest, headersMap);

// Path: app/src/main/java/com/etiennelawlor/loop/models/AccessToken.java
// public class AccessToken {
// 
//     // region Fields
//     private String tokenType;
//     private String accessToken;
//     // endregion
// 
//     // region Constructors
//     public AccessToken(String tokenType, String accessToken) {
//         this.tokenType = tokenType;
//         this.accessToken = accessToken;
//     }
//     // endregion
// 
//     // region Getters
//     public String getTokenType() {
//         // OAuth requires uppercase Authorization HTTP header value for token type
//         if ( ! Character.isUpperCase(tokenType.charAt(0))) {
//             tokenType = Character.toString(tokenType.charAt(0)).toUpperCase() + tokenType.substring(1);
//         }
// 
//         return tokenType;
//     }
// 
//     public String getAccessToken() {
//         return accessToken;
//     }
//     // endregion
// }
// 
// Path: app/src/main/java/com/etiennelawlor/loop/utilities/RequestUtility.java
// public class RequestUtility {
// 
//     public static Request addQueryParams(Request originalRequest, Map<String, String> queryParamsMap){
//         HttpUrl originalHttpUrl = originalRequest.url();
//         HttpUrl.Builder httpUrlBuilder = originalHttpUrl.newBuilder();
// 
//         for (Map.Entry<String, String> entry : queryParamsMap.entrySet()) {
//             String key = entry.getKey();
//             String value = entry.getValue();
//             httpUrlBuilder.addQueryParameter(key, value);
//         }
// 
//         HttpUrl httpUrl = httpUrlBuilder.build();
//         Request.Builder requestBuilder = originalRequest.newBuilder()
//                 .url(httpUrl);
// 
//         return requestBuilder.build();
//     }
// 
//     public static Request updateHeaders(Request originalRequest, Map<String, String> headersMap){
//         Request.Builder requestBuilder = originalRequest.newBuilder();
// 
//         for (Map.Entry<String, String> entry : headersMap.entrySet()) {
//             String key = entry.getKey();
//             String value = entry.getValue();
//             requestBuilder.header(key, value);
//         }
// 
//         return requestBuilder.build();
//     }
// }


// Path: app/src/main/java/com/etiennelawlor/loop/network/interceptors/AuthorizedNetworkInterceptor.java
import com.etiennelawlor.loop.models.AccessToken;
import com.etiennelawlor.loop.utilities.RequestUtility;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

package com.etiennelawlor.loop.network.interceptors;




/**
 * Created by etiennelawlor on 12/5/16.
 */

public class AuthorizedNetworkInterceptor implements Interceptor {

    // region Member Variables
    private AccessToken accessToken;
    // endregion

    // region Constructors
    public AuthorizedNetworkInterceptor(AccessToken accessToken) {
        this.accessToken = accessToken;
    }
    // endregion

    @Override
    public Response intercept(Chain chain) throws IOException {
        if (chain != null) {
            Request originalRequest = chain.request();

            if (accessToken != null) {
                Map<String, String> headersMap = new HashMap<>();
                headersMap.put("Authorization", String.format("%s %s", accessToken.getTokenType(), accessToken.getAccessToken()));
                headersMap.put("Accept", "application/vnd.vimeo.*+json; version=3.2");
                Request modifiedRequest = RequestUtility.updateHeaders(originalRequest, headersMap);

                return chain.proceed(modifiedRequest);