Created
June 13, 2015 22:05
-
-
Save nsk-mironov/3270b103fc3326a325e2 to your computer and use it in GitHub Desktop.
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 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