Skip to content

Commit 583fa07

Browse files
committed
Added Star, Unstar, list people who star a repository, and list repositories you star support.
1 parent d88671f commit 583fa07

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

lib/src/common/github.dart

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,53 @@ class GitHub {
310310
return copyOf(input.map((it) => Gist.fromJSON(github, it)));
311311
});
312312
}
313+
314+
/**
315+
* Fetches the Stargazers for a Repository
316+
*
317+
* [slug] is a repository slug.
318+
*/
319+
Future<List<User>> stargazers(RepositorySlug slug) {
320+
return getJSON("/repos/${slug.fullName}/stargazers", statusCode: 200, convert: (GitHub github, List<dynamic> input) {
321+
return copyOf(input.map((it) => User.fromJSON(github, it)));
322+
});
323+
}
324+
325+
/**
326+
* Fetches the repositories that [user] has starred.
327+
*/
328+
Future<List<Repository>> starred(String user) {
329+
return getJSON("/users/${user}/starred", statusCode: 200, convert: (GitHub github, List<dynamic> input) {
330+
return copyOf(input.map((it) => Repository.fromJSON(github, it)));
331+
});
332+
}
333+
334+
/**
335+
* Checks if the currently authenticated user has starred the specified repository.
336+
*/
337+
Future<bool> hasStarred(RepositorySlug slug) {
338+
return request("GET", "/user/starred/${slug.fullName}").then((response) {
339+
return response.statusCode == 204;
340+
});
341+
}
342+
343+
/**
344+
* Stars the specified repository for the currently authenticated user.
345+
*/
346+
Future star(RepositorySlug slug) {
347+
return request("PUT", "/user/starred/${slug.fullName}", headers: { "Content-Length": 0 }).then((response) {
348+
return null;
349+
});
350+
}
351+
352+
/**
353+
* Unstars the specified repository for the currently authenticated user.
354+
*/
355+
Future unstar(RepositorySlug slug) {
356+
return request("DELETE", "/user/starred/${slug.fullName}", headers: { "Content-Length": 0 }).then((response) {
357+
return null;
358+
});
359+
}
313360

314361
/**
315362
* Handles Get Requests that respond with JSON

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