@@ -93,7 +93,7 @@ class Codebird
93
93
/**
94
94
* The current Codebird version
95
95
*/
96
- private $ _version = '2.2.1 ' ;
96
+ private $ _version = '2.2.2 ' ;
97
97
98
98
/**
99
99
* Returns singleton class instance
@@ -228,7 +228,7 @@ public function __call($fn, $params)
228
228
$ method_template = str_replace (chr (65 + $ i ), '_ ' . chr (97 + $ i ), $ method_template );
229
229
}
230
230
231
- $ httpmethod = $ this ->_detectMethod ($ method_template );
231
+ $ httpmethod = $ this ->_detectMethod ($ method_template, $ apiparams );
232
232
$ multipart = $ this ->_detectMultipart ($ method_template );
233
233
234
234
// geek-geek: Now allowing to specify filenames as params
@@ -424,153 +424,157 @@ private function _sign($httpmethod, $method, $params = array(), $multipart = fal
424
424
*
425
425
* @return string The HTTP method that should be used
426
426
*/
427
- private function _detectMethod ($ method )
427
+ private function _detectMethod ($ method, $ params )
428
428
{
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 ' ,
429
+ // multi-HTTP method endpoints
430
+ switch ($ method ) {
431
+ case 'account/settings ' :
432
+ $ method = count ($ params ) > 0 ? $ method .= '__post ' : $ method ;
433
+ break ;
434
+ }
435
+
436
+ $ httpmethods = array ();
437
+ $ httpmethods ['GET ' ] = array (
438
+ // Timelines
439
+ 'statuses/mentions_timeline ' ,
437
440
'statuses/user_timeline ' ,
438
- 'statuses/retweeted_to_user ' ,
439
- ' statuses/retweeted_by_user ' ,
441
+ 'statuses/home_timeline ' ,
442
+
440
443
// Tweets
441
- 'statuses/:id/retweeted_by ' ,
442
- 'statuses/:id/retweeted_by/ids ' ,
443
444
'statuses/retweets/:id ' ,
444
445
'statuses/show/:id ' ,
445
446
'statuses/oembed ' ,
447
+
448
+ // Search
449
+ 'search/tweets ' ,
450
+
446
451
// Direct Messages
447
452
'direct_messages ' ,
448
453
'direct_messages/sent ' ,
449
- 'direct_messages/show/:id ' ,
454
+ 'direct_messages/show ' ,
455
+
450
456
// Friends & Followers
451
- 'followers/ids ' ,
452
457
'friends/ids ' ,
453
- 'friendships/exists ' ,
458
+ 'followers/ids ' ,
459
+ 'friendships/lookup ' ,
454
460
'friendships/incoming ' ,
455
461
'friendships/outgoing ' ,
456
462
'friendships/show ' ,
457
- 'friendships/lookup ' ,
458
- 'friendships/no_retweet_ids ' ,
463
+
459
464
// Users
465
+ 'account/settings ' ,
466
+ 'account/verify_credentials ' ,
467
+ 'blocks/list ' ,
468
+ 'blocks/ids ' ,
460
469
'users/lookup ' ,
461
- 'users/profile_image/:screen_name ' ,
462
- 'users/search ' ,
463
470
'users/show ' ,
471
+ 'users/search ' ,
464
472
'users/contributees ' ,
465
473
'users/contributors ' ,
474
+ 'users/recommendations ' ,
475
+
466
476
// Suggested Users
467
- 'users/suggestions ' ,
468
477
'users/suggestions/:slug ' ,
478
+ 'users/suggestions ' ,
469
479
'users/suggestions/:slug/members ' ,
480
+
470
481
// Favorites
471
- 'favorites ',
482
+ 'favorites/list ' ,
483
+
472
484
// Lists
473
- 'lists/all ' ,
485
+ 'lists/list ' ,
474
486
'lists/statuses ' ,
475
487
'lists/memberships ' ,
476
488
'lists/subscribers ' ,
477
489
'lists/subscribers/show ' ,
478
490
'lists/members/show ' ,
479
491
'lists/members ' ,
480
- 'lists ' ,
481
492
'lists/show ' ,
482
493
'lists/subscriptions ' ,
483
- // Accounts
484
- 'account/rate_limit_status ' ,
485
- 'account/verify_credentials ' ,
486
- 'account/totals ' ,
487
- 'account/settings ' ,
494
+
488
495
// Saved searches
489
- 'saved_searches ' ,
496
+ 'saved_searches/list ' ,
490
497
'saved_searches/show/:id ' ,
498
+
491
499
// Places & Geo
492
500
'geo/id/:place_id ' ,
493
501
'geo/reverse_geocode ' ,
494
502
'geo/search ' ,
495
503
'geo/similar_places ' ,
504
+
496
505
// Trends
497
- 'trends/:woeid ' ,
506
+ 'trends/place ' ,
498
507
'trends/available ' ,
499
- 'trends/daily ' ,
500
- 'trends/weekly ' ,
501
- // Block
502
- 'blocks/blocking ' ,
503
- 'blocks/blocking/ids ' ,
504
- 'blocks/exists ' ,
508
+ 'trends/closest ' ,
509
+
505
510
// OAuth
506
511
'oauth/authenticate ' ,
507
512
'oauth/authorize ' ,
513
+
508
514
// Help
509
- 'help/test ' ,
510
515
'help/configuration ' ,
511
516
'help/languages ' ,
512
- // Legal
513
- 'legal/privacy ' ,
514
- 'legal/tos '
517
+ ' help/privacy ' ,
518
+ 'help/tos ' ,
519
+ 'application/rate_limit_status '
515
520
);
516
- $ httpmethods ['POST ' ] = array (
517
- // Timeline
521
+ $ httpmethods ['POST ' ] = array (
522
+ // Tweets
518
523
'statuses/destroy/:id ' ,
519
- 'statuses/retweet/:id ' ,
520
524
'statuses/update ' ,
525
+ 'statuses/retweet/:id ' ,
521
526
'statuses/update_with_media ' ,
527
+
522
528
// Direct Messages
529
+ 'direct_messages/destroy ' ,
523
530
'direct_messages/new ' ,
531
+
524
532
// Friends & Followers
525
533
'friendships/create ' ,
534
+ 'friendships/destroy ' ,
526
535
'friendships/update ' ,
527
- // Favorites
528
- 'favorites/create/:id ' ,
529
- // Lists
530
- 'lists/destroy ' ,
531
- 'lists/update ' ,
532
- 'lists/create ' ,
533
- 'lists/members/destroy ' ,
534
- 'lists/members/create_all ' ,
535
- 'lists/members/create ' ,
536
- 'lists/subscribers/create ' ,
537
- 'lists/subscribers/destroy ' ,
538
- // Accounts
539
- 'account/end_session ' ,
536
+
537
+ // Users
538
+ 'account/settings__post ' ,
539
+ 'account/update_delivery_device ' ,
540
540
'account/update_profile ' ,
541
541
'account/update_profile_background_image ' ,
542
542
'account/update_profile_colors ' ,
543
543
'account/update_profile_image ' ,
544
544
'account/update_profile_banner ' ,
545
545
'account/remove_profile_banner ' ,
546
- 'account/settings ' ,
547
- // Notifications
548
- 'notifications/follow ' ,
549
- 'notifications/leave ' ,
546
+ 'blocks/create ' ,
547
+ 'blocks/destroy ' ,
548
+
549
+ // Favorites
550
+ 'favorites/destroy ' ,
551
+ 'favorites/create ' ,
552
+
553
+ // Lists
554
+ 'lists/members/destroy ' ,
555
+ 'lists/subscribers/create ' ,
556
+ 'lists/subscribers/destroy ' ,
557
+ 'lists/members/create_all ' ,
558
+ 'lists/members/create ' ,
559
+ 'lists/destroy ' ,
560
+ 'lists/update ' ,
561
+ 'lists/create ' ,
562
+ 'lists/members/destroy_all ' ,
563
+
550
564
// Saved Searches
551
565
'saved_searches/create ' ,
566
+ 'saved_searches/destroy/:id ' ,
567
+
552
568
// Places & Geo
553
569
'geo/place ' ,
554
- // Block
555
- 'blocks/create ' ,
570
+
556
571
// Spam Reporting
557
572
'report_spam ' ,
573
+
558
574
// OAuth
559
575
'oauth/access_token ' ,
560
576
'oauth/request_token '
561
577
);
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
578
foreach ($ httpmethods as $ httpmethod => $ methods ) {
575
579
if (in_array ($ method , $ methods )) {
576
580
return $ httpmethod ;
@@ -591,14 +595,33 @@ private function _detectMultipart($method)
591
595
$ multiparts = array (
592
596
// Tweets
593
597
'statuses/update_with_media ' ,
594
- // Accounts
598
+
599
+ // Users
595
600
'account/update_profile_background_image ' ,
596
601
'account/update_profile_image ' ,
597
602
'account/update_profile_banner '
598
603
);
599
604
return in_array ($ method , $ multiparts );
600
605
}
601
606
607
+ /**
608
+ * Detects if API call should use the old endpoint
609
+ *
610
+ * @param string $method The API method to call
611
+ *
612
+ * @return bool Whether the method is defined in old API
613
+ */
614
+ private function _detectOld ($ method )
615
+ {
616
+ $ olds = array (
617
+ // Users
618
+ 'account/update_profile_banner ' ,
619
+ 'account/remove_profile_banner ' ,
620
+ 'users/recommendations '
621
+ );
622
+ return in_array ($ method , $ olds );
623
+ }
624
+
602
625
/**
603
626
* Detects filenames in upload parameters
604
627
*
@@ -670,14 +693,17 @@ private function _detectFilenames($method, &$params)
670
693
/**
671
694
* Builds the complete API endpoint url
672
695
*
673
- * @param string $method The API method to call
696
+ * @param string $method The API method to call
697
+ * @param string $method_template The API method template to call
674
698
*
675
699
* @return string The URL to send the request to
676
700
*/
677
- private function _getEndpoint ($ method )
701
+ private function _getEndpoint ($ method, $ method_template )
678
702
{
679
703
if (substr ($ method , 0 , 6 ) == 'oauth/ ' ) {
680
704
$ url = $ this ->_endpoint_oauth . $ method ;
705
+ } elseif ($ this ->_detectOld ($ method_template )) {
706
+ $ url = $ this ->_endpoint_old . $ method . '.json ' ;
681
707
} else {
682
708
$ url = $ this ->_endpoint . $ method . '.json ' ;
683
709
}
@@ -701,7 +727,7 @@ private function _callApi($httpmethod, $method, $method_template, $params = arra
701
727
if (! function_exists ('curl_init ' )) {
702
728
throw new Exception ('To make API requests, the PHP curl extension must be available. ' );
703
729
}
704
- $ url = $ this ->_getEndpoint ($ method );
730
+ $ url = $ this ->_getEndpoint ($ method, $ method_template );
705
731
$ ch = false ;
706
732
if ($ httpmethod == 'GET ' ) {
707
733
$ ch = curl_init ($ this ->_sign ($ httpmethod , $ url , $ params ));
@@ -727,7 +753,7 @@ private function _callApi($httpmethod, $method, $method_template, $params = arra
727
753
'Expect: '
728
754
));
729
755
}
730
- $ reply = curl_exec ($ ch );die ( $ reply );
756
+ $ reply = curl_exec ($ ch );
731
757
$ httpstatus = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
732
758
$ reply = $ this ->_parseApiReply ($ method_template , $ reply );
733
759
if ($ this ->_return_format == CODEBIRD_RETURNFORMAT_OBJECT ) {
0 commit comments