dvGitHubHttps function
GitHub's API over HTTPS, as token.
Implementation
DVGitHubTransport dvGitHubHttps(String token) =>
(String method, String path, {Object? body}) async {
final HttpClient client = HttpClient();
try {
final HttpClientRequest request =
await client.openUrl(method, Uri.parse('https://api.github.com$path'));
request.headers
..set('authorization', 'Bearer $token')
..set('accept', 'application/vnd.github+json')
..set('x-github-api-version', '2022-11-28')
..set('user-agent', 'dartvel-studio');
if (body != null) {
request.headers.contentType = ContentType.json;
request.write(jsonEncode(body));
}
final HttpClientResponse response =
await request.close().timeout(const Duration(seconds: 30));
final String text = await response.transform(utf8.decoder).join();
Object? json;
try {
json = text.isEmpty ? null : jsonDecode(text);
} on FormatException {
json = null;
}
return DVGitHubReply(response.statusCode, json);
} finally {
client.close(force: true);
}
};