Skip to content
This repository
Browse code

Merge remote-tracking branch 'christopherwright/master'

  • Loading branch information...
commit 3617fea8e5e2e9eae5bbcf3418f9592fc7d67b4a 2 parents 2d4dad4 + 01c2569
Olly Smith oesmith authored

Showing 2 changed files with 184 additions and 35 deletions. Show diff stats Hide diff stats

  1. +183 34 lib/twitter.js
  2. +1 1  package.json
217 lib/twitter.js
... ... @@ -1,4 +1,4 @@
1   -var VERSION = '0.1.16',
  1 +var VERSION = '0.1.17',
2 2 http = require('http'),
3 3 querystring = require('querystring'),
4 4 oauth = require('oauth'),
@@ -41,10 +41,10 @@ function Twitter(options) {
41 41 callback_url: null,
42 42
43 43 rest_base: 'https://api.twitter.com/1',
44   - search_base: 'http://search.twitter.com',
45   - stream_base: 'http://stream.twitter.com/1',
  44 + search_base: 'https://search.twitter.com',
  45 + stream_base: 'https://stream.twitter.com/1',
46 46 user_stream_base: 'https://userstream.twitter.com/2',
47   - site_stream_base: 'http://sitestream.twitter.com/2b',
  47 + site_stream_base: 'https://sitestream.twitter.com/2b',
48 48
49 49 secure: false, // force use of https for login/gatekeeper
50 50 cookie: 'twauth',
@@ -591,50 +591,68 @@ Twitter.prototype.getWeeklyTrends = function(params, callback) {
591 591
592 592 // List resources
593 593
594   -Twitter.prototype.getLists = function(screen_name, params, callback) {
  594 +Twitter.prototype.getLists = function(id, params, callback) {
595 595 if (typeof params === 'function') {
596 596 callback = params;
597 597 params = null;
598 598 }
599 599
600   - var url = '/' + escape(screen_name) + '/lists.json';
601   - params = merge(params, {key:'lists'});
  600 + var defaults = {key:'lists'};
  601 + if (typeof id === 'string')
  602 + defaults.screen_name = id;
  603 + else
  604 + defaults.user_id = id;
  605 + params = merge(defaults, params);
  606 +
  607 + var url = '/lists.json';
602 608 this._getUsingCursor(url, params, callback);
603 609 return this;
604 610 }
605 611
606   -Twitter.prototype.createList = function(screen_name, list_name, params, callback) {
  612 +Twitter.prototype.getListMemberships = function(id, params, callback) {
607 613 if (typeof params === 'function') {
608 614 callback = params;
609 615 params = null;
610 616 }
611 617
612   - var url = '/' + escape(screen_name) + '/lists.json';
613   - params = merge(params, {name:list_name});
614   - this.post(url, params, null, callback);
  618 + var defaults = {key:'lists'};
  619 + if (typeof id === 'string')
  620 + defaults.screen_name = id;
  621 + else
  622 + defaults.user_id = id;
  623 + params = merge(defaults, params);
  624 +
  625 + var url = '/lists/memberships.json';
  626 + this._getUsingCursor(url, params, callback);
615 627 return this;
616 628 }
617 629
618   -Twitter.prototype.updateList = function(screen_name, list_id, params, callback) {
619   - var url = '/' + escape(screen_name) + '/lists/' + escape(list_id) + '.json';
620   - this.post(url, params, null, callback);
  630 +Twitter.prototype.getListSubscriptions = function(id, params, callback) {
  631 + if (typeof params === 'function') {
  632 + callback = params;
  633 + params = null;
  634 + }
  635 +
  636 + var defaults = {key:'lists'};
  637 + if (typeof id === 'string')
  638 + defaults.screen_name = id;
  639 + else
  640 + defaults.user_id = id;
  641 + params = merge(defaults, params);
  642 +
  643 + var url = '/lists/subscriptions.json';
  644 + this._getUsingCursor(url, params, callback);
621 645 return this;
622 646 }
623 647
  648 +// FIXME: Uses deprecated Twitter lists API
624 649 Twitter.prototype.showList = function(screen_name, list_id, callback) {
625 650 var url = '/' + escape(screen_name) + '/lists/' + escape(list_id) + '.json';
626 651 this.get(url, null, callback);
627 652 return this;
628 653 }
629 654
630   -Twitter.prototype.deleteList = function(screen_name, list_id, callback) {
631   - var url = '/' + escape(screen_name) + '/lists/' + escape(list_id) + '.json?_method=DELETE';
632   - this.post(url, null, callback);
633   - return this;
634   -}
635   -Twitter.prototype.destroyList
636   - = Twitter.prototype.deleteList;
637   -
  655 +// FIXME: Uses deprecated Twitter lists API
638 656 Twitter.prototype.getListTimeline = function(screen_name, list_id, params, callback) {
639 657 var url = '/' + escape(screen_name) + '/lists/' + escape(list_id) + '/statuses.json';
640 658 this.get(url, params, callback);
@@ -643,32 +661,38 @@ Twitter.prototype.getListTimeline = function(screen_name, list_id, params, callb
643 661 Twitter.prototype.showListStatuses
644 662 = Twitter.prototype.getListTimeline;
645 663
646   -Twitter.prototype.getListMemberships = function(screen_name, params, callback) {
  664 +// FIXME: Uses deprecated Twitter lists API
  665 +Twitter.prototype.createList = function(screen_name, list_name, params, callback) {
647 666 if (typeof params === 'function') {
648 667 callback = params;
649 668 params = null;
650 669 }
651 670
652   - var url = '/' + escape(screen_name) + '/lists/memberships.json';
653   - params = merge(params, {key:'lists'});
654   - this._getUsingCursor(url, params, callback);
  671 + var url = '/' + escape(screen_name) + '/lists.json';
  672 + params = merge(params, {name:list_name});
  673 + this.post(url, params, null, callback);
655 674 return this;
656 675 }
657 676
658   -Twitter.prototype.getListSubscriptions = function(screen_name, params, callback) {
659   - if (typeof params === 'function') {
660   - callback = params;
661   - params = null;
662   - }
  677 +// FIXME: Uses deprecated Twitter lists API
  678 +Twitter.prototype.updateList = function(screen_name, list_id, params, callback) {
  679 + var url = '/' + escape(screen_name) + '/lists/' + escape(list_id) + '.json';
  680 + this.post(url, params, null, callback);
  681 + return this;
  682 +}
663 683
664   - var url = '/' + escape(screen_name) + '/lists/subscriptions.json';
665   - params = merge(params, {key:'lists'});
666   - this._getUsingCursor(url, params, callback);
  684 +// FIXME: Uses deprecated Twitter lists API
  685 +Twitter.prototype.deleteList = function(screen_name, list_id, callback) {
  686 + var url = '/' + escape(screen_name) + '/lists/' + escape(list_id) + '.json?_method=DELETE';
  687 + this.post(url, null, callback);
667 688 return this;
668 689 }
  690 +Twitter.prototype.destroyList
  691 + = Twitter.prototype.deleteList;
669 692
670 693 // List Members resources
671 694
  695 +// FIXME: Uses deprecated Twitter lists API
672 696 Twitter.prototype.getListMembers = function(screen_name, list_id, params, callback) {
673 697 if (typeof params === 'function') {
674 698 callback = params;
@@ -685,6 +709,7 @@ Twitter.prototype.getListMembers = function(screen_name, list_id, params, callba
685 709
686 710 // List Subscribers resources
687 711
  712 +// FIXME: Uses deprecated Twitter lists API
688 713 Twitter.prototype.getListSubscribers = function(screen_name, list_id, params, callback) {
689 714 if (typeof params === 'function') {
690 715 callback = params;
@@ -749,6 +774,83 @@ Twitter.prototype.deleteDirectMessage
749 774
750 775 // Friendship resources
751 776
  777 +Twitter.prototype.createFriendship = function(id, params, callback) {
  778 + if (typeof params === 'function') {
  779 + callback = params;
  780 + params = null;
  781 + }
  782 +
  783 + var defaults = {
  784 + include_entities: 1
  785 + };
  786 + if (typeof id === 'string')
  787 + defaults.screen_name = id;
  788 + else
  789 + defaults.user_id = id;
  790 + params = merge(defaults, params);
  791 +
  792 + var url = '/friendships/create.json';
  793 + this.post(url, params, null, callback);
  794 + return this;
  795 +}
  796 +
  797 +Twitter.prototype.destroyFriendship = function(id, callback) {
  798 + if (typeof id === 'function') {
  799 + callback = id;
  800 + id = null;
  801 + }
  802 +
  803 + var params = {
  804 + include_entities: 1
  805 + };
  806 + if (typeof id === 'string')
  807 + params.screen_name = id;
  808 + else
  809 + params.user_id = id;
  810 +
  811 + var url = '/friendships/destroy.json?_method=DELETE';
  812 + this.post(url, params, null, callback);
  813 + return this;
  814 +}
  815 +Twitter.prototype.deleteFriendship
  816 + = Twitter.prototype.destroyFriendship;
  817 +
  818 +// Only exposing friendships/show instead of friendships/exist
  819 +
  820 +Twitter.prototype.showFriendship = function(source, target, callback) {
  821 + var params = {};
  822 +
  823 + if (typeof source === 'string')
  824 + params.source_screen_name = source;
  825 + else
  826 + params.source_id = source;
  827 +
  828 + if (typeof target === 'string')
  829 + params.target_screen_name = target;
  830 + else
  831 + params.target_id = target;
  832 +
  833 + var url = '/friendships/show.json';
  834 + this.get(url, params, callback);
  835 + return this;
  836 +}
  837 +
  838 +Twitter.prototype.incomingFriendship = function(callback) {
  839 + var url = '/friendships/incoming.json';
  840 + this._getUsingCursor(url, {key:'ids'}, callback);
  841 + return this;
  842 +}
  843 +Twitter.prototype.incomingFriendships
  844 + = Twitter.prototype.incomingFriendship;
  845 +
  846 +Twitter.prototype.outgoingFriendship = function(callback) {
  847 + var url = '/friendships/outgoing.json';
  848 + this._getUsingCursor(url, {key:'ids'}, callback);
  849 + return this;
  850 +}
  851 +Twitter.prototype.outgoingFriendships
  852 + = Twitter.prototype.outgoingFriendship;
  853 +
752 854 // Friends and Followers resources
753 855
754 856 Twitter.prototype.getFriendsIds = function(id, callback) {
@@ -793,6 +895,24 @@ Twitter.prototype.verifyCredentials = function(callback) {
793 895 return this;
794 896 }
795 897
  898 +Twitter.prototype.rateLimitStatus = function(callback) {
  899 + var url = '/account/rate_limit_status.json';
  900 + this.get(url, null, callback);
  901 + return this;
  902 +}
  903 +
  904 +Twitter.prototype.updateProfile = function(params, callback) {
  905 + // params: name, url, location, description
  906 + var defaults = {
  907 + include_entities: 1
  908 + };
  909 + params = merge(defaults, params);
  910 +
  911 + var url = '/account/update_profile.json';
  912 + this.post(url, params, null, callback);
  913 + return this;
  914 +}
  915 +
796 916 // FIXME: Account resources section not complete
797 917
798 918 // Favorites resources
@@ -887,6 +1007,34 @@ Twitter.prototype.reportSpam = function(id, callback) {
887 1007
888 1008 // Saved Searches resources
889 1009
  1010 +Twitter.prototype.savedSearches = function(callback) {
  1011 + var url = '/saved_searches.json';
  1012 + this.get(url, null, callback);
  1013 + return this;
  1014 +}
  1015 +
  1016 +Twitter.prototype.showSavedSearch = function(id, callback) {
  1017 + var url = '/saved_searches/' + escape(id) + '.json';
  1018 + this.get(url, null, callback);
  1019 + return this;
  1020 +}
  1021 +
  1022 +Twitter.prototype.createSavedSearch = function(query, callback) {
  1023 + var url = '/saved_searches/create.json';
  1024 + this.post(url, {query: query}, null, callback);
  1025 + return this;
  1026 +}
  1027 +Twitter.prototype.newSavedSearch =
  1028 + Twitter.prototype.createSavedSearch;
  1029 +
  1030 +Twitter.prototype.destroySavedSearch = function(id, callback) {
  1031 + var url = '/saved_searches/destroy/' + escape(id) + '.json?_method=DELETE';
  1032 + this.post(url, null, null, callback);
  1033 + return this;
  1034 +}
  1035 +Twitter.prototype.deleteSavedSearch =
  1036 + Twitter.prototype.destroySavedSearch;
  1037 +
890 1038 // OAuth resources
891 1039
892 1040 // Geo resources
@@ -957,6 +1105,7 @@ Twitter.prototype.geoGetPlace = function(place_id, callback) {
957 1105
958 1106 Twitter.prototype._getUsingCursor = function(url, params, callback) {
959 1107 var self = this,
  1108 + params = params || {},
960 1109 key = params.key || null,
961 1110 result = [];
962 1111
2  package.json
... ... @@ -1,5 +1,5 @@
1 1 { "name": "twitter"
2   -, "version": "v0.1.16"
  2 +, "version": "v0.1.17"
3 3 , "description": "Asynchronous Twitter REST/stream/search client API for node.js."
4 4 , "keywords": ["twitter","streaming","oauth"]
5 5 , "homepage": "https://github.com/jdub/node-twitter"

0 comments on commit 3617fea

Please sign in to comment.
Something went wrong with that request. Please try again.