Skip to content

Commit ffc7ff8

Browse files
committed
Implement more user methods.
1 parent 8d84891 commit ffc7ff8

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

lib/src/common/users_service.dart

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,56 @@ class UsersService extends Service {
6565
Stream<UserEmail> listEmails() => new PaginationHelper(_github).objects(
6666
"GET", "/user/emails", UserEmail.fromJSON);
6767

68-
// TODO: Implement addEmails: https://developer.github.com/v3/users/emails/#add-email-addresses
68+
/// Add Emails
69+
///
70+
/// API docs: https://developer.github.com/v3/users/emails/#add-email-addresses
71+
Stream<UserEmail> addEmails(List<String> emails) => new PaginationHelper(_github).objects(
72+
"POST",
73+
"/user/emails",
74+
UserEmail.fromJSON,
75+
statusCode: 201,
76+
body: JSON.encode(emails)
77+
);
78+
79+
/// Delete Emails
80+
///
81+
/// API docs: https://developer.github.com/v3/users/emails/#delete-email-addresses
82+
Future<bool> deleteEmails(List<String> emails) => _github.request("DELETE", "/user/emails", body: JSON.encode(emails), statusCode: 204)
83+
.then((x) => x.statusCode == 204);
84+
85+
/// List user followers.
86+
///
87+
/// API docs: https://developer.github.com/v3/users/followers/#list-followers-of-a-user
88+
Stream<User> listUserFollowers(String user) => new PaginationHelper(_github).objects("GET", "/users/${user}/followers", User.fromJSON, statusCode: 200);
89+
90+
/// Check if the current user is following the specified user.
91+
Future<bool> isFollowingUser(String user) => _github.request("GET", "/user/following/${user}").then((response) {
92+
return response.statusCode == 204;
93+
});
94+
95+
/// Check if the specified user is following target.
96+
Future<bool> isUserFollowing(String user, String target) => _github.request("GET", "/users/${user}/following/${target}").then((x) {
97+
return x.statusCode == 204;
98+
});
99+
100+
/// Follows a user.
101+
Future<bool> followUser(String user) {
102+
return _github.request("POST", "/user/following/${user}", statusCode: 204).then((response) {
103+
return response.statusCode == 204;
104+
});
105+
}
69106

70-
// TODO: Implement deleteEmails: https://developer.github.com/v3/users/emails/#delete-email-addresses
107+
/// Unfollows a user.
108+
Future<bool> unfollowUser(String user) {
109+
return _github.request("DELETE", "/user/following/${user}", statusCode: 204).then((response) {
110+
return response.statusCode == 204;
111+
});
112+
}
71113

72-
// TODO: Implement follower methods: https://developer.github.com/v3/users/followers/
114+
/// List current user followers.
115+
///
116+
/// API docs: https://developer.github.com/v3/users/followers/#list-followers-of-a-user
117+
Stream<User> listCurrentUserFollowers() => new PaginationHelper(_github).objects("GET", "/user/followers", User.fromJSON, statusCode: 200);
73118

74119
/// Lists the verified public keys for a [userLogin]. If no [userLogin] is specified,
75120
/// the public keys for the authenticated user are fetched.
@@ -93,5 +138,4 @@ class UsersService extends Service {
93138

94139
// TODO: Implement updatePublicKey: https://developer.github.com/v3/users/keys/#update-a-public-key
95140
// TODO: Implement deletePublicKey: https://developer.github.com/v3/users/keys/#delete-a-public-key
96-
97141
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy