@@ -65,11 +65,56 @@ class UsersService extends Service {
65
65
Stream <UserEmail > listEmails () => new PaginationHelper (_github).objects (
66
66
"GET" , "/user/emails" , UserEmail .fromJSON);
67
67
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
+ }
69
106
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
+ }
71
113
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 );
73
118
74
119
/// Lists the verified public keys for a [userLogin] . If no [userLogin] is specified,
75
120
/// the public keys for the authenticated user are fetched.
@@ -93,5 +138,4 @@ class UsersService extends Service {
93
138
94
139
// TODO: Implement updatePublicKey: https://developer.github.com/v3/users/keys/#update-a-public-key
95
140
// TODO: Implement deletePublicKey: https://developer.github.com/v3/users/keys/#delete-a-public-key
96
-
97
141
}
0 commit comments