Skip to content

Commit 2446c27

Browse files
authored
Merge pull request #266 from CaseyHillers/rate-limit-json-fix
Fix getRateLimit json double casting ints
2 parents 40540ea + 8a87923 commit 2446c27

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 8.1.2
2+
- Fixes `RateLimit.fromRateLimitResponse` to not double cast int
3+
14
## 8.1.1
25
- 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
36

lib/src/common/model/misc.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class RateLimit {
4444
/// API docs: https://developer.github.com/v3/rate_limit/
4545
factory RateLimit.fromRateLimitResponse(Map<String, dynamic> response) {
4646
final rateJson = response['rate'] as Map<String, dynamic>;
47-
final limit = int.parse(rateJson['limit']!);
48-
final remaining = int.parse(rateJson['remaining']!);
47+
final limit = rateJson['limit'] as int?;
48+
final remaining = rateJson['remaining'] as int?;
4949
final resets = DateTime.fromMillisecondsSinceEpoch(rateJson['reset']!);
5050
return RateLimit(limit, remaining, resets);
5151
}

pubspec.yaml

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

test/unit/common/model/misc_test.dart

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'dart:convert';
2+
3+
import 'package:github/src/common/model/misc.dart';
4+
import 'package:test/test.dart';
5+
6+
void main() {
7+
group('RateLimit', () {
8+
test('fromRateLimitResponse', () {
9+
// This is a truncated version of the response
10+
const rateLimitJson = '''{
11+
"resources": {
12+
"rate": {
13+
"limit": 5000,
14+
"remaining": 4999,
15+
"reset": 1372700873,
16+
"used": 1
17+
}
18+
}''';
19+
final rateLimit = RateLimit.fromRateLimitResponse(jsonDecode(rateLimitJson));
20+
21+
expect(rateLimit.limit, 5000);
22+
expect(rateLimit.remaining, 4999);
23+
expect(rateLimit.resets, DateTime.fromMillisecondsSinceEpoch(1372700873));
24+
});
25+
});
26+
}

0 commit comments

Comments
 (0)