Documentation
¶
Overview ¶
Package reddit provides Reddit API wrapper utilities.
Index ¶
- Constants
- Variables
- func NewError(resp *http.Response) error
- type Account
- type Authenticator
- type Award
- type Client
- func (c *Client) CommentOnLink(linkID string, text string) error
- func (c *Client) DeleteComment(commentID string) error
- func (c *Client) DeleteLink(linkID string) error
- func (c *Client) EditCommentText(commentID string, text string) error
- func (c *Client) EditLinkText(linkID string, text string) error
- func (c *Client) GetDefaultSubreddits() ([]*Subreddit, error)
- func (c *Client) GetGoldSubreddits() ([]*Subreddit, error)
- func (c *Client) GetHotLinks(subreddit string) ([]*Link, error)
- func (c *Client) GetInboxMessages() ([]*Message, error)
- func (c *Client) GetLinkComments(linkID string) ([]*Comment, error)
- func (c *Client) GetMe() (*Account, error)
- func (c *Client) GetMyPreferences() (*Preferences, error)
- func (c *Client) GetMyTrophies() ([]*Award, error)
- func (c *Client) GetNewLinks(subreddit, before, after string) ([]*Link, error)
- func (c *Client) GetNewSubreddits() ([]*Subreddit, error)
- func (c *Client) GetPopularSubreddits() ([]*Subreddit, error)
- func (c *Client) GetSentMessages() ([]*Message, error)
- func (c *Client) GetTopLinks(subreddit string) ([]*Link, error)
- func (c *Client) GetUnreadMessages() ([]*Message, error)
- func (c *Client) GetUserInfo(username string) (*Account, error)
- func (c *Client) HideLink(linkID string) error
- func (c *Client) IsUsernameAvailable(username string) (bool, error)
- func (c *Client) LinksInfo(fullnames []string) ([]*Link, error)
- func (c *Client) ReplyToComment(commentID string, text string) error
- func (c *Client) ReplyToMessage(messageID string, text string) error
- func (c *Client) UpdateMyPreferences(preferences *Preferences) (*Preferences, error)
- type Comment
- type Error
- type Link
- type Media
- type Message
- type Oembed
- type Preferences
- type Subreddit
Constants ¶
const ( // ScopeIdentity allows access to account information. ScopeIdentity = "identity" // ScopeEdit allows modification and deletion of comments and submissions. ScopeEdit = "edit" // ScopeFlair allows modification of user link flair on submissions. ScopeFlair = "flair" // ScopeHistory allows access to user voting history on comments and submissions ScopeHistory = "history" // ScopeModConfig allows management of configuration, sidebar, and CSS of user managed subreddits. ScopeModConfig = "modconfig" // ScopeModFlair allows management and assignment of user moderated subreddits. ScopeModFlair = "modflair" // ScopeModLog allows access to moderation log for user moderated subreddits. ScopeModLog = "modlog" // ScopeModWiki allows changing of editors and visibility of wiki pages in user moderated subreddits. ScopeModWiki = "modwiki" // ScopeMySubreddits allows access to the list of subreddits user moderates, contributes to, and is subscribed to. ScopeMySubreddits = "mysubreddits" // ScopePrivateMessages allows access to user inbox and the sending of private messages to other users. ScopePrivateMessages = "privatemessages" // ScopeRead allows access to user posts and comments. ScopeRead = "read" // ScopeReport allows reporting of content for rules violations. ScopeReport = "report" // ScopeSave allows saving and unsaving of user comments and submissions. ScopeSave = "save" // ScopeSubmit allows user submission of links and comments. ScopeSubmit = "submit" // ScopeSubscribe allows management of user subreddit subscriptions and friends. ScopeSubscribe = "subscribe" // ScopeVote allows user submission and changing of votes on comments and submissions. ScopeVote = "vote" // ScopeWikiEdit allows user editing of wiki pages. ScopeWikiEdit = "wikiedit" // ScopeWikiRead allow user viewing of wiki pages. ScopeWikiRead = "wikiread" )
Variables ¶
var NoAuthClient = &Client{ http: new(http.Client), }
NoAuthClient is the unauthenticated client for interacting with the Reddit API.
Functions ¶
Types ¶
type Account ¶
type Account struct {
CommentKarma int `json:"comment_karma"`
Created float32 `json:"created"`
CreatedUtc float32 `json:"created_utc"`
Features struct {
ActivityServiceRead bool `json:"activity_service_read"`
ActivityServiceWrite bool `json:"activity_service_write"`
AdblockTest bool `json:"adblock_test"`
AdsAuction bool `json:"ads_auction"`
AdsAutoExtend bool `json:"ads_auto_extend"`
AdsAutoRefund bool `json:"ads_auto_refund"`
AdserverReporting bool `json:"adserver_reporting"`
AdzerkDoNotTrack bool `json:"adzerk_do_not_track"`
AdzerkReporting2 bool `json:"adzerk_reporting_2"`
DoNotTrack bool `json:"do_not_track"`
EuCookiePolicy bool `json:"eu_cookie_policy"`
ExpandoEvents bool `json:"expando_events"`
ForceHTTPS bool `json:"force_https"`
GiveHstsGrants bool `json:"give_hsts_grants"`
HTTPSRedirect bool `json:"https_redirect"`
ImageUploads bool `json:"image_uploads"`
ImgurGifConversion bool `json:"imgur_gif_conversion"`
LegacySearchPref bool `json:"legacy_search_pref"`
LiveHappeningNow bool `json:"live_happening_now"`
MoatTracking bool `json:"moat_tracking"`
MobileNativeBanner bool `json:"mobile_native_banner"`
MobileSettings bool `json:"mobile_settings"`
MobileWebTargeting bool `json:"mobile_web_targeting"`
NewLoggedinCachePolicy bool `json:"new_loggedin_cache_policy"`
NewReportDialog bool `json:"new_report_dialog"`
OrangeredsAsEmails bool `json:"orangereds_as_emails"`
OutboundClicktracking bool `json:"outbound_clicktracking"`
PauseAds bool `json:"pause_ads"`
PostEmbed bool `json:"post_embed"`
ScreenviewEvents bool `json:"screenview_events"`
ScrollEvents bool `json:"scroll_events"`
ShowNewIcons bool `json:"show_new_icons"`
StickyComments bool `json:"sticky_comments"`
SubredditRules bool `json:"subreddit_rules"`
Timeouts bool `json:"timeouts"`
UpgradeCookies bool `json:"upgrade_cookies"`
YoutubeScraper bool `json:"youtube_scraper"`
} `json:"features"`
GoldCreddits int `json:"gold_creddits"`
GoldExpiration int `json:"gold_expiration"`
HasVerifiedEmail bool `json:"has_verified_email"`
HideFromRobots bool `json:"hide_from_robots"`
ID string `json:"id"`
InBeta bool `json:"in_beta"`
InboxCount int `json:"inbox_count"`
IsEmployee bool `json:"is_employee"`
IsGold bool `json:"is_gold"`
IsMod bool `json:"is_mod"`
IsSuspended bool `json:"is_suspended"`
LinkKarma int `json:"link_karma"`
Name string `json:"name"`
Over18 bool `json:"over_18"`
SuspensionExpirationUtc int `json:"suspension_expiration_utc"`
}
Account contains user account information.
type Authenticator ¶
type Authenticator struct {
// contains filtered or unexported fields
}
Authenticator provides functions for authenticating a user via OAuth2 and generating a client that can be used to access authorized API endpoints.
func NewAuthenticator ¶
func NewAuthenticator(ua string, clientID string, clientSecret string, redirectURL string, state string, scopes ...string) *Authenticator
NewAuthenticator generates a new authenticator with the supplied client, state, and requested scopes.
func (*Authenticator) GetAuthClient ¶
func (a *Authenticator) GetAuthClient(token *oauth2.Token, userAgent string) *Client
GetAuthClient generates a new authenticated client using the supplied access token.
func (*Authenticator) GetAuthenticationURL ¶
func (a *Authenticator) GetAuthenticationURL() string
GetAuthenticationURL retrieves the URL used to direct the authenticating user to Reddit for permissions approval.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the client for interacting with the Reddit API.
func (*Client) CommentOnLink ¶
CommentOnLink posts a top-level comment to the given link. Requires the 'submit' OAuth scope.
func (*Client) DeleteComment ¶
DeleteComment deletes a comment submitted by the currently authenticated user. Requires the 'edit' OAuth scope.
func (*Client) DeleteLink ¶
DeleteLink deletes a link submitted by the currently authenticated user. Requires the 'edit' OAuth scope.
func (*Client) EditCommentText ¶
EditCommentText edits the text of a comment by the currently authenticated user. Requires the 'edit' OAuth scope.
func (*Client) EditLinkText ¶
EditLinkText edits the text of a self post by the currently authenticated user. Requires the 'edit' OAuth scope.
func (*Client) GetDefaultSubreddits ¶
GetDefaultSubreddits retrieves a listing of default subreddits.
func (*Client) GetGoldSubreddits ¶
GetGoldSubreddits retrieves a listing of gold subreddits.
func (*Client) GetHotLinks ¶
GetHotLinks retrieves a listing of hot links.
func (*Client) GetInboxMessages ¶
GetInboxMessages retrieves a list of messages in the user's inbox. Requires the 'privatemessages' OAuth scope.
func (*Client) GetLinkComments ¶
GetLinkComments retrieves a listing of comments for the given link.
func (*Client) GetMe ¶
GetMe retrieves the user account for the currently authenticated user. Requires the 'identity' OAuth scope.
func (*Client) GetMyPreferences ¶
func (c *Client) GetMyPreferences() (*Preferences, error)
GetMyPreferences retrieves the accouunt preferences for the currently authenticated user. Requires the 'identity' OAuth scope.
func (*Client) GetMyTrophies ¶
GetMyTrophies retrieves a list of awards for the currently authenticated user. Requires the 'identity' OAuth scope.
func (*Client) GetNewLinks ¶
GetNewLinks retrieves a listing of new links.
func (*Client) GetNewSubreddits ¶
GetNewSubreddits retrieves a listing of new subreddits.
func (*Client) GetPopularSubreddits ¶
GetPopularSubreddits retrieves a listing of popular subreddits.
func (*Client) GetSentMessages ¶
GetSentMessages retrieves a list of messages sent by the user. Requires the 'privatemessages' OAuth scope.
func (*Client) GetTopLinks ¶
GetTopLinks retrieves a listing of top links.
func (*Client) GetUnreadMessages ¶
GetUnreadMessages retrieves a list of unread messages in the user's inbox. Requires the 'privatemessages' OAuth scope.
func (*Client) GetUserInfo ¶
GetUserInfo retrieves user account information for the supplied username.
func (*Client) HideLink ¶
HideLink removes the given link from the user's default view of subreddit listings. Requires the 'report' OAuth scope.
func (*Client) IsUsernameAvailable ¶
IsUsernameAvailable determines if the supplied username is available for registration.
func (*Client) ReplyToComment ¶
ReplyToComment creates a reply to the given comment. Requires the 'submit' OAuth scope.
func (*Client) ReplyToMessage ¶
ReplyToMessage creates a reply to a message sent to the user. Requires the 'privatemessages' OAuth scope.
func (*Client) UpdateMyPreferences ¶
func (c *Client) UpdateMyPreferences(preferences *Preferences) (*Preferences, error)
UpdateMyPreferences updates the accouunt preferences for the currently authenticated user. Requires the 'account' OAuth scope.
type Comment ¶
type Comment struct {
ApprovedBy interface{} `json:"approved_by"`
Archived bool `json:"archived"`
Author string `json:"author"`
AuthorFlairCSSClass interface{} `json:"author_flair_css_class"`
AuthorFlairText interface{} `json:"author_flair_text"`
BannedBy interface{} `json:"banned_by"`
Body string `json:"body"`
BodyHTML string `json:"body_html"`
Controversiality int `json:"controversiality"`
Created int `json:"created"`
CreatedUtc int `json:"created_utc"`
Distinguished interface{} `json:"distinguished"`
Downs int `json:"downs"`
Edited bool `json:"edited"`
Gilded int `json:"gilded"`
ID string `json:"id"`
Likes interface{} `json:"likes"`
LinkID string `json:"link_id"`
ModReports []interface{} `json:"mod_reports"`
Name string `json:"name"`
NumReports interface{} `json:"num_reports"`
ParentID string `json:"parent_id"`
RemovalReason interface{} `json:"removal_reason"`
ReportReasons interface{} `json:"report_reasons"`
Replies string `json:"replies"`
Saved bool `json:"saved"`
Score int `json:"score"`
ScoreHidden bool `json:"score_hidden"`
Stickied bool `json:"stickied"`
Subreddit string `json:"subreddit"`
SubredditID string `json:"subreddit_id"`
Ups int `json:"ups"`
UserReports []interface{} `json:"user_reports"`
}
Comment is a response to a link or another comment.
type Link ¶
type Link struct {
ApprovedBy string `json:"approved_by"`
Archived bool `json:"archived"`
Author string `json:"author"`
AuthorFlairCSSClass string `json:"author_flair_css_class"`
AuthorFlairText string `json:"author_flair_text"`
BannedBy string `json:"banned_by"`
Clicked bool `json:"clicked"`
ContestMode bool `json:"contest_mode"`
Created float64 `json:"created"`
CreatedUtc float64 `json:"created_utc"`
CrosspostParent string `json:"crosspost_parent"`
CrosspostParentList []*Link `json:"crosspost_parent_list"`
Distinguished string `json:"distinguished"`
Domain string `json:"domain"`
Downs int `json:"downs"`
// This can be a bool or a timestamp apperentely, what the fuck
Edited interface{} `json:"edited"`
Gilded int `json:"gilded"`
Hidden bool `json:"hidden"`
HideScore bool `json:"hide_score"`
ID string `json:"id"`
IsSelf bool `json:"is_self"`
Likes bool `json:"likes"`
LinkFlairCSSClass string `json:"link_flair_css_class"`
LinkFlairText string `json:"link_flair_text"`
Locked bool `json:"locked"`
Media Media `json:"media"`
MediaEmbed interface{} `json:"media_embed"`
ModReports []interface{} `json:"mod_reports"`
Name string `json:"name"`
NumComments int `json:"num_comments"`
NumReports int `json:"num_reports"`
Over18 bool `json:"over_18"`
Permalink string `json:"permalink"`
PostHint string `json:"post_hint"`
Quarantine bool `json:"quarantine"`
RemovalReason interface{} `json:"removal_reason"`
ReportReasons []interface{} `json:"report_reasons"`
Saved bool `json:"saved"`
Score int `json:"score"`
SecureMedia interface{} `json:"secure_media"`
SecureMediaEmbed interface{} `json:"secure_media_embed"`
SelftextHTML string `json:"selftext_html"`
Selftext string `json:"selftext"`
Stickied bool `json:"stickied"`
Subreddit string `json:"subreddit"`
SubredditID string `json:"subreddit_id"`
SuggestedSort string `json:"suggested_sort"`
Thumbnail string `json:"thumbnail"`
Title string `json:"title"`
URL string `json:"url"`
Ups int `json:"ups"`
UserReports []interface{} `json:"user_reports"`
Visited bool `json:"visited"`
IsRobotIndexable bool `json:"is_robot_indexable"`
Spoiler bool `json:"spoiler"`
}
Link contains information about a link.
type Message ¶
type Message struct {
Author string `json:"author"`
Body string `json:"body"`
BodyHTML string `json:"body_html"`
Context string `json:"context"`
Created int `json:"created"`
CreatedUtc int `json:"created_utc"`
Dest string `json:"dest"`
Distinguished string `json:"distinguished"`
FirstMessage interface{} `json:"first_message"`
FirstMessageName interface{} `json:"first_message_name"`
ID string `json:"id"`
Name string `json:"name"`
New bool `json:"new"`
ParentID interface{} `json:"parent_id"`
Replies string `json:"replies"`
Subject string `json:"subject"`
Subreddit interface{} `json:"subreddit"`
WasComment bool `json:"was_comment"`
}
Message is a private message between users.
type Oembed ¶
type Oembed struct {
Description string `json:"description"`
HTML string `json:"html"`
Height int `json:"height"`
ProviderName string `json:"provider_name"`
ProviderURL string `json:"provider_url"`
ThumbnailHeight int `json:"thumbnail_height"`
ThumbnailURL string `json:"thumbnail_url"`
ThumbnailWidth int `json:"thumbnail_width"`
Title string `json:"title"`
Type string `json:"type"`
Version string `json:"version"`
Width int `json:"width"`
}
Oembed contains embedding information for a media item.
type Preferences ¶
type Preferences struct {
AffiliateLinks bool `json:"affiliate_links"`
AllowClicktracking bool `json:"allow_clicktracking"`
Beta bool `json:"beta"`
Clickgadget bool `json:"clickgadget"`
CollapseLeftBar bool `json:"collapse_left_bar"`
Compress bool `json:"compress"`
CollapseReadMessages bool `json:"collapse_read_messages"`
ContentLangs []string `json:"content_langs"`
CredditAutorenew bool `json:"creddit_autorenew"`
DefaultCommentSort string `json:"default_comment_sort"`
DefaultThemeSr interface{} `json:"default_theme_sr"`
DomainDetails bool `json:"domain_details"`
EmailMessages bool `json:"email_messages"`
EnableDefaultThemes bool `json:"enable_default_themes"`
ForceHTTPS bool `json:"force_https"`
HideAds bool `json:"hide_ads"`
HideDowns bool `json:"hide_downs"`
HideFromRobots bool `json:"hide_from_robots"`
HideLocationbar bool `json:"hide_locationbar"`
HideUps bool `json:"hide_ups"`
HighlightControversial bool `json:"highlight_controversial"`
HighlightNewComments bool `json:"highlight_new_comments"`
IgnoreSuggestedSort bool `json:"ignore_suggested_sort"`
LabelNsfw bool `json:"label_nsfw"`
Lang string `json:"lang"`
LegacySearch bool `json:"legacy_search"`
LiveOrangereds bool `json:"live_orangereds"`
MarkMessagesRead bool `json:"mark_messages_read"`
Media string `json:"media"`
MediaPreview string `json:"media_preview"`
MinCommentScore int `json:"min_comment_score"`
MinLinkScore int `json:"min_link_score"`
MonitorMentions bool `json:"monitor_mentions"`
Newwindow bool `json:"newwindow"`
NoProfanity bool `json:"no_profanity"`
NumComments int `json:"num_comments"`
Numsites int `json:"numsites"`
Organic bool `json:"organic"`
Over18 bool `json:"over_18"`
PrivateFeeds bool `json:"private_feeds"`
PublicServerSeconds bool `json:"public_server_seconds"`
PublicVotes bool `json:"public_votes"`
Research bool `json:"research"`
ShowFlair bool `json:"show_flair"`
ShowGoldExpiration bool `json:"show_gold_expiration"`
ShowLinkFlair bool `json:"show_link_flair"`
ShowPromote bool `json:"show_promote"`
ShowSnoovatar bool `json:"show_snoovatar"`
ShowStylesheets bool `json:"show_stylesheets"`
ShowTrending bool `json:"show_trending"`
StoreVisits bool `json:"store_visits"`
ThreadedMessages bool `json:"threaded_messages"`
ThreadedModmail bool `json:"threaded_modmail"`
UseGlobalDefaults bool `json:"use_global_defaults"`
}
Preferences contains a user's account preferences.
type Subreddit ¶
type Subreddit struct {
AccountsActive int `json:"accounts_active"`
BannerImg string `json:"banner_img"`
BannerSize []int `json:"banner_size"`
CollapseDeletedComments bool `json:"collapse_deleted_comments"`
CommentScoreHideMins int `json:"comment_score_hide_mins"`
Created int `json:"created"`
CreatedUtc int `json:"created_utc"`
Description string `json:"description"`
DescriptionHTML string `json:"description_html"`
DisplayName string `json:"display_name"`
HeaderImg string `json:"header_img"`
HeaderSize []int `json:"header_size"`
HeaderTitle string `json:"header_title"`
HideAds bool `json:"hide_ads"`
IconImg string `json:"icon_img"`
IconSize []int `json:"icon_size"`
ID string `json:"id"`
KeyColor string `json:"key_color"`
Lang string `json:"lang"`
Name string `json:"name"`
Over18 bool `json:"over18"`
PublicDescription string `json:"public_description"`
PublicDescriptionHTML string `json:"public_description_html"`
PublicTraffic bool `json:"public_traffic"`
Quarantine bool `json:"quarantine"`
ShowMedia bool `json:"show_media"`
ShowMediaPreview bool `json:"show_media_preview"`
SubmissionType string `json:"submission_type"`
SubmitLinkLabel string `json:"submit_link_label"`
SubmitText string `json:"submit_text"`
SubmitTextHTML string `json:"submit_text_html"`
SubmitTextLabel string `json:"submit_text_label"`
SubredditType string `json:"subreddit_type"`
Subscribers int `json:"subscribers"`
SuggestedCommentSort string `json:"suggested_comment_sort"`
Title string `json:"title"`
URL string `json:"url"`
UserIsBanned bool `json:"user_is_banned"`
UserIsContributor bool `json:"user_is_contributor"`
UserIsModerator bool `json:"user_is_moderator"`
UserIsMuted bool `json:"user_is_muted"`
UserIsSubscriber bool `json:"user_is_subscriber"`
UserSrThemeEnabled bool `json:"user_sr_theme_enabled"`
WikiEnabled bool `json:"wiki_enabled"`
}
Subreddit contains subreddit information.