Last active
November 18, 2016 03:56
-
-
Save enginebai/ad01b4064f50413c89b6749f0057a520 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Observable<String> getUserInfo(final Context context, | |
final String userId) { | |
return Observable.create(new ObservableOnSubscribe<String>() { | |
@Override | |
public void subscribe(ObservableEmitter<String> subscriber) throws Exception { | |
try { | |
HttpUrl url = new HttpUrl.Builder() | |
.scheme(SCHEME_HTTPS) | |
.host(API_HOST) | |
.addPathSegment(API_VERSION).addPathSegment(MODULE_NAME).addPathSegment(PATH_GET_USER_INFO) | |
.addQueryParameter(User.FIELD_USER_ID, userId) | |
.build(); | |
subscriber.onNext(ApiService.get(context, url)); | |
} | |
catch (Exception e) { | |
subscriber.onError(e); | |
} | |
} | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String get(Context context, HttpUrl url) throws IOException { | |
Request request = ApiService.createRequestBuilder(context) | |
.url(url) | |
.build(); | |
return ((GlobalContext) context.getApplicationContext()) | |
.getHttpClientDebug(HttpLoggingInterceptor.Level.BODY) | |
.newCall(request) | |
.execute().body().string(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public OkHttpClient getHttpClientDebug(HttpLoggingInterceptor.Level debugLevel) { | |
if (isDebugMode()) | |
return new OkHttpClient.Builder() | |
.addInterceptor(new HttpLoggingInterceptor().setLevel(debugLevel)) | |
.addNetworkInterceptor(new StethoInterceptor()) | |
.build(); | |
else | |
return getHttpClient(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment