listPublicRepositories method

Stream<Repository> listPublicRepositories({
  1. int limit = 50,
  2. DateTime? since,
})

Lists all the public repositories on GitHub, in the order that they were created.

If limit is not null, it is used to specify the amount of repositories to fetch. If limit is null, it will fetch ALL the repositories on GitHub.

API docs: https://developer.github.com/v3/repos/#list-all-public-repositories

Implementation

Stream<Repository> listPublicRepositories({int limit = 50, DateTime? since}) {
  final params = <String, dynamic>{};

  if (since != null) {
    params['since'] = since.toIso8601String();
  }

  final pages = (limit / 30).ceil();

  return PaginationHelper(github)
      .fetchStreamed('GET', '/repositories', pages: pages, params: params)
      .expand<Repository>((http.Response response) {
    final list = jsonDecode(response.body) as List<Map<String, dynamic>>;

    return list.map((Map<String, dynamic> it) => Repository.fromJson(it));
  });
}