Skip to content

Commit

Permalink
Merge pull request #266 from CaseyHillers/rate-limit-json-fix
Browse files Browse the repository at this point in the history
Fix getRateLimit json double casting ints
  • Loading branch information
Pacane authored Sep 28, 2021
2 parents 40540ea + 8a87923 commit 2446c27
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 8.1.2
- Fixes `RateLimit.fromRateLimitResponse` to not double cast int

## 8.1.1
- Fix up examples and license file https://github.com/SpinlockLabs/github.dart/pull/255 https://github.com/SpinlockLabs/github.dart/pull/254 https://github.com/SpinlockLabs/github.dart/pull/253

Expand Down
4 changes: 2 additions & 2 deletions lib/src/common/model/misc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class RateLimit {
/// 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 limit = rateJson['limit'] as int?;
final remaining = rateJson['remaining'] as int?;
final resets = DateTime.fromMillisecondsSinceEpoch(rateJson['reset']!);
return RateLimit(limit, remaining, resets);
}
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.1.1
version: 8.1.2
description: A high-level GitHub API Client Library that uses Github's v3 API
homepage: https://github.com/SpinlockLabs/github.dart

Expand Down
26 changes: 26 additions & 0 deletions test/unit/common/model/misc_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'dart:convert';

import 'package:github/src/common/model/misc.dart';
import 'package:test/test.dart';

void main() {
group('RateLimit', () {
test('fromRateLimitResponse', () {
// This is a truncated version of the response
const rateLimitJson = '''{
"resources": {
"rate": {
"limit": 5000,
"remaining": 4999,
"reset": 1372700873,
"used": 1
}
}''';
final rateLimit = RateLimit.fromRateLimitResponse(jsonDecode(rateLimitJson));

expect(rateLimit.limit, 5000);
expect(rateLimit.remaining, 4999);
expect(rateLimit.resets, DateTime.fromMillisecondsSinceEpoch(1372700873));
});
});
}

0 comments on commit 2446c27

Please sign in to comment.