package com.uwetrottmann.thetvdb;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

public class TheTvdbInterceptor implements Interceptor {

    private TheTvdb theTvdb;

    public TheTvdbInterceptor(TheTvdb theTvdb) {
        this.theTvdb = theTvdb;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        if (!TheTvdb.API_HOST.equals(request.url().host())) {
            // do not intercept requests for other hosts
            // this allows the interceptor to be used on a shared okhttp client
            return chain.proceed(request);
        }

        Request.Builder builder = request.newBuilder();

        // request specific API version
        builder.header(TheTvdb.HEADER_ACCEPT, "application/vnd.thetvdb.v" + TheTvdb.API_VERSION);

        // add authorization header
        if (hasNoAuthorizationHeader(request) && jsonWebTokenIsNotEmpty()) {
            builder.header(TheTvdb.HEADER_AUTHORIZATION, "Bearer" + " " + jsonWebToken());
        }
        return chain.proceed(builder.build());
    }

    private String jsonWebToken() {
        return theTvdb.jsonWebToken();
    }

    private boolean hasNoAuthorizationHeader(Request request) {
        return request.header(TheTvdb.HEADER_AUTHORIZATION) == null;
    }

    private boolean jsonWebTokenIsNotEmpty() {
        return jsonWebToken() != null && jsonWebToken().length() != 0;
    }

}

@@ -389,16 +389,392 @@
 ption %7B%0A
+        return handleIntercept(chain, jsonWebToken());%0A    %7D%0A%0A    /**%0A     * If the host matches %7B@link TheTvdb#API_HOST%7D adds an Accept header for the current %7B@link TheTvdb#API_VERSION%7D%0A     * and if not present an Authorization header using the given JSON web token.%0A     */%0A    public static Response handleIntercept(Chain chain, String jsonWebToken) throws IOException %7B%0A
         
@@ -804,24 +804,24 @@
 .request();%0A
-
         if (
@@ -1365,16 +1365,28 @@
 otEmpty(
+jsonWebToken
 )) %7B%0A   
@@ -1464,26 +1464,24 @@
 jsonWebToken
-()
 );%0A        %7D
@@ -1540,22 +1540,21 @@
 %7D%0A%0A    p
-rivate
+ublic
  String 
@@ -1620,32 +1620,39 @@
  %7D%0A%0A    private 
+static 
 boolean hasNoAut
@@ -1775,16 +1775,23 @@
 private 
+static 
 boolean 
@@ -1813,16 +1813,35 @@
 otEmpty(
+String jsonWebToken
 ) %7B%0A    
@@ -1863,18 +1863,16 @@
 WebToken
-()
  != null
@@ -1887,18 +1887,16 @@
 WebToken
-()
 .length(

Make interceptor handling publicly accessible.