Skip to content

Commit 24efe04

Browse files
committed
- added extended test of API connection
1 parent 54ee885 commit 24efe04

4 files changed

Lines changed: 28 additions & 2 deletions

File tree

admin/settings.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@
161161
} else {
162162
$info = 'Github/GithubClient testApi1 (reading github public repos) failed';
163163
}
164+
$result = $client->testUserRepositories();
165+
if ($result) {
166+
$info .= '<br>Github/GithubClient testUserRepositories (reading github repos of primary setting) successfully finished';
167+
} else {
168+
$info .= '<br>Github/GithubClient testUserRepositories (reading github repos of primary setting) failed';
169+
}
170+
164171
$GLOBALS['xoopsTpl']->assign('info1', $info);
165172
break;
166173
}

class/Github/GithubClient.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class GithubClient extends Api
4040
/**
4141
* @var string
4242
*/
43-
//public $userAuth = 'myusername';
43+
public $userAuth = 'myusername';
4444

4545
/**
4646
* @var string
@@ -107,6 +107,18 @@ public function testApi2($url) {
107107
return $data;
108108
}
109109

110+
/**
111+
* Get repositories of given user
112+
*
113+
* @return array|bool
114+
*/
115+
public function testUserRepositories()
116+
{
117+
$url = static::BASE_URL . 'users/' . \rawurlencode($this->userAuth) . '/repos?per_page=1&page=1';
118+
119+
return $this->_get($url);
120+
}
121+
110122
/**
111123
* Get repositories of given user
112124
*
@@ -343,7 +355,7 @@ private function getSetting()
343355
if (0 == \count($setting)) {
344356
\redirect_header(\XOOPS_URL . '/index.php', 3, \_AM_WGGITHUB_THEREARENT_SETTINGS);
345357
}
346-
//$this->userAuth = $setting['user'];
358+
$this->userAuth = $setting['user'];
347359
$this->tokenAuth = $setting['token'];
348360

349361
return true;

class/Github/exceptions.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ class JsonException extends RuntimeException
149149
class BadResponseException extends Github\RuntimeException
150150
{}
151151

152+
/**
153+
* HTTP response is somehow wrong and cannot be processed.
154+
*/
155+
class RateLimitExceedException extends Github\RuntimeException
156+
{}
157+
152158
}
153159

154160

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- permanent display of filter with enabled/disabled buttons (alain01/goffy)
77
- added new bt4 templates (alain01/goffy)
88
- fixed bug with wrong icon and link (alain01/goffy)
9+
- added extended test of API connection (goffy)
910

1011
===================================================================
1112
2021/03/31 Version 1.03 Final

0 commit comments

Comments
 (0)