-
-
Save Gizmodo/c65ca41310e3e02454e61c48bcfe2f7e to your computer and use it in GitHub Desktop.
OkHttp With RxAndroid and RxJava
This file contains 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<Response> getData() { | |
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); | |
StrictMode.setThreadPolicy(policy); | |
final OkHttpClient client = new OkHttpClient(); | |
final Request request = new Request.Builder() | |
.url("https://github.com/ar-android/panfic/raw/master/Panfic/gen/com/ocit/data.json") | |
.get() | |
.addHeader("cache-control", "no-cache") | |
.addHeader("postman-token", "ac8311d5-3876-ea1e-53d3-85f9e397ea21") | |
.build(); | |
return Observable.create(new Observable.OnSubscribe<Response>() { | |
@Override public void call(Subscriber<? super Response> subscriber) { | |
try { | |
Response response = client.newCall(request).execute(); | |
subscriber.onNext(response); | |
subscriber.onCompleted(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
subscriber.onError(e); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment