Skip to content

Commit aeaf9bf

Browse files
committed
add logging lines
1 parent daa736f commit aeaf9bf

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Next, add this line to your `app/build.gradle` file:
2424

2525
```gradle
2626
dependencies {
27-
compile 'com.codepath.libraries:android-oauth-handler:2.1.1'
27+
compile 'com.codepath.libraries:android-oauth-handler:2.1.3'
2828
}
2929
```
3030

library/build.gradle

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ext {
88

99
GROUP = 'com.codepath.libraries'
1010
BASE_VERSION = "2.0"
11-
VERSION_NAME = "2.1.2"
11+
VERSION_NAME = "2.1.3"
1212
POM_PACKAGING = "aar"
1313
POM_DESCRIPTION = "CodePath OAuth Handler"
1414

@@ -98,6 +98,8 @@ dependencies {
9898
implementation 'oauth.signpost:signpost-core:1.2.1.2'
9999
implementation 'com.facebook.stetho:stetho:1.5.1'
100100
implementation 'com.facebook.stetho:stetho-okhttp3:1.5.1'
101+
implementation "com.squareup.okhttp3:logging-interceptor:4.1.0"
102+
101103
}
102104

103105
/*task jar(type: Jar) {

library/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import okhttp3.OkHttpClient;
1414
import okhttp3.Request;
1515
import okhttp3.Response;
16+
import okhttp3.logging.HttpLoggingInterceptor;
1617
import se.akerfeldt.okhttp.signpost.OkHttpOAuthConsumer;
1718
import se.akerfeldt.okhttp.signpost.SigningInterceptor;
1819

@@ -22,10 +23,21 @@ protected OAuthAsyncHttpClient(OkHttpClient httpClient) {
2223
super(httpClient);
2324
}
2425

26+
private static String BEARER = "Bearer";
27+
28+
public static HttpLoggingInterceptor createLogger() {
29+
HttpLoggingInterceptor logger = new HttpLoggingInterceptor();
30+
logger.level(HttpLoggingInterceptor.Level.HEADERS);
31+
return logger;
32+
}
33+
2534
public static OAuthAsyncHttpClient create(String consumerKey, String consumerSecret, OAuth1AccessToken token) {
2635
OkHttpOAuthConsumer consumer = new OkHttpOAuthConsumer(consumerKey, consumerSecret);
36+
HttpLoggingInterceptor logging = createLogger();
37+
2738
consumer.setTokenWithSecret(token.getToken(), token.getTokenSecret());
2839
OkHttpClient httpClient = new OkHttpClient.Builder()
40+
.addInterceptor(logging)
2941
.addNetworkInterceptor(new StethoInterceptor())
3042
.addInterceptor(new SigningInterceptor(consumer)).build();
3143

@@ -34,9 +46,12 @@ public static OAuthAsyncHttpClient create(String consumerKey, String consumerSec
3446
}
3547

3648
public static OAuthAsyncHttpClient create(final OAuth2AccessToken token) {
37-
final String bearer = String.format("Bearer %s", token.getAccessToken());
49+
final String bearer = String.format("%s %s", BEARER, token.getAccessToken());
50+
51+
HttpLoggingInterceptor logging = createLogger();
3852

3953
OkHttpClient httpClient = new OkHttpClient.Builder()
54+
.addInterceptor(logging)
4055
.addNetworkInterceptor(new StethoInterceptor())
4156
.addInterceptor(new Interceptor() {
4257
@NotNull

0 commit comments

Comments
 (0)