我正在使用Spotify API,并希望使用RxJava链接一些分页结果.Spotify使用基于游标的分页,因此像@lopar那样的解决方案将无效.
响应来自此调用,看起来像这样(想象有50个items):
{
"artists" : {
"items" : [ {
"id" : "6liAMWkVf5LH7YR9yfFy1Y",
"name" : "Portishead",
"type" : "artist"
}],
"next" : "https://api.spotify.com/v1/me/following?type=artist&after=6liAMWkVf5LH7YR9yfFy1Y&limit=50",
"total" : 119,
"cursors" : {
"after" : "6liAMWkVf5LH7YR9yfFy1Y"
},
"limit" : 50,
"href" : "https://api.spotify.com/v1/me/following?type=artist&limit=50"
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我正在使用改造这样的前50个结果:
public class CursorPager<T> {
public String href;
public List<T> items;
public int limit;
public String next;
public Cursor cursors;
public int total;
public CursorPager() {
}
}
public class ArtistsCursorPager { …Run Code Online (Sandbox Code Playgroud)