Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Commit

Permalink
feat: get flair selections for subreddit (#317)
Browse files Browse the repository at this point in the history
Subreddit#getLinkFlairTemplates does now have ability to get all flair
templates if no `linkId` was given
  • Loading branch information
Eric Gustavsson authored May 15, 2021
1 parent e8cf41c commit 498a8d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/objects/Subreddit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default class Subreddit extends RedditContent<Subreddit> {
getControversial(options?: ListingOptions & { time?: string }): Promise<Listing<Submission>>;
getEdited(options?: ListingOptions & { only?: 'links' | 'comments' }): Promise<Listing<Submission | Comment>>;
getHot(options?: ListingOptions): Promise<Listing<Submission>>;
getLinkFlairTemplates(linkId: string): Promise<FlairTemplate[]>;
getLinkFlairTemplates(linkId?: string): Promise<FlairTemplate[]>;
getModerationLog(opts?: ListingOptions & { mods?: string[]; type?: ModActionType}): Promise<Listing<ModAction>>;
getModerators(options?: ListingOptions & { name?: string }): RedditUser[];
getModmail(options?: ListingOptions): Promise<Listing<PrivateMessage>>;
Expand Down
13 changes: 7 additions & 6 deletions src/objects/Subreddit.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ const Subreddit = class Subreddit extends RedditContent {
createLinkFlairTemplate (options) {
return this._createFlairTemplate({...options, flair_type: 'LINK_FLAIR'});
}
_getFlairOptions ({name, link} = {}) { // TODO: Add shortcuts for this on RedditUser and Submission
return this._post({uri: `r/${this.display_name}/api/flairselector`, form: {name, link}});
_getFlairOptions ({name, link, is_newlink} = {}) { // TODO: Add shortcuts for this on RedditUser and Submission
return this._post({uri: `r/${this.display_name}/api/flairselector`, form: {name, link, is_newlink}});
}
/**
* @summary Gets the flair templates for a given link.
* @param {string} linkId The link's base36 ID
* @summary Gets the flair templates for the subreddit or a given link.
* @param {string} [linkId] The link's base36 ID
* @returns {Promise} An Array of flair template options
* @example
*
Expand All @@ -116,8 +116,9 @@ const Subreddit = class Subreddit extends RedditContent {
// ...
// ]
*/
getLinkFlairTemplates (linkId) {
return this._getFlairOptions({link: linkId}).get('choices');
getLinkFlairTemplates (linkId = null) {
const options = linkId ? {link: linkId} : {is_newlink: true};
return this._getFlairOptions(options).get('choices');
}
/**
* @summary Gets the list of user flair templates on this subreddit.
Expand Down

0 comments on commit 498a8d5

Please sign in to comment.