Debug interceptor.
parent
72276f373a
commit
306c6c0f68
|
@ -2,7 +2,9 @@ package pl.tpolgrabia.googleutils.utils;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import com.androidquery.AQuery;
|
import com.androidquery.AQuery;
|
||||||
|
import okhttp3.Interceptor;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
import okhttp3.logging.HttpLoggingInterceptor;
|
import okhttp3.logging.HttpLoggingInterceptor;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -50,10 +52,8 @@ public class PlacesUtils {
|
||||||
throw new IllegalArgumentException("Search radius cannot be null");
|
throw new IllegalArgumentException("Search radius cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
|
|
||||||
// set your desired log level
|
|
||||||
logging.setLevel(HttpLoggingInterceptor.Level.HEADERS);
|
|
||||||
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
|
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
|
||||||
|
// httpClient.addInterceptor(new RetrofitDebugInterceptor());
|
||||||
|
|
||||||
Retrofit retrofit = new Retrofit.Builder()
|
Retrofit retrofit = new Retrofit.Builder()
|
||||||
.baseUrl(GooglePlacesConstants.GOOGLE_MAPS_PLACES_API_BASEURL)
|
.baseUrl(GooglePlacesConstants.GOOGLE_MAPS_PLACES_API_BASEURL)
|
||||||
|
@ -73,4 +73,23 @@ public class PlacesUtils {
|
||||||
searchItemType).execute();
|
searchItemType).execute();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class RetrofitDebugInterceptor implements Interceptor {
|
||||||
|
@Override
|
||||||
|
public okhttp3.Response intercept(Chain chain) throws IOException {
|
||||||
|
final Request req = chain.request();
|
||||||
|
okhttp3.Response response = chain.proceed(req);
|
||||||
|
boolean successFull = response.isSuccessful();
|
||||||
|
int code = response.code();
|
||||||
|
String message = response.message();
|
||||||
|
String msg = response.body().string();
|
||||||
|
lg.debug("Got response. Is successfull: {}, code: {}, message: {}, msg: {}",
|
||||||
|
successFull,
|
||||||
|
code,
|
||||||
|
message,
|
||||||
|
msg);
|
||||||
|
// now we repeat once again (because we have used the stream)
|
||||||
|
return chain.proceed(chain.request());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue