mirror of
https://github.com/git-touch/git-touch
synced 2024-12-16 10:20:55 +01:00
66 lines
1.4 KiB
Dart
66 lines
1.4 KiB
Dart
import 'dart:convert';
|
|
import 'dart:async';
|
|
import 'dart:io';
|
|
import 'package:http/http.dart' as http;
|
|
import 'token.dart';
|
|
|
|
final prefix = 'https://api.github.com';
|
|
|
|
class Event {
|
|
String type;
|
|
String actor;
|
|
String id;
|
|
String avatar;
|
|
String repo;
|
|
Map<String, dynamic> payload;
|
|
|
|
Event.fromJson(data) {
|
|
id = data['id'];
|
|
type = data['type'];
|
|
actor = data['actor']['login'];
|
|
avatar = data['actor']['avatar_url'];
|
|
repo = data['repo']['name'];
|
|
payload = data['payload'];
|
|
}
|
|
}
|
|
|
|
class User {
|
|
String login;
|
|
String avatar;
|
|
String name;
|
|
int repos;
|
|
int followers;
|
|
int following;
|
|
|
|
User.fromJson(data) {
|
|
login = data['login'];
|
|
avatar = data['avatar_url'];
|
|
name = data['name'];
|
|
repos = data['public_repos'];
|
|
followers = data['followers'];
|
|
following = data['following'];
|
|
}
|
|
}
|
|
|
|
Future<List<Event>> fetchEvents([int page = 1]) async {
|
|
final res = await http.get(
|
|
prefix + '/users/pd4d10/received_events/public?page=$page',
|
|
headers: {HttpHeaders.AUTHORIZATION: 'token $token'},
|
|
);
|
|
List<dynamic> data = json.decode(res.body);
|
|
|
|
return data.map((item) {
|
|
return Event.fromJson(item);
|
|
}).toList();
|
|
}
|
|
|
|
Future<User> fetchUser(String login) async {
|
|
final res = await http.get(
|
|
prefix + '/users/$login',
|
|
headers: {HttpHeaders.AUTHORIZATION: 'token $token'},
|
|
);
|
|
Map<String, dynamic> data = json.decode(res.body);
|
|
|
|
return User.fromJson(data);
|
|
}
|