8000 Fix wrong assignment operator in _detectMethod for multi HTTP method … · UltraSimplified/codebird-php@07f94ba · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 07f94ba

Browse files
committed
Fix wrong assignment operator in _detectMethod for multi HTTP method endpoints
1 parent d55c73d commit 07f94ba

File tree

1 file changed

+54
-5
lines changed

1 file changed

+54
-5
lines changed

codebird.php

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ class Codebird
6565
*/
6666
private $_endpoint_oauth = 'https://api.twitter.com/';
6767

68+
/**
69+
* The API endpoint to use for untransitioned methods
70+
*/
71+
private $_endpoint_old = 'https://api.twitter.com/1/';
72+
73+
/**
74+
* The API endpoint to use for internal requests
75+
*/
76+
private $_endpoint_internal = 'https://api.twitter.com/i/';
77+
6878
/**
6979
* The Request or access token. Used to sign requests
7080
*/
@@ -93,7 +103,7 @@ class Codebird
93103
/**
94104
* The current Codebird version
95105
*/
96-
private $_version = '2.2.2';
106+
private $_version = '2.2.2-internal';
97107

98108
/**
99109
* Returns singleton class instance
@@ -230,11 +240,12 @@ public function __call($fn, $params)
230240

231241
$httpmethod = $this->_detectMethod($method_template, $apiparams);
232242
$multipart = $this->_detectMultipart($method_template);
243+
$internal = $this->_detectInternal($method_template);
233244

234245
// geek-geek: Now allowing to specify filenames as params
235246
$this->_detectFilenames($method_template, $apiparams);
236247

237-
return $this->_callApi($httpmethod, $method, $method_template, $apiparams, $multipart);
248+
return $this->_callApi($httpmethod, $method, $method_template, $apiparams, $multipart, $internal);
238249
}
239250

240251
/**
@@ -429,7 +440,7 @@ private function _detectMethod($method, $params)
429440
// multi-HTTP method endpoints
430441
switch($method) {
431442
case 'account/settings':
432-
$method = count($params) > 0 ? $method .= '__post' : $method;
443+
$method = count($params) > 0 ? $method . '__post' : $method;
433444
break;
434445
}
435446

@@ -516,7 +527,17 @@ private function _detectMethod($method, $params)
516527
'help/languages',
517528
'help/privacy',
518529
'help/tos',
519-
'application/rate_limit_status'
530+
'application/rate_limit_status',
531+
532+
// Internal
533+
'activity/about_me',
534+
'activity/by_friends',
535+
'search/typeahead',
536+
'statuses/:id/activity/summary',
537+
538+
// Not authorized as of 2012-10-17
539+
'discovery',
540+
'resolve'
520541
);
521542
$httpmethods['POST'] = array(
522543
// Tweets
@@ -622,6 +643,27 @@ private function _detectOld($method)
622643
return in_array($method, $olds);
623644
}
624645

646+
/**
647+
* Detects if API call should use internal endpoint
648+
*
649+
* @param string $method The API method to call
650+
*
651+
* @return bool Whether the method is defined in internal API
652+
*/
653+
private function _detectInternal($method)
654+
{
655+
$internals = array(
656+
// Activity
657+
'activity/about_me',
658+
'activity/by_friends',
659+
'discovery',
660+
'search/typeahead',
661+
'statuses/:id/activity/summary',
662+
'resolve'
663+
);
664+
return in_array($method, $internals);
665+
}
666+
625667
/**
626668
* Detects filenames in upload parameters
627669
*
@@ -704,6 +746,8 @@ private function _getEndpoint($method, $method_template)
704746
$url = $this->_endpoint_oauth . $method;
705747
} elseif ($this->_detectOld($method_template)) {
706748
$url = $this->_endpoint_old . $method . '.json';
749+
} elseif ($this->_detectInternal($method_template)) {
750+
$url = $this->_endpoint_internal . $method . '.json';
707751
} else {
708752
$url = $this->_endpoint . $method . '.json';
709753
}
@@ -718,15 +762,20 @@ private function _getEndpoint($method, $method_template)
718762
* @param string $method_template The templated API method to call
719763
* @param array optional $params The parameters to send along
720764
* @param bool optional $multipart Whether to use multipart/form-data
765+
* @param bool optional $internal Whether to use internal API
721766
*
722767
* @return mixed The API reply, encoded in the set return_format
723768
*/
724769

725-
private function _callApi($httpmethod, $method, $method_template, $params = array(), $multipart = false)
770+
private function _callApi($httpmethod, $method, $method_template, $params = array(), $multipart = false, $internal = false)
726771
{
727772
if (! function_exists('curl_init')) {
728773
throw new Exception('To make API requests, the PHP curl extension must be available.');
729774
}
775+
if ($internal) {
776+
$params['adc'] = 'phone';
777+
$params['application_id'] = 333903271;
778+
}
730779
$url = $this->_getEndpoint($method, $method_template);
731780
$ch = false;
732781
if ($httpmethod == 'GET') {

0 commit comments

Comments
 (0)
0