Created
December 1, 2011 09:52
-
-
Save nodesocket/1415442 to your computer and use it in GitHub Desktop.
GitHub API Wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //// | |
| // Dependencies | |
| //// | |
| require_once(dirname(dirname(__FILE__)) . "/classes/Curl.php"); | |
| /** | |
| * GitHub | |
| * | |
| * @todo | |
| * | |
| * @version 1.0.0 | |
| * @date last modified 11/07/2011 | |
| */ | |
| class GitHub { | |
| private $curl = null; | |
| private $github_username = ""; | |
| private $github_password = ''; | |
| private $base_url = "https://api.github.com"; | |
| private $org = ""; | |
| //// | |
| // Constructor | |
| //// | |
| public function __construct() { | |
| $this->curl = new Curl($this->github_username, $this->github_password); | |
| } | |
| //// | |
| // Parameters: | |
| // $repo_name: Can only be [a-zA-Z0-9-._+] the rest of the characters are stripped out | |
| // $repo_description: A string description of the repo | |
| // $public: "false" (default) or "true" | |
| // $has_wiki: "false" (default) or "true" | |
| //// | |
| public function create_repo($repo_name, $repo_description = "", $public = "false", $has_wiki = "false") { | |
| $request = $this->base_url . "/orgs/" . $this->org . "/repos"; | |
| $data = array(); | |
| $data['name'] = trim(preg_replace('/[^a-zA-Z0-9-\._\+]/', '', $repo_name)); | |
| $data['description'] = $repo_description; | |
| $data['public'] = $public; | |
| $data['has_wiki'] = $has_wiki; | |
| return $this->curl->post_request($request, json_encode($data)); | |
| } | |
| //// | |
| // Parameters | |
| // $team_name: Can only be [a-zA-Z0-9-._+] the rest of the characters are stripped out | |
| // $repos: Array of repos | |
| // $permissions: "pull", "push" (default), "admin" | |
| //// | |
| public function create_team($team_name, $repos, $permissions = "push") { | |
| if(!is_array($repos)) { | |
| return; | |
| } | |
| $request = $this->base_url . "/orgs/" . $this->org . "/teams"; | |
| $temp = array(); | |
| foreach($repos as $key => $value) { | |
| $temp[$key] = $this->org . "/" . $value; | |
| } | |
| $repos = $temp; | |
| $data = array(); | |
| $data['name'] = trim(preg_replace('/[^a-zA-Z0-9-\._\+]/', '', $team_name)); | |
| $data['repo_names'] = $repos; | |
| $data['permission'] = $permissions; | |
| return $this->curl->post_request($request, json_encode($data)); | |
| } | |
| //// | |
| // Parameters | |
| // $team_id: The id of the team returned from the create team request. NOT the team name. | |
| // $user: The user to add to the team | |
| //// | |
| public function add_team_member($team_id, $user) { | |
| $request = $this->base_url . "/teams/" . $team_id . "/members/" . $user; | |
| return $this->curl->put_request($request); | |
| } | |
| //// | |
| // Parameters | |
| // none | |
| //// | |
| public function get_repos() { | |
| $request = $this->base_url . "/orgs/" . $this->org . "/repos"; | |
| return $this->curl->get_request($request); | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment