Repo created
This commit is contained in:
parent
2fd78f5dc9
commit
489cf0b2ea
148 changed files with 30898 additions and 2 deletions
67
lib/mass_app_sources/githubstars.dart
Normal file
67
lib/mass_app_sources/githubstars.dart
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:obtainium/app_sources/github.dart';
|
||||
import 'package:obtainium/custom_errors.dart';
|
||||
import 'package:obtainium/providers/source_provider.dart';
|
||||
|
||||
class GitHubStars implements MassAppUrlSource {
|
||||
@override
|
||||
late String name = tr('githubStarredRepos');
|
||||
|
||||
@override
|
||||
late List<String> requiredArgs = [tr('uname')];
|
||||
|
||||
Future<Map<String, List<String>>> getOnePageOfUserStarredUrlsWithDescriptions(
|
||||
String username,
|
||||
int page,
|
||||
) async {
|
||||
Response res = await get(
|
||||
Uri.parse(
|
||||
'https://api.github.com/users/$username/starred?per_page=100&page=$page',
|
||||
),
|
||||
headers: await GitHub().getRequestHeaders({}),
|
||||
);
|
||||
if (res.statusCode == 200) {
|
||||
Map<String, List<String>> urlsWithDescriptions = {};
|
||||
for (var e in (jsonDecode(res.body) as List<dynamic>)) {
|
||||
urlsWithDescriptions.addAll({
|
||||
e['html_url'] as String: [
|
||||
e['full_name'] as String,
|
||||
e['description'] != null
|
||||
? e['description'] as String
|
||||
: tr('noDescription'),
|
||||
],
|
||||
});
|
||||
}
|
||||
return urlsWithDescriptions;
|
||||
} else {
|
||||
var gh = GitHub();
|
||||
gh.rateLimitErrorCheck(res);
|
||||
throw getObtainiumHttpError(res);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, List<String>>> getUrlsWithDescriptions(
|
||||
List<String> args,
|
||||
) async {
|
||||
if (args.length != requiredArgs.length) {
|
||||
throw ObtainiumError(tr('wrongArgNum'));
|
||||
}
|
||||
Map<String, List<String>> urlsWithDescriptions = {};
|
||||
var page = 1;
|
||||
while (true) {
|
||||
var pageUrls = await getOnePageOfUserStarredUrlsWithDescriptions(
|
||||
args[0],
|
||||
page++,
|
||||
);
|
||||
urlsWithDescriptions.addAll(pageUrls);
|
||||
if (pageUrls.length < 100) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return urlsWithDescriptions;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue