Skip to content

Switch to dedicated rate_limit endpoint #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 8.1.0
- `RateLimit` queries `/rate_limit` and no longer uses quota

## 8.0.1
- Minor tweaks to improve pub score

Expand Down
5 changes: 3 additions & 2 deletions lib/src/common/misc_service.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'package:github/src/common.dart';

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

Expand Down
11 changes: 11 additions & 0 deletions lib/src/common/model/misc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ class RateLimit {
return RateLimit(limit, remaining, resets);
}

/// Construct [RateLimit] from JSON response of /rate_limit.
///
/// API docs: https://developer.github.com/v3/rate_limit/
factory RateLimit.fromRateLimitResponse(Map<String, dynamic> response) {
final rateJson = response['rate'] as Map<String, dynamic>;
final limit = int.parse(rateJson['limit']!);
final remaining = int.parse(rateJson['remaining']!);
final resets = DateTime.fromMillisecondsSinceEpoch(rateJson['reset']!);
return RateLimit(limit, remaining, resets);
}

factory RateLimit.fromJson(Map<String, dynamic> input) =>
_$RateLimitFromJson(input);
Map<String, dynamic> toJson() => _$RateLimitToJson(this);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: github
version: 8.0.1
version: 8.1.0
description: A high-level GitHub API Client Library that uses Github's v3 API
homepage: https://github.com/SpinlockLabs/github.dart

Expand Down