Skip to content
This repository was archived by the owner on Jul 28, 2022. It is now read-only.

Commit a7c61cf

Browse files
committed
Added methods implementing Repository Starring API.
1 parent eda7837 commit a7c61cf

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

lib/GitHub/API/Repo/Repo.php

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,4 +410,104 @@ public function events()
410410

411411
return $this->event;
412412
}
413+
414+
/**
415+
* List repository stargazers.
416+
*
417+
* Authentication Required: false|true
418+
*
419+
* @link http://developer.github.com/v3/activity/starring/#list-stargazers
420+
*
421+
* @param string $username GitHub username of repo owner
422+
* @param string $repo Name of repository
423+
* @param int $page Paginated page to get
424+
* @param int $pageSize Size of paginated page. Max 100
425+
* @return array|bool Returns the list of stargazers or FALSE
426+
* if the request failed
427+
*/
428+
public function stargazers($username, $repo, $page = 1, $pageSize = self::DEFAULT_PAGE_SIZE)
429+
{
430+
return $this->processResponse(
431+
$this->requestGet("repos/$username/$repo/stargazers", $this->buildPageParams($page, $pageSize))
432+
);
433+
}
434+
435+
/**
436+
* List repositories being starred by user.
437+
*
438+
* Authentication Required: false|true
439+
*
440+
* @link http://developer.github.com/v3/activity/starring/#list-repositories-being-starred
441+
*
442+
* @param string $username GitHub username
443+
* @return array|bool Returns the list of starred repos or FALSE
444+
* if the request failed
445+
*/
446+
public function starred($username = null)
447+
{
448+
if (is_null($username))
449+
$url = 'user/starred';
450+
else
451+
$url = "users/$username/starred";
452+
453+
return $this->processResponse(
454+
$this->requestGet($url)
455+
);
456+
}
457+
458+
/**
459+
* Check if a repository is being starred by authenticated user.
460+
*
461+
* Authentication Required: true
462+
*
463+
* @link http://developer.github.com/v3/activity/starring/#check-if-you-are-starring-a-repository
464+
*
465+
* @param string $username GitHub username
466+
* @param string $repo Name of repository
467+
* @return array|bool Returns TRUE if the repo is being starred
468+
*/
469+
public function isStarred($username, $repo)
470+
{
471+
$url = "users/starred/$username/$repo";
472+
473+
return $this->processResponse(
474+
$this->requestGet($url)
475+
);
476+
}
477+
478+
/**
479+
* Star a repository.
480+
*
481+
* Authentication Required: true
482+
*
483+
* @link http://developer.github.com/v3/activity/starring/#star-a-repository
484+
*
485+
* @param string $username GitHub username
486+
* @param string $repo Name of repository
487+
* @return array|bool Returns TRUE if the repo is being starred
488+
*/
489+
public function star($username, $repo)
490+
{
491+
return $this->processResponse(
492+
$this->requestPut("user/starred/$username/$repo")
493+
);
494+
}
495+
496+
/**
497+
* Unstar a repository.
498+
*
499+
* Authentication Required: true
500+
*
501+
* @link http://developer.github.com/v3/activity/starring/#unstar-a-repository
502+
*
503+
* @param string $username GitHub username
504+
* @param string $repo Name of repository
505+
* @return array|bool Returns TRUE if the repo is being unstarred
506+
*/
507+
public function unstar($username, $repo)
508+
{
509+
return $this->processResponse(
510+
$this->requestDelete("user/starred/$username/$repo")
511+
);
512+
}
413513
}

0 commit comments

Comments
 (0)