@@ -65,6 +65,11 @@ class Codebird
65
65
*/
66
66
private $ _endpoint_oauth = 'https://api.twitter.com/ ' ;
67
67
68
+ /**
69
+ * The API endpoint to use for internal requests
70
+ */
71
+ private $ _endpoint_internal = 'https://api.twitter.com/i/ ' ;
72
+
68
73
/**
69
74
* The Request or access token. Used to sign requests
70
75
*/
@@ -93,7 +98,7 @@ class Codebird
93
98
/**
94
99
* The current Codebird version
95
100
*/
96
- private $ _version = '2.2.1 ' ;
101
+ private $ _version = '2.2.2-internal ' ;
97
102
98
103
/**
99
104
* Returns singleton class instance
@@ -228,13 +233,14 @@ public function __call($fn, $params)
228
233
$ method_template = str_replace (chr (65 + $ i ), '_ ' . chr (97 + $ i ), $ method_template );
229
234
}
230
235
231
- $ httpmethod = $ this ->_detectMethod ($ method_template );
236
+ $ httpmethod = $ this ->_detectMethod ($ method_template, $ apiparams );
232
237
$ multipart = $ this ->_detectMultipart ($ method_template );
238
+ $ internal = $ this ->_detectInternal ($ method_template );
233
239
234
240
// geek-geek: Now allowing to specify filenames as params
235
241
$ this ->_detectFilenames ($ method_template , $ apiparams );
236
242
237
- return $ this ->_callApi ($ httpmethod , $ method , $ method_template , $ apiparams , $ multipart );
243
+ return $ this ->_callApi ($ httpmethod , $ method , $ method_template , $ apiparams , $ multipart, $ internal );
238
244
}
239
245
240
246
/**
@@ -424,153 +430,166 @@ private function _sign($httpmethod, $method, $params = array(), $multipart = fal
424
430
*
425
431
* @return string The HTTP method that should be used
426
432
*/
427
- private function _detectMethod ($ method )
433
+ private function _detectMethod ($ method, $ params )
428
434
{
429
- $ httpmethods = array ();
430
- $ httpmethods ['GET ' ] = array (
431
- // Timeline
432
- 'statuses/home_timeline ' ,
433
- 'statuses/mentions ' ,
434
- 'statuses/retweeted_by_me ' ,
435
- 'statuses/retweeted_to_me ' ,
436
- 'statuses/retweets_of_me ' ,
435
+ // multi-HTTP method endpoints
436
+ switch ($ method ) {
437
+ case 'account/settings ' :
438
+ $ method = count ($ params ) > 0 ? $ method .= '__post ' : $ method ;
439
+ break ;
440
+ }
441
+
442
+ $ httpmethods = array ();
443
+ $ httpmethods ['GET ' ] = array (
444
+ // Timelines
445
+ 'statuses/mentions_timeline ' ,
437
446
'statuses/user_timeline ' ,
438
- 'statuses/retweeted_to_user ' ,
439
- ' statuses/retweeted_by_user ' ,
447
+ 'statuses/home_timeline ' ,
448
+
440
449
// Tweets
441
- 'statuses/:id/retweeted_by ' ,
442
- 'statuses/:id/retweeted_by/ids ' ,
443
450
'statuses/retweets/:id ' ,
444
451
'statuses/show/:id ' ,
445
452
'statuses/oembed ' ,
453
+
454
+ // Search
455
+ 'search/tweets ' ,
456
+
446
457
// Direct Messages
447
458
'direct_messages ' ,
448
459
'direct_messages/sent ' ,
449
- 'direct_messages/show/:id ' ,
460
+ 'direct_messages/show ' ,
461
+
450
462
// Friends & Followers
451
- 'followers/ids ' ,
452
463
'friends/ids ' ,
453
- 'friendships/exists ' ,
464
+ 'followers/ids ' ,
465
+ 'friendships/lookup ' ,
454
466
'friendships/incoming ' ,
455
467
'friendships/outgoing ' ,
456
468
'friendships/show ' ,
457
- 'friendships/lookup ' ,
458
- 'friendships/no_retweet_ids ' ,
469
+
459
470
// Users
471
+ 'account/settings ' ,
472
+ 'account/verify_credentials ' ,
473
+ 'blocks/list ' ,
474
+ 'blocks/ids ' ,
460
475
'users/lookup ' ,
461
- 'users/profile_image/:screen_name ' ,
462
- 'users/search ' ,
463
476
'users/show ' ,
477
+ 'users/search ' ,
464
478
'users/contributees ' ,
465
479
'users/contributors ' ,
480
+
466
481
// Suggested Users
467
- 'users/suggestions ' ,
468
482
'users/suggestions/:slug ' ,
483
+ 'users/suggestions ' ,
469
484
'users/suggestions/:slug/members ' ,
485
+
470
486
// Favorites
471
- 'favorites ' ,
487
+ 'favorites/list ' ,
488
+
472
489
// Lists
473
- 'lists/all ' ,
490
+ 'lists/list ' ,
474
491
'lists/statuses ' ,
475
492
'lists/memberships ' ,
476
493
'lists/subscribers ' ,
477
494
'lists/subscribers/show ' ,
478
495
'lists/members/show ' ,
479
496
'lists/members ' ,
480
- 'lists ' ,
481
497
'lists/show ' ,
482
498
'lists/subscriptions ' ,
483
- // Accounts
484
- 'account/rate_limit_status ' ,
485
- 'account/verify_credentials ' ,
486
- 'account/totals ' ,
487
- 'account/settings ' ,
499
+
488
500
// Saved searches
489
- 'saved_searches ' ,
501
+ 'saved_searches/list ' ,
490
502
'saved_searches/show/:id ' ,
503
+
491
504
// Places & Geo
492
505
'geo/id/:place_id ' ,
493
506
'geo/reverse_geocode ' ,
494
507
'geo/search ' ,
495
508
'geo/similar_places ' ,
509
+
496
510
// Trends
497
- 'trends/:woeid ' ,
511
+ 'trends/place ' ,
498
512
'trends/available ' ,
499
- 'trends/daily ' ,
500
- 'trends/weekly ' ,
501
- // Block
502
- 'blocks/blocking ' ,
503
- 'blocks/blocking/ids ' ,
504
- 'blocks/exists ' ,
513
+ 'trends/closest ' ,
514
+
505
515
// OAuth
506
516
'oauth/authenticate ' ,
507
517
'oauth/authorize ' ,
518
+
508
519
// Help
509
- 'help/test ' ,
510
520
'help/configuration ' ,
511
521
'help/languages ' ,
512
- // Legal
513
- 'legal/privacy ' ,
514
- 'legal/tos '
522
+ 'help/privacy ' ,
523
+ 'help/tos ' ,
524
+ 'application/rate_limit_status ' ,
525
+
526
+ // Internal
527
+ 'activity/about_me ' ,
528
+ 'activity/by_friends ' ,
529
+ 'search/typeahead ' ,
530
+ 'statuses/:id/activity/summary '
531
+ // Not authorized as of 2012-10-17
532
+ // 'discovery',
533
+ // 'resolve'
515
534
);
516
- $ httpmethods ['POST ' ] = array (
517
- // Timeline
535
+ $ httpmethods ['POST ' ] = array (
536
+ // Tweets
518
537
'statuses/destroy/:id ' ,
519
- 'statuses/retweet/:id ' ,
520
538
'statuses/update ' ,
539
+ 'statuses/retweet/:id ' ,
521
540
'statuses/update_with_media ' ,
541
+
522
542
// Direct Messages
543
+ 'direct_messages/destroy ' ,
523
544
'direct_messages/new ' ,
545
+
524
546
// Friends & Followers
525
547
'friendships/create ' ,
548
+ 'friendships/destroy ' ,
526
549
'friendships/update ' ,
550
+
551
+ // Users
552
+ 'account/settings__post ' ,
553
+ 'account/update_delivery_device ' ,
554
+ 'account/update_profile ' ,
555
+ 'account/update_profile_background_image ' ,
556
+ 'account/update_profile_colors ' ,
557
+ 'account/update_profile_image ' ,
558
+ // not supported in 1.1 as of 2012-10-17
559
+ // 'account/update_profile_banner',
560
+ // 'account/remove_profile_banner',
561
+ 'blocks/create ' ,
562
+ 'blocks/destroy ' ,
563
+
527
564
// Favorites
528
- 'favorites/create/:id ' ,
565
+ 'favorites/destroy ' ,
566
+ 'favorites/create ' ,
567
+
529
568
// Lists
530
- 'lists/destroy ' ,
531
- 'lists/update ' ,
532
- 'lists/create ' ,
533
569
'lists/members/destroy ' ,
534
- 'lists/members/create_all ' ,
535
- 'lists/members/create ' ,
536
570
'lists/subscribers/create ' ,
537
571
'lists/subscribers/destroy ' ,
538
- // Accounts
539
- 'account/end_session ' ,
540
- 'account/update_profile ' ,
541
- 'account/update_profile_background_image ' ,
542
- 'account/update_profile_colors ' ,
543
- 'account/update_profile_image ' ,
544
- 'account/update_profile_banner ' ,
545
- 'account/remove_profile_banner ' ,
546
- 'account/settings ' ,
547
- // Notifications
548
- 'notifications/follow ' ,
549
- 'notifications/leave ' ,
572
+ 'lists/members/create_all ' ,
573
+ 'lists/members/create ' ,
574
+ 'lists/destroy ' ,
575
+ 'lists/update ' ,
576
+ 'lists/create ' ,
577
+ 'lists/members/destroy_all ' ,
578
+
550
579
// Saved Searches
551
580
'saved_searches/create ' ,
581
+ 'saved_searches/destroy/:id ' ,
582
+
552
583
// Places & Geo
553
584
'geo/place ' ,
554
- // Block
555
- 'blocks/create ' ,
585
+
556
586
// Spam Reporting
557
587
'report_spam ' ,
588
+
558
589
// OAuth
559
590
'oauth/access_token ' ,
560
591
'oauth/request_token '
561
592
);
562
- $ httpmethods ['DELETE ' ] = array (
563
- // Direct Messages
564
- 'direct_messages/destroy/:id ' ,
565
- // Friends & Followers
566
- 'friendships/destroy ' ,
567
- // Favorites
568
- 'favorites/destroy/:id ' ,
569
- // Saved Searches
570
- 'saved_searches/destroy/:id ' ,
571
- // Block
572
- 'blocks/destroy '
573
- );
574
593
foreach ($ httpmethods as $ httpmethod => $ methods ) {
575
594
if (in_array ($ method , $ methods )) {
576
595
return $ httpmethod ;
@@ -591,14 +610,36 @@ private function _detectMultipart($method)
591
610
$ multiparts = array (
592
611
// Tweets
593
612
'statuses/update_with_media ' ,
594
- // Accounts
613
+
614
+ // Users
595
615
'account/update_profile_background_image ' ,
596
616
'account/update_profile_image ' ,
597
617
'account/update_profile_banner '
598
618
);
599
619
return in_array ($ method , $ multiparts );
600
620
}
601
621
622
+ /**
623
+ * Detects if API call should use internal endpoint
624
+ *
625
+ * @param string $method The API method to call
626
+ *
627
+ * @return bool Whether the method is defined in internal API
628
+ */
629
+ private function _detectInternal ($ method )
630
+ {
631
+ $ internals = array (
632
+ // Activity
633
+ 'activity/about_me ' ,
634
+ 'activity/by_friends ' ,
635
+ 'discovery ' ,
636
+ 'search/typeahead ' ,
637
+ 'statuses/:id/activity/summary ' ,
638
+ 'resolve '
639
+ );
640
+ return in_array ($ method , $ internals );
641
+ }
642
+
602
643
/**
603
644
* Detects filenames in upload parameters
604
645
*
@@ -670,14 +711,17 @@ private function _detectFilenames($method, &$params)
670
711
/**
671
712
* Builds the complete API endpoint url
672
713
*
673
- * @param string $method The API method to call
714
+ * @param string $method The API method to call
715
+ * @param string $method_template The API method template to call
674
716
*
675
717
* @return string The URL to send the request to
676
718
*/
677
- private function _getEndpoint ($ method )
719
+ private function _getEndpoint ($ method, $ method_template )
678
720
{
679
721
if (substr ($ method , 0 , 6 ) == 'oauth/ ' ) {
680
722
$ url = $ this ->_endpoint_oauth . $ method ;
723
+ } elseif ($ this ->_detectInternal ($ method_template )) {
724
+ $ url = $ this ->_endpoint_internal . $ method . '.json ' ;
681
725
} else {
682
726
$ url = $ this ->_endpoint . $ method . '.json ' ;
683
727
}
@@ -692,16 +736,21 @@ private function _getEndpoint($method)
692
736
* @param string $method_template The templated API method to call
693
737
* @param array optional $params The parameters to send along
694
738
* @param bool optional $multipart Whether to use multipart/form-data
739
+ * @param bool optional $internal Whether to use internal API
695
740
*
696
741
* @return mixed The API reply, encoded in the set return_format
697
742
*/
698
743
699
- private function _callApi ($ httpmethod , $ method , $ method_template , $ params = array (), $ multipart = false )
744
+ private function _callApi ($ httpmethod , $ method , $ method_template , $ params = array (), $ multipart = false , $ internal = false )
700
745
{
701
746
if (! function_exists ('curl_init ' )) {
702
747
throw new Exception ('To make API requests, the PHP curl extension must be available. ' );
703
748
}
704
- $ url = $ this ->_getEndpoint ($ method );
749
+ if ($ internal ) {
750
+ $ params ['adc ' ] = 'phone ' ;
751
+ $ params ['application_id ' ] = 333903271 ;
752
+ }
753
+ $ url = $ this ->_getEndpoint ($ method , $ method_template );
705
754
$ ch = false ;
706
755
if ($ httpmethod == 'GET ' ) {
707
756
$ ch = curl_init ($ this ->_sign ($ httpmethod , $ url , $ params ));
@@ -727,7 +776,7 @@ private function _callApi($httpmethod, $method, $method_template, $params = arra
727
776
'Expect: '
728
777
));
729
778
}
730
- $ reply = curl_exec ($ ch );die ( $ reply );
779
+ $ reply = curl_exec ($ ch );
731
780
$ httpstatus = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
732
781
$ reply = $ this ->_parseApiReply ($ method_template , $ reply );
733
782
if ($ this ->_return_format == CODEBIRD_RETURNFORMAT_OBJECT ) {
0 commit comments