operators - RxAndroid response of one call to make another request -


i'm new rxandroid , trying chain responses.

i'm using github api retrieve data. along each issue there comments link , events link associated want fetch , update existing object list of comments , events form this.

[  issue: {   comments: [      {      .      .     },     {      .      .     }  ]  events : [      {      .      .     },     {      .      .     }  ]  ]  ] 

i retrieve initial response following code

githubservice githubservice = servicefactory.createservicefrom(githubservice.class, githubservice.endpoint);      githubservice.getissueslist()             .subscribeon(schedulers.newthread())             .observeon(androidschedulers.mainthread())             .map(issues -> arrays.aslist(issues))             .subscribe(adapter::add); 

now how retrieve comments , events before updating adapter ? want show 3 comments , 3 events well.

thanks @riccardo ciovati example !

here solution. , works !

public static void getissuesforrepo(final issueslistadapter adapter) {      githubservice githubservice = servicefactory.createservicefrom(githubservice.class, githubservice.endpoint);      githubservice.getissueslist()             .subscribeon(schedulers.newthread())             .observeon(androidschedulers.mainthread())             .map(issues -> arrays.aslist(issues))             .flatmap(issues -> observable.from(issues))             .filter(issue -> issue.getcommentsurl() != null)             .flatmap(new func1<issue, observable<issue>>() {                 @override                 public observable<issue> call(issue issue) {                       return githubservice.getcomments(issue.getnumber())                             .subscribeon(schedulers.newthread())                             .observeon(androidschedulers.mainthread())                             .map(comments -> {                                  issue.setcommentlist(arrays.aslist(comments));                                  return issue;                             });                 }               })             .tolist()             .subscribe(adapter::add);  } 

where

public interface githubservice {    string endpoint = "https://api.github.com/";    @get("repos/crashlytics/secureudid/issues")   observable<issue[]> getissueslist();    @get("repos/crashlytics/secureudid/issues/{number}/comments")   observable<comment[]> getcomments(@path("number") long number);   } 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -