reddit

package
v2.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2022 License: BSD-3-Clause, MIT Imports: 22 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. Reddit also sometimes sends errors with 200 codes; we check for those too.

func DoRequest

func DoRequest(ctx context.Context, req *http.Request) (*http.Response, error)

DoRequest submits an HTTP request.

func DoRequestWithClient

func DoRequestWithClient(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error)

DoRequestWithClient submits an HTTP request using the specified client.

func FromEnv

func FromEnv(c *Client) error

FromEnv configures the client with values from environment variables. Supported environment variables: GO_REDDIT_CLIENT_ID to set the client's id. GO_REDDIT_CLIENT_SECRET to set the client's secret. GO_REDDIT_CLIENT_USERNAME to set the client's username. GO_REDDIT_CLIENT_PASSWORD to set the client's password.

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int value to store v and returns a pointer to it.

func StreamDiscardInitial

func StreamDiscardInitial(c *streamConfig)

StreamDiscardInitial will discard data from the first fetch for the stream.

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

Types

type APIError

type APIError struct {
	Label  string
	Reason string
	Field  string
}

APIError is an error coming from Reddit.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) UnmarshalJSON

func (e *APIError) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type AccountService

type AccountService struct {
	// contains filtered or unexported fields
}

AccountService handles communication with the account related methods of the Reddit API.

Reddit API docs: https://www.reddit.com/dev/api/#section_account

func (*AccountService) AddTrusted

func (s *AccountService) AddTrusted(ctx context.Context, username string) (*Response, error)

AddTrusted adds a user to your trusted users. This is not visible in the Reddit API docs.

func (*AccountService) Blocked

func (s *AccountService) Blocked(ctx context.Context) ([]Relationship, *Response, error)

Blocked returns a list of your blocked users.

func (*AccountService) Friends

func (s *AccountService) Friends(ctx context.Context) ([]Relationship, *Response, error)

Friends returns a list of your friends.

func (*AccountService) Info

func (s *AccountService) Info(ctx context.Context) (*User, *Response, error)

Info returns some general information about your account.

func (*AccountService) Karma

Karma returns a breakdown of your karma per subreddit.

func (*AccountService) Messaging

Messaging returns blocked users and trusted users, respectively.

func (*AccountService) RemoveTrusted

func (s *AccountService) RemoveTrusted(ctx context.Context, username string) (*Response, error)

RemoveTrusted removes a user from your trusted users. This is not visible in the Reddit API docs.

func (*AccountService) Settings

func (s *AccountService) Settings(ctx context.Context) (*Settings, *Response, error)

Settings returns your account settings.

func (*AccountService) Trophies

func (s *AccountService) Trophies(ctx context.Context) ([]*Trophy, *Response, error)

Trophies returns a list of your trophies.

func (*AccountService) Trusted

func (s *AccountService) Trusted(ctx context.Context) ([]Relationship, *Response, error)

Trusted returns a list of your trusted users.

func (*AccountService) UpdateSettings

func (s *AccountService) UpdateSettings(ctx context.Context, settings *Settings) (*Settings, *Response, error)

UpdateSettings updates your account settings and returns the modified version.

type Ban

type Ban struct {
	*Relationship
	// nil means the ban is permanent
	DaysLeft *int   `json:"days_left"`
	Note     string `json:"note,omitempty"`
}

Ban represents a banned relationship.

type BanConfig

type BanConfig struct {
	Reason string `url:"reason,omitempty"`
	// Not visible to the user being banned.
	ModNote string `url:"note,omitempty"`
	// How long the ban will last. 0-999. Leave nil for permanent.
	Days *int `url:"duration,omitempty"`
	// Note to include in the ban message to the user.
	Message string `url:"ban_message,omitempty"`
}

BanConfig configures the ban of the user being banned.

type Blocked

type Blocked struct {
	Blocked   string     `json:"name,omitempty"`
	BlockedID string     `json:"id,omitempty"`
	Created   *Timestamp `json:"date,omitempty"`
}

Blocked represents a blocked relationship.

type ButtonWidget

type ButtonWidget struct {
	Name        string          `json:"shortName,omitempty"`
	Description string          `json:"description,omitempty"`
	Buttons     []*WidgetButton `json:"buttons,omitempty"`
	// contains filtered or unexported fields
}

ButtonWidget displays up to 10 button style links with customizable font colors for each button.

func (*ButtonWidget) GetID

func (w *ButtonWidget) GetID() string

type Client

type Client struct {
	BaseURL  *url.URL
	TokenURL *url.URL

	ID       string
	Secret   string
	Username string
	Password string

	Account    *AccountService
	Collection *CollectionService
	Comment    *CommentService
	Emoji      *EmojiService
	Flair      *FlairService
	Gold       *GoldService
	Listings   *ListingsService
	LiveThread *LiveThreadService
	Message    *MessageService
	Moderation *ModerationService
	Multi      *MultiService
	Post       *PostService
	Stream     *StreamService
	Subreddit  *SubredditService
	User       *UserService
	Widget     *WidgetService
	Wiki       *WikiService
	// contains filtered or unexported fields
}

Client manages communication with the Reddit API.

func DefaultClient

func DefaultClient() *Client

DefaultClient returns a valid, read-only client with limited access to the Reddit API.

func NewClient

func NewClient(credentials Credentials, opts ...Opt) (*Client, error)

NewClient returns a new Reddit API client. Use an Opt to configure the client credentials, such as WithHTTPClient or WithUserAgent. If the FromEnv option is used with the correct environment variables, an empty struct can be passed in as the credentials, since they will be overridden.

func NewReadonlyClient

func NewReadonlyClient(opts ...Opt) (*Client, error)

NewReadonlyClient returns a new read-only Reddit API client. The client will have limited access to the Reddit API. Options that modify credentials (such as FromEnv) won't have any effect on this client.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response will be written to v, without attempting to decode it.

func (*Client) NewJSONRequest

func (c *Client) NewJSONRequest(method string, path string, body interface{}) (*http.Request, error)

NewJSONRequest creates an API request with a JSON body. The path is the relative URL which will be resolved to the BaseURL of the Client. It should always be specified without a preceding slash.

func (*Client) NewRequest

func (c *Client) NewRequest(method string, path string, form url.Values) (*http.Request, error)

NewRequest creates an API request with form data as the body. The path is the relative URL which will be resolved to the BaseURL of the Client. It should always be specified without a preceding slash.

func (*Client) OnRequestCompleted

func (c *Client) OnRequestCompleted(rc RequestCompletionCallback)

OnRequestCompleted sets the client's request completion callback.

func (*Client) UserAgent

func (c *Client) UserAgent() string

UserAgent returns the client's user agent.

type Collection

type Collection struct {
	ID      string     `json:"collection_id,omitempty"`
	Created *Timestamp `json:"created_at_utc,omitempty"`
	Updated *Timestamp `json:"last_update_utc,omitempty"`

	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	Permalink   string `json:"permalink,omitempty"`
	Layout      string `json:"display_layout,omitempty"`

	SubredditID string `json:"subreddit_id,omitempty"`
	Author      string `json:"author_name,omitempty"`
	AuthorID    string `json:"author_id,omitempty"`

	// Post at the top of the collection.
	// This does not appear when getting a list of collections.
	PrimaryPostID string   `json:"primary_link_id,omitempty"`
	PostIDs       []string `json:"link_ids,omitempty"`
}

Collection is a mod curated group of posts within a subreddit.

type CollectionCreateRequest

type CollectionCreateRequest struct {
	Title       string `url:"title"`
	Description string `url:"description,omitempty"`
	SubredditID string `url:"sr_fullname"`
	// One of: TIMELINE, GALLERY.
	Layout string `url:"display_layout,omitempty"`
}

CollectionCreateRequest represents a request to create a collection.

type CollectionService

type CollectionService struct {
	// contains filtered or unexported fields
}

CollectionService handles communication with the collection related methods of the Reddit API.

Reddit API docs: https://www.reddit.com/dev/api/#section_collections

func (*CollectionService) AddPost

func (s *CollectionService) AddPost(ctx context.Context, postID, collectionID string) (*Response, error)

AddPost adds a post (via its full ID) to a collection (via its id).

func (*CollectionService) Create

func (s *CollectionService) Create(ctx context.Context, createRequest *CollectionCreateRequest) (*Collection, *Response, error)

Create a collection.

func (*CollectionService) Delete

func (s *CollectionService) Delete(ctx context.Context, id string) (*Response, error)

Delete a collection via its id.

func (*CollectionService) Follow

func (s *CollectionService) Follow(ctx context.Context, id string) (*Response, error)

Follow a collection.

func (*CollectionService) FromSubreddit

func (s *CollectionService) FromSubreddit(ctx context.Context, id string) ([]*Collection, *Response, error)

FromSubreddit gets all collections in the subreddit.

func (*CollectionService) Get

Get gets a collection by its ID.

func (*CollectionService) RemovePost

func (s *CollectionService) RemovePost(ctx context.Context, postID, collectionID string) (*Response, error)

RemovePost removes a post (via its full ID) from a collection (via its id).

func (*CollectionService) ReorderPosts

func (s *CollectionService) ReorderPosts(ctx context.Context, collectionID string, postIDs ...string) (*Response, error)

ReorderPosts reorders posts in a collection.

func (*CollectionService) Unfollow

func (s *CollectionService) Unfollow(ctx context.Context, id string) (*Response, error)

Unfollow a collection.

func (*CollectionService) UpdateDescription

func (s *CollectionService) UpdateDescription(ctx context.Context, id string, description string) (*Response, error)

UpdateDescription updates a collection's description.

func (*CollectionService) UpdateLayoutGallery

func (s *CollectionService) UpdateLayoutGallery(ctx context.Context, id string) (*Response, error)

UpdateLayoutGallery updates a collection's layout to the gallery format.

func (*CollectionService) UpdateLayoutTimeline

func (s *CollectionService) UpdateLayoutTimeline(ctx context.Context, id string) (*Response, error)

UpdateLayoutTimeline updates a collection's layout to the timeline format.

func (*CollectionService) UpdateTitle

func (s *CollectionService) UpdateTitle(ctx context.Context, id string, title string) (*Response, error)

UpdateTitle updates a collection's title.

type Comment

type Comment struct {
	ID      string     `json:"id,omitempty"`
	FullID  string     `json:"name,omitempty"`
	Created *Timestamp `json:"created_utc,omitempty"`
	Edited  *Timestamp `json:"edited,omitempty"`

	ParentID  string `json:"parent_id,omitempty"`
	Permalink string `json:"permalink,omitempty"`

	Body            string `json:"body,omitempty"`
	Author          string `json:"author,omitempty"`
	AuthorID        string `json:"author_fullname,omitempty"`
	AuthorFlairText string `json:"author_flair_text,omitempty"`
	AuthorFlairID   string `json:"author_flair_template_id,omitempty"`

	SubredditName         string `json:"subreddit,omitempty"`
	SubredditNamePrefixed string `json:"subreddit_name_prefixed,omitempty"`
	SubredditID           string `json:"subreddit_id,omitempty"`

	// Indicates if you've upvote/downvoted (true/false).
	// If neither, it will be nil.
	Likes *bool `json:"likes"`

	Score            int `json:"score"`
	Controversiality int `json:"controversiality"`

	PostID string `json:"link_id,omitempty"`
	// This doesn't appear consistently.
	PostTitle string `json:"link_title,omitempty"`
	// This doesn't appear consistently.
	PostPermalink string `json:"link_permalink,omitempty"`
	// This doesn't appear consistently.
	PostAuthor string `json:"link_author,omitempty"`
	// This doesn't appear consistently.
	PostNumComments *int `json:"num_comments,omitempty"`

	IsSubmitter bool `json:"is_submitter"`
	ScoreHidden bool `json:"score_hidden"`
	Saved       bool `json:"saved"`
	Stickied    bool `json:"stickied"`
	Locked      bool `json:"locked"`
	CanGild     bool `json:"can_gild"`
	NSFW        bool `json:"over_18"`

	Replies Replies `json:"replies"`
}

Comment is a comment posted by a user.

func (*Comment) HasMore

func (c *Comment) HasMore() bool

HasMore determines whether the comment has more replies to load in its reply tree.

type CommentService

type CommentService struct {
	// contains filtered or unexported fields
}

CommentService handles communication with the comment related methods of the Reddit API.

Reddit API docs: https://www.reddit.com/dev/api/#section_links_and_comments

func (CommentService) Delete

func (s CommentService) Delete(ctx context.Context, id string) (*Response, error)

Delete a post or comment via its full ID.

func (CommentService) DisableReplies

func (s CommentService) DisableReplies(ctx context.Context, id string) (*Response, error)

DisableReplies dsables inbox replies for one of your posts or comments.

func (CommentService) Downvote

func (s CommentService) Downvote(ctx context.Context, id string) (*Response, error)

Downvote a post or a comment.

func (*CommentService) Edit

func (s *CommentService) Edit(ctx context.Context, id string, text string) (*Comment, *Response, error)

Edit a comment.

func (CommentService) EnableReplies

func (s CommentService) EnableReplies(ctx context.Context, id string) (*Response, error)

EnableReplies enables inbox replies for one of your posts or comments.

func (*CommentService) LoadMoreReplies

func (s *CommentService) LoadMoreReplies(ctx context.Context, comment *Comment) (*Response, error)

LoadMoreReplies retrieves more replies that were left out when initially fetching the comment.

func (CommentService) Lock

func (s CommentService) Lock(ctx context.Context, id string) (*Response, error)

Lock a post or comment, preventing it from receiving new comments.

func (CommentService) RemoveVote

func (s CommentService) RemoveVote(ctx context.Context, id string) (*Response, error)

RemoveVote removes your vote on a post or a comment.

func (CommentService) Report

func (s CommentService) Report(ctx context.Context, id string, reason string) (*Response, error)

Report a post or comment. The reason must not be longer than 100 characters.

func (CommentService) Save

func (s CommentService) Save(ctx context.Context, id string) (*Response, error)

Save a post or comment.

func (*CommentService) Submit

func (s *CommentService) Submit(ctx context.Context, parentID string, text string) (*Comment, *Response, error)

Submit a comment as a reply to a post, comment, or message. parentID is the full ID of the thing being replied to.

func (CommentService) Unlock

func (s CommentService) Unlock(ctx context.Context, id string) (*Response, error)

Unlock a post or comment, allowing it to receive new comments.

func (CommentService) Unsave

func (s CommentService) Unsave(ctx context.Context, id string) (*Response, error)

Unsave a post or comment.

func (CommentService) Upvote

func (s CommentService) Upvote(ctx context.Context, id string) (*Response, error)

Upvote a post or a comment.

type CommunityDetailsWidget

type CommunityDetailsWidget struct {
	Name        string `json:"shortName,omitempty"`
	Description string `json:"description,omitempty"`

	Subscribers      int `json:"subscribersCount"`
	CurrentlyViewing int `json:"currentlyViewingCount"`

	SubscribersText      string `json:"subscribersText,omitempty"`
	CurrentlyViewingText string `json:"currentlyViewingText,omitempty"`
	// contains filtered or unexported fields
}

CommunityDetailsWidget displays your subscriber count, users online, and community description, as defined in your subreddit settings. You can customize the displayed text for subscribers and users currently viewing the community.

func (*CommunityDetailsWidget) GetID

func (w *CommunityDetailsWidget) GetID() string

type CommunityListWidget

type CommunityListWidget struct {
	Name        string             `json:"shortName,omitempty"`
	Communities []*WidgetCommunity `json:"data,omitempty"`
	// contains filtered or unexported fields
}

CommunityListWidget display a list of up to 10 other communities (subreddits).

func (*CommunityListWidget) GetID

func (w *CommunityListWidget) GetID() string

type CommunityListWidgetCreateRequest

type CommunityListWidgetCreateRequest struct {
	Style *WidgetStyle `json:"styles,omitempty"`
	// No longer than 30 characters.
	Name        string   `json:"shortName,omitempty"`
	Communities []string `json:"data,omitempty"`
}

CommunityListWidgetCreateRequest represents a requets to create a community list widget.

func (*CommunityListWidgetCreateRequest) MarshalJSON

func (r *CommunityListWidgetCreateRequest) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

type Credentials

type Credentials struct {
	ID       string
	Secret   string
	Username string
	Password string
}

Credentials are used to authenticate to make requests to the Reddit API.

type CustomWidget

type CustomWidget struct {
	Name string `json:"shortName,omitempty"`
	Text string `json:"text,omitempty"`

	StyleSheet    string         `json:"css,omitempty"`
	StyleSheetURL string         `json:"stylesheetUrl,omitempty"`
	Images        []*WidgetImage `json:"imageData,omitempty"`
	// contains filtered or unexported fields
}

CustomWidget is a custom widget.

func (*CustomWidget) GetID

func (w *CustomWidget) GetID() string

type Emoji

type Emoji struct {
	Name             string `json:"name,omitempty"`
	URL              string `json:"url,omitempty"`
	UserFlairAllowed bool   `json:"user_flair_allowed,omitempty"`
	PostFlairAllowed bool   `json:"post_flair_allowed,omitempty"`
	ModFlairOnly     bool   `json:"mod_flair_only,omitempty"`
	// ID of the user who created this emoji.
	CreatedBy string `json:"created_by,omitempty"`
}

Emoji is a graphic element you can include in a post flair or user flair.

type EmojiCreateOrUpdateRequest

type EmojiCreateOrUpdateRequest struct {
	Name             string `url:"name"`
	UserFlairAllowed *bool  `url:"user_flair_allowed,omitempty"`
	PostFlairAllowed *bool  `url:"post_flair_allowed,omitempty"`
	ModFlairOnly     *bool  `url:"mod_flair_only,omitempty"`
}

EmojiCreateOrUpdateRequest represents a request to create/update an emoji.

type EmojiService

type EmojiService struct {
	// contains filtered or unexported fields
}

EmojiService handles communication with the emoji related methods of the Reddit API.

Reddit API docs: https://www.reddit.com/dev/api/#section_emoji

func (*EmojiService) Delete

func (s *EmojiService) Delete(ctx context.Context, subreddit string, emoji string) (*Response, error)

Delete the emoji from the subreddit.

func (*EmojiService) DisableCustomSize

func (s *EmojiService) DisableCustomSize(ctx context.Context, subreddit string) (*Response, error)

DisableCustomSize disables the custom emoji size in the subreddit.

func (*EmojiService) Get

func (s *EmojiService) Get(ctx context.Context, subreddit string) ([]*Emoji, []*Emoji, *Response, error)

Get the default set of Reddit emojis and those of the subreddit, respectively.

func (*EmojiService) SetSize

func (s *EmojiService) SetSize(ctx context.Context, subreddit string, height, width int) (*Response, error)

SetSize sets the custom emoji size in the subreddit. Both height and width must be between 1 and 40 (inclusive).

func (*EmojiService) Update

func (s *EmojiService) Update(ctx context.Context, subreddit string, updateRequest *EmojiCreateOrUpdateRequest) (*Response, error)

Update updates an emoji on the subreddit.

func (*EmojiService) Upload

func (s *EmojiService) Upload(ctx context.Context, subreddit string, createRequest *EmojiCreateOrUpdateRequest, imagePath string) (*Response, error)

Upload an emoji to the subreddit.

type ErrorResponse

type ErrorResponse struct {
	// HTTP response that caused this error
	Response *http.Response `json:"-"`

	// Error message
	Message string `json:"message"`
}

An ErrorResponse reports the error caused by an API request

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Flair

type Flair struct {
	ID   string `json:"id,omitempty"`
	Type string `json:"type,omitempty"`
	Text string `json:"text,omitempty"`

	Color           string `json:"text_color,omitempty"`
	BackgroundColor string `json:"background_color,omitempty"`
	CSSClass        string `json:"css_class,omitempty"`

	Editable bool `json:"text_editable"`
	ModOnly  bool `json:"mod_only"`
}

Flair is a tag that can be attached to a user or a post.

type FlairChangeRequest

type FlairChangeRequest struct {
	User     string
	Text     string
	CSSClass string
}

FlairChangeRequest represents a request to change a user's flair. If Text and CSSClass are empty, the request will just clear the user's flair.

type FlairChangeResponse

type FlairChangeResponse struct {
	// Whether or not the request was successful.
	OK       bool              `json:"ok"`
	Status   string            `json:"status"`
	Warnings map[string]string `json:"warnings,omitempty"`
	Errors   map[string]string `json:"errors,omitempty"`
}

FlairChangeResponse represents a response to a FlairChangeRequest.

type FlairChoice

type FlairChoice struct {
	TemplateID string `json:"flair_template_id"`
	Text       string `json:"flair_text"`
	Editable   bool   `json:"flair_text_editable"`
	Position   string `json:"flair_position"`
	CSSClass   string `json:"flair_css_class"`
}

FlairChoice is a choice of flair when selecting one for yourself or for a post.

type FlairConfigureRequest

type FlairConfigureRequest struct {
	// Enable user flair in the subreddit.
	UserFlairEnabled *bool `url:"flair_enabled,omitempty"`
	// One of: left, right.
	UserFlairPosition string `url:"flair_position,omitempty"`
	// Allow users to assign their own flair.
	UserFlairSelfAssignEnabled *bool `url:"flair_self_assign_enabled,omitempty"`

	// One of: none, left, right.
	PostFlairPosition string `url:"link_flair_position,omitempty"`
	// Allow submitters to assign their own post flair.
	PostFlairSelfAssignEnabled *bool `url:"link_flair_self_assign_enabled,omitempty"`
}

FlairConfigureRequest represents a request to configure a subreddit's flair settings. Not setting an attribute can have unexpected side effects, so assign every one just in case.

type FlairSelectRequest

type FlairSelectRequest struct {
	// The id of the template.
	ID string `url:"flair_template_id,omitempty"`
	// No longer than 64 characters.
	// Only use this if the flair is editable (it is by default if you're a mod of the subreddit).
	Text string `url:"text,omitempty"`
}

FlairSelectRequest represents a request to select a flair.

type FlairService

type FlairService struct {
	// contains filtered or unexported fields
}

FlairService handles communication with the flair related methods of the Reddit API.

Reddit API docs: https://www.reddit.com/dev/api/#section_flair

func (*FlairService) Assign

func (s *FlairService) Assign(ctx context.Context, subreddit, user string, request *FlairSelectRequest) (*Response, error)

Assign a flair to another user in the subreddit. This only works if you're a moderator of the subreddit, or if the user is you.

func (*FlairService) Change

func (s *FlairService) Change(ctx context.Context, subreddit string, requests []FlairChangeRequest) ([]*FlairChangeResponse, *Response, error)

Change the flair of multiple users in the subreddit at once. You have to be a moderator of the subreddit for this to work.

func (*FlairService) Choices

func (s *FlairService) Choices(ctx context.Context, subreddit string) ([]*FlairChoice, *FlairChoice, *Response, error)

Choices returns a list of flairs you can assign to yourself in the subreddit, and your current one.

func (*FlairService) ChoicesForNewPost

func (s *FlairService) ChoicesForNewPost(ctx context.Context, subreddit string) ([]*FlairChoice, *Response, error)

ChoicesForNewPost returns a list of flairs you can assign to a new post in a subreddit.

func (*FlairService) ChoicesForPost

func (s *FlairService) ChoicesForPost(ctx context.Context, postID string) ([]*FlairChoice, *FlairChoice, *Response, error)

ChoicesForPost returns a list of flairs you can assign to an existing post, and the current one assigned to it. If the post isn't yours, this only works if you're the moderator of the subreddit it's in.

func (*FlairService) ChoicesOf

func (s *FlairService) ChoicesOf(ctx context.Context, subreddit, username string) ([]*FlairChoice, *FlairChoice, *Response, error)

ChoicesOf returns a list of flairs the user can assign to themself in the subreddit, and their current one. Unless the user is you, this only works if you're a moderator of the subreddit.

func (*FlairService) Configure

func (s *FlairService) Configure(ctx context.Context, subreddit string, request *FlairConfigureRequest) (*Response, error)

Configure the subreddit's flair settings.

func (*FlairService) Delete

func (s *FlairService) Delete(ctx context.Context, subreddit, username string) (*Response, error)

Delete the flair of the user.

func (*FlairService) DeleteAllPostTemplates

func (s *FlairService) DeleteAllPostTemplates(ctx context.Context, subreddit string) (*Response, error)

DeleteAllPostTemplates deletes all post flair templates.

func (*FlairService) DeleteAllUserTemplates

func (s *FlairService) DeleteAllUserTemplates(ctx context.Context, subreddit string) (*Response, error)

DeleteAllUserTemplates deletes all user flair templates.

func (*FlairService) DeleteTemplate

func (s *FlairService) DeleteTemplate(ctx context.Context, subreddit, id string) (*Response, error)

DeleteTemplate deletes the flair template via its id.

func (*FlairService) Disable

func (s *FlairService) Disable(ctx context.Context, subreddit string) (*Response, error)

Disable your flair in the subreddit.

func (*FlairService) Enable

func (s *FlairService) Enable(ctx context.Context, subreddit string) (*Response, error)

Enable your flair in the subreddit.

func (*FlairService) GetPostFlairs

func (s *FlairService) GetPostFlairs(ctx context.Context, subreddit string) ([]*Flair, *Response, error)

GetPostFlairs returns the post flairs from the subreddit.

func (*FlairService) GetUserFlairs

func (s *FlairService) GetUserFlairs(ctx context.Context, subreddit string) ([]*Flair, *Response, error)

GetUserFlairs returns the user flairs from the subreddit.

func (*FlairService) ListUserFlairs

func (s *FlairService) ListUserFlairs(ctx context.Context, subreddit string) ([]*FlairSummary, *Response, error)

ListUserFlairs returns all flairs of individual users in the subreddit.

func (*FlairService) RemoveFromPost

func (s *FlairService) RemoveFromPost(ctx context.Context, postID string) (*Response, error)

RemoveFromPost removes the flair from the post. If the post isn't yours, you have to be a moderator of the post's subreddit for this to work.

func (*FlairService) ReorderPostTemplates

func (s *FlairService) ReorderPostTemplates(ctx context.Context, subreddit string, ids []string) (*Response, error)

ReorderPostTemplates reorders the post flair templates in the order provided in the slice. The order should contain every single flair id of this flair type; omitting any id will result in an error.

func (*FlairService) ReorderUserTemplates

func (s *FlairService) ReorderUserTemplates(ctx context.Context, subreddit string, ids []string) (*Response, error)

ReorderUserTemplates reorders the user flair templates in the order provided in the slice. The order should contain every single flair id of this flair type; omitting any id will result in an error.

func (*FlairService) Select

func (s *FlairService) Select(ctx context.Context, subreddit string, request *FlairSelectRequest) (*Response, error)

Select a flair to display next to your username in the subreddit.

func (*FlairService) SelectForPost

func (s *FlairService) SelectForPost(ctx context.Context, postID string, request *FlairSelectRequest) (*Response, error)

SelectForPost assigns a flair to the post. If the post isn't yours, you have to be a moderator of the post's subreddit for this to work.

func (*FlairService) UpsertPostTemplate

func (s *FlairService) UpsertPostTemplate(ctx context.Context, subreddit string, request *FlairTemplateCreateOrUpdateRequest) (*FlairTemplate, *Response, error)

UpsertPostTemplate creates a post flair template, or updates it if the request.ID is valid. It returns the created/updated flair template.

func (*FlairService) UpsertUserTemplate

func (s *FlairService) UpsertUserTemplate(ctx context.Context, subreddit string, request *FlairTemplateCreateOrUpdateRequest) (*FlairTemplate, *Response, error)

UpsertUserTemplate creates a user flair template, or updates it if the request.ID is valid. It returns the created/updated flair template.

type FlairSummary

type FlairSummary struct {
	User     string `json:"user,omitempty"`
	Text     string `json:"flair_text,omitempty"`
	CSSClass string `json:"flair_css_class,omitempty"`
}

FlairSummary is a condensed version of Flair.

type FlairTemplate

type FlairTemplate struct {
	ID string `json:"id"`
	// USER_FLAIR (for users) or LINK_FLAIR (for posts).
	Type    string `json:"flairType"`
	ModOnly bool   `json:"modOnly"`

	AllowableContent string              `json:"allowableContent"`
	Text             string              `json:"text"`
	TextType         string              `json:"type"`
	TextColor        string              `json:"textColor"`
	TextEditable     bool                `json:"textEditable"`
	RichText         []map[string]string `json:"richtext"`

	OverrideCSS     bool   `json:"overrideCss"`
	MaxEmojis       int    `json:"maxEmojis"`
	BackgroundColor string `json:"backgroundColor"`
	CSSClass        string `json:"cssClass"`
}

FlairTemplate is a generic flair structure that can users can use next to their username or posts in a subreddit.

type FlairTemplateCreateOrUpdateRequest

type FlairTemplateCreateOrUpdateRequest struct {
	// The id of the template. Only provide this if it's an update request.
	// If provided and it's not a valid id, the template will be created.
	ID string `url:"flair_template_id,omitempty"`

	// One of: all, emoji, text.
	AllowableContent string `url:"allowable_content,omitempty"`
	// No longer than 64 characters.
	Text string `url:"text,omitempty"`
	// One of: light, dark.
	TextColor string `url:"text_color,omitempty"`
	// Allow user to edit the text of the flair.
	TextEditable *bool `url:"text_editable,omitempty"`

	ModOnly *bool `url:"mod_only,omitempty"`

	// Between 1 and 10 (inclusive). Default: 10.
	MaxEmojis *int `url:"max_emojis,omitempty"`

	// One of: none, transparent, 6-digit rgb hex color, e.g. #AABBCC.
	BackgroundColor string `url:"background_color,omitempty"`
	CSSClass        string `url:"css_class,omitempty"`
}

FlairTemplateCreateOrUpdateRequest represents a request to create/update a flair template. Not setting an attribute can have unexpected side effects, so assign every one just in case.

type GoldService

type GoldService struct {
	// contains filtered or unexported fields
}

GoldService handles communication with the gold related methods of the Reddit API.

Reddit API docs: https://www.reddit.com/dev/api/#section_gold

func (*GoldService) Gild

func (s *GoldService) Gild(ctx context.Context, id string) (*Response, error)

Gild the post or comment via its full ID. This requires you to own Reddit coins and will consume them.

func (*GoldService) Give

func (s *GoldService) Give(ctx context.Context, username string, months int) (*Response, error)

Give the user between 1 and 36 (inclusive) months of gold. This requires you to own Reddit coins and will consume them.

type ImageWidget

type ImageWidget struct {
	Name   string             `json:"shortName,omitempty"`
	Images []*WidgetImageLink `json:"data,omitempty"`
	// contains filtered or unexported fields
}

ImageWidget display a random image from up to 10 selected images. The image can be clickable links.

func (*ImageWidget) GetID

func (w *ImageWidget) GetID() string

type JSONErrorResponse

type JSONErrorResponse struct {
	// HTTP response that caused this error.
	Response *http.Response `json:"-"`

	JSON struct {
		Errors []APIError `json:"errors,omitempty"`
	} `json:"json"`
}

JSONErrorResponse is an error response that sometimes gets returned with a 200 code.

func (*JSONErrorResponse) Error

func (r *JSONErrorResponse) Error() string

type ListDuplicatePostOptions

type ListDuplicatePostOptions struct {
	ListOptions
	// If empty, it'll search for duplicates in all subreddits.
	Subreddit string `url:"sr,omitempty"`
	// One of: num_comments, new.
	Sort string `url:"sort,omitempty"`
	// If true, the search will only return duplicates that are
	// crossposts of the original post.
	CrosspostsOnly bool `url:"crossposts_only,omitempty"`
}

ListDuplicatePostOptions defines possible options used when getting duplicates of a post, i.e. other submissions of the same URL.

type ListModActionOptions

type ListModActionOptions struct {
	// The max for the limit parameter here is 500.
	ListOptions
	// If empty, the search will return all action types.
	// One of: banuser, unbanuser, spamlink, removelink, approvelink, spamcomment, removecomment,
	// approvecomment, addmoderator, showcomment, invitemoderator, uninvitemoderator, acceptmoderatorinvite,
	// removemoderator, addcontributor, removecontributor, editsettings, editflair, distinguish, marknsfw,
	// wikibanned, wikicontributor, wikiunbanned, wikipagelisted, removewikicontributor, wikirevise,
	// wikipermlevel, ignorereports, unignorereports, setpermissions, setsuggestedsort, sticky, unsticky,
	// setcontestmode, unsetcontestmode, lock, unlock, muteuser, unmuteuser, createrule, editrule,
	// reorderrules, deleterule, spoiler, unspoiler, modmail_enrollment, community_styling, community_widgets,
	// markoriginalcontent, collections, events, hidden_award, add_community_topics, remove_community_topics,
	// create_scheduled_post, edit_scheduled_post, delete_scheduled_post, submit_scheduled_post,
	// edit_post_requirements, invitesubscriber, submit_content_rating_survey.
	Type string `url:"type,omitempty"`
	// If provided, only return the actions of this moderator.
	Moderator string `url:"mod,omitempty"`
}

ListModActionOptions defines possible options used when getting moderation actions in a subreddit.

type ListOptions

type ListOptions struct {
	// Maximum number of items to be returned.
	// Generally, the default is 25 and max is 100.
	Limit int `url:"limit,omitempty"`

	// The full ID of an item in the listing to use
	// as the anchor point of the list. Only items
	// appearing after it will be returned.
	After string `url:"after,omitempty"`

	// The full ID of an item in the listing to use
	// as the anchor point of the list. Only items
	// appearing before it will be returned.
	Before string `url:"before,omitempty"`
}

ListOptions specifies the optional parameters to various API calls that return a listing.

type ListPostOptions

type ListPostOptions struct {
	ListOptions
	// One of: hour, day, week, month, year, all.
	Time string `url:"t,omitempty"`
}

ListPostOptions defines possible options used when getting posts from a subreddit.

type ListPostSearchOptions

type ListPostSearchOptions struct {
	ListPostOptions
	// One of: relevance, hot, top, new, comments.
	Sort string `url:"sort,omitempty"`
}

ListPostSearchOptions defines possible options used when searching for posts within a subreddit.

type ListSubredditOptions

type ListSubredditOptions struct {
	ListOptions
	// One of: relevance, activity.
	Sort string `url:"sort,omitempty"`
}

ListSubredditOptions defines possible options used when searching for subreddits.

type ListUserOverviewOptions

type ListUserOverviewOptions struct {
	ListOptions
	// One of: hot, new, top, controversial.
	Sort string `url:"sort,omitempty"`
	// One of: hour, day, week, month, year, all.
	Time string `url:"t,omitempty"`
}

ListUserOverviewOptions defines possible options used when getting a user's post and/or comments.

type ListingsService

type ListingsService struct {
	// contains filtered or unexported fields
}

ListingsService handles communication with the listing related methods of the Reddit API.

Reddit API docs: https://www.reddit.com/dev/api/#section_listings

func (*ListingsService) Get

func (s *ListingsService) Get(ctx context.Context, ids ...string) ([]*Post, []*Comment, []*Subreddit, *Response, error)

Get posts, comments, and subreddits from their full IDs.

func (*ListingsService) GetPosts

func (s *ListingsService) GetPosts(ctx context.Context, ids ...string) ([]*Post, *Response, error)

GetPosts returns posts from their full IDs.

type LiveThread

type LiveThread struct {
	ID      string     `json:"id,omitempty"`
	FullID  string     `json:"name,omitempty"`
	Created *Timestamp `json:"created_utc,omitempty"`

	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	Resources   string `json:"resources,omitempty"`

	State             string `json:"state,omitempty"`
	ViewerCount       int    `json:"viewer_count"`
	ViewerCountFuzzed bool   `json:"viewer_count_fuzzed"`

	// Empty when a live thread has ended.
	WebSocketURL string `json:"websocket_url,omitempty"`

	Announcement bool `json:"is_announcement"`
	NSFW         bool `json:"nsfw"`
}

LiveThread is a thread on Reddit that provides real-time updates.

type LiveThreadContributor

type LiveThreadContributor struct {
	ID          string   `json:"id,omitempty"`
	Name        string   `json:"name,omitempty"`
	Permissions []string `json:"permissions,omitempty"`
}

LiveThreadContributor is a user that can contribute to a live thread.

type LiveThreadContributors

type LiveThreadContributors struct {
	Current []*LiveThreadContributor `json:"current_contributors"`
	// This is only filled if you are a contributor in the live thread with the "manage" permission.
	Invited []*LiveThreadContributor `json:"invited_contributors,omitempty"`
}

LiveThreadContributors is a list of users that can contribute to a live thread.

func (*LiveThreadContributors) UnmarshalJSON

func (c *LiveThreadContributors) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type LiveThreadCreateOrUpdateRequest

type LiveThreadCreateOrUpdateRequest struct {
	// No longer than 120 characters.
	Title       string `url:"title,omitempty"`
	Description string `url:"description,omitempty"`
	Resources   string `url:"resources,omitempty"`
	NSFW        *bool  `url:"nsfw,omitempty"`
}

LiveThreadCreateOrUpdateRequest represents a request to create/update a live thread.

type LiveThreadPermissions

type LiveThreadPermissions struct {
	All         bool `permission:"all"`
	Close       bool `permission:"close"`
	Discussions bool `permission:"discussions"`
	Edit        bool `permission:"edit"`
	Manage      bool `permission:"manage"`
	Settings    bool `permission:"settings"`
	// Posting updates to the thread.
	Update bool `permission:"update"`
}

LiveThreadPermissions are the different permissions contributors have or don't have for a live thread. Read about them here: https://mods.reddithelp.com/hc/en-us/articles/360009381491-User-Management-moderators-and-permissions

func (*LiveThreadPermissions) String

func (p *LiveThreadPermissions) String() (s string)

type LiveThreadService

type LiveThreadService struct {
	// contains filtered or unexported fields
}

LiveThreadService handles communication with the live thread related methods of the Reddit API.

Reddit API docs: https://www.reddit.com/dev/api/#section_live

func (*LiveThreadService) Accept

func (s *LiveThreadService) Accept(ctx context.Context, id string) (*Response, error)

Accept a pending invite to contribute to the live thread.

func (*LiveThreadService) Close

func (s *LiveThreadService) Close(ctx context.Context, id string) (*Response, error)

Close the thread permanently, disallowing future updates.

func (*LiveThreadService) Configure

Configure the thread. Requires the "settings" permission.

func (*LiveThreadService) Contributors

Contributors gets a list of users that are contributors to the live thread. If you are a contributor and you have the "manage" permission (to manage contributors), you also get a list of invited contributors that haven't yet accepted/refused their invitation.

func (*LiveThreadService) Create

Create a live thread and get its id.

func (*LiveThreadService) Delete

func (s *LiveThreadService) Delete(ctx context.Context, threadID, updateID string) (*Response, error)

Delete an update from the live thread. You must either be the author of the update or have the "edit" permission.

func (*LiveThreadService) Discussions

func (s *LiveThreadService) Discussions(ctx context.Context, id string, opts *ListOptions) ([]*Post, *Response, error)

Discussions gets a list of discussions (posts) about the live thread.

func (*LiveThreadService) Get

Get information about a live thread.

func (*LiveThreadService) GetMultiple

func (s *LiveThreadService) GetMultiple(ctx context.Context, ids ...string) ([]*LiveThread, *Response, error)

GetMultiple gets information about multiple live threads.

func (*LiveThreadService) HideDiscussion

func (s *LiveThreadService) HideDiscussion(ctx context.Context, threadID, postID string) (*Response, error)

HideDiscussion hides a linked post from the live thread's discussion sidebar. The postID should be the base36 ID of the post, i.e. not its full id.

func (*LiveThreadService) Invite

func (s *LiveThreadService) Invite(ctx context.Context, id, username string, permissions *LiveThreadPermissions) (*Response, error)

Invite another user to contribute to the live thread. If permissions is nil, all permissions will be granted. Requires the "manage" permission.

func (*LiveThreadService) Leave

func (s *LiveThreadService) Leave(ctx context.Context, id string) (*Response, error)

Leave the live thread by abdicating your status as contributor.

func (*LiveThreadService) Now

Now gets information about the currently featured live thread. This returns an empty 204 response if no thread is currently featured.

func (*LiveThreadService) Report

func (s *LiveThreadService) Report(ctx context.Context, id, reason string) (*Response, error)

Report the live thread. The reason should be one of: spam, vote-manipulation, personal-information, sexualizing-minors, site-breaking

func (*LiveThreadService) Revoke

func (s *LiveThreadService) Revoke(ctx context.Context, threadID, userID string) (*Response, error)

Revoke a user's contributorship via their full ID. Requires the "manage" permission.

func (*LiveThreadService) SetPermissions

func (s *LiveThreadService) SetPermissions(ctx context.Context, id, username string, permissions *LiveThreadPermissions) (*Response, error)

SetPermissions sets the permissions for the contributor in the live thread. If permissions is nil, all permissions will be granted. Requires the "manage" permission.

func (*LiveThreadService) SetPermissionsForInvite

func (s *LiveThreadService) SetPermissionsForInvite(ctx context.Context, id, username string, permissions *LiveThreadPermissions) (*Response, error)

SetPermissionsForInvite sets the permissions for a contributor who's yet to accept/refuse their invite. If permissions is nil, all permissions will be granted. Requires the "manage" permission.

func (*LiveThreadService) Strike

func (s *LiveThreadService) Strike(ctx context.Context, threadID, updateID string) (*Response, error)

Strike (mark incorrect and cross out) the content of an update. You must either be the author of the update or have the "edit" permission.

func (*LiveThreadService) UnhideDiscussion

func (s *LiveThreadService) UnhideDiscussion(ctx context.Context, threadID, postID string) (*Response, error)

UnhideDiscussion unhides a linked post from the live thread's discussion sidebar. The postID should be the base36 ID of the post, i.e. not its full id.

func (*LiveThreadService) Uninvite

func (s *LiveThreadService) Uninvite(ctx context.Context, threadID, userID string) (*Response, error)

Uninvite a user that's been invited to contribute to a live thread via their full ID. Requires the "manage" permission.

func (*LiveThreadService) Update

func (s *LiveThreadService) Update(ctx context.Context, id, text string) (*Response, error)

Update the live thread by posting an update to it. Requires the "update" permission.

func (*LiveThreadService) UpdateByID

func (s *LiveThreadService) UpdateByID(ctx context.Context, threadID, updateID string) (*LiveThreadUpdate, *Response, error)

UpdateByID gets a specific update in the live thread by its id. The ID of the update is the "short" one, i.e. the one that doesn't start with "LiveUpdate_".

func (*LiveThreadService) Updates

Updates gets a list of updates posted in the live thread.

type LiveThreadUpdate

type LiveThreadUpdate struct {
	ID      string     `json:"id,omitempty"`
	FullID  string     `json:"name,omitempty"`
	Author  string     `json:"author,omitempty"`
	Created *Timestamp `json:"created_utc,omitempty"`

	Body         string   `json:"body,omitempty"`
	EmbeddedURLs []string `json:"embeds,omitempty"`
	Stricken     bool     `json:"stricken"`
}

LiveThreadUpdate is an update in a live thread.

func (*LiveThreadUpdate) UnmarshalJSON

func (u *LiveThreadUpdate) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type MenuWidget struct {
	ShowWiki bool           `json:"showWiki"`
	Links    WidgetLinkList `json:"data,omitempty"`
	// contains filtered or unexported fields
}

MenuWidget displays tabs for your community's menu. These can be direct links or submenus that create a drop-down menu to multiple links.

func (w *MenuWidget) GetID() string

type Message

type Message struct {
	ID      string     `json:"id"`
	FullID  string     `json:"name"`
	Created *Timestamp `json:"created_utc"`

	Subject  string `json:"subject"`
	Text     string `json:"body"`
	ParentID string `json:"parent_id"`

	Author string `json:"author"`
	To     string `json:"dest"`

	IsComment bool `json:"was_comment"`
}

Message is a message.

type MessageService

type MessageService struct {
	// contains filtered or unexported fields
}

MessageService handles communication with the message related methods of the Reddit API.

Reddit API docs: https://www.reddit.com/dev/api/#section_messages

func (*MessageService) Block

func (s *MessageService) Block(ctx context.Context, id string) (*Response, error)

Block the author of a post, comment or message via its full ID.

func (*MessageService) Collapse

func (s *MessageService) Collapse(ctx context.Context, ids ...string) (*Response, error)

Collapse messages.

func (*MessageService) Delete

func (s *MessageService) Delete(ctx context.Context, id string) (*Response, error)

Delete a message.

func (*MessageService) Inbox

func (s *MessageService) Inbox(ctx context.Context, opts *ListOptions) ([]*Message, []*Message, *Response, error)

Inbox returns comments and messages that appear in your inbox, respectively.

func (*MessageService) InboxUnread

func (s *MessageService) InboxUnread(ctx context.Context, opts *ListOptions) ([]*Message, []*Message, *Response, error)

InboxUnread returns unread comments and messages that appear in your inbox, respectively.

func (*MessageService) Read

func (s *MessageService) Read(ctx context.Context, ids ...string) (*Response, error)

Read marks a message/comment as read via its full ID.

func (*MessageService) ReadAll

func (s *MessageService) ReadAll(ctx context.Context) (*Response, error)

ReadAll marks all messages/comments as read. It queues up the task on Reddit's end. A successful response returns 202 to acknowledge acceptance of the request. This endpoint is heavily rate limited.

func (*MessageService) Send

func (s *MessageService) Send(ctx context.Context, sendRequest *SendMessageRequest) (*Response, error)

Send a message.

func (*MessageService) Sent

func (s *MessageService) Sent(ctx context.Context, opts *ListOptions) ([]*Message, *Response, error)

Sent returns messages that you've sent.

func (*MessageService) Uncollapse

func (s *MessageService) Uncollapse(ctx context.Context, ids ...string) (*Response, error)

Uncollapse messages.

func (*MessageService) Unread

func (s *MessageService) Unread(ctx context.Context, ids ...string) (*Response, error)

Unread marks a message/comment as unread via its full ID.

type ModAction

type ModAction struct {
	ID      string     `json:"id,omitempty"`
	Action  string     `json:"action,omitempty"`
	Created *Timestamp `json:"created_utc,omitempty"`

	Moderator string `json:"mod,omitempty"`
	// Not the full ID, just the ID36.
	ModeratorID string `json:"mod_id36,omitempty"`

	// The author of whatever the action was produced on, e.g. a user, post, comment, etc.
	TargetAuthor string `json:"target_author,omitempty"`
	// This is the full ID of whatever the target was.
	TargetID        string `json:"target_fullname,omitempty"`
	TargetTitle     string `json:"target_title,omitempty"`
	TargetPermalink string `json:"target_permalink,omitempty"`
	TargetBody      string `json:"target_body,omitempty"`

	Subreddit string `json:"subreddit,omitempty"`
	// Not the full ID, just the ID36.
	SubredditID string `json:"sr_id36,omitempty"`
}

ModAction is an action executed by a moderator of a subreddit, such as inviting another user to be a mod, or setting permissions.

type ModPermissions

type ModPermissions struct {
	All          bool `permission:"all"`
	Access       bool `permission:"access"`
	ChatConfig   bool `permission:"chat_config"`
	ChatOperator bool `permission:"chat_operator"`
	Config       bool `permission:"config"`
	Flair        bool `permission:"flair"`
	Mail         bool `permission:"mail"`
	Posts        bool `permission:"posts"`
	Wiki         bool `permission:"wiki"`
}

ModPermissions are the different permissions moderators have or don't have on a subreddit. Read about them here: https://mods.reddithelp.com/hc/en-us/articles/360009381491-User-Management-moderators-and-permissions

func (*ModPermissions) String

func (p *ModPermissions) String() (s string)

type ModerationService

type ModerationService struct {
	// contains filtered or unexported fields
}

ModerationService handles communication with the moderation related methods of the Reddit API.

Reddit API docs: https://www.reddit.com/dev/api/#section_moderation

func (*ModerationService) AcceptInvite

func (s *ModerationService) AcceptInvite(ctx context.Context, subreddit string) (*Response, error)

AcceptInvite accepts a pending invite to moderate the specified subreddit.

func (*ModerationService) Actions

func (s *ModerationService) Actions(ctx context.Context, subreddit string, opts *ListModActionOptions) ([]*ModAction, *Response, error)

Actions gets a list of moderator actions on a subreddit.

func (*ModerationService) Approve

func (s *ModerationService) Approve(ctx context.Context, id string) (*Response, error)

Approve a post or comment via its full ID.

func (*ModerationService) ApproveUser

func (s *ModerationService) ApproveUser(ctx context.Context, subreddit string, username string) (*Response, error)

ApproveUser adds a user as an approved user to the subreddit.

func (*ModerationService) ApproveUserWiki

func (s *ModerationService) ApproveUserWiki(ctx context.Context, subreddit string, username string) (*Response, error)

ApproveUserWiki adds a user as an approved wiki contributor in the subreddit.

func (*ModerationService) Ban

func (s *ModerationService) Ban(ctx context.Context, subreddit string, username string, config *BanConfig) (*Response, error)

Ban a user from the subreddit.

func (*ModerationService) BanWiki

func (s *ModerationService) BanWiki(ctx context.Context, subreddit string, username string, config *BanConfig) (*Response, error)

BanWiki bans a user from contributing to the subreddit wiki.

func (*ModerationService) Distinguish

func (s *ModerationService) Distinguish(ctx context.Context, id string) (*Response, error)

Distinguish your post or comment via its full ID, adding a moderator tag to it. todo: add how=admin and how=special? They require special privileges.

func (*ModerationService) DistinguishAndSticky

func (s *ModerationService) DistinguishAndSticky(ctx context.Context, id string) (*Response, error)

DistinguishAndSticky your comment via its full ID, adding a moderator tag to it and stickying the comment at the top of the thread.

func (*ModerationService) Edited

func (s *ModerationService) Edited(ctx context.Context, subreddit string, opts *ListOptions) ([]*Post, []*Comment, *Response, error)

Edited gets posts and comments that have been edited recently.

func (*ModerationService) IgnoreReports

func (s *ModerationService) IgnoreReports(ctx context.Context, id string) (*Response, error)

IgnoreReports prevents reports on a post or comment from causing notifications.

func (*ModerationService) Invite

func (s *ModerationService) Invite(ctx context.Context, subreddit string, username string, permissions *ModPermissions) (*Response, error)

Invite a user to become a moderator of the subreddit. If permissions is nil, all permissions will be granted.

func (*ModerationService) Leave

func (s *ModerationService) Leave(ctx context.Context, subredditID string) (*Response, error)

Leave abdicates your moderator status in a subreddit via its full ID.

func (*ModerationService) LeaveContributor

func (s *ModerationService) LeaveContributor(ctx context.Context, subredditID string) (*Response, error)

LeaveContributor abdicates your approved user status in a subreddit via its full ID.

func (*ModerationService) Mute

func (s *ModerationService) Mute(ctx context.Context, subreddit string, username string) (*Response, error)

Mute a user in the subreddit.

func (*ModerationService) Queue

func (s *ModerationService) Queue(ctx context.Context, subreddit string, opts *ListOptions) ([]*Post, []*Comment, *Response, error)

Queue returns posts and comments requiring moderator reviews, such as one that have been reported or caught in the spam filter.

func (*ModerationService) Remove

func (s *ModerationService) Remove(ctx context.Context, id string) (*Response, error)

Remove a post, comment or modmail message via its full ID.

func (*ModerationService) RemoveSpam

func (s *ModerationService) RemoveSpam(ctx context.Context, id string) (*Response, error)

RemoveSpam removes a post, comment or modmail message via its full ID and marks it as spam.

func (*ModerationService) Reported

func (s *ModerationService) Reported(ctx context.Context, subreddit string, opts *ListOptions) ([]*Post, []*Comment, *Response, error)

Reported returns posts and comments that have been reported.

func (*ModerationService) SetPermissions

func (s *ModerationService) SetPermissions(ctx context.Context, subreddit string, username string, permissions *ModPermissions) (*Response, error)

SetPermissions sets the mod permissions for the user in the subreddit. If permissions is nil, all permissions will be granted.

func (*ModerationService) Spam

func (s *ModerationService) Spam(ctx context.Context, subreddit string, opts *ListOptions) ([]*Post, []*Comment, *Response, error)

Spam returns posts and comments marked as spam.

func (*ModerationService) UnapproveUser

func (s *ModerationService) UnapproveUser(ctx context.Context, subreddit string, username string) (*Response, error)

UnapproveUser removes a user as an approved user to the subreddit.

func (*ModerationService) UnapproveUserWiki

func (s *ModerationService) UnapproveUserWiki(ctx context.Context, subreddit string, username string) (*Response, error)

UnapproveUserWiki removes a user as an approved wiki contributor in the subreddit.

func (*ModerationService) Unban

func (s *ModerationService) Unban(ctx context.Context, subreddit string, username string) (*Response, error)

Unban a user from the subreddit.

func (*ModerationService) UnbanWiki

func (s *ModerationService) UnbanWiki(ctx context.Context, subreddit string, username string) (*Response, error)

UnbanWiki unbans a user from contributing to the subreddit wiki.

func (*ModerationService) Undistinguish

func (s *ModerationService) Undistinguish(ctx context.Context, id string) (*Response, error)

Undistinguish your post or comment via its full ID, removing the moderator tag from it.

func (*ModerationService) UnignoreReports

func (s *ModerationService) UnignoreReports(ctx context.Context, id string) (*Response, error)

UnignoreReports allows reports on a post or comment to cause notifications.

func (*ModerationService) Uninvite

func (s *ModerationService) Uninvite(ctx context.Context, subreddit string, username string) (*Response, error)

Uninvite a user from becoming a moderator of the subreddit.

func (*ModerationService) Unmoderated

func (s *ModerationService) Unmoderated(ctx context.Context, subreddit string, opts *ListOptions) ([]*Post, *Response, error)

Unmoderated returns posts that have yet to be approved/removed by a mod.

func (*ModerationService) Unmute

func (s *ModerationService) Unmute(ctx context.Context, subreddit string, username string) (*Response, error)

Unmute a user in the subreddit.

type Moderator

type Moderator struct {
	*Relationship
	Permissions []string `json:"mod_permissions"`
}

Moderator is a user who moderates a subreddit.

type ModeratorsWidget

type ModeratorsWidget struct {
	Mods  []string `json:"mods"`
	Total int      `json:"totalMods"`
	// contains filtered or unexported fields
}

ModeratorsWidget displays the list of moderators of the subreddit.

func (*ModeratorsWidget) GetID

func (w *ModeratorsWidget) GetID() string

func (*ModeratorsWidget) UnmarshalJSON

func (w *ModeratorsWidget) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type More

type More struct {
	ID       string `json:"id"`
	FullID   string `json:"name"`
	ParentID string `json:"parent_id"`
	// Total number of replies to the parent + replies to those replies (recursively).
	Count int `json:"count"`
	// Number of comment nodes from the parent down to the furthest comment node.
	Depth    int      `json:"depth"`
	Children []string `json:"children"`
}

More holds information used to retrieve additional comments omitted from a base comment tree.

type Multi

type Multi struct {
	Name        string `json:"name,omitempty"`
	DisplayName string `json:"display_name,omitempty"`
	// Format: user/{username}/m/{multiname}
	Path        string         `json:"path,omitempty"`
	Description string         `json:"description_md,omitempty"`
	Subreddits  SubredditNames `json:"subreddits"`
	CopiedFrom  *string        `json:"copied_from"`

	Owner   string     `json:"owner,omitempty"`
	OwnerID string     `json:"owner_id,omitempty"`
	Created *Timestamp `json:"created_utc,omitempty"`

	NumberOfSubscribers int    `json:"num_subscribers"`
	Visibility          string `json:"visibility,omitempty"`
	Subscribed          bool   `json:"is_subscriber"`
	Favorite            bool   `json:"is_favorited"`
	CanEdit             bool   `json:"can_edit"`
	NSFW                bool   `json:"over_18"`
}

Multi is a multireddit, i.e. a customizable group of subreddits. Users can create multis for custom navigation, instead of browsing one subreddit or all subreddits at a time.

type MultiCopyRequest

type MultiCopyRequest struct {
	FromPath string `url:"from"`
	ToPath   string `url:"to"`
	// Raw markdown text.
	Description string `url:"description_md,omitempty"`
	// No longer than 50 characters.
	DisplayName string `url:"display_name,omitempty"`
}

MultiCopyRequest represents a request to copy a multireddit.

type MultiCreateOrUpdateRequest

type MultiCreateOrUpdateRequest struct {
	// For updates, this is the display name, i.e. the header of the multi.
	// Not part of the path necessarily.
	Name        string         `json:"display_name,omitempty"`
	Description string         `json:"description_md,omitempty"`
	Subreddits  SubredditNames `json:"subreddits,omitempty"`
	// One of: private, public, hidden.
	Visibility string `json:"visibility,omitempty"`
}

MultiCreateOrUpdateRequest represents a request to create/update a multireddit.

type MultiService

type MultiService struct {
	// contains filtered or unexported fields
}

MultiService handles communication with the multireddit related methods of the Reddit API.

Reddit API docs: https://www.reddit.com/dev/api#section_multis

func (*MultiService) AddSubreddit

func (s *MultiService) AddSubreddit(ctx context.Context, multiPath string, subreddit string) (*Response, error)

AddSubreddit adds a subreddit to a multireddit.

func (*MultiService) Copy

func (s *MultiService) Copy(ctx context.Context, copyRequest *MultiCopyRequest) (*Multi, *Response, error)

Copy a multireddit.

func (*MultiService) Create

func (s *MultiService) Create(ctx context.Context, createRequest *MultiCreateOrUpdateRequest) (*Multi, *Response, error)

Create a multireddit.

func (*MultiService) Delete

func (s *MultiService) Delete(ctx context.Context, multiPath string) (*Response, error)

Delete a multireddit.

func (*MultiService) DeleteSubreddit

func (s *MultiService) DeleteSubreddit(ctx context.Context, multiPath string, subreddit string) (*Response, error)

DeleteSubreddit removes a subreddit from a multireddit.

func (*MultiService) Description

func (s *MultiService) Description(ctx context.Context, multiPath string) (string, *Response, error)

Description gets a multireddit's description.

func (*MultiService) Get

func (s *MultiService) Get(ctx context.Context, multiPath string) (*Multi, *Response, error)

Get the multireddit from its url path.

func (*MultiService) Mine

func (s *MultiService) Mine(ctx context.Context) ([]*Multi, *Response, error)

Mine returns your multireddits.

func (*MultiService) Of

func (s *MultiService) Of(ctx context.Context, username string) ([]*Multi, *Response, error)

Of returns the user's public multireddits. Or, if the user is you, all of your multireddits.

func (*MultiService) Update

func (s *MultiService) Update(ctx context.Context, multiPath string, updateRequest *MultiCreateOrUpdateRequest) (*Multi, *Response, error)

Update a multireddit. If the multireddit does not exist, it will be created.

func (*MultiService) UpdateDescription

func (s *MultiService) UpdateDescription(ctx context.Context, multiPath string, description string) (string, *Response, error)

UpdateDescription updates a multireddit's description.

type Opt

type Opt func(*Client) error

Opt is used to further configure a client upon initialization.

func WithApplicationOnlyOAuth

func WithApplicationOnlyOAuth(o bool) Opt

WithApplicationOnlyOAuth sets authentication flow to "Application Only OAuth". Only ID and Secret are required to be set in client. Username and Password are ignored. The flow is described here: https://github.com/reddit-archive/reddit/wiki/OAuth2#application-only-oauth

func WithBaseURL

func WithBaseURL(u string) Opt

WithBaseURL sets the base URL for the client to make requests to.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Opt

WithHTTPClient sets the HTTP client which will be used to make requests.

func WithTokenURL

func WithTokenURL(u string) Opt

WithTokenURL sets the url used to get access tokens.

func WithUserAgent

func WithUserAgent(ua string) Opt

WithUserAgent sets the User-Agent header for requests made with the client. Reddit recommends the following format for the user agent: <platform>:<app ID>:<version string> (by /u/<reddit username>)

type Post

type Post struct {
	ID      string     `json:"id,omitempty"`
	FullID  string     `json:"name,omitempty"`
	Created *Timestamp `json:"created_utc,omitempty"`
	Edited  *Timestamp `json:"edited,omitempty"`

	Permalink string `json:"permalink,omitempty"`
	URL       string `json:"url,omitempty"`

	Title string `json:"title,omitempty"`
	Body  string `json:"selftext,omitempty"`

	// Indicates if you've upvoted/downvoted (true/false).
	// If neither, it will be nil.
	Likes *bool `json:"likes"`

	Score            int     `json:"score"`
	UpvoteRatio      float32 `json:"upvote_ratio"`
	NumberOfComments int     `json:"num_comments"`

	SubredditName         string `json:"subreddit,omitempty"`
	SubredditNamePrefixed string `json:"subreddit_name_prefixed,omitempty"`
	SubredditID           string `json:"subreddit_id,omitempty"`
	SubredditSubscribers  int    `json:"subreddit_subscribers"`

	Author   string `json:"author,omitempty"`
	AuthorID string `json:"author_fullname,omitempty"`

	Spoiler    bool `json:"spoiler"`
	Locked     bool `json:"locked"`
	NSFW       bool `json:"over_18"`
	IsSelfPost bool `json:"is_self"`
	Saved      bool `json:"saved"`
	Stickied   bool `json:"stickied"`
}

Post is a submitted post on Reddit.

type PostAndComments

type PostAndComments struct {
	Post     *Post      `json:"post"`
	Comments []*Comment `json:"comments"`
	More     *More      `json:"-"`
}

PostAndComments is a post and its comments.

func (*PostAndComments) HasMore

func (pc *PostAndComments) HasMore() bool

HasMore determines whether the post has more replies to load in its reply tree.

func (*PostAndComments) UnmarshalJSON

func (pc *PostAndComments) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. When getting a sticky post, you get an array of 2 Listings The 1st one contains the single post in its children array The 2nd one contains the comments to the post

type PostService

type PostService struct {
	// contains filtered or unexported fields
}

PostService handles communication with the post related methods of the Reddit API.

Reddit API docs: https://www.reddit.com/dev/api/#section_links_and_comments

func (*PostService) ClearSuggestedSort

func (s *PostService) ClearSuggestedSort(ctx context.Context, id string) (*Response, error)

ClearSuggestedSort clears the suggested comment sort for the post.

func (PostService) Delete

func (s PostService) Delete(ctx context.Context, id string) (*Response, error)

Delete a post or comment via its full ID.

func (*PostService) DisableContestMode

func (s *PostService) DisableContestMode(ctx context.Context, id string) (*Response, error)

DisableContestMode disables contest mode for the post.

func (PostService) DisableReplies

func (s PostService) DisableReplies(ctx context.Context, id string) (*Response, error)

DisableReplies dsables inbox replies for one of your posts or comments.

func (PostService) Downvote

func (s PostService) Downvote(ctx context.Context, id string) (*Response, error)

Downvote a post or a comment.

func (*PostService) Duplicates

func (s *PostService) Duplicates(ctx context.Context, id string, opts *ListDuplicatePostOptions) (*Post, []*Post, *Response, error)

Duplicates returns the post with the id, and a list of its duplicates. id is the ID36 of the post, not its full id. Example: instead of t3_abc123, use abc123.

func (*PostService) Edit

func (s *PostService) Edit(ctx context.Context, id string, text string) (*Post, *Response, error)

Edit a post.

func (*PostService) EnableContestMode

func (s *PostService) EnableContestMode(ctx context.Context, id string) (*Response, error)

EnableContestMode enables contest mode for the post. Comments will be sorted randomly and regular users cannot see comment scores.

func (PostService) EnableReplies

func (s PostService) EnableReplies(ctx context.Context, id string) (*Response, error)

EnableReplies enables inbox replies for one of your posts or comments.

func (*PostService) Get

Get a post with its comments. id is the ID36 of the post, not its full id. Example: instead of t3_abc123, use abc123.

func (*PostService) Hide

func (s *PostService) Hide(ctx context.Context, ids ...string) (*Response, error)

Hide posts.

func (*PostService) LoadMoreComments

func (s *PostService) LoadMoreComments(ctx context.Context, pc *PostAndComments) (*Response, error)

LoadMoreComments retrieves more comments that were left out when initially fetching the post.

func (PostService) Lock

func (s PostService) Lock(ctx context.Context, id string) (*Response, error)

Lock a post or comment, preventing it from receiving new comments.

func (*PostService) MarkNSFW

func (s *PostService) MarkNSFW(ctx context.Context, id string) (*Response, error)

MarkNSFW marks a post as NSFW.

func (*PostService) MarkVisited

func (s *PostService) MarkVisited(ctx context.Context, ids ...string) (*Response, error)

MarkVisited marks the post(s) as visited. This method requires a subscription to Reddit premium.

func (*PostService) PinToProfile

func (s *PostService) PinToProfile(ctx context.Context, id string) (*Response, error)

PinToProfile pins one of your posts to your profile. TODO: very inconsistent behaviour, not sure I'm ready to include this parameter yet. The pos parameter should be a number between 1-4 (inclusive), indicating the position at which the post should appear on your profile. Note: The position will be bumped upward if there's space. E.g. if you only have 1 pinned post, and you try to pin another post to position 3, it will be pinned at 2. When attempting to pin a post that's already pinned, it will return a 409 Conflict error.

func (*PostService) Random

Random returns a random post and its comments from all of Reddit.

func (*PostService) RandomFromSubreddits

func (s *PostService) RandomFromSubreddits(ctx context.Context, subreddits ...string) (*PostAndComments, *Response, error)

RandomFromSubreddits returns a random post and its comments from the subreddits. If no subreddits are provided, Reddit runs the query against your subscriptions.

func (*PostService) RandomFromSubscriptions

func (s *PostService) RandomFromSubscriptions(ctx context.Context) (*PostAndComments, *Response, error)

RandomFromSubscriptions returns a random post and its comments from your subscriptions.

func (PostService) RemoveVote

func (s PostService) RemoveVote(ctx context.Context, id string) (*Response, error)

RemoveVote removes your vote on a post or a comment.

func (PostService) Report

func (s PostService) Report(ctx context.Context, id string, reason string) (*Response, error)

Report a post or comment. The reason must not be longer than 100 characters.

func (PostService) Save

func (s PostService) Save(ctx context.Context, id string) (*Response, error)

Save a post or comment.

func (*PostService) SetSuggestedSortAMA

func (s *PostService) SetSuggestedSortAMA(ctx context.Context, id string) (*Response, error)

SetSuggestedSortAMA sets the suggested comment sort for the post to a Q&A styled fashion.

func (*PostService) SetSuggestedSortBest

func (s *PostService) SetSuggestedSortBest(ctx context.Context, id string) (*Response, error)

SetSuggestedSortBest sets the suggested comment sort for the post to best.

func (*PostService) SetSuggestedSortControversial

func (s *PostService) SetSuggestedSortControversial(ctx context.Context, id string) (*Response, error)

SetSuggestedSortControversial sets the suggested comment sort for the post to controversial.

func (*PostService) SetSuggestedSortLive

func (s *PostService) SetSuggestedSortLive(ctx context.Context, id string) (*Response, error)

SetSuggestedSortLive sets the suggested comment sort for the post to stream new comments as they're posted. As of now, this is still in beta, so it's not a fully developed feature yet. It just sets the sort as "new" for now.

func (*PostService) SetSuggestedSortNew

func (s *PostService) SetSuggestedSortNew(ctx context.Context, id string) (*Response, error)

SetSuggestedSortNew sets the suggested comment sort for the post to new.

func (*PostService) SetSuggestedSortOld

func (s *PostService) SetSuggestedSortOld(ctx context.Context, id string) (*Response, error)

SetSuggestedSortOld sorts the comments on the posts randomly.

func (*PostService) SetSuggestedSortRandom

func (s *PostService) SetSuggestedSortRandom(ctx context.Context, id string) (*Response, error)

SetSuggestedSortRandom sets the suggested comment sort for the post to random.

func (*PostService) SetSuggestedSortTop

func (s *PostService) SetSuggestedSortTop(ctx context.Context, id string) (*Response, error)

SetSuggestedSortTop sets the suggested comment sort for the post to top.

func (*PostService) Spoiler

func (s *PostService) Spoiler(ctx context.Context, id string) (*Response, error)

Spoiler marks a post as a spoiler.

func (*PostService) Sticky

func (s *PostService) Sticky(ctx context.Context, id string, bottom bool) (*Response, error)

Sticky a post in its subreddit. When bottom is true, the post will be set as the bottom sticky (the 2nd one). If no top sticky exists, the post will become the top sticky regardless. When attempting to sticky a post that's already stickied, it will return a 409 Conflict error.

func (s *PostService) SubmitLink(ctx context.Context, opts SubmitLinkRequest) (*Submitted, *Response, error)

SubmitLink submits a link post.

func (*PostService) SubmitText

func (s *PostService) SubmitText(ctx context.Context, opts SubmitTextRequest) (*Submitted, *Response, error)

SubmitText submits a text post.

func (*PostService) Unhide

func (s *PostService) Unhide(ctx context.Context, ids ...string) (*Response, error)

Unhide posts.

func (PostService) Unlock

func (s PostService) Unlock(ctx context.Context, id string) (*Response, error)

Unlock a post or comment, allowing it to receive new comments.

func (*PostService) UnmarkNSFW

func (s *PostService) UnmarkNSFW(ctx context.Context, id string) (*Response, error)

UnmarkNSFW unmarks a post as NSFW.

func (*PostService) UnpinFromProfile

func (s *PostService) UnpinFromProfile(ctx context.Context, id string) (*Response, error)

UnpinFromProfile unpins one of your posts from your profile.

func (PostService) Unsave

func (s PostService) Unsave(ctx context.Context, id string) (*Response, error)

Unsave a post or comment.

func (*PostService) Unspoiler

func (s *PostService) Unspoiler(ctx context.Context, id string) (*Response, error)

Unspoiler unmarks a post as a spoiler.

func (*PostService) Unsticky

func (s *PostService) Unsticky(ctx context.Context, id string) (*Response, error)

Unsticky unstickies a post in its subreddit.

func (PostService) Upvote

func (s PostService) Upvote(ctx context.Context, id string) (*Response, error)

Upvote a post or a comment.

type Rate

type Rate struct {
	// The number of remaining requests the client can make in the current 10-minute window.
	Remaining int `json:"remaining"`
	// The number of requests the client has made in the current 10-minute window.
	Used int `json:"used"`
	// The time at which the current rate limit will reset.
	Reset time.Time `json:"reset"`
}

Rate represents the rate limit for the client.

type RateLimitError

type RateLimitError struct {
	// Rate specifies the last known rate limit for the client
	Rate Rate
	// HTTP response that caused this error
	Response *http.Response
	// Error message
	Message string
}

RateLimitError occurs when the client is sending too many requests to Reddit in a given time frame.

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

type Relationship

type Relationship struct {
	ID      string     `json:"rel_id,omitempty"`
	User    string     `json:"name,omitempty"`
	UserID  string     `json:"id,omitempty"`
	Created *Timestamp `json:"date,omitempty"`
}

Relationship holds information about a relationship (friend/blocked).

type Replies

type Replies struct {
	Comments []*Comment `json:"comments,omitempty"`
	More     *More      `json:"-"`
}

Replies holds replies to a comment. It contains both comments and "more" comments, which are entrypoints to other comments that were left out.

func (*Replies) MarshalJSON

func (r *Replies) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Replies) UnmarshalJSON

func (r *Replies) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type RequestCompletionCallback

type RequestCompletionCallback func(*http.Request, *http.Response)

RequestCompletionCallback defines the type of the request callback function.

type Response

type Response struct {
	*http.Response

	// Pagination anchor indicating there are more results after this id.
	After string

	// Rate limit information.
	Rate Rate
}

Response is a Reddit response. This wraps the standard http.Response returned from Reddit.

type SendMessageRequest

type SendMessageRequest struct {
	// Username, or /r/name for that subreddit's moderators.
	To      string `url:"to"`
	Subject string `url:"subject"`
	Text    string `url:"text"`
	// Optional. If specified, the message will look like it came from the subreddit.
	FromSubreddit string `url:"from_sr,omitempty"`
}

SendMessageRequest represents a request to send a message.

type Settings

type Settings struct {
	// Control whose private messages you see.
	// - "everyone": everyone except blocked users
	// - "whitelisted": only trusted users
	AcceptPrivateMessages *string `json:"accept_pms,omitempty"`
	// Allow Reddit to use your activity on Reddit to show you more relevant advertisements.
	ActivityRelevantAds *bool `json:"activity_relevant_ads,omitempty"`
	// Allow reddit to log my outbound clicks for personalization.
	AllowClickTracking *bool `json:"allow_clicktracking,omitempty"`

	// Beta test features for reddit. By enabling, you will join r/beta immediately.
	Beta *bool `json:"beta,omitempty"`
	// Show me links I've recently viewed.
	ShowRecentlyViewedPosts *bool `json:"clickgadget,omitempty"`

	CollapseReadMessages *bool `json:"collapse_read_messages,omitempty"`

	// Compress the post display (make them look more compact).
	Compress *bool `json:"compress,omitempty"`

	CredditAutorenew *bool `json:"creddit_autorenew,omitempty"`

	// One of "confidence", "top", "new", "controversial", "old", "random", "qa", "live".
	DefaultCommentSort *string `json:"default_comment_sort,omitempty"`

	// Show additional details in the domain text when available,
	// such as the source subreddit or the content author’s url/name.
	ShowDomainDetails *bool `json:"domain_details,omitempty"`

	SendEmailDigests         *bool `json:"email_digests,omitempty"`
	SendMessagesAsEmails     *bool `json:"email_messages,omitempty"`
	UnsubscribeFromAllEmails *bool `json:"email_unsubscribe_all,omitempty"`

	// Disable subreddits from displaying their custom themes.
	DisableCustomThemes *bool `json:"enable_default_themes,omitempty"`

	// One of "GLOBAL", "AR", "AU", "BG", "CA", "CL", "CO", "CZ", "FI", "GB", "GR", "HR", "HU",
	// "IE", "IN", "IS", "JP", "MX", "MY", "NZ", "PH", "PL", "PR", "PT", "RO", "RS", "SE", "SG",
	// "TH", "TR", "TW", "US", "US_AK", "US_AL", "US_AR", "US_AZ", "US_CA", "US_CO", "US_CT",
	// "US_DC", "US_DE", "US_FL", "US_GA", "US_HI", "US_IA", "US_ID", "US_IL", "US_IN", "US_KS",
	// "US_KY", "US_LA", "US_MA", "US_MD", "US_ME", "US_MI", "US_MN", "US_MO", "US_MS", "US_MT",
	// "US_NC", "US_ND", "US_NE", "US_NH", "US_NJ", "US_NM", "US_NV", "US_NY", "US_OH", "US_OK",
	// "US_OR", "US_PA", "US_RI", "US_SC", "US_SD", "US_TN", "US_TX", "US_UT", "US_VA", "US_VT",
	// "US_WA", "US_WI", "US_WV", "US_WY".
	Location *string `json:"geopopular,omitempty"`

	HideAds *bool `json:"hide_ads,omitempty"`

	// Don't allow search engines to index my user profile.
	HideFromSearchEngines *bool `json:"hide_from_robots,omitempty"`

	// Don’t show me posts after I’ve upvoted them, except my own.
	HideUpvotedPosts *bool `json:"hide_ups,omitempty"`
	// Don’t show me posts after I’ve downvoted them, except my own.
	HideDownvotedPosts *bool `json:"hide_downs,omitempty"`

	// Show a dagger (†) on comments voted controversial (one that's been
	// upvoted and downvoted significantly).
	HighlightControversialComments *bool `json:"highlight_controversial,omitempty"`
	HighlightNewComments           *bool `json:"highlight_new_comments,omitempty"`

	// Ignore suggested sorts for specific threads/subreddits, like Q&As.
	IgnoreSuggestedSorts *bool `json:"ignore_suggested_sort,omitempty"`

	// Use new Reddit as my default experience.
	// Use this to SET the setting.
	UseNewReddit *bool `json:"in_redesign_beta,omitempty"`

	// Use new Reddit as my default experience.
	// Use this to GET the setting.
	UsesNewReddit *bool `json:"design_beta,omitempty"`

	// Label posts that are not safe for work (NSFW).
	LabelNSFW *bool `json:"label_nsfw,omitempty"`

	// A valid IETF language tag (underscore separated).
	Language *string `json:"lang,omitempty"`

	ShowOldSearchPage *bool `json:"legacy_search,omitempty"`

	// Send message notifications in my browser.
	EnableNotifications *bool `json:"live_orangereds,omitempty"`

	MarkMessagesAsRead *bool `json:"mark_messages_read,omitempty"`

	// Determine whether to show thumbnails next to posts in subreddits.
	// - "on": show thumbnails next to posts
	// - "off": do not show thumbnails next to posts
	// - "subreddit": show thumbnails next to posts based on the subreddit's preferences
	ShowThumbnails *string `json:"media,omitempty"`

	// Determine whether to auto-expand media in subreddits.
	// - "on": auto-expand media previews
	// - "off": do not auto-expand media previews
	// - "subreddit": auto-expand media previews based on the subreddit's preferences
	AutoExpandMedia *string `json:"media_preview,omitempty"`

	// Don't show me comments with a score less than this number.
	// Must be between -100 and 100 (inclusive).
	MinimumCommentScore *int `json:"min_comment_score,omitempty"`

	// Don't show me posts with a score less than this number.
	// Must be between -100 and 100 (inclusive).
	MinimumPostScore *int `json:"min_link_score,omitempty"`

	// Notify me when people say my username.
	EnableMentionNotifications *bool `json:"monitor_mentions,omitempty"`

	// Opens link in a new window/tab.
	OpenLinksInNewWindow *bool `json:"newwindow,omitempty"`

	DarkMode         *bool `json:"nightmode,omitempty"`
	DisableProfanity *bool `json:"no_profanity,omitempty"`

	// Display this many comments by default.
	// Must be between 1 and 500 (inclusive).
	NumberOfComments *int `json:"num_comments,omitempty,omitempty"`

	// Display this many posts by default.
	// Must be between 1 and 100 (inclusive).
	NumberOfPosts *int `json:"numsites,omitempty,omitempty"`

	// Show the spotlight box on the home feed.
	// Not sure what this is though...
	ShowSpotlightBox *bool `json:"organic,omitempty"`

	SubredditTheme *string `json:"other_theme,omitempty"`

	// Show content that is labeled not safe for work (NSFW).
	ShowNSFW *bool `json:"over_18,omitempty"`

	EnablePrivateRSSFeeds *bool `json:"private_feeds,omitempty"`

	// View user profiles on desktop using legacy mode.
	ProfileOptOut *bool `json:"profile_opt_out,omitempty"`
	// Make my upvotes and downvotes public.
	PublicizeVotes *bool `json:"public_votes,omitempty"`

	// Allow my data to be used for research purposes.
	AllowResearch *bool `json:"research,omitempty"`

	IncludeNSFWSearchResults *bool `json:"search_include_over_18,omitempty"`

	// Receive a message when my post gets cross-posted.
	ReceiveCrosspostMessages *bool `json:"send_crosspost_messages,omitempty"`
	// Receive welcome messages from moderators when I join a community.
	ReceiveWelcomeMessages *bool `json:"send_welcome_messages,omitempty"`

	// Show a user's flair (next to their name on a post or comment).
	ShowUserFlair *bool `json:"show_flair,omitempty"`
	// Show a post's flair.
	ShowPostFlair *bool `json:"show_link_flair,omitempty"`

	// Show how much gold you have remaining on your profile.
	ShowGoldExpiration               *bool `json:"show_gold_expiration,omitempty"`
	ShowLocationBasedRecommendations *bool `json:"show_location_based_recommendations,omitempty"`
	ShowPromote                      *bool `json:"show_promote,omitempty"`
	ShowCustomSubredditThemes        *bool `json:"show_stylesheets,omitempty"`

	// Show trending subreddits on the home feed.
	ShowTrendingSubreddits *bool `json:"show_trending,omitempty"`
	ShowTwitter            *bool `json:"show_twitter,omitempty"`

	// Store whether or not you want to track posts you've visited.
	StoreVisits   *bool   `json:"store_visits,omitempty"`
	ThemeSelector *string `json:"theme_selector,omitempty"`

	// Allow Reddit to use data provided by third-parties to show you more relevant advertisements on Reddit.i
	AllowThirdPartyDataAdPersonalization *bool `json:"third_party_data_personalized_ads,omitempty"`
	// Allow personalization of advertisements using data from third-party websites.
	AllowThirdPartySiteDataAdPersonalization *bool `json:"third_party_site_data_personalized_ads,omitempty"`
	// Allow personalization of content using data from third-party websites.
	AllowThirdPartySiteDataContentPersonalization *bool `json:"third_party_site_data_personalized_content,omitempty"`

	EnableThreadedMessages *bool `json:"threaded_messages,omitempty"`
	EnableThreadedModmail  *bool `json:"threaded_modmail,omitempty"`

	// Show the communities you are active in on your profile (mobile only).
	TopKarmaSubreddits *bool `json:"top_karma_subreddits,omitempty"`

	UseGlobalDefaults   *bool `json:"use_global_defaults,omitempty"`
	EnableVideoAutoplay *bool `json:"video_autoplay,omitempty"`
}

Settings are the user's account settings. Some of the fields' descriptions are taken from: https://praw.readthedocs.io/en/latest/code_overview/other/preferences.html#praw.models.Preferences.update

type StreamOpt

type StreamOpt func(*streamConfig)

StreamOpt is a configuration option to configure a stream.

func StreamInterval

func StreamInterval(v time.Duration) StreamOpt

StreamInterval sets the frequency at which data will be fetched for the stream. If the duration is 0 or less, it will not be set and the default will be used.

func StreamMaxRequests

func StreamMaxRequests(v int) StreamOpt

StreamMaxRequests sets a limit on the number of times data is fetched for a stream. If less than or equal to 0, it is assumed to be infinite.

type StreamService

type StreamService struct {
	// contains filtered or unexported fields
}

StreamService allows streaming new content from Reddit as it appears.

func (*StreamService) Posts

func (s *StreamService) Posts(subreddit string, opts ...StreamOpt) (<-chan *Post, <-chan error, func())

Posts streams posts from the specified subreddit. It returns 2 channels and a function:

  • a channel into which new posts will be sent
  • a channel into which any errors will be sent
  • a function that the client can call once to stop the streaming and close the channels

Because of the 100 post limit imposed by Reddit when fetching posts, some high-traffic streams might drop submissions between API requests, such as when streaming r/all.

type SubmitLinkRequest

type SubmitLinkRequest struct {
	Subreddit string `url:"sr,omitempty"`
	Title     string `url:"title,omitempty"`
	URL       string `url:"url,omitempty"`

	FlairID   string `url:"flair_id,omitempty"`
	FlairText string `url:"flair_text,omitempty"`

	SendReplies *bool `url:"sendreplies,omitempty"`
	Resubmit    bool  `url:"resubmit,omitempty"`
	NSFW        bool  `url:"nsfw,omitempty"`
	Spoiler     bool  `url:"spoiler,omitempty"`
}

SubmitLinkRequest are options used for link posts.

type SubmitTextRequest

type SubmitTextRequest struct {
	Subreddit string `url:"sr,omitempty"`
	Title     string `url:"title,omitempty"`
	Text      string `url:"text,omitempty"`

	FlairID   string `url:"flair_id,omitempty"`
	FlairText string `url:"flair_text,omitempty"`

	SendReplies *bool `url:"sendreplies,omitempty"`
	NSFW        bool  `url:"nsfw,omitempty"`
	Spoiler     bool  `url:"spoiler,omitempty"`
}

SubmitTextRequest are options used for text posts.

type Submitted

type Submitted struct {
	ID     string `json:"id,omitempty"`
	FullID string `json:"name,omitempty"`
	URL    string `json:"url,omitempty"`
}

Submitted is a newly submitted post on Reddit.

type Subreddit

type Subreddit struct {
	ID      string     `json:"id,omitempty"`
	FullID  string     `json:"name,omitempty"`
	Created *Timestamp `json:"created_utc,omitempty"`

	URL                  string `json:"url,omitempty"`
	Name                 string `json:"display_name,omitempty"`
	NamePrefixed         string `json:"display_name_prefixed,omitempty"`
	Title                string `json:"title,omitempty"`
	Description          string `json:"public_description,omitempty"`
	Type                 string `json:"subreddit_type,omitempty"`
	SuggestedCommentSort string `json:"suggested_comment_sort,omitempty"`

	Subscribers     int  `json:"subscribers"`
	ActiveUserCount *int `json:"active_user_count,omitempty"`
	NSFW            bool `json:"over18"`
	UserIsMod       bool `json:"user_is_moderator"`
	Subscribed      bool `json:"user_is_subscriber"`
	Favorite        bool `json:"user_has_favorited"`
}

Subreddit holds information about a subreddit

type SubredditImage

type SubredditImage struct {
	Name string `json:"name"`
	Link string `json:"link"`
	URL  string `json:"url"`
}

SubredditImage is an image part of the image set of a subreddit.

type SubredditKarma

type SubredditKarma struct {
	Subreddit    string `json:"sr"`
	PostKarma    int    `json:"link_karma"`
	CommentKarma int    `json:"comment_karma"`
}

SubredditKarma holds user karma data for the subreddit.

type SubredditNames

type SubredditNames []string

SubredditNames is a list of subreddit names.

func (*SubredditNames) MarshalJSON

func (n *SubredditNames) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*SubredditNames) UnmarshalJSON

func (n *SubredditNames) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type SubredditPostRequirements

type SubredditPostRequirements struct {
	// Sentence or two on how to successfully post to the subreddit.
	Guidelines              string `json:"guidelines_text"`
	GuidelinesDisplayPolicy string `json:"guidelines_display_policy"`

	TitleMinLength int `json:"title_text_min_length"`
	TitleMaxLength int `json:"title_text_max_length"`

	BodyMinLength int `json:"body_text_min_length"`
	BodyMaxLength int `json:"body_text_max_length"`

	// Do not allow any of these words in the title.
	TitleBlacklistedStrings []string `json:"title_blacklisted_strings"`
	// Do not allow any of these words in the body.
	BodyBlacklistedStrings []string `json:"body_blacklisted_strings"`

	// Require at least one of these words in the title.
	TitleRequiredStrings []string `json:"title_required_strings"`
	// Require at least one of these words in the body.
	BodyRequiredStrings []string `json:"body_required_strings"`

	// Block link posts with these domains.
	DomainBlacklist []string `json:"domain_blacklist"`
	// Only allow link posts with these domains.
	DomainWhitelist []string `json:"domain_whitelist"`

	// One of: required, notAllowed, none.
	// Meaning that a selftext post's body is required, not allowed, or optional, respectively.
	BodyRestrictionPolicy string `json:"body_restriction_policy"`
	LinkRestrictionPolicy string `json:"link_restriction_policy"`

	GalleryMinItems            int    `json:"gallery_min_items"`
	GalleryMaxItems            int    `json:"gallery_max_items"`
	GalleryCaptionsRequirement string `json:"gallery_captions_requirement"`
	GalleryURLsRequirement     string `json:"gallery_urls_requirement"`

	// Prevent users from posting a link that was already posted to your community within x days of the original.
	LinkRepostAge int  `json:"link_repost_age"`
	FlairRequired bool `json:"is_flair_required"`

	TitleRegexes []string `json:"title_regexes"`
	BodyRegexes  []string `json:"body_regexes"`
}

SubredditPostRequirements is a list of moderator-designed requirements to post to a subreddit.

type SubredditRule

type SubredditRule struct {
	// One of: comment, link (i.e. post), or all (i.e. both comment and link).
	Kind string `json:"kind,omitempty"`
	// Short description of the rule.
	Name string `json:"short_name,omitempty"`
	// The reason that will appear when a thing is reported in violation to this rule.
	ViolationReason string     `json:"violation_reason,omitempty"`
	Description     string     `json:"description,omitempty"`
	Priority        int        `json:"priority"`
	Created         *Timestamp `json:"created_utc,omitempty"`
}

SubredditRule is a rule in the subreddit.

type SubredditRuleCreateRequest

type SubredditRuleCreateRequest struct {
	// One of: comment, link (i.e. post) or all (i.e. both).
	Kind string `url:"kind"`
	// Short description of the rule. No longer than 100 characters.
	Name string `url:"short_name"`
	// The reason that will appear when a thing is reported in violation to this rule.
	// If this is empty, Reddit will set its value to Name by default.
	// No longer than 100 characters.
	ViolationReason string `url:"violation_reason,omitempty"`
	// Optional. No longer than 500 characters.
	Description string `url:"description,omitempty"`
}

SubredditRuleCreateRequest represents a request to add a subreddit rule.

type SubredditRulesWidget

type SubredditRulesWidget struct {
	Name string `json:"shortName,omitempty"`
	// One of: full (includes description), compact (rule is collapsed).
	Display string   `json:"display,omitempty"`
	Rules   []string `json:"rules,omitempty"`
	// contains filtered or unexported fields
}

SubredditRulesWidget displays your community rules.

func (*SubredditRulesWidget) GetID

func (w *SubredditRulesWidget) GetID() string

func (*SubredditRulesWidget) UnmarshalJSON

func (w *SubredditRulesWidget) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type SubredditService

type SubredditService struct {
	// contains filtered or unexported fields
}

SubredditService handles communication with the subreddit related methods of the Reddit API.

Reddit API docs: https://www.reddit.com/dev/api/#section_subreddits

func (*SubredditService) Approved

Approved returns the list of subreddits you are an approved user in.

func (*SubredditService) Banned

func (s *SubredditService) Banned(ctx context.Context, subreddit string, opts *ListOptions) ([]*Ban, *Response, error)

Banned gets banned users from the subreddit.

func (*SubredditService) Contributors

func (s *SubredditService) Contributors(ctx context.Context, subreddit string, opts *ListOptions) ([]*Relationship, *Response, error)

Contributors gets contributors (also known as approved users) from the subreddit.

func (*SubredditService) ControversialPosts

func (s *SubredditService) ControversialPosts(ctx context.Context, subreddit string, opts *ListPostOptions) ([]*Post, *Response, error)

ControversialPosts returns the most controversial posts from the specified subreddit. To search through multiple, separate the names with a plus (+), e.g. "golang+test". If none are defined, it returns the ones from your subscribed subreddits. To search through all, just specify "all". To search through all and filter out subreddits, provide "all-name1-name2".

func (*SubredditService) Create

func (s *SubredditService) Create(ctx context.Context, name string, request *SubredditSettings) (*Response, error)

Create a subreddit.

func (*SubredditService) CreateRule

func (s *SubredditService) CreateRule(ctx context.Context, subreddit string, request *SubredditRuleCreateRequest) (*Response, error)

CreateRule adds a rule to the subreddit.

func (*SubredditService) Default

Default returns default subreddits.

func (*SubredditService) Edit

func (s *SubredditService) Edit(ctx context.Context, subredditID string, request *SubredditSettings) (*Response, error)

Edit a subreddit. This endpoint expects all values of the request to be provided. To make this easier, it might be useful to get the subreddit's current settings via GetSettings(), and use that as a starting point. It even returns the subreddit's ID, which is needed for this.

func (*SubredditService) Favorite

func (s *SubredditService) Favorite(ctx context.Context, subreddit string) (*Response, error)

Favorite the subreddit.

func (*SubredditService) Get

func (s *SubredditService) Get(ctx context.Context, name string) (*Subreddit, *Response, error)

Get a subreddit by name.

func (*SubredditService) GetSettings

func (s *SubredditService) GetSettings(ctx context.Context, subreddit string) (*SubredditSettings, *Response, error)

GetSettings gets the settings of a subreddit.

func (*SubredditService) GetSticky1

func (s *SubredditService) GetSticky1(ctx context.Context, subreddit string) (*PostAndComments, *Response, error)

GetSticky1 returns the first stickied post on a subreddit (if it exists).

func (*SubredditService) GetSticky2

func (s *SubredditService) GetSticky2(ctx context.Context, subreddit string) (*PostAndComments, *Response, error)

GetSticky2 returns the second stickied post on a subreddit (if it exists).

func (*SubredditService) Gold

Gold returns gold subreddits (i.e. only accessible to users with gold). It seems like it returns an empty list if you don't have gold.

func (*SubredditService) HotPosts

func (s *SubredditService) HotPosts(ctx context.Context, subreddit string, opts *ListOptions) ([]*Post, *Response, error)

HotPosts returns the hottest posts from the specified subreddit. To search through multiple, separate the names with a plus (+), e.g. "golang+test". If none are defined, it returns the ones from your subscribed subreddits. To search through all, just specify "all". To search through all and filter out subreddits, provide "all-name1-name2". Note: when looking for hot posts in a subreddit, it will include the stickied posts (if any) PLUS posts from the limit parameter (25 by default).

func (*SubredditService) Moderated

func (s *SubredditService) Moderated(ctx context.Context, opts *ListSubredditOptions) ([]*Subreddit, *Response, error)

Moderated returns the list of subreddits you are a moderator of.

func (*SubredditService) Moderators

func (s *SubredditService) Moderators(ctx context.Context, subreddit string) ([]*Moderator, *Response, error)

Moderators gets the moderators of the subreddit.

func (*SubredditService) Muted

func (s *SubredditService) Muted(ctx context.Context, subreddit string, opts *ListOptions) ([]*Relationship, *Response, error)

Muted gets muted users from the subreddit.

func (*SubredditService) New

New returns new subreddits.

func (*SubredditService) NewPosts

func (s *SubredditService) NewPosts(ctx context.Context, subreddit string, opts *ListOptions) ([]*Post, *Response, error)

NewPosts returns the newest posts from the specified subreddit. To search through multiple, separate the names with a plus (+), e.g. "golang+test". If none are defined, it returns the ones from your subscribed subreddits. To search through all, just specify "all". To search through all and filter out subreddits, provide "all-name1-name2".

func (*SubredditService) Popular

Popular returns popular subreddits.

func (*SubredditService) PostRequirements

func (s *SubredditService) PostRequirements(ctx context.Context, subreddit string) (*SubredditPostRequirements, *Response, error)

PostRequirements returns the subreddit's moderator-designed requirements to post to it. Clients may use the values returned by this method to pre-validate submissions to the subreddit.

func (*SubredditService) Random

func (s *SubredditService) Random(ctx context.Context) (*Subreddit, *Response, error)

Random returns a random SFW subreddit.

func (*SubredditService) RandomNSFW

func (s *SubredditService) RandomNSFW(ctx context.Context) (*Subreddit, *Response, error)

RandomNSFW returns a random NSFW subreddit.

func (*SubredditService) RemoveHeader

func (s *SubredditService) RemoveHeader(ctx context.Context, subreddit string) (*Response, error)

RemoveHeader removes the subreddit's current header image. The call succeeds even if there's no header image.

func (*SubredditService) RemoveImage

func (s *SubredditService) RemoveImage(ctx context.Context, subreddit, imageName string) (*Response, error)

RemoveImage removes an image from the subreddit's custom image set. The call succeeds even if the named image does not exist.

func (*SubredditService) RemoveMobileHeader

func (s *SubredditService) RemoveMobileHeader(ctx context.Context, subreddit string) (*Response, error)

RemoveMobileHeader removes the subreddit's current mobile header. The call succeeds even if there's no mobile header.

func (*SubredditService) RemoveMobileIcon

func (s *SubredditService) RemoveMobileIcon(ctx context.Context, subreddit string) (*Response, error)

RemoveMobileIcon removes the subreddit's current mobile icon. The call succeeds even if there's no mobile icon.

func (*SubredditService) RisingPosts

func (s *SubredditService) RisingPosts(ctx context.Context, subreddit string, opts *ListOptions) ([]*Post, *Response, error)

RisingPosts returns the rising posts from the specified subreddit. To search through multiple, separate the names with a plus (+), e.g. "golang+test". If none are defined, it returns the ones from your subscribed subreddits. To search through all, just specify "all". To search through all and filter out subreddits, provide "all-name1-name2".

func (*SubredditService) Rules

func (s *SubredditService) Rules(ctx context.Context, subreddit string) ([]*SubredditRule, *Response, error)

Rules gets the rules of the subreddit.

func (*SubredditService) Search

func (s *SubredditService) Search(ctx context.Context, query string, opts *ListSubredditOptions) ([]*Subreddit, *Response, error)

Search for subreddits.

func (*SubredditService) SearchNames

func (s *SubredditService) SearchNames(ctx context.Context, query string) ([]string, *Response, error)

SearchNames searches for subreddits with names beginning with the query provided.

func (*SubredditService) SearchPosts

func (s *SubredditService) SearchPosts(ctx context.Context, query string, subreddit string, opts *ListPostSearchOptions) ([]*Post, *Response, error)

SearchPosts searches for posts in the specified subreddit. To search through multiple, separate the names with a plus (+), e.g. "golang+test". If no subreddit is provided, the search is run against r/all.

func (*SubredditService) StyleSheet

func (s *SubredditService) StyleSheet(ctx context.Context, subreddit string) (*SubredditStyleSheet, *Response, error)

StyleSheet returns the subreddit's style sheet, as well as some information about images.

func (*SubredditService) StyleSheetRaw

func (s *SubredditService) StyleSheetRaw(ctx context.Context, subreddit string) (string, *Response, error)

StyleSheetRaw returns the subreddit's style sheet with all comments and newlines stripped.

func (*SubredditService) SubmissionText

func (s *SubredditService) SubmissionText(ctx context.Context, name string) (string, *Response, error)

SubmissionText gets the submission text for the subreddit. This text is set by the subreddit moderators and intended to be displayed on the submission form.

func (*SubredditService) Subscribe

func (s *SubredditService) Subscribe(ctx context.Context, subreddits ...string) (*Response, error)

Subscribe subscribes to subreddits based on their names.

func (*SubredditService) SubscribeByID

func (s *SubredditService) SubscribeByID(ctx context.Context, ids ...string) (*Response, error)

SubscribeByID subscribes to subreddits based on their id.

func (*SubredditService) Subscribed

func (s *SubredditService) Subscribed(ctx context.Context, opts *ListSubredditOptions) ([]*Subreddit, *Response, error)

Subscribed returns the list of subreddits you are subscribed to.

func (*SubredditService) TopPosts

func (s *SubredditService) TopPosts(ctx context.Context, subreddit string, opts *ListPostOptions) ([]*Post, *Response, error)

TopPosts returns the top posts from the specified subreddit. To search through multiple, separate the names with a plus (+), e.g. "golang+test". If none are defined, it returns the ones from your subscribed subreddits. To search through all, just specify "all". To search through all and filter out subreddits, provide "all-name1-name2".

func (*SubredditService) Traffic

Traffic gets the traffic data of the subreddit. It returns traffic data by day, hour, and month, respectively.

func (*SubredditService) Unfavorite

func (s *SubredditService) Unfavorite(ctx context.Context, subreddit string) (*Response, error)

Unfavorite the subreddit.

func (*SubredditService) Unsubscribe

func (s *SubredditService) Unsubscribe(ctx context.Context, subreddits ...string) (*Response, error)

Unsubscribe unsubscribes from subreddits based on their names.

func (*SubredditService) UnsubscribeByID

func (s *SubredditService) UnsubscribeByID(ctx context.Context, ids ...string) (*Response, error)

UnsubscribeByID unsubscribes from subreddits based on their id.

func (*SubredditService) UpdateStyleSheet

func (s *SubredditService) UpdateStyleSheet(ctx context.Context, subreddit, styleSheet, reason string) (*Response, error)

UpdateStyleSheet updates the style sheet of the subreddit. Providing a reason is optional.

func (*SubredditService) UploadHeader

func (s *SubredditService) UploadHeader(ctx context.Context, subreddit, imagePath, imageName string) (string, *Response, error)

UploadHeader uploads an image to be user as the subreddit's header image. A successful call returns a link to the uploaded image.

func (*SubredditService) UploadImage

func (s *SubredditService) UploadImage(ctx context.Context, subreddit, imagePath, imageName string) (string, *Response, error)

UploadImage uploads an image to the subreddit. If an image with the image name already exists, it it replaced. A successful call returns a link to the uploaded image.

func (*SubredditService) UploadMobileHeader

func (s *SubredditService) UploadMobileHeader(ctx context.Context, subreddit, imagePath, imageName string) (string, *Response, error)

UploadMobileHeader uploads an image to be user as the subreddit's mobile header image. A successful call returns a link to the uploaded image.

func (*SubredditService) UploadMobileIcon

func (s *SubredditService) UploadMobileIcon(ctx context.Context, subreddit, imagePath, imageName string) (string, *Response, error)

UploadMobileIcon uploads an image to be user as the subreddit's mobile icon. A successful call returns a link to the uploaded image.

func (*SubredditService) WikiBanned

func (s *SubredditService) WikiBanned(ctx context.Context, subreddit string, opts *ListOptions) ([]*Ban, *Response, error)

WikiBanned gets banned users from the subreddit.

func (*SubredditService) WikiContributors

func (s *SubredditService) WikiContributors(ctx context.Context, subreddit string, opts *ListOptions) ([]*Relationship, *Response, error)

WikiContributors gets contributors of the wiki from the subreddit.

type SubredditSettings

type SubredditSettings struct {
	// The id of the subreddit.
	ID string `url:"-" json:"subreddit_id,omitempty"`

	// One of: public, restricted, private, gold_restricted, archived, employees_only, gold_only, user.
	Type *string `url:"type,omitempty" json:"subreddit_type,omitempty"`

	// A valid IETF language tag (underscore separated).
	Language *string `url:"lang,omitempty" json:"language,omitempty"`

	// No longer than 100 characters.
	Title *string `url:"title,omitempty" json:"title,omitempty"`
	// Raw markdown text. No longer than 500 characters.
	Description *string `url:"public_description,omitempty" json:"public_description,omitempty"`
	// Raw markdown text. No longer than 10240 characters.
	Sidebar *string `url:"description,omitempty" json:"description,omitempty"`
	// Raw markdown text. No longer than 1024 characters.
	SubmissionText *string `url:"submit_text,omitempty" json:"submit_text,omitempty"`
	// Raw markdown text. No longer than 5000 characters.
	WelcomeMessage        *string `url:"welcome_message_text,omitempty" json:"welcome_message_text,omitempty"`
	WelcomeMessageEnabled *bool   `url:"welcome_message_enabled,omitempty" json:"welcome_message_enabled,omitempty"`

	AllowCrossposts      *bool `url:"allow_post_crossposts,omitempty" json:"allow_post_crossposts,omitempty"`
	AllowChatPosts       *bool `url:"allow_chat_post_creation,omitempty" json:"allow_chat_post_creation,omitempty"`
	AllowPollPosts       *bool `url:"allow_polls,omitempty" json:"allow_polls,omitempty"`
	AllowFreeFormReports *bool `url:"free_form_reports,omitempty" json:"free_form_reports,omitempty"`
	AllowOriginalContent *bool `url:"original_content_tag_enabled,omitempty" json:"original_content_tag_enabled,omitempty"`
	// Allow image uploads and links to image hosting sites.
	AllowImages                *bool `url:"allow_images,omitempty" json:"allow_images,omitempty"`
	AllowMultipleImagesPerPost *bool `url:"allow_galleries,omitempty" json:"allow_galleries,omitempty"`

	ExcludeSitewideBannedUsersContent *bool `url:"exclude_banned_modqueue,omitempty" json:"exclude_banned_modqueue,omitempty"`

	// An integer from 0 to 3.
	CrowdControlChalLevel *int `url:"crowd_control_chat_level,omitempty" json:"crowd_control_chat_level,omitempty"`

	// Mark all posts in this subreddit as Original Content (OC) on the desktop redesign.
	AllOriginalContent *bool `url:"all_original_content,omitempty" json:"all_original_content,omitempty"`

	// One of: none (recommended), confidence, top, new, controversial, old, random, qa, live.
	SuggestedCommentSort *string `url:"suggested_comment_sort,omitempty" json:"suggested_comment_sort,omitempty"`

	// No longer than 60 characters.
	SubmitLinkPostLabel *string `url:"submit_link_label,omitempty" json:"submit_link_label,omitempty"`
	// No longer than 60 characters.
	SubmitTextPostLabel *string `url:"submit_text_label,omitempty" json:"submit_text_label,omitempty"`

	// One of: any, link, self.
	PostType *string `url:"link_type,omitempty" json:"content_options,omitempty"`

	// One of: low (disable most filtering), high (standard), all (filter everything, requiring mod approval).
	SpamFilterStrengthLinkPosts *string `url:"spam_links,omitempty" json:"spam_links,omitempty"`
	// One of: low (disable most filtering), high (standard), all (filter everything, requiring mod approval).
	SpamFilterStrengthTextPosts *string `url:"spam_selfposts,omitempty" json:"spam_selfposts,omitempty"`
	// One of: low (disable most filtering), high (standard), all (filter everything, requiring mod approval).
	SpamFilterStrengthComments *string `url:"spam_comments,omitempty" json:"spam_comments,omitempty"`

	ShowContentThumbnails              *bool `url:"show_media,omitempty" json:"show_media,omitempty"`
	ExpandMediaPreviewsOnCommentsPages *bool `url:"show_media_preview,omitempty" json:"show_media_preview,omitempty"`

	CollapseDeletedComments *bool `url:"collapse_deleted_comments,omitempty" json:"collapse_deleted_comments,omitempty"`
	// An integer between 0 and 1440.
	MinutesToHideCommentScores *int `url:"comment_score_hide_mins,omitempty" json:"comment_score_hide_mins,omitempty"`

	// Enable marking posts as containing spoilers.
	SpoilersEnabled *bool `url:"spoilers_enabled,omitempty" json:"spoilers_enabled,omitempty"`

	// If there's an image header set, hovering the mouse over it will display this text.
	HeaderMouseoverText *string `url:"header-title,omitempty" json:"header_hover_text,omitempty"`

	// 6-digit rgb hex colour, e.g. #AABBCC.
	// Thematic colour for the subreddit on mobile.
	MobileColour *string `url:"key_color,omitempty" json:"key_color,omitempty"`

	// Can only be set to true if subreddit type is gold_only.
	HideAds *bool `url:"hide_ads,omitempty" json:"hide_ads,omitempty"`
	// Require viewers to be over 18 years old.
	NSFW *bool `url:"over_18,omitempty" json:"over_18,omitempty"`

	// Show up in high-traffic feeds: Allow your community to be in r/all, r/popular, and trending lists where it can be
	// seen by the general Reddit population.
	AllowDiscoveryInHighTrafficFeeds *bool `url:"allow_top,omitempty" json:"default_set,omitempty"`
	// Get recommended to individual redditors. Let Reddit recommend your community to people who have similar interests.
	AllowDiscoveryByIndividualUsers *bool `url:"allow_discovery,omitempty" json:"allow_discovery,omitempty"`

	// One of:
	// - disabled: wiki is disabled for everyone except mods.
	// - modonly: only mods, approved wiki contributors, or those on a page's edit list may edit.
	// - anyone: anyone who can submit to the subreddit may edit.
	WikiMode *string `url:"wikimode,omitempty" json:"wikimode,omitempty"`
	// Account age (in days) required to create and edit wiki pages.
	WikiMinimumAccountAge *int `url:"wiki_edit_age,omitempty" json:"wiki_edit_age,omitempty"`
	// Subreddit karma required to create and edit wiki pages.
	WikiMinimumKarma *int `url:"wiki_edit_karma,omitempty" json:"wiki_edit_karma,omitempty"`
}

SubredditSettings are a subreddit's settings.

type SubredditStyleSheet

type SubredditStyleSheet struct {
	SubredditID string            `json:"subreddit_id"`
	Images      []*SubredditImage `json:"images"`
	StyleSheet  string            `json:"stylesheet"`
}

SubredditStyleSheet contains the subreddit's styling information.

type SubredditTrafficStats

type SubredditTrafficStats struct {
	// Traffic data is returned in the form of day, hour, and month.
	// Start is a timestamp indicating the start of the category, i.e.
	// start of the day for day, start of the hour for hour, and start of the month for month.
	Start       *Timestamp `json:"start"`
	UniqueViews int        `json:"unique_views"`
	TotalViews  int        `json:"total_views"`
	// This is only available for "day" traffic, not hour and month.
	// Therefore, it is always 0 by default for hour and month.
	Subscribers int `json:"subscribers"`
}

SubredditTrafficStats hold information about subreddit traffic.

func (*SubredditTrafficStats) UnmarshalJSON

func (s *SubredditTrafficStats) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type TextAreaWidget

type TextAreaWidget struct {
	Name string `json:"shortName,omitempty"`
	Text string `json:"text,omitempty"`
	// contains filtered or unexported fields
}

TextAreaWidget displays a box of text in the subreddit.

func (*TextAreaWidget) GetID

func (w *TextAreaWidget) GetID() string

type TextAreaWidgetCreateRequest

type TextAreaWidgetCreateRequest struct {
	Style *WidgetStyle `json:"styles,omitempty"`
	// No longer than 30 characters.
	Name string `json:"shortName,omitempty"`
	// Raw markdown text.
	Text string `json:"text,omitempty"`
}

TextAreaWidgetCreateRequest represents a requets to create a text area widget.

func (*TextAreaWidgetCreateRequest) MarshalJSON

func (r *TextAreaWidgetCreateRequest) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp represents a time that can be unmarshalled from a JSON string formatted as either an RFC3339 or Unix timestamp.

func (Timestamp) Equal

func (t Timestamp) Equal(u Timestamp) bool

Equal reports whether t and u are equal based on time.Equal

func (*Timestamp) MarshalJSON

func (t *Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface. Time is expected in RFC3339 or Unix format.

type Trophy

type Trophy struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

Trophy is a Reddit award.

type User

type User struct {
	// this is not the full ID, watch out.
	ID      string     `json:"id,omitempty"`
	Name    string     `json:"name,omitempty"`
	Created *Timestamp `json:"created_utc,omitempty"`

	PostKarma    int `json:"link_karma"`
	CommentKarma int `json:"comment_karma"`

	IsFriend         bool `json:"is_friend"`
	IsEmployee       bool `json:"is_employee"`
	HasVerifiedEmail bool `json:"has_verified_email"`
	NSFW             bool `json:"over_18"`
	IsSuspended      bool `json:"is_suspended"`
}

User represents a Reddit user.

type UserService

type UserService struct {
	// contains filtered or unexported fields
}

UserService handles communication with the user related methods of the Reddit API.

Reddit API docs: https://www.reddit.com/dev/api/#section_users

func (*UserService) Block

func (s *UserService) Block(ctx context.Context, username string) (*Blocked, *Response, error)

Block a user.

func (*UserService) BlockByID

func (s *UserService) BlockByID(ctx context.Context, id string) (*Blocked, *Response, error)

BlockByID blocks a user via their full id.

func (*UserService) Comments

func (s *UserService) Comments(ctx context.Context, opts *ListUserOverviewOptions) ([]*Comment, *Response, error)

Comments returns a list of your comments.

func (*UserService) CommentsOf

func (s *UserService) CommentsOf(ctx context.Context, username string, opts *ListUserOverviewOptions) ([]*Comment, *Response, error)

CommentsOf returns a list of the user's comments.

func (*UserService) Downvoted

func (s *UserService) Downvoted(ctx context.Context, opts *ListUserOverviewOptions) ([]*Post, *Response, error)

Downvoted returns a list of your downvoted posts.

func (*UserService) DownvotedOf

func (s *UserService) DownvotedOf(ctx context.Context, username string, opts *ListUserOverviewOptions) ([]*Post, *Response, error)

DownvotedOf returns a list of the user's downvoted posts. The user's votes must be public for this to work (unless the user is you).

func (*UserService) Friend

func (s *UserService) Friend(ctx context.Context, username string) (*Relationship, *Response, error)

Friend a user.

func (*UserService) Get

func (s *UserService) Get(ctx context.Context, username string) (*User, *Response, error)

Get returns information about the user.

func (*UserService) GetFriendship

func (s *UserService) GetFriendship(ctx context.Context, username string) (*Relationship, *Response, error)

GetFriendship returns relationship details with the specified user. If the user is not your friend, it will return an error.

func (*UserService) GetMultipleByID

func (s *UserService) GetMultipleByID(ctx context.Context, ids ...string) (map[string]*UserSummary, *Response, error)

GetMultipleByID returns multiple users from their full IDs. The response body is a map where the keys are the IDs (if they exist), and the value is the user.

func (*UserService) Gilded

func (s *UserService) Gilded(ctx context.Context, opts *ListUserOverviewOptions) ([]*Post, *Response, error)

Gilded returns a list of the user's gilded posts.

func (*UserService) Hidden

func (s *UserService) Hidden(ctx context.Context, opts *ListUserOverviewOptions) ([]*Post, *Response, error)

Hidden returns a list of the user's hidden posts.

func (*UserService) New

New gets the most recently created user subreddits.

func (*UserService) Overview

func (s *UserService) Overview(ctx context.Context, opts *ListUserOverviewOptions) ([]*Post, []*Comment, *Response, error)

Overview returns a list of your posts and comments.

func (*UserService) OverviewOf

func (s *UserService) OverviewOf(ctx context.Context, username string, opts *ListUserOverviewOptions) ([]*Post, []*Comment, *Response, error)

OverviewOf returns a list of the user's posts and comments.

func (*UserService) Popular

func (s *UserService) Popular(ctx context.Context, opts *ListOptions) ([]*Subreddit, *Response, error)

Popular gets the user subreddits with the most activity.

func (*UserService) Posts

func (s *UserService) Posts(ctx context.Context, opts *ListUserOverviewOptions) ([]*Post, *Response, error)

Posts returns a list of your posts.

func (*UserService) PostsOf

func (s *UserService) PostsOf(ctx context.Context, username string, opts *ListUserOverviewOptions) ([]*Post, *Response, error)

PostsOf returns a list of the user's posts.

func (*UserService) Saved

func (s *UserService) Saved(ctx context.Context, opts *ListUserOverviewOptions) ([]*Post, []*Comment, *Response, error)

Saved returns a list of the user's saved posts and comments.

func (*UserService) Search

func (s *UserService) Search(ctx context.Context, query string, opts *ListOptions) ([]*User, *Response, error)

Search for users. todo: maybe include the sort option? (relevance, activity)

func (*UserService) Trophies

func (s *UserService) Trophies(ctx context.Context) ([]*Trophy, *Response, error)

Trophies returns a list of your trophies.

func (*UserService) TrophiesOf

func (s *UserService) TrophiesOf(ctx context.Context, username string) ([]*Trophy, *Response, error)

TrophiesOf returns a list of the specified user's trophies.

func (*UserService) Unblock

func (s *UserService) Unblock(ctx context.Context, username string) (*Response, error)

Unblock a user.

func (*UserService) UnblockByID

func (s *UserService) UnblockByID(ctx context.Context, id string) (*Response, error)

UnblockByID unblocks a user via their full id.

func (*UserService) Unfriend

func (s *UserService) Unfriend(ctx context.Context, username string) (*Response, error)

Unfriend a user.

func (*UserService) Upvoted

func (s *UserService) Upvoted(ctx context.Context, opts *ListUserOverviewOptions) ([]*Post, *Response, error)

Upvoted returns a list of your upvoted posts.

func (*UserService) UpvotedOf

func (s *UserService) UpvotedOf(ctx context.Context, username string, opts *ListUserOverviewOptions) ([]*Post, *Response, error)

UpvotedOf returns a list of the user's upvoted posts. The user's votes must be public for this to work (unless the user is you).

func (*UserService) UsernameAvailable

func (s *UserService) UsernameAvailable(ctx context.Context, username string) (bool, *Response, error)

UsernameAvailable checks whether a username is available for registration.

type UserSummary

type UserSummary struct {
	Name    string     `json:"name,omitempty"`
	Created *Timestamp `json:"created_utc,omitempty"`

	PostKarma    int `json:"link_karma"`
	CommentKarma int `json:"comment_karma"`

	NSFW bool `json:"profile_over_18"`
}

UserSummary represents a Reddit user, but contains fewer pieces of information.

type Widget

type Widget interface {

	// GetID returns the widget's id.
	GetID() string
	// contains filtered or unexported methods
}

Widget is a section of useful content on a subreddit. They can feature information such as rules, links, the origins of the subreddit, etc. Read about them here: https://mods.reddithelp.com/hc/en-us/articles/360010364372-Sidebar-Widgets

type WidgetButton

type WidgetButton struct {
	Text      string `json:"text,omitempty"`
	URL       string `json:"url,omitempty"`
	TextColor string `json:"textColor,omitempty"`
	FillColor string `json:"fillColor,omitempty"`
	// The color of the button's "outline".
	StrokeColor string                  `json:"color,omitempty"`
	HoverState  *WidgetButtonHoverState `json:"hoverState,omitempty"`
}

WidgetButton is a button that's part of a widget.

type WidgetButtonHoverState

type WidgetButtonHoverState struct {
	Text      string `json:"text,omitempty"`
	TextColor string `json:"textColor,omitempty"`
	FillColor string `json:"fillColor,omitempty"`
	// The color of the button's "outline".
	StrokeColor string `json:"color,omitempty"`
}

WidgetButtonHoverState is the behaviour of a button that's part of a widget when it's hovered over with the mouse.

type WidgetCommunity

type WidgetCommunity struct {
	Name        string `json:"name,omitempty"`
	Subscribers int    `json:"subscribers"`
	Subscribed  bool   `json:"isSubscribed"`
	NSFW        bool   `json:"isNSFW"`
}

WidgetCommunity is a community (subreddit) that's displayed in a widget.

type WidgetCreateRequest

type WidgetCreateRequest interface {
	// contains filtered or unexported methods
}

WidgetCreateRequest represents a request to create a widget.

type WidgetImage

type WidgetImage struct {
	Name string `json:"name"`
	URL  string `json:"url"`
}

WidgetImage is an image in a widget.

type WidgetImageLink struct {
	URL     string `json:"url,omitempty"`
	LinkURL string `json:"linkURL,omitempty"`
}

WidgetImageLink is an image that links to an URL within a widget.

type WidgetLink interface {
	// contains filtered or unexported methods
}

WidgetLink is a link or a group of links that's part of a widget.

type WidgetLinkList []WidgetLink

WidgetLinkList is a list of widgets links.

func (*WidgetLinkList) UnmarshalJSON

func (l *WidgetLinkList) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type WidgetLinkMultiple

type WidgetLinkMultiple struct {
	Text string              `json:"text,omitempty"`
	URLs []*WidgetLinkSingle `json:"children,omitempty"`
}

WidgetLinkMultiple is a dropdown of multiple links that's part of a widget.

type WidgetLinkSingle

type WidgetLinkSingle struct {
	Text string `json:"text,omitempty"`
	URL  string `json:"url,omitempty"`
}

WidgetLinkSingle is a link that's part of a widget.

type WidgetList

type WidgetList []Widget

WidgetList is a list of widgets.

func (*WidgetList) UnmarshalJSON

func (l *WidgetList) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type WidgetService

type WidgetService struct {
	// contains filtered or unexported fields
}

WidgetService handles communication with the widget related methods of the Reddit API.

Reddit API docs: https://www.reddit.com/dev/api/#section_widgets

func (*WidgetService) Create

func (s *WidgetService) Create(ctx context.Context, subreddit string, request WidgetCreateRequest) (Widget, *Response, error)

Create a widget for the subreddit.

func (*WidgetService) Delete

func (s *WidgetService) Delete(ctx context.Context, subreddit, id string) (*Response, error)

Delete a widget via its id.

func (*WidgetService) Get

func (s *WidgetService) Get(ctx context.Context, subreddit string) ([]Widget, *Response, error)

Get the subreddit's widgets.

func (*WidgetService) Reorder

func (s *WidgetService) Reorder(ctx context.Context, subreddit string, ids []string) (*Response, error)

Reorder the widgets in the subreddit. The order should contain every single widget id in the subreddit; omitting any id will result in an error. The id list should only contain sidebar widgets. It should exclude the community details and moderators widgets.

type WidgetStyle

type WidgetStyle struct {
	HeaderColor     string `json:"headerColor,omitempty"`
	BackgroundColor string `json:"backgroundColor,omitempty"`
}

WidgetStyle contains style information for the widget.

type WikiPage

type WikiPage struct {
	Content   string `json:"content_md,omitempty"`
	Reason    string `json:"reason,omitempty"`
	MayRevise bool   `json:"may_revise"`

	RevisionID   string     `json:"revision_id,omitempty"`
	RevisionDate *Timestamp `json:"revision_date,omitempty"`
	RevisionBy   *User      `json:"revision_by,omitempty"`
}

WikiPage is a wiki page in a subreddit.

func (*WikiPage) UnmarshalJSON

func (p *WikiPage) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type WikiPageEditRequest

type WikiPageEditRequest struct {
	Subreddit string `url:"-"`
	Page      string `url:"page"`
	Content   string `url:"content"`
	// Optional, up to 256 characters long.
	Reason string `url:"reason,omitempty"`
}

WikiPageEditRequest represents a request to edit a wiki page in a subreddit.

type WikiPagePermissionLevel

type WikiPagePermissionLevel int

WikiPagePermissionLevel defines who can edit a specific wiki page in a subreddit.

const (
	// PermissionSubredditWikiPermissions uses subreddit wiki permissions.
	PermissionSubredditWikiPermissions WikiPagePermissionLevel = iota
	// PermissionApprovedContributorsOnly is only for approved wiki contributors.
	PermissionApprovedContributorsOnly
	// PermissionModeratorsOnly is only for moderators.
	PermissionModeratorsOnly
)

type WikiPageRevision

type WikiPageRevision struct {
	ID      string     `json:"id,omitempty"`
	Page    string     `json:"page,omitempty"`
	Created *Timestamp `json:"timestamp,omitempty"`
	Reason  string     `json:"reason,omitempty"`
	Hidden  bool       `json:"revision_hidden"`
	Author  *User      `json:"author,omitempty"`
}

WikiPageRevision is a revision of a wiki page.

func (*WikiPageRevision) UnmarshalJSON

func (r *WikiPageRevision) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type WikiPageSettings

type WikiPageSettings struct {
	PermissionLevel WikiPagePermissionLevel `json:"permlevel"`
	Listed          bool                    `json:"listed"`
	Editors         []*User                 `json:"editors"`
}

WikiPageSettings holds the settings for a specific wiki page.

func (*WikiPageSettings) UnmarshalJSON

func (s *WikiPageSettings) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type WikiPageSettingsUpdateRequest

type WikiPageSettingsUpdateRequest struct {
	// This HAS to be provided no matter what, or else we get a 500 response.
	PermissionLevel WikiPagePermissionLevel `url:"permlevel"`
	Listed          *bool                   `url:"listed,omitempty"`
}

WikiPageSettingsUpdateRequest represents a request to update the visibility and permissions of a wiki page.

type WikiService

type WikiService struct {
	// contains filtered or unexported fields
}

WikiService handles communication with the wiki related methods of the Reddit API.

Reddit API docs: https://www.reddit.com/dev/api/#section_wiki

func (*WikiService) Allow

func (s *WikiService) Allow(ctx context.Context, subreddit, page, username string) (*Response, error)

Allow the user to edit the specified wiki page in the subreddit.

func (*WikiService) Deny

func (s *WikiService) Deny(ctx context.Context, subreddit, page, username string) (*Response, error)

Deny the user the ability to edit the specified wiki page in the subreddit.

func (*WikiService) Discussions

func (s *WikiService) Discussions(ctx context.Context, subreddit, page string, opts *ListOptions) ([]*Post, *Response, error)

Discussions gets a list of discussions (posts) about the wiki page.

func (*WikiService) Edit

func (s *WikiService) Edit(ctx context.Context, editRequest *WikiPageEditRequest) (*Response, error)

Edit a wiki page.

func (*WikiService) Page

func (s *WikiService) Page(ctx context.Context, subreddit, page string) (*WikiPage, *Response, error)

Page gets a wiki page.

func (*WikiService) PageRevision

func (s *WikiService) PageRevision(ctx context.Context, subreddit, page, revisionID string) (*WikiPage, *Response, error)

PageRevision gets a wiki page at the version it was at the revisionID provided. If revisionID is an empty string, it will get the most recent version.

func (*WikiService) Pages

func (s *WikiService) Pages(ctx context.Context, subreddit string) ([]string, *Response, error)

Pages gets a list of wiki pages in the subreddit. Returns 403 Forbidden if the wiki is disabled.

func (*WikiService) Revert

func (s *WikiService) Revert(ctx context.Context, subreddit, page, revisionID string) (*Response, error)

Revert a wiki page to a specific revision.

func (*WikiService) Revisions

func (s *WikiService) Revisions(ctx context.Context, subreddit string, opts *ListOptions) ([]*WikiPageRevision, *Response, error)

Revisions gets revisions of all pages in the wiki.

func (*WikiService) RevisionsPage

func (s *WikiService) RevisionsPage(ctx context.Context, subreddit, page string, opts *ListOptions) ([]*WikiPageRevision, *Response, error)

RevisionsPage gets revisions of the specific wiki page. If page is an empty string, it gets revisions of all pages in the wiki.

func (*WikiService) Settings

func (s *WikiService) Settings(ctx context.Context, subreddit, page string) (*WikiPageSettings, *Response, error)

Settings gets the subreddit's wiki page's settings.

func (*WikiService) ToggleVisibility

func (s *WikiService) ToggleVisibility(ctx context.Context, subreddit, page, revisionID string) (bool, *Response, error)

ToggleVisibility toggles the public visibility of a wiki page revision. The returned bool is whether the page was set to hidden or not.

func (*WikiService) UpdateSettings

func (s *WikiService) UpdateSettings(ctx context.Context, subreddit, page string, updateRequest *WikiPageSettingsUpdateRequest) (*WikiPageSettings, *Response, error)

UpdateSettings updates the subreddit's wiki page's settings.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL