Skip to content

Commit 4875e4b

Browse files
authored
Merge pull request SpinlockLabs#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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 11 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy