snoowrap
Advanced tools
Comparing version 0.9.4 to 0.9.5
@@ -140,6 +140,6 @@ 'use strict'; | ||
* @summary Marks this submission as 'visited'. | ||
* @desc **Note**: This function only works if the authenticated account has a subscription to reddit gold. | ||
* @returns {Promise} The updated version of this Submission | ||
*/ | ||
mark_as_read() { | ||
// Requires reddit gold | ||
return this._post({ uri: 'api/store_visits', form: { links: this.name } }).return(this); | ||
@@ -146,0 +146,0 @@ } |
@@ -51,3 +51,3 @@ 'use strict'; | ||
transform(body, response) { | ||
r.ratelimit_remaining = response.headers['x-ratelimit-remaining']; | ||
r.ratelimit_remaining = parseInt(response.headers['x-ratelimit-remaining']); | ||
r.ratelimit_reset_point = Date.now() + response.headers['x-ratelimit-reset'] * 1000; | ||
@@ -54,0 +54,0 @@ const populated = helpers._populate(body, r); |
@@ -84,2 +84,6 @@ 'use strict'; | ||
* @returns {object} An updated Object containing all of the configuration values | ||
* @example | ||
* | ||
* r.config({request_delay: 1000, suppress_warnings: true}); | ||
* // sets the request delay to 1000 milliseconds, and suppresses warnings. | ||
*/ | ||
@@ -89,31 +93,2 @@ config(options) { | ||
} | ||
_revoke_token(token) { | ||
return request_handler.base_client_request(this, 'post', [{ uri: 'api/v1/revoke_token', form: { token } }]); | ||
} | ||
/** | ||
* @summary Invalidates the current access token. | ||
* @returns {Promise} A Promise that fulfills when this request is complete | ||
* @desc **Note**: This can only be used if the current requester was supplied with a `client_id` and `client_secret`. If the | ||
current requester was supplied with a refresh token, it will automatically create a new access token if any more requests | ||
are made after this one. | ||
*/ | ||
revoke_access_token() { | ||
return this._revoke_token(this.access_token).then(() => { | ||
this.access_token = undefined; | ||
}); | ||
} | ||
/** | ||
* @summary Invalidates the current refresh token. | ||
* @returns {Promise} A Promise that fulfills when this request is complete | ||
* @desc **Note**: This can only be used if the current requester was supplied with a `client_id` and `client_secret`. All | ||
access tokens generated by this refresh token will also be invalidated. This effectively de-authenticates the requester and | ||
prevents it from making any more valid requests. This should only be used in a few cases, e.g. if this token has | ||
been accidentally leaked to a third party. | ||
*/ | ||
revoke_refresh_token() { | ||
return this._revoke_token(this.refresh_token).then(() => { | ||
this.refresh_token = undefined; | ||
this.access_token = undefined; // Revoking a refresh token also revokes any associated access tokens. | ||
}); | ||
} | ||
inspect() { | ||
@@ -138,18 +113,11 @@ // Hide confidential information (tokens, client IDs, etc.), as well as private properties, from the console.log output. | ||
/** | ||
* @summary Gets information on the requester's own user profile. | ||
* @returns {RedditUser} A RedditUser object corresponding to the requester's profile | ||
*/ | ||
get_me() { | ||
return promise_wrap(this._get('api/v1/me').then(result => { | ||
this.own_user_info = this._new_object('RedditUser', result, true); | ||
return this.own_user_info; | ||
})); | ||
} | ||
_get_my_name() { | ||
return Promise.resolve(this.own_user_info ? this.own_user_info.name : this.get_me().get('name')); | ||
} | ||
/** | ||
* @summary Gets information on a reddit user with a given name. | ||
* @param {string} name - The user's username | ||
* @returns {RedditUser} An unfetched RedditUser object for the requested user | ||
* @example | ||
* | ||
* r.get_user('not_an_aardvark') | ||
* // => RedditUser { name: 'not_an_aardvark' } | ||
* r.get_user('not_an_aardvark').link_karma.then(console.log) | ||
* // => 6 | ||
*/ | ||
@@ -163,2 +131,8 @@ get_user(name) { | ||
* @returns {Comment} An unfetched Comment object for the requested comment | ||
* @example | ||
* | ||
* r.get_comment('c0b6xx0') | ||
* // => Comment { name: 't1_c0b6xx0' } | ||
* r.get_comment('c0b6xx0').author.name.then(console.log) | ||
* // => 'Kharos' | ||
*/ | ||
@@ -172,2 +146,8 @@ get_comment(comment_id) { | ||
* @returns {Subreddit} An unfetched Subreddit object for the requested subreddit | ||
* @example | ||
* | ||
* r.get_subreddit('AskReddit') | ||
* // => Subreddit { display_name: 'AskReddit' } | ||
* r.get_subreddit('AskReddit').created_utc.then(console.log) | ||
* // => 1201233135 | ||
*/ | ||
@@ -181,2 +161,8 @@ get_subreddit(display_name) { | ||
* @returns {Submission} An unfetched Submission object for the requested submission | ||
* @example | ||
* | ||
* r.get_submission('2np694') | ||
* // => Submission { name: 't3_2np694' } | ||
* r.get_submission('2np694').title.then(console.log) | ||
* // => 'What tasty food would be distusting if eaten over rice?' | ||
*/ | ||
@@ -190,2 +176,9 @@ get_submission(submission_id) { | ||
* @returns {PrivateMessage} An unfetched PrivateMessage object for the requested message | ||
* @example | ||
* | ||
* r.get_message('51shnw') | ||
* // => PrivateMessage { name: 't4_51shnw' } | ||
* r.get_message('51shnw').subject.then(console.log) | ||
* // => 'Example' | ||
* // See here for a screenshot of the PM in question https://i.gyazo.com/24f3b97e55b6ff8e3a74cb026a58b167.png | ||
*/ | ||
@@ -199,2 +192,8 @@ get_message(message_id) { | ||
* @returns {LiveThread} An unfetched LiveThread object | ||
* @example | ||
* | ||
* r.get_livethread('whrdxo8dg9n0') | ||
* // => LiveThread { id: 'whrdxo8dg9n0' } | ||
* r.get_livethread('whrdxo8dg9n0').nsfw.then(console.log) | ||
* // => false | ||
*/ | ||
@@ -205,4 +204,25 @@ get_livethread(thread_id) { | ||
/** | ||
* @summary Gets information on the requester's own user profile. | ||
* @returns {RedditUser} A RedditUser object corresponding to the requester's profile | ||
* @example | ||
* | ||
* r.get_me().then(console.log); | ||
* // => RedditUser { is_employee: false, has_mail: false, name: 'snoowrap_testing', ... } | ||
*/ | ||
get_me() { | ||
return promise_wrap(this._get('api/v1/me').then(result => { | ||
this.own_user_info = this._new_object('RedditUser', result, true); | ||
return this.own_user_info; | ||
})); | ||
} | ||
_get_my_name() { | ||
return Promise.resolve(this.own_user_info ? this.own_user_info.name : this.get_me().get('name')); | ||
} | ||
/** | ||
* @summary Gets a distribution of the requester's own karma distribution by subreddit. | ||
* @returns {Promise} A Promise for an object with karma information | ||
* @example | ||
* | ||
* r.get_karma().then(console.log) | ||
* // => [ {sr: 'redditdev', comment_karma: 16, link_karma: 1}, { sr: 'programming', comment_karma: 2, link_karma: 1 }, ... ] | ||
*/ | ||
@@ -215,2 +235,6 @@ get_karma() { | ||
* @returns {Promise} A promise for an object containing the user's current preferences | ||
* @example | ||
* | ||
* r.get_preferences().then(console.log) | ||
* // => { default_theme_sr: null, threaded_messages: true, hide_downs: false, ... } | ||
*/ | ||
@@ -225,2 +249,7 @@ get_preferences() { | ||
* @returns {Promise} A Promise that fulfills when the request is complete | ||
* @example | ||
* | ||
* r.update_preferences({threaded_messages: false, hide_downs: true}) | ||
* // => { default_theme_sr: null, threaded_messages: false,hide_downs: true, ... } | ||
* // (preferences updated on reddit) | ||
*/ | ||
@@ -233,2 +262,15 @@ update_preferences(updated_preferences) { | ||
* @returns {Promise} A TrophyList containing the user's trophies | ||
* @example | ||
* | ||
* r.get_my_trophies().then(console.log) | ||
* // => TrophyList { trophies: [ | ||
* // Trophy { icon_70: 'https://s3.amazonaws.com/redditstatic/award/verified_email-70.png', | ||
* // description: null, | ||
* // url: null, | ||
* // icon_40: 'https://s3.amazonaws.com/redditstatic/award/verified_email-40.png', | ||
* // award_id: 'o', | ||
* // id: '16fn29', | ||
* // name: 'Verified Email' | ||
* // } | ||
* // ] } | ||
*/ | ||
@@ -241,2 +283,6 @@ get_my_trophies() { | ||
* @returns {Promise} A Promise that resolves with a list of friends | ||
* @example | ||
* | ||
* r.get_friends().then(console.log) | ||
* // => [ [ RedditUser { date: 1457927963, name: 'not_an_aardvark', id: 't2_k83md' } ], [] ] | ||
*/ | ||
@@ -249,2 +295,6 @@ get_friends() { | ||
* @returns {Promise} A Promise that resolves with a list of blocked users | ||
* @example | ||
* | ||
* r.get_blocked_users().then(console.log) | ||
* // => [ RedditUser { date: 1457928120, name: 'actually_an_aardvark', id: 't2_q3519' } ] | ||
*/ | ||
@@ -257,2 +307,6 @@ get_blocked_users() { | ||
* @returns {Promise} A Promise that resolves with a boolean value | ||
* @example | ||
* | ||
* r.check_captcha_requirement().then(console.log) | ||
* // => false | ||
*/ | ||
@@ -265,2 +319,6 @@ check_captcha_requirement() { | ||
* @returns {Promise} A Promise that resolves with a string | ||
* @example | ||
* | ||
* r.get_new_captcha_identifier().then(console.log) | ||
* // => 'o5M18uy4mk0IW4hs0fu2GNPdXb1Dxe9d' | ||
*/ | ||
@@ -274,2 +332,6 @@ get_new_captcha_identifier() { | ||
* @returns {Promise} A string containing raw image data in PNG format | ||
* @example | ||
* | ||
* r.get_captcha_image('o5M18uy4mk0IW4hs0fu2GNPdXb1Dxe9d').then(console.log) | ||
// => (A long, incoherent string representing the image in PNG format) | ||
*/ | ||
@@ -282,2 +344,6 @@ get_captcha_image(identifier) { | ||
* @returns {Promise} An array of categories | ||
* @example | ||
* | ||
* r.get_saved_categories().then(console.log) | ||
* // => [ { category: 'cute cat pictures' }, { category: 'interesting articles' } ] | ||
*/ | ||
@@ -289,4 +355,10 @@ get_saved_categories() { | ||
* @summary Marks a list of submissions as 'visited'. | ||
* @desc **Note**: This endpoint only works if the authenticated user is subscribed to reddit gold. | ||
* @param {Submission[]} links A list of Submission objects to mark | ||
* @returns {Promise} A Promise that fulfills when the request is complete | ||
* @example | ||
* | ||
* var submissions = [r.get_submission('4a9u54'), r.get_submission('4a95nb')] | ||
* r.mark_as_visited(submissions) | ||
* // (the links will now appear purple on reddit) | ||
*/ | ||
@@ -325,2 +397,11 @@ mark_as_visited(links) { | ||
* @returns {Promise} The newly-created Submission object | ||
* @example | ||
* | ||
* r.submit_selfpost({ | ||
* subreddit_name: 'snoowrap_testing', | ||
* title: 'This is a selfpost', | ||
* body: 'This is the body of the selfpost' | ||
* }).then(console.log) | ||
* // => Submission { name: 't3_4abmsz' } | ||
* // (new selfpost created on reddit) | ||
*/ | ||
@@ -343,2 +424,11 @@ submit_selfpost(options) { | ||
* @returns {Promise} The newly-created Submission object | ||
* @example | ||
* | ||
* r.submit_link({ | ||
* subreddit_name: 'snoowrap_testing', | ||
* title: 'I found a cool website!', | ||
* url: 'https://google.com' | ||
* }).then(console.log) | ||
* // => Submission { name: 't3_4abnfe' } | ||
* // (new linkpost created on reddit) | ||
*/ | ||
@@ -369,2 +459,22 @@ submit_link(options) { | ||
* @returns {Promise} A Listing containing the retrieved submissions | ||
* @example | ||
* | ||
* r.get_hot().then(console.log) | ||
* // => Listing [ | ||
* // Submission { domain: 'imgur.com', banned_by: null, subreddit: Subreddit { display_name: 'pics' }, ... }, | ||
* // Submission { domain: 'i.imgur.com', banned_by: null, subreddit: Subreddit { display_name: 'funny' }, ... }, | ||
* // ... | ||
* // ] | ||
* | ||
* r.get_hot('gifs').then(console.log) | ||
* // => Listing [ | ||
* // Submission { domain: 'i.imgur.com', banned_by: null, subreddit: Subreddit { display_name: 'gifs' }, ... }, | ||
* // Submission { domain: 'i.imgur.com', banned_by: null, subreddit: Subreddit { display_name: 'gifs' }, ... }, | ||
* // ... | ||
* // ] | ||
* | ||
* r.get_hot('redditdev', {limit: 1}).then(console.log) | ||
* // => Listing [ | ||
// Submission { domain: 'self.redditdev', banned_by: null, subreddit: Subreddit { display_name: 'redditdev' }, ...} | ||
* // ] | ||
*/ | ||
@@ -380,2 +490,11 @@ get_hot(subreddit_name, options) { | ||
* @returns {Promise} A Listing containing the retrieved submissions | ||
* @example | ||
* | ||
* r.get_new().then(console.log) | ||
* // => Listing [ | ||
* // Submission { domain: 'self.Jokes', banned_by: null, subreddit: Subreddit { display_name: 'Jokes' }, ... }, | ||
* // Submission { domain: 'self.AskReddit', banned_by: null, subreddit: Subreddit { display_name: 'AskReddit' }, ... }, | ||
* // ... | ||
* // ] | ||
* | ||
*/ | ||
@@ -391,2 +510,9 @@ get_new(subreddit_name, options) { | ||
* @returns {Promise} A Listing containing the retrieved comments | ||
* @example | ||
* | ||
* r.get_new_comments().then(console.log) | ||
* // => Listing [ | ||
* // Comment { link_title: 'What amazing book should be made into a movie, but hasn\'t been yet?', ... } | ||
* // Comment { link_title: 'How far back in time could you go and still understand English?', ... } | ||
* // ] | ||
*/ | ||
@@ -401,2 +527,6 @@ get_new_comments(subreddit_name, options) { | ||
* @returns {Promise} The retrieved Submission object | ||
* @example | ||
* | ||
* r.get_random_submission('aww').then(console.log) | ||
* // => Submission { domain: 'i.imgur.com', banned_by: null, subreddit: Subreddit { display_name: 'aww' }, ... } | ||
*/ | ||
@@ -410,11 +540,24 @@ get_random_submission(subreddit_name) { | ||
the front page of reddit. | ||
* @param {object} [options={}] | ||
* @param {object} [options={}] Options for the resulting Listing | ||
* @param {string} [options.time] Describes the timespan that posts should be retrieved from. Should be one of | ||
`hour, day, week, month, year, all` | ||
* @returns {Promise} A Listing containing the retrieved submissions | ||
* @example | ||
* | ||
* r.get_top({time: 'all', limit: 2}).then(console.log) | ||
* // => Listing [ | ||
* // Submission { domain: 'self.AskReddit', banned_by: null, subreddit: Subreddit { display_name: 'AskReddit' }, ... }, | ||
* // Submission { domain: 'imgur.com', banned_by: null, subreddit: Subreddit { display_name: 'funny' }, ... } | ||
* // ] | ||
* | ||
* r.get_top('AskReddit').then(console.log) | ||
* // => Listing [ | ||
* // Submission { domain: 'self.AskReddit', banned_by: null, subreddit: Subreddit { display_name: 'AskReddit' }, ... }, | ||
* // Submission { domain: 'self.AskReddit', banned_by: null, subreddit: Subreddit { display_name: 'AskReddit' }, ... }, | ||
* // Submission { domain: 'self.AskReddit', banned_by: null, subreddit: Subreddit { display_name: 'AskReddit' }, ... }, | ||
* // ... | ||
* // ] | ||
*/ | ||
get_top(subreddit_name) { | ||
let options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
return this._get_sorted_frontpage('top', subreddit_name, { time: options.time }); | ||
get_top(subreddit_name, options) { | ||
return this._get_sorted_frontpage('top', subreddit_name, options); | ||
} | ||
@@ -425,43 +568,28 @@ /** | ||
the front page of reddit. | ||
* @param {object} [options={}] | ||
* @param {object} [options={}] Options for the resulting Listing | ||
* @param {string} [options.time] Describes the timespan that posts should be retrieved from. Should be one of | ||
`hour, day, week, month, year, all` | ||
* @returns {Promise} A Listing containing the retrieved submissions | ||
* @example | ||
* | ||
* r.get_controversial('technology').then(console.log) | ||
* // => Listing [ | ||
* // Submission { domain: 'thenextweb.com', banned_by: null, subreddit: Subreddit { display_name: 'technology' }, ... }, | ||
* // Submission { domain: 'pcmag.com', banned_by: null, subreddit: Subreddit { display_name: 'technology' }, ... } | ||
* // ] | ||
*/ | ||
get_controversial(subreddit_name, options) { | ||
return this._get_sorted_frontpage('controversial', subreddit_name, { time: options.time }); | ||
return this._get_sorted_frontpage('controversial', subreddit_name, options); | ||
} | ||
_select_flair(_ref3) { | ||
var _this = this; | ||
let flair_template_id = _ref3.flair_template_id; | ||
let link = _ref3.link; | ||
let name = _ref3.name; | ||
let text = _ref3.text; | ||
let subreddit_name = _ref3.subreddit_name; | ||
return _asyncToGenerator(function* () { | ||
if (!flair_template_id) { | ||
throw new errors.InvalidMethodCallError('Error: No flair template ID provided'); | ||
} | ||
return yield _this._post({ uri: `r/${ yield subreddit_name }/api/selectflair`, form: { | ||
api_type, flair_template_id, link, name, text } | ||
}); | ||
})(); | ||
} | ||
_assign_flair(_ref4) { | ||
var _this2 = this; | ||
let css_class = _ref4.css_class; | ||
let link = _ref4.link; | ||
let name = _ref4.name; | ||
let text = _ref4.text; | ||
let subreddit_name = _ref4.subreddit_name; | ||
return _asyncToGenerator(function* () { | ||
return yield _this2._post({ uri: `r/${ yield subreddit_name }/api/flair`, form: { api_type, name, text, link, css_class } }); | ||
})(); | ||
} | ||
/** | ||
* @summary Gets the authenticated user's unread messages. | ||
* @param {object} options | ||
* @param {object} [options={}] Options for the resulting Listing | ||
* @returns {Promise} A Listing containing unread items in the user's inbox | ||
* @example | ||
* | ||
* r.get_unread_messages().then(console.log) | ||
* // => Listing [ | ||
* // PrivateMessage { body: 'hi!', was_comment: false, first_message: null, ... }, | ||
* // Comment { body: 'this is a reply', link_title: 'Yay, a selfpost!', was_comment: true, ... } | ||
* // ] | ||
*/ | ||
@@ -475,4 +603,11 @@ get_unread_messages() { | ||
* @summary Gets the items in the authenticated user's inbox. | ||
* @param {object} options | ||
* @param {object} [options={}] Options for the resulting Listing | ||
* @returns {Promise} A Listing containing items in the user's inbox | ||
* @example | ||
* | ||
* r.get_unread_messages().then(console.log) | ||
* // => Listing [ | ||
* // PrivateMessage { body: 'hi!', was_comment: false, first_message: null, ... }, | ||
* // Comment { body: 'this is a reply', link_title: 'Yay, a selfpost!', was_comment: true, ... } | ||
* // ] | ||
*/ | ||
@@ -486,4 +621,11 @@ get_inbox() { | ||
* @summary Gets the authenticated user's modmail. | ||
* @param {object} options | ||
* @param {object} [options={}] Options for the resulting Listing | ||
* @returns {Promise} A Listing of the user's modmail | ||
* @example | ||
* | ||
* r.get_modmail({limit: 2}).then(console.log) | ||
* // => Listing [ | ||
* // PrivateMessage { body: '/u/not_an_aardvark has accepted an invitation to become moderator ... ', ... }, | ||
* // PrivateMessage { body: '/u/not_an_aardvark has been invited by /u/actually_an_aardvark to ...', ... } | ||
* // ] | ||
*/ | ||
@@ -499,2 +641,9 @@ get_modmail() { | ||
* @returns {Promise} A Listing of the user's sent messages | ||
* @example | ||
* | ||
* r.get_sent_messages().then(console.log) | ||
* // => Listing [ | ||
* // PrivateMessage { body: 'you have been added as an approved submitter to ...', ... }, | ||
* // PrivateMessage { body: 'you have been banned from posting to ...' ... } | ||
* // ] | ||
*/ | ||
@@ -509,2 +658,9 @@ get_sent_messages() { | ||
* @returns {Promise} A Promise that resolves when the request is complete | ||
* @example | ||
* | ||
* r.read_all_messages().then(function () { | ||
* r.get_unread_messages().then(console.log) | ||
* }) | ||
* // => Listing [] | ||
* // (messages marked as 'read' on reddit) | ||
*/ | ||
@@ -525,10 +681,18 @@ read_all_messages() { | ||
* @returns {Promise} A Promise that fulfills when the request is complete | ||
* @example | ||
* | ||
* r.compose_message({ | ||
* to: 'actually_an_aardvark', | ||
* subject: "Hi, how's it going?", | ||
* text: 'Long time no see' | ||
* }) | ||
* // (message created on reddit) | ||
*/ | ||
compose_message(_ref5) { | ||
let captcha = _ref5.captcha; | ||
let from_subreddit = _ref5.from_subreddit; | ||
let captcha_iden = _ref5.captcha_iden; | ||
let subject = _ref5.subject; | ||
let text = _ref5.text; | ||
let to = _ref5.to; | ||
compose_message(_ref3) { | ||
let captcha = _ref3.captcha; | ||
let from_subreddit = _ref3.from_subreddit; | ||
let captcha_iden = _ref3.captcha_iden; | ||
let subject = _ref3.subject; | ||
let text = _ref3.text; | ||
let to = _ref3.to; | ||
@@ -549,8 +713,24 @@ let parsed_to = to; | ||
api_type, captcha, iden: captcha_iden, from_sr: parsed_from_sr, subject, text, to: parsed_to | ||
} }); | ||
} }).tap(helpers._handle_json_errors).return({}); | ||
} | ||
/** | ||
* @summary Gets a list of all oauth scopes supported by the reddit API. | ||
* @desc **Note**: This lists every single oauth scope. To get the scope of this requester, use the `scope` property instead. | ||
* @returns {Promise} An object containing oauth scopes. | ||
* @desc **Note**: To get the scope of this requester, use the `scope` property instead. | ||
* @example | ||
* | ||
* r.get_oauth_scope_list().then(console.log) | ||
* // => { | ||
* // creddits: { | ||
* // description: 'Spend my reddit gold creddits on giving gold to other users.', | ||
* // id: 'creddits', | ||
* // name: 'Spend reddit gold creddits' | ||
* // }, | ||
* // modcontributors: { | ||
* // description: 'Add/remove users to approved submitter lists and ban/unban or mute/unmute users from ...', | ||
* // id: 'modcontributors', | ||
* // name: 'Approve submitters and ban users' | ||
* // }, | ||
* // ... | ||
* // } | ||
*/ | ||
@@ -571,2 +751,14 @@ get_oauth_scope_list() { | ||
* @returns {Promise} A Listing containing the search results. | ||
* @example | ||
* | ||
* r.search({ | ||
* query: 'Cute kittens', | ||
* subreddit: 'aww', | ||
* sort: 'top' | ||
* }).then(console.log) | ||
* // => Listing [ | ||
* // Submission { domain: 'i.imgur.com', banned_by: null, ... }, | ||
* // Submission { domain: 'imgur.com', banned_by: null, ... }, | ||
* // ... | ||
* // ] | ||
*/ | ||
@@ -577,2 +769,4 @@ search(options) { | ||
} | ||
options.restrict_sr = options.restrict_sr || true; | ||
options.syntax = options.syntax || 'plain'; | ||
const parsed_query = _(options).assign({ t: options.time, q: options.query }).omit('time', 'query').value(); | ||
@@ -588,63 +782,72 @@ return this._get({ uri: `${ options.subreddit ? `r/${ options.subreddit }/` : '' }search`, qs: parsed_query }); | ||
* @returns {Promise} An Array containing subreddit names | ||
* @example | ||
* | ||
* r.search_subreddit_names({query: 'programming'}).then(console.log) | ||
* // => [ | ||
* // 'programming', | ||
* // 'programmingcirclejerk', | ||
* // 'programminghorror', | ||
* // ... | ||
* // ] | ||
*/ | ||
search_subreddit_names(_ref6) { | ||
var _ref6$exact = _ref6.exact; | ||
let exact = _ref6$exact === undefined ? false : _ref6$exact; | ||
var _ref6$include_nsfw = _ref6.include_nsfw; | ||
let include_nsfw = _ref6$include_nsfw === undefined ? true : _ref6$include_nsfw; | ||
let query = _ref6.query; | ||
search_subreddit_names(_ref4) { | ||
var _ref4$exact = _ref4.exact; | ||
let exact = _ref4$exact === undefined ? false : _ref4$exact; | ||
var _ref4$include_nsfw = _ref4.include_nsfw; | ||
let include_nsfw = _ref4$include_nsfw === undefined ? true : _ref4$include_nsfw; | ||
let query = _ref4.query; | ||
return this._post({ uri: 'api/search_reddit_names', qs: { exact, include_over_18: include_nsfw, query } }).names; | ||
} | ||
_create_or_edit_subreddit(_ref7) { | ||
var _ref7$allow_top = _ref7.allow_top; | ||
let allow_top = _ref7$allow_top === undefined ? true : _ref7$allow_top; | ||
let captcha = _ref7.captcha; | ||
let captcha_iden = _ref7.captcha_iden; | ||
var _ref7$collapse_delete = _ref7.collapse_deleted_comments; | ||
let collapse_deleted_comments = _ref7$collapse_delete === undefined ? false : _ref7$collapse_delete; | ||
var _ref7$comment_score_h = _ref7.comment_score_hide_mins; | ||
let comment_score_hide_mins = _ref7$comment_score_h === undefined ? 0 : _ref7$comment_score_h; | ||
let description = _ref7.description; | ||
var _ref7$exclude_banned_ = _ref7.exclude_banned_modqueue; | ||
let exclude_banned_modqueue = _ref7$exclude_banned_ === undefined ? false : _ref7$exclude_banned_; | ||
let header_title = _ref7['header-title']; | ||
var _ref7$hide_ads = _ref7.hide_ads; | ||
let hide_ads = _ref7$hide_ads === undefined ? false : _ref7$hide_ads; | ||
var _ref7$lang = _ref7.lang; | ||
let lang = _ref7$lang === undefined ? 'en' : _ref7$lang; | ||
var _ref7$link_type = _ref7.link_type; | ||
let link_type = _ref7$link_type === undefined ? 'any' : _ref7$link_type; | ||
let name = _ref7.name; | ||
var _ref7$over_ = _ref7.over_18; | ||
let over_18 = _ref7$over_ === undefined ? false : _ref7$over_; | ||
let public_description = _ref7.public_description; | ||
var _ref7$public_traffic = _ref7.public_traffic; | ||
let public_traffic = _ref7$public_traffic === undefined ? false : _ref7$public_traffic; | ||
var _ref7$show_media = _ref7.show_media; | ||
let show_media = _ref7$show_media === undefined ? false : _ref7$show_media; | ||
var _ref7$spam_comments = _ref7.spam_comments; | ||
let spam_comments = _ref7$spam_comments === undefined ? 'high' : _ref7$spam_comments; | ||
var _ref7$spam_links = _ref7.spam_links; | ||
let spam_links = _ref7$spam_links === undefined ? 'high' : _ref7$spam_links; | ||
var _ref7$spam_selfposts = _ref7.spam_selfposts; | ||
let spam_selfposts = _ref7$spam_selfposts === undefined ? 'high' : _ref7$spam_selfposts; | ||
let sr = _ref7.sr; | ||
var _ref7$submit_link_lab = _ref7.submit_link_label; | ||
let submit_link_label = _ref7$submit_link_lab === undefined ? '' : _ref7$submit_link_lab; | ||
var _ref7$submit_text_lab = _ref7.submit_text_label; | ||
let submit_text_label = _ref7$submit_text_lab === undefined ? '' : _ref7$submit_text_lab; | ||
var _ref7$submit_text = _ref7.submit_text; | ||
let submit_text = _ref7$submit_text === undefined ? '' : _ref7$submit_text; | ||
var _ref7$suggested_comme = _ref7.suggested_comment_sort; | ||
let suggested_comment_sort = _ref7$suggested_comme === undefined ? 'confidence' : _ref7$suggested_comme; | ||
let title = _ref7.title; | ||
var _ref7$type = _ref7.type; | ||
let type = _ref7$type === undefined ? 'public' : _ref7$type; | ||
let subreddit_type = _ref7.subreddit_type; | ||
_create_or_edit_subreddit(_ref5) { | ||
var _ref5$allow_top = _ref5.allow_top; | ||
let allow_top = _ref5$allow_top === undefined ? true : _ref5$allow_top; | ||
let captcha = _ref5.captcha; | ||
let captcha_iden = _ref5.captcha_iden; | ||
var _ref5$collapse_delete = _ref5.collapse_deleted_comments; | ||
let collapse_deleted_comments = _ref5$collapse_delete === undefined ? false : _ref5$collapse_delete; | ||
var _ref5$comment_score_h = _ref5.comment_score_hide_mins; | ||
let comment_score_hide_mins = _ref5$comment_score_h === undefined ? 0 : _ref5$comment_score_h; | ||
let description = _ref5.description; | ||
var _ref5$exclude_banned_ = _ref5.exclude_banned_modqueue; | ||
let exclude_banned_modqueue = _ref5$exclude_banned_ === undefined ? false : _ref5$exclude_banned_; | ||
let header_title = _ref5['header-title']; | ||
var _ref5$hide_ads = _ref5.hide_ads; | ||
let hide_ads = _ref5$hide_ads === undefined ? false : _ref5$hide_ads; | ||
var _ref5$lang = _ref5.lang; | ||
let lang = _ref5$lang === undefined ? 'en' : _ref5$lang; | ||
var _ref5$link_type = _ref5.link_type; | ||
let link_type = _ref5$link_type === undefined ? 'any' : _ref5$link_type; | ||
let name = _ref5.name; | ||
var _ref5$over_ = _ref5.over_18; | ||
let over_18 = _ref5$over_ === undefined ? false : _ref5$over_; | ||
let public_description = _ref5.public_description; | ||
var _ref5$public_traffic = _ref5.public_traffic; | ||
let public_traffic = _ref5$public_traffic === undefined ? false : _ref5$public_traffic; | ||
var _ref5$show_media = _ref5.show_media; | ||
let show_media = _ref5$show_media === undefined ? false : _ref5$show_media; | ||
var _ref5$spam_comments = _ref5.spam_comments; | ||
let spam_comments = _ref5$spam_comments === undefined ? 'high' : _ref5$spam_comments; | ||
var _ref5$spam_links = _ref5.spam_links; | ||
let spam_links = _ref5$spam_links === undefined ? 'high' : _ref5$spam_links; | ||
var _ref5$spam_selfposts = _ref5.spam_selfposts; | ||
let spam_selfposts = _ref5$spam_selfposts === undefined ? 'high' : _ref5$spam_selfposts; | ||
let sr = _ref5.sr; | ||
var _ref5$submit_link_lab = _ref5.submit_link_label; | ||
let submit_link_label = _ref5$submit_link_lab === undefined ? '' : _ref5$submit_link_lab; | ||
var _ref5$submit_text_lab = _ref5.submit_text_label; | ||
let submit_text_label = _ref5$submit_text_lab === undefined ? '' : _ref5$submit_text_lab; | ||
var _ref5$submit_text = _ref5.submit_text; | ||
let submit_text = _ref5$submit_text === undefined ? '' : _ref5$submit_text; | ||
var _ref5$suggested_comme = _ref5.suggested_comment_sort; | ||
let suggested_comment_sort = _ref5$suggested_comme === undefined ? 'confidence' : _ref5$suggested_comme; | ||
let title = _ref5.title; | ||
var _ref5$type = _ref5.type; | ||
let type = _ref5$type === undefined ? 'public' : _ref5$type; | ||
let subreddit_type = _ref5.subreddit_type; | ||
let // This is the same as `type`, but for some reason the name is changed when fetching current settings | ||
wiki_edit_age = _ref7.wiki_edit_age; | ||
let wiki_edit_karma = _ref7.wiki_edit_karma; | ||
var _ref7$wikimode = _ref7.wikimode; | ||
let wikimode = _ref7$wikimode === undefined ? 'modonly' : _ref7$wikimode; | ||
wiki_edit_age = _ref5.wiki_edit_age; | ||
let wiki_edit_karma = _ref5.wiki_edit_karma; | ||
var _ref5$wikimode = _ref5.wikimode; | ||
let wikimode = _ref5$wikimode === undefined ? 'modonly' : _ref5$wikimode; | ||
@@ -704,2 +907,13 @@ return promise_wrap(this._post({ uri: 'api/site_admin', form: { | ||
* @returns {Promise} A Promise for the newly-created subreddit object. | ||
* @example | ||
* | ||
* r.create_subreddit({ | ||
* name: 'snoowrap_testing2', | ||
* title: 'snoowrap testing: the sequel', | ||
* public_description: 'thanks for reading the snoowrap docs!', | ||
* description: 'This text will go on the sidebar', | ||
* type: 'private' | ||
* }).then(console.log) | ||
* // => Subreddit { display_name: 'snoowrap_testing2' } | ||
* // (/r/snoowrap_testing2 created on reddit) | ||
*/ | ||
@@ -714,5 +928,14 @@ create_subreddit(options) { | ||
* @returns {Promise} An Array of subreddit objects corresponding to the search results | ||
* @example | ||
* | ||
* r.search_subreddit_topics({query: 'movies'}).then(console.log) | ||
* // => [ | ||
* // Subreddit { display_name: 'tipofmytongue' }, | ||
* // Subreddit { display_name: 'remove' }, | ||
* // Subreddit { display_name: 'horror' }, | ||
* // ... | ||
* // ] | ||
*/ | ||
search_subreddit_topics(_ref8) { | ||
let query = _ref8.query; | ||
search_subreddit_topics(_ref6) { | ||
let query = _ref6.query; | ||
@@ -725,2 +948,17 @@ return promise_wrap(this._get({ uri: 'api/subreddits_by_topic', qs: { query } }).then(results => _.map(results, 'name').map(this.get_subreddit.bind(this)))); | ||
* @returns {Promise} A Listing containing Subreddits | ||
* @example | ||
* | ||
* r.get_subscriptions({limit: 2}).then(console.log) | ||
* // => Listing [ | ||
* // Subreddit { | ||
* // display_name: 'gadgets', | ||
* // title: 'reddit gadget guide', | ||
* // ... | ||
* // }, | ||
* // Subreddit { | ||
* // display_name: 'sports', | ||
* // title: 'the sportspage of the Internet', | ||
* // ... | ||
* // } | ||
* // ] | ||
*/ | ||
@@ -734,2 +972,13 @@ get_subscriptions(options) { | ||
* @returns {Promise} A Listing containing Subreddits | ||
* @example | ||
* | ||
* r.get_contributor_subreddits().then(console.log) | ||
* // => Listing [ | ||
* // Subreddit { | ||
* // display_name: 'snoowrap_testing', | ||
* // title: 'snoowrap', | ||
* // ... | ||
* // } | ||
* // ] | ||
* | ||
*/ | ||
@@ -743,2 +992,12 @@ get_contributor_subreddits(options) { | ||
* @returns {Promise} A Listing containing Subreddits | ||
* @example | ||
* | ||
* r.get_moderated_subreddits().then(console.log) | ||
* // => Listing [ | ||
* // Subreddit { | ||
* // display_name: 'snoowrap_testing', | ||
* // title: 'snoowrap', | ||
* // ... | ||
* // } | ||
* // ] | ||
*/ | ||
@@ -790,8 +1049,2 @@ get_moderated_subreddits(options) { | ||
} | ||
_friend(options) { | ||
return this._post({ uri: `${ options.sub ? `r/${ options.sub }/` : '' }api/friend`, form: _.assign(options, { api_type }) }); | ||
} | ||
_unfriend(options) { | ||
return this._post({ uri: `${ options.sub ? `r/${ options.sub }/` : '' }api/unfriend`, form: _.assign(options, { api_type }) }); | ||
} | ||
/** | ||
@@ -818,8 +1071,8 @@ * @summary Checks whether a given username is available for registration | ||
*/ | ||
create_livethread(_ref9) { | ||
let title = _ref9.title; | ||
let description = _ref9.description; | ||
let resources = _ref9.resources; | ||
var _ref9$nsfw = _ref9.nsfw; | ||
let nsfw = _ref9$nsfw === undefined ? false : _ref9$nsfw; | ||
create_livethread(_ref7) { | ||
let title = _ref7.title; | ||
let description = _ref7.description; | ||
let resources = _ref7.resources; | ||
var _ref7$nsfw = _ref7.nsfw; | ||
let nsfw = _ref7$nsfw === undefined ? false : _ref7$nsfw; | ||
@@ -853,14 +1106,14 @@ return promise_wrap(this._post({ | ||
*/ | ||
create_multireddit(_ref10) { | ||
let name = _ref10.name; | ||
let description = _ref10.description; | ||
let subreddits = _ref10.subreddits; | ||
var _ref10$visibility = _ref10.visibility; | ||
let visibility = _ref10$visibility === undefined ? 'private' : _ref10$visibility; | ||
var _ref10$icon_name = _ref10.icon_name; | ||
let icon_name = _ref10$icon_name === undefined ? '' : _ref10$icon_name; | ||
var _ref10$key_color = _ref10.key_color; | ||
let key_color = _ref10$key_color === undefined ? '#000000' : _ref10$key_color; | ||
var _ref10$weighting_sche = _ref10.weighting_scheme; | ||
let weighting_scheme = _ref10$weighting_sche === undefined ? 'classic' : _ref10$weighting_sche; | ||
create_multireddit(_ref8) { | ||
let name = _ref8.name; | ||
let description = _ref8.description; | ||
let subreddits = _ref8.subreddits; | ||
var _ref8$visibility = _ref8.visibility; | ||
let visibility = _ref8$visibility === undefined ? 'private' : _ref8$visibility; | ||
var _ref8$icon_name = _ref8.icon_name; | ||
let icon_name = _ref8$icon_name === undefined ? '' : _ref8$icon_name; | ||
var _ref8$key_color = _ref8.key_color; | ||
let key_color = _ref8$key_color === undefined ? '#000000' : _ref8$key_color; | ||
var _ref8$weighting_schem = _ref8.weighting_scheme; | ||
let weighting_scheme = _ref8$weighting_schem === undefined ? 'classic' : _ref8$weighting_schem; | ||
@@ -877,2 +1130,72 @@ return this._post({ uri: 'api/multi', form: { model: JSON.stringify({ | ||
} | ||
_revoke_token(token) { | ||
return request_handler.base_client_request(this, 'post', [{ uri: 'api/v1/revoke_token', form: { token } }]); | ||
} | ||
/** | ||
* @summary Invalidates the current access token. | ||
* @returns {Promise} A Promise that fulfills when this request is complete | ||
* @desc **Note**: This can only be used if the current requester was supplied with a `client_id` and `client_secret`. If the | ||
current requester was supplied with a refresh token, it will automatically create a new access token if any more requests | ||
are made after this one. | ||
* @example | ||
* | ||
* r.revoke_access_token(); | ||
*/ | ||
revoke_access_token() { | ||
return this._revoke_token(this.access_token).then(() => { | ||
this.access_token = undefined; | ||
}); | ||
} | ||
/** | ||
* @summary Invalidates the current refresh token. | ||
* @returns {Promise} A Promise that fulfills when this request is complete | ||
* @desc **Note**: This can only be used if the current requester was supplied with a `client_id` and `client_secret`. All | ||
access tokens generated by this refresh token will also be invalidated. This effectively de-authenticates the requester and | ||
prevents it from making any more valid requests. This should only be used in a few cases, e.g. if this token has | ||
been accidentally leaked to a third party. | ||
* @example | ||
* | ||
* r.revoke_refresh_token(); | ||
*/ | ||
revoke_refresh_token() { | ||
return this._revoke_token(this.refresh_token).then(() => { | ||
this.refresh_token = undefined; | ||
this.access_token = undefined; // Revoking a refresh token also revokes any associated access tokens. | ||
}); | ||
} | ||
_select_flair(_ref9) { | ||
var _this = this; | ||
let flair_template_id = _ref9.flair_template_id; | ||
let link = _ref9.link; | ||
let name = _ref9.name; | ||
let text = _ref9.text; | ||
let subreddit_name = _ref9.subreddit_name; | ||
return _asyncToGenerator(function* () { | ||
if (!flair_template_id) { | ||
throw new errors.InvalidMethodCallError('Error: No flair template ID provided'); | ||
} | ||
return yield _this._post({ uri: `r/${ yield subreddit_name }/api/selectflair`, form: { | ||
api_type, flair_template_id, link, name, text } | ||
}); | ||
})(); | ||
} | ||
_assign_flair(_ref10) { | ||
var _this2 = this; | ||
let css_class = _ref10.css_class; | ||
let link = _ref10.link; | ||
let name = _ref10.name; | ||
let text = _ref10.text; | ||
let subreddit_name = _ref10.subreddit_name; | ||
return _asyncToGenerator(function* () { | ||
return yield _this2._post({ uri: `r/${ yield subreddit_name }/api/flair`, form: { api_type, name, text, link, css_class } }); | ||
})(); | ||
} | ||
_friend(options) { | ||
return this._post({ uri: `${ options.sub ? `r/${ options.sub }/` : '' }api/friend`, form: _.assign(options, { api_type }) }); | ||
} | ||
_unfriend(options) { | ||
return this._post({ uri: `${ options.sub ? `r/${ options.sub }/` : '' }api/unfriend`, form: _.assign(options, { api_type }) }); | ||
} | ||
}; | ||
@@ -879,0 +1202,0 @@ |
{ | ||
"name": "snoowrap", | ||
"version": "0.9.4", | ||
"version": "0.9.5", | ||
"license": "MIT", | ||
@@ -29,10 +29,2 @@ "description": "A Node.js wrapper for the reddit API", | ||
}, | ||
"babel": { | ||
"plugins": [ | ||
"transform-async-to-generator", | ||
"transform-es2015-destructuring", | ||
"transform-es2015-parameters", | ||
"transform-es2015-spread" | ||
] | ||
}, | ||
"homepage": "https://github.com/not-an-aardvark/snoowrap", | ||
@@ -39,0 +31,0 @@ "dependencies": { |
@@ -63,3 +63,4 @@ # snoowrap [![Build Status](https://travis-ci.org/not-an-aardvark/snoowrap.svg?branch=master)](https://travis-ci.org/not-an-aardvark/snoowrap) | ||
client_secret: 'put your client secret here', | ||
refresh_token: 'put your refresh token here' | ||
refresh_token: 'put your refresh token here', | ||
user_agent: 'myApp v1.0.0 by me' // learn more about User-Agent here: https://github.com/reddit/reddit/wiki/API | ||
}); | ||
@@ -66,0 +67,0 @@ |
178576
3654
154