@@ -65,6 +65,16 @@ class Codebird
65
65
*/
66
66
private $ _endpoint_oauth = 'https://api.twitter.com/ ' ;
67
67
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
+
68
78
/**
69
79
* The Request or access token. Used to sign requests
70
80
*/
@@ -93,7 +103,7 @@ class Codebird
93
103
/**
94
104
* The current Codebird version
95
105
*/
96
- private $ _version = '2.2.2 ' ;
106
+ private $ _version = '2.2.2-internal ' ;
97
107
98
108
/**
99
109
* Returns singleton class instance
@@ -230,11 +240,12 @@ public function __call($fn, $params)
230
240
231
241
$ httpmethod = $ this ->_detectMethod ($ method_template , $ apiparams );
232
242
$ multipart = $ this ->_detectMultipart ($ method_template );
243
+ $ internal = $ this ->_detectInternal ($ method_template );
233
244
234
245
// geek-geek: Now allowing to specify filenames as params
235
246
$ this ->_detectFilenames ($ method_template , $ apiparams );
236
247
237
- return $ this ->_callApi ($ httpmethod , $ method , $ method_template , $ apiparams , $ multipart );
248
+ return $ this ->_callApi ($ httpmethod , $ method , $ method_template , $ apiparams , $ multipart, $ internal );
238
249
}
239
250
240
251
/**
@@ -429,7 +440,7 @@ private function _detectMethod($method, $params)
429
440
// multi-HTTP method endpoints
430
441
switch ($ method ) {
431
442
case 'account/settings ' :
432
- $ method = count ($ params ) > 0 ? $ method .= '__post ' : $ method ;
443
+ $ method = count ($ params ) > 0 ? $ method . '__post ' : $ method ;
433
444
break ;
434
445
}
435
446
@@ -516,7 +527,17 @@ private function _detectMethod($method, $params)
516
527
'help/languages ' ,
517
528
'help/privacy ' ,
518
529
'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 '
520
541
);
521
542
$ httpmethods ['POST ' ] = array (
522
543
// Tweets
@@ -622,6 +643,27 @@ private function _detectOld($method)
622
643
return in_array ($ method , $ olds );
623
644
}
624
645
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
+
625
667
/**
626
668
* Detects filenames in upload parameters
627
669
*
@@ -704,6 +746,8 @@ private function _getEndpoint($method, $method_template)
704
746
$ url = $ this ->_endpoint_oauth . $ method ;
705
747
} elseif ($ this ->_detectOld ($ method_template )) {
706
748
$ url = $ this ->_endpoint_old . $ method . '.json ' ;
749
+ } elseif ($ this ->_detectInternal ($ method_template )) {
750
+ $ url = $ this ->_endpoint_internal . $ method . '.json ' ;
707
751
} else {
708
752
$ url = $ this ->_endpoint . $ method . '.json ' ;
709
753
}
@@ -718,15 +762,20 @@ private function _getEndpoint($method, $method_template)
718
762
* @param string $method_template The templated API method to call
719
763
* @param array optional $params The parameters to send along
720
764
* @param bool optional $multipart Whether to use multipart/form-data
765
+ * @param bool optional $internal Whether to use internal API
721
766
*
722
767
* @return mixed The API reply, encoded in the set return_format
723
768
*/
724
769
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 )
726
771
{
727
772
if (! function_exists ('curl_init ' )) {
728
773
throw new Exception ('To make API requests, the PHP curl extension must be available. ' );
729
774
}
775
+ if ($ internal ) {
776
+ $ params ['adc ' ] = 'phone ' ;
777
+ $ params ['application_id ' ] = 333903271 ;
778
+ }
730
779
$ url = $ this ->_getEndpoint ($ method , $ method_template );
731
780
$ ch = false ;
732
781
if ($ httpmethod == 'GET ' ) {
0 commit comments