Skip to content

Commit

Permalink
Update MiscService.getApiStatus to v2 (#393)
Browse files Browse the repository at this point in the history
* v1 has been deleted

Co-authored-by: Rob Becker <[email protected]>
  • Loading branch information
Casey Hillers and robbecker-wf authored Dec 28, 2023
1 parent 7bc0667 commit 741c26d
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 9.21.0

* Update MiscService.getApiStatus() to use the v2 API
* `APIStatus` has been refactored to match, now exposing `page` and `status`

## 9.20.0

* Add a Changes object to the PullRequestEvent object so we can see what changed in edited PR events by @ricardoamador in https://github.com/SpinlockLabs/github.dart/pull/390
Expand Down
4 changes: 3 additions & 1 deletion lib/src/common/misc_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ class MiscService extends Service {
}

/// Gets the GitHub API Status.
///
/// API docs: https://www.githubstatus.com/api
Future<APIStatus> getApiStatus() =>
github.getJSON('https://status.github.com/api/status.json',
github.getJSON('https://status.github.com/api/v2/status.json',
statusCode: StatusCodes.OK, convert: APIStatus.fromJson);

/// Returns an ASCII Octocat with the specified [text].
Expand Down
62 changes: 50 additions & 12 deletions lib/src/common/model/misc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,65 @@ class RateLimit {
Map<String, dynamic> toJson() => _$RateLimitToJson(this);
}

/// Model class for the GitHub api status.
/// Model class for the GitHub API status.
@JsonSerializable()
class APIStatus {
APIStatus({
this.page,
this.status,
this.lastUpdatedAt,
this.createdOn,
this.message,
});
final String? status;

@JsonKey(name: 'last_updated')
final DateTime? lastUpdatedAt;
/// Details about where to find more information.
final APIStatusPage? page;

@JsonKey(name: 'created_on')
final DateTime? createdOn;

@JsonKey(name: 'body')
final String? message;
/// An overview of the current status.
final APIStatusMessage? status;

factory APIStatus.fromJson(Map<String, dynamic> input) =>
_$APIStatusFromJson(input);
Map<String, dynamic> toJson() => _$APIStatusToJson(this);
}

@JsonSerializable()
class APIStatusPage {
const APIStatusPage({
this.id,
this.name,
this.url,
this.updatedAt,
});

/// Unique identifier for the current status.
final String? id;

final String? name;

/// Where to get more detailed information.
final String? url;

@JsonKey(name: 'updated_at')
final DateTime? updatedAt;

factory APIStatusPage.fromJson(Map<String, dynamic> input) =>
_$APIStatusPageFromJson(input);
Map<String, dynamic> toJson() => _$APIStatusPageToJson(this);
}

/// Overview class of the GitHub API status.
@JsonSerializable()
class APIStatusMessage {
const APIStatusMessage({
this.description,
this.indicator,
});

/// A human description of the blended component status.
final String? description;

/// An indicator - one of none, minor, major, or critical.
final String? indicator;

factory APIStatusMessage.fromJson(Map<String, dynamic> input) =>
_$APIStatusMessageFromJson(input);
Map<String, dynamic> toJson() => _$APIStatusMessageToJson(this);
}
44 changes: 35 additions & 9 deletions lib/src/common/model/misc.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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: 9.20.0
version: 9.21.0
description: A high-level GitHub API Client Library that uses Github's v3 API
homepage: https://github.com/SpinlockLabs/github.dart

Expand Down
37 changes: 37 additions & 0 deletions test/common/misc_service_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'dart:io';

import 'package:github/src/common.dart';
import 'package:http/http.dart';
import 'package:http/testing.dart';
import 'package:test/test.dart';

void main() {
MiscService create(Future<Response> Function(Request) f) {
final client = MockClient(f);
final github = GitHub(client: client);
return MiscService(github);
}

test('api status', () async {
final miscService = create(
(_) async => Response('''
{
"page":{
"id":"kctbh9vrtdwd",
"name":"GitHub",
"url":"https://www.githubstatus.com",
"updated_at": "2023-11-29T08:03:04Z"
},
"status": {
"description": "Partial System Outage",
"indicator": "major"
}
}''', HttpStatus.ok),
);
final status = await miscService.getApiStatus();
expect(status.page, isNotNull);
expect(status.page?.id, 'kctbh9vrtdwd');
expect(status.status, isNotNull);
expect(status.status?.indicator, 'major');
});
}

0 comments on commit 741c26d

Please sign in to comment.