getContributions function

Future<List<Contribution>> getContributions(
  1. String login, {
  2. String from,
  3. String to,
})

Implementation

Future<List<Contribution>> getContributions(
  String login, {
  String from,
  String to,
}) async {
  var url = 'https://github.com/$login';
  if (from != null && to != null) {
    url += '?from=$from&to=$to';
  }
  var res = await http.get(url);
  var document = parse(res.body);
  var rectNodes =
      document.querySelector('.js-calendar-graph-svg').querySelectorAll('rect');
  return rectNodes.map((rectNode) {
    return Contribution(
      color: rectNode.attributes['fill'],
      count: int.tryParse(rectNode.attributes['data-count']),
      date: rectNode.attributes['data-date'],
    );
  }).toList();
}