Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next_urlに対応させる #5

Open
MnyaCat opened this issue Feb 25, 2023 · 1 comment
Open

next_urlに対応させる #5

MnyaCat opened this issue Feb 25, 2023 · 1 comment

Comments

@MnyaCat
Copy link
Owner

MnyaCat commented Feb 25, 2023

v1/illust/rankingv1/illust/recommendedなどはレスポンスに以降のイラストを取得するためのnext_urlが含まれる。
メソッドの引数でnext_urlを受け取れるようにして、next_urlが渡された時はそれを使って取得するようにする。

Before

Future<Illusts> fetchIllustRanking({
  IllustRankingMode? mode,
  int? offset,
  DateTime? date,
}) async {
  final body = <String, String?>{
    'mode': mode?.toSnakeCaseString(),
    'offset': offset?.toString(),
    'date': date?.toDateString()
  }..removeWhere((key, value) => value == null);
  print(body);
  final url = Uri.https(apiHostname, '/v1/illust/ranking', body);
  final header = await getRefreshedHeader();
  final response = await innerClient.get(url, headers: header);
  final jsonResponse = parse(response);
  return Illusts.fromJson(jsonResponse);
}

After

Future<Illusts> fetchIllustRanking({
  IllustRankingMode? mode,
  int? offset,
  DateTime? date,
  // 引数でnext_urlを受け取る
  String? nextUrl
}) async {
  final Uri url;
  // next_urlが渡されたかで分岐
  if (next_url == null) {
    final body = <String, String?>{
      'mode': mode?.toSnakeCaseString(),
      'offset': offset?.toString(),
      'date': date?.toDateString()
    }..removeWhere((key, value) => value == null);
    url = Uri.https(apiHostname, '/v1/illust/ranking', body);
  } else {
    // 渡されている時はURLをパース
    url = Uri.parse(nextUrl);
  }
  final header = await getRefreshedHeader();
  final response = await innerClient.get(url, headers: header);
  final jsonResponse = parse(response);
  return Illusts.fromJson(jsonResponse);
}
@MnyaCat
Copy link
Owner Author

MnyaCat commented Feb 25, 2023

対応させたらfetchUserIllustBookmarksByNextUrlfetchUserNovelBookmarksByNextUrlを削除する。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant