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