8000 Merge branch 'pull-182' into develop · rana07i/codebird-php@4baf8da · GitHub
[go: up one dir, main page]

Skip to content

Commit 4baf8da

Browse files
committed
Merge branch 'pull-182' into develop
2 parents 0562683 + 2dfc945 commit 4baf8da

File tree

1 file changed

+46
-14
lines changed

1 file changed

+46
-14
lines changed

src/codebird.php

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ public function oauth_authenticate($force_login = NULL, $screen_name = NULL, $ty
10451045
throw new \Exception('To get the ' . $type . ' URL, use the correct third parameter, or omit it.');
10461046
}
10471047
if ($this->_oauth_token === null) {
1048-
throw new \Exception('To get the ' . $type . ' URL, the OAuth token must be set.');
1048+
throw new CodebirdCredentialsException('To get the ' . $type . ' URL, the OAuth token must be set.');
10491049
}
10501050
$url = self::$_endpoints['oauth'] . 'oauth/' . $type . '?oauth_token=' . $this->_url($this->_oauth_token);
10511051
if ($force_login) {
@@ -1240,7 +1240,7 @@ private function _getProxyData($name)
12401240
protected function _oauth2TokenCurl()
12411241
{
12421242
if (self::$_consumer_key === null) {
1243-
throw new \Exception('To obtain a bearer token, the consumer key must be set.');
1243+
throw new CodebirdCredentialsException('To obtain a bearer token, the consumer key must be set.');
12441244
}
12451245
$post_fields = [
12461246
'grant_type' => 'client_credentials'
@@ -1258,7 +1258,7 @@ protected function _oauth2TokenCurl()
12581258

12591259
// catch request errors
12601260
if ($result === false) {
1261-
throw new \Exception('Request error for bearer token: ' . $this->_curl_error($connection));
1261+
throw new CodebirdAuthException('Request error for bearer token: ' . $this->_curl_error($connection));
12621262
}
12631263

12641264
// certificate validation results
@@ -1280,14 +1280,14 @@ protected function _oauth2TokenCurl()
12801280
protected function _oauth2TokenNoCurl()
12811281
{
12821282
if (self::$_consumer_key == null) {
1283-
throw new \Exception('To obtain a bearer token, the consumer key must be set.');
1283+
throw new CodebirdCredentialsException('To obtain a bearer token, the consumer key must be set.');
12841284
}
12851285

12861286
$url = self::$_endpoints['oauth'] . 'oauth2/token';
12871287
$hostname = parse_url($url, PHP_URL_HOST);
12881288

12891289
if ($hostname === false) {
1290-
throw new \Exception('Incorrect API endpoint host.');
1290+
throw new CodebirdEndpointException('Incorrect API endpoint host.');
12911291
}
12921292

12931293
$contextOptions = [
@@ -1479,7 +1479,7 @@ protected function _url($data)
14791479
protected function _sha1($data)
14801480
{
14811481
if (self::$_consumer_secret === null) {
1482-
throw new \Exception('To generate a hash, the consumer secret must be set.');
1482+
throw new CodebirdCredentialsException('To generate a hash, the consumer secret must be set.');
14831483
}
14841484
if (!function_exists('hash_hmac')) {
14851485
throw new \Exception('To generate a hash, the PHP hash extension must be available.');
@@ -1554,7 +1554,7 @@ protected function _getSignature($httpmethod, $method, $base_params)
15541554
protected function _sign($httpmethod, $method, $params = [])
15551555
{
15561556
if (self::$_consumer_key === null) {
1557-
throw new \Exception('To generate a signature, the consumer key must be set.');
1557+
throw new CodebirdCredentialsException('To generate a signature, the consumer key must be set.');
15581558
}
15591559
$sign_base_params = array_map(
15601560
[$this, '_url'],
@@ -1757,7 +1757,7 @@ protected function _getMultipartRequestFromParams($method_template, $border, $pa
17571757
foreach ($params as $key => $value) {
17581758
// is it an array?
17591759
if (is_array($value)) {
1760-
throw new \Exception('Using URL-encoded parameters is not supported for uploading media.');
1760+
throw new CodebirdMediaException('Using URL-encoded parameters is not supported for uploading media.');
17611761
}
17621762
$request .=
17631763
'--' . $border . "\r\n"
@@ -1888,7 +1888,7 @@ protected function _fetchRemoteFile($url)
18881888
) {
18891889
return $result;
18901890
}
1891-
throw new \Exception('Downloading a remote media file failed.');
1891+
throw new CodebirdMediaException('Downloading a remote media file failed.');
18921892
return false;
18931893
}
18941894
// no cURL
@@ -1908,7 +1908,7 @@ protected function _fetchRemoteFile($url)
19081908
) {
19091909
return $result;
19101910
}
1911-
throw new \Exception('Downloading a remote media file failed.');
1911+
throw new CodebirdMediaException('Downloading a remote media file failed.');
19121912
return false;
19131913
}
19141914

@@ -2039,7 +2039,7 @@ protected function _callApi($httpmethod, $method, $method_template, $params = []
20392039
&& $this->_oauth_token === null
20402040
&& substr($method, 0, 5) !== 'oauth'
20412041
) {
2042-
throw new \Exception('To call this API, the OAuth access token must be set.');
2042+
throw new CodebirdCredentialsException('To call this API, the OAuth access token must be set.');
20432043
}
20442044
// use separate API access for streaming API
20452045
if ($this->_detectStreaming($method) !== false) {
@@ -2138,7 +2138,7 @@ protected function _callApiNoCurl(
21382138

21392139
$hostname = parse_url($url, PHP_URL_HOST);
21402140
if ($hostname === false) {
2141-
throw new \Exception('Incorrect API endpoint host.');
2141+
throw new CodebirdEndpointException('Incorrect API endpoint host.');
21422142
}
21432143

21442144
$request_headers[] = 'Authorization: ' . $authorization;
@@ -2310,7 +2310,7 @@ protected function _getBearerAuthorization()
23102310
if (self::$_consumer_key === null
23112311
&& self::$_bearer_token === null
23122312
) {
2313-
throw new \Exception('To make an app-only auth API request, consumer key or bearer token must be set.');
2313+
throw new CodebirdCredentialsException('To make an app-only auth API request, consumer key or bearer token must be set.');
23142314
}
23152315
// automatically fetch bearer token, if necessary
23162316
if (self::$_bearer_token === null) {
@@ -2387,7 +2387,7 @@ protected function _callApiStreaming(
23872387
$path = parse_url($url, PHP_URL_PATH);
23882388
$query = parse_url($url, PHP_URL_QUERY);
23892389
if ($hostname === false) {
2390-
throw new \Exception('Incorrect API endpoint host.');
2390+
throw new CodebirdEndpointException('Incorrect API endpoint host.');
23912391
}
23922392

23932393
$request_headers[] = 'Authorization: ' . $authorization;
@@ -2649,4 +2649,36 @@ protected function _parseApiReply($reply)
26492649
}
26502650
return $parsed;
26512651
}
2652+
2653+
}
2654+
2655+
/**
2656+
* Catch errors when authtoken is expired
2657+
*/
2658+
class CodebirdAuthException extends \Exception {
2659+
2660+
}
2661+
2662+
2663+
/**
2664+
* Catch error when credentials are not set correclty
2665+
*/
2666+
class CodebirdCredentialsException extends \Exception {
2667+
26522668
}
2669+
2670+
/**
2671+
* Catch errors r elated to bad endpoi ts
2672+
*/
2673+
class CodebirdEndpointException extends \Exception {
2674+
2675+
}
2676+
2677+
/*
2678+
* Catch errors relatedto media
2679+
*/
2680+
2681+
class CodebirdMediaException extends \Exception {
2682+
2683+
}
2684+

0 commit comments

Comments
 (0)
0