Skip to content

Commit 4875e4b

Browse files
authored
Merge pull request #250 from CaseyHillers/rate-limit
Switch to dedicated rate_limit endpoint
2 parents e620ff3 + e086b62 commit 4875e4b

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 8.1.0
2+
- `RateLimit` queries `/rate_limit` and no longer uses quota
3+
14
## 8.0.1
25
- Minor tweaks to improve pub score
36

lib/src/common/misc_service.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:async';
2+
import 'dart:convert';
23
import 'package:github/src/common.dart';
34

45
/// The [MiscService] handles communication with misc related methods of the
@@ -61,8 +62,8 @@ class MiscService extends Service {
6162
///
6263
/// API docs: https://developer.github.com/v3/rate_limit/
6364
Future<RateLimit> getRateLimit() {
64-
return github.request('GET', '/').then((response) {
65-
return RateLimit.fromHeaders(response.headers);
65+
return github.request('GET', '/rate_limit').then((response) {
66+
return RateLimit.fromRateLimitResponse(jsonDecode(response.body));
6667
});
6768
}
6869

lib/src/common/model/misc.dart

+11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ class RateLimit {
3939
return RateLimit(limit, remaining, resets);
4040
}
4141

42+
/// Construct [RateLimit] from JSON response of /rate_limit.
43+
///
44+
/// API docs: https://developer.github.com/v3/rate_limit/
45+
factory RateLimit.fromRateLimitResponse(Map<String, dynamic> response) {
46+
final rateJson = response['rate'] as Map<String, dynamic>;
47+
final limit = int.parse(rateJson['limit']!);
48+
final remaining = int.parse(rateJson['remaining']!);
49+
final resets = DateTime.fromMillisecondsSinceEpoch(rateJson['reset']!);
50+
return RateLimit(limit, remaining, resets);
51+
}
52+
4253
factory RateLimit.fromJson(Map<String, dynamic> input) =>
4354
_$RateLimitFromJson(input);
4455
Map<String, dynamic> toJson() => _$RateLimitToJson(this);

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: github
2-
version: 8.0.1
2+
version: 8.1.0
33
description: A high-level GitHub API Client Library that uses Github's v3 API
44
homepage: https://github.com/SpinlockLabs/github.dart
55

0 commit comments

Comments
 (0)