Skip to content
This repository has been archived by the owner on Oct 22, 2022. It is now read-only.

Commit

Permalink
feat: add since and language params
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Mar 5, 2019
1 parent 4a99551 commit ab7a7f0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/src/github_trending_base.dart
@@ -1,6 +1,12 @@
import 'package:http/http.dart' as http;
import 'package:html/parser.dart' show parse;

class TrendingRepositorySince {
static const daily = 'daily';
static const weekly = 'weekly';
static const monthly = 'monthly';
}

class TrendingRepository {
String owner;
String name;
Expand All @@ -25,8 +31,19 @@ class TrendingRepositoryPrimaryLanguage {
TrendingRepositoryPrimaryLanguage({this.name, this.color});
}

Future<List<TrendingRepository>> getTrendingRepositories() async {
var res = await http.get('https://github.com/trending');
Future<List<TrendingRepository>> getTrendingRepositories({
String since,
String language,
}) async {
var url = 'https://github.com/trending';
if (language != null) {
url += '/$language';
}
if (since != null) {
url += '?since=$since';
}

var res = await http.get(url);
var document = parse(res.body);
var items = document.querySelectorAll('.repo-list>li');

Expand Down
13 changes: 13 additions & 0 deletions test/github_trending_test.dart
Expand Up @@ -42,4 +42,17 @@ void main() {
});
});
});

group('specify language', () {
setUp(() async {
items = await getTrendingRepositories(language: 'dart');
});

test('correct language', () {
items.forEach((item) {
expect(item.primaryLanguage, isNotNull);
expect(item.primaryLanguage.name, equals('Dart'));
});
});
});
}

0 comments on commit ab7a7f0

Please sign in to comment.