Skip to content

Instantly share code, notes, and snippets.

@nsk-mironov
Created June 13, 2015 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsk-mironov/3270b103fc3326a325e2 to your computer and use it in GitHub Desktop.
Save nsk-mironov/3270b103fc3326a325e2 to your computer and use it in GitHub Desktop.
public class Main {
public static void main(String[] args) {
ContentManager cm = new ContentManager();
Observable
.from(cm.getPermalinks(10))
.flatMap(permalink -> Observable.zip(
Observable.<Content>create(subscriber -> cm.getDataByPermalink(permalink, new SubscribingRestCallback(subscriber))),
Observable.<Content>create(subscriber -> cm.getStreamByPermalink(permalink, new SubscribingRestCallback(subscriber))),
(dataContent, streamUrlContent) -> {
return new Content(dataContent.permalink, dataContent.logoUrl, streamUrlContent.streamUrl);
}).onErrorResumeNext(Observable.empty()))
.subscribe(System.out::println);
}
}
class SubscribingRestCallback implements RestCallback {
private final Subscriber<? super Content> subscriber;
public SubscribingRestCallback(Subscriber<? super Content> subscriber) {
this.subscriber = subscriber;
}
@Override
public void onSuccess(Content content) {
subscriber.onNext(content);
subscriber.onCompleted();
}
@Override
public void onFailure(int code, String message) {
subscriber.onError(new Exception(message));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment