| @@ -13,15 +13,13 @@ | ||
| 13 | 13 | if ( ! defined( 'GITHUB_API_LEVEL' ) ) { |
| 14 | 14 | define( 'GITHUB_API_LEVEL', GEDEBUG_NONE ); |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - | |
| 18 | 17 | /** |
| 19 | 18 | * This class contains all the functions that actually retrieve information from the GitHub API |
| 20 | 19 | */ |
| 21 | 20 | class github_api { |
| 22 | 21 | |
| 23 | - | |
| 24 | 22 | private $client_id = null; |
| 25 | 23 | private $client_secret = null; |
| 26 | 24 | private $access_token = null; |
| 27 | 25 | private $access_token_username = null; |
| @@ -28,9 +26,9 @@ | ||
| 28 | 26 | |
| 29 | 27 | /** |
| 30 | 28 | * Allow the client ID / secret to be set, and used for subsequent calls |
| 31 | 29 | */ |
| 32 | - function __construct() { | |
| 30 | + public function __construct() { | |
| 33 | 31 | add_action( 'plugins_loaded', array( $this, 'set_credentials' ) ); |
| 34 | 32 | add_filter( 'http_request_timeout', array( $this, 'http_request_timeout' ) ); |
| 35 | 33 | } |
| 36 | 34 | |
| @@ -40,9 +38,9 @@ | ||
| 40 | 38 | * @param int $seconds The current timeout setting |
| 41 | 39 | * |
| 42 | 40 | * @return int The revised timeout setting |
| 43 | 41 | */ |
| 44 | - function http_request_timeout( $seconds ) { | |
| 42 | + public function http_request_timeout( $seconds ) { | |
| 45 | 43 | return $seconds < 25 ? 25 : $seconds; |
| 46 | 44 | } |
| 47 | 45 | |
| 48 | 46 | /** |
| @@ -91,9 +89,8 @@ | ||
| 91 | 89 | return $results; |
| 92 | 90 | |
| 93 | 91 | } |
| 94 | 92 | |
| 95 | - | |
| 96 | 93 | /** |
| 97 | 94 | * Get a repository from the GitHub API |
| 98 | 95 | * |
| 99 | 96 | * @param string $owner The repository's owner |
| @@ -101,11 +98,9 @@ | ||
| 101 | 98 | * |
| 102 | 99 | * @return object The response from the GitHub API |
| 103 | 100 | */ |
| 104 | 101 | public function get_repo( $owner, $repository ) { |
| 105 | - | |
| 106 | 102 | $this->log( "get_repo( $owner, $repository )", GEDEBUG_CALL ); |
| 107 | - | |
| 108 | 103 | $results = $this->call_api( "https://api.github.com/repos/$owner/$repository" ); |
| 109 | 104 | |
| 110 | 105 | return json_decode( $results['body'] ); |
| 111 | 106 | |
| @@ -110,9 +105,8 @@ | ||
| 110 | 105 | return json_decode( $results['body'] ); |
| 111 | 106 | |
| 112 | 107 | } |
| 113 | 108 | |
| 114 | - | |
| 115 | 109 | /** |
| 116 | 110 | * Get commit information for a repository from the GitHub API |
| 117 | 111 | * |
| 118 | 112 | * @param string $owner The repository's owner |
| @@ -120,18 +114,14 @@ | ||
| 120 | 114 | * |
| 121 | 115 | * @return object The response from the GitHub API |
| 122 | 116 | */ |
| 123 | 117 | public function get_repo_commits( $owner, $repository ) { |
| 124 | - | |
| 125 | 118 | $this->log( "get_repo_commits( $owner, $repository )", GEDEBUG_CALL ); |
| 126 | - | |
| 127 | 119 | $results = $this->call_api( "https://api.github.com/repos/$owner/$repository/commits" ); |
| 128 | 120 | |
| 129 | 121 | return json_decode( $results['body'] ); |
| 130 | - | |
| 131 | 122 | } |
| 132 | 123 | |
| 133 | - | |
| 134 | 124 | /** |
| 135 | 125 | * Get a milestone summary from the GitHub API |
| 136 | 126 | * |
| 137 | 127 | * @param string $owner The repository's owner |
| @@ -140,29 +130,21 @@ | ||
| 140 | 130 | * |
| 141 | 131 | * @return object The response from the GitHub API |
| 142 | 132 | */ |
| 143 | 133 | public function get_repo_milestone_summary( $owner, $repository, $milestone ) { |
| 144 | - | |
| 145 | 134 | $this->log( "get_repo_milestone_summary( $owner, $repository, $milestone )", GEDEBUG_CALL ); |
| 146 | - | |
| 147 | 135 | $results = $this->call_api( "https://api.github.com/repos/$owner/$repository/milestones/$milestone" ); |
| 148 | 136 | |
| 149 | 137 | return json_decode( $results['body'] ); |
| 150 | - | |
| 151 | 138 | } |
| 152 | 139 | |
| 153 | - | |
| 154 | 140 | public function get_repo_contributors( $owner, $repository ) { |
| 155 | - | |
| 156 | 141 | $this->log( "get_repo_contributors( $owner, $repository )", GEDEBUG_CALL ); |
| 157 | - | |
| 158 | 142 | $results = $this->call_api( "https://api.github.com/repos/$owner/$repository/stats/contributors" ); |
| 159 | 143 | |
| 160 | 144 | return json_decode( $results['body'] ); |
| 161 | - | |
| 162 | 145 | } |
| 163 | 146 | |
| 164 | - | |
| 165 | 147 | /** |
| 166 | 148 | * Get a user from the GitHub API |
| 167 | 149 | * |
| 168 | 150 | * @param string $user The username |
| @@ -169,22 +151,16 @@ | ||
| 169 | 151 | * |
| 170 | 152 | * @return object The response from the GitHub API |
| 171 | 153 | */ |
| 172 | 154 | public function get_user( $user ) { |
| 173 | - | |
| 174 | 155 | $this->log( "get_user( $user )", GEDEBUG_CALL ); |
| 175 | - | |
| 176 | 156 | $results = $this->call_api( "https://api.github.com/users/$user" ); |
| 177 | 157 | |
| 178 | 158 | return json_decode( $results['body'] ); |
| 179 | - | |
| 180 | 159 | } |
| 181 | 160 | |
| 182 | - | |
| 183 | 161 | private function log( $msg, $level ) { |
| 184 | 162 | if ( GITHUB_API_LEVEL >= $level ) { |
| 185 | 163 | error_log( "[GE$level]: " . $msg ); |
| 186 | 164 | } |
| 187 | 165 | } |
| 188 | - | |
| 189 | - | |
| 190 | 166 | } |