Documentation
¶
Overview ¶
Package grape (Go Reddit Api PackagE) is an all encompassing Reddit API wrapper
This library is currently under active development and the functionality is growing rapidly.
Index ¶
- Constants
- Variables
- type Comment
- type Message
- type Redditor
- func (r *Redditor) ClearSessions(pass string) error
- func (r *Redditor) ComposeMessage() error
- func (r *Redditor) DeleteAccount(passwd string) error
- func (r *Redditor) GetFrontpage() (*Subreddit, error)
- func (r *Redditor) GetFrontpageN(n int) (*Subreddit, error)
- func (r *Redditor) GetInbox(limit int) ([]Message, error)
- func (r *Redditor) GetUnreadMail(limit int) ([]Message, error)
- func (r *Redditor) IsLoggedIn() bool
- func (r *Redditor) Me() error
- func (r *Redditor) PostComment(parent *Submission, body string) error
- func (r *Redditor) ReplyToComment(parent *Comment, body string) error
- func (r *Redditor) SubmitLink(subreddit, title, link string, resubmit bool) error
- func (r *Redditor) SubmitSelf(subreddit, title, body string) error
- func (r *Redditor) UpdateEmailAndPass(email, newpass, curpass string) error
- type Submission
- type Subreddit
- type Thing
Constants ¶
const ( CommentPrefix = "t1_" AccountPrefix = "t2_" LinkPrefix = "t3_" MessagePrefix = "t4_" SubredditPrefix = "t5_" AwardPrefix = "t6_" PromoCampaign = "t8_" )
reddit Id prefixes
const ( Hot sort = "hot" Top sort = "top" New sort = "new" Cont sort = "controversial" Conf sort = "confidence" DefaultSort sort = "subreddit" )
Listing sort constants
const ( Hour period = "hour" Day period = "day" Week period = "week" Month period = "month" Year period = "year" All period = "all" DefaultPeriod period = "" )
time period constants
const ( Banuser = "banuser" Unbanuser = "unbanuser" Removelink = "removelink" Approvelink = "approvelink" Removecomment = "removecomment" Approvecomment = "approvecomment" Addmoderator = "addmoderator" Invitemoderator = "invitemoderator" Uninvitemoderator = "uninvitemoderator" Acceptmoderatorinvite = "acceptmoderatorinvite" Removemoderator = "removemoderator" Addcontributor = "addcontributor" Removecontributor = "removecontributor" Editsettings = "editsettings" Editflair = "editflair" Distinguish = "distinguish" Marknsfw = "marknsfw" Wikibanned = "wikibanned" Wikicontributor = "wikicontributor" Wikiunbanned = "wikiunbanned" Removewikicontributor = "removewikicontributor" Wikirevise = "wikirevise" Wikipermlevel = "wikipermlevel" Ignorereports = "ignorereports" Unignorereports = "unignorereports" Setpermissions = "setpermissions" Sticky = "sticky" Unsticky = "unsticky" )
Moderator Actions
Variables ¶
var Config = new(cfg)
Configuration structures
Functions ¶
This section is empty.
Types ¶
type Comment ¶
type Comment struct { Author string Body string ScoreHidden bool Ups int Downs int ApprovedBy string `json:"approved_by"` AuthorFlairCSS string `json:"author_flair_css_class"` AuthorFlairText string `json:"author_flair_text"` BannedBy string `json:"banned_by"` Edited time.Time Gilded int Likes bool LinkId string `json:"link_id"` LinkTitle string `json:"link_title"` NumReports int `json:"num_reports"` ParentId string `json:"parent_id"` Sub string `json:"subreddit"` SubId string `json:"subreddit_id"` Distinguished string Replies []Comment *Thing }
func (*Comment) MoreChildren ¶
type Message ¶
type Message struct { WasComment bool Body string Subject string Subreddit string // if comment ParentId string `json:"parent_id"` New bool Author string Recipient string `json:"dest"` Context string Likes bool LinkTitle string `json:"link_title"` // if comment Replies string *Thing }
func (*Message) MarkAsRead ¶
MarkAsRead marks the messages as read for the user
func (*Message) MarkAsUnread ¶
MarkAsUnread marks the message as unread for the user
type Redditor ¶
type Redditor struct { LKarma int `json:"link_karma"` CKarma int `json:"comment_karma"` IsFriend bool `json:"is_friend"` HasMail bool `json:"has_mail"` IsOver18 bool `json:"over_18"` IsGold bool `json:"is_gold"` IsMod bool `json:"is_mod"` Created int CreatedUTC time.Time `json:"created_utc"` HasModMail bool `json:"has_mod_mail"` VerifiedEmail bool `json:"has_verified_email"` ModHash string *Thing }
func GetRedditor ¶
GetRedditor returns a redditor object containing all information relevant to that reddit user
func Login ¶
Login logs a user into reddit through the api login page returns the same errors recieved from reddit, if applicable otherwise returns a redditor with populated modhash TODO(Stringy): add support for ssl.reddit.com/login
func NewRedditor ¶
func NewRedditor() *Redditor
func (*Redditor) ClearSessions ¶
ClearSessions clears the current user's reddit sessions This will result in immediate logging out of the user
func (*Redditor) ComposeMessage ¶
func (*Redditor) DeleteAccount ¶
DeleteAccount deletes the user from reddit
func (*Redditor) GetFrontpage ¶
GetFrontpage returns the frontpage for the user, including all subscribed subreddits
func (*Redditor) GetFrontpageN ¶
GetFrontpageN returns the first n submissions from their frontpage similar semantics to GetSubredditN
func (*Redditor) GetInbox ¶
GetInbox gets all mail from the user's mail doesn't require modhash for reading
func (*Redditor) GetUnreadMail ¶
GetUnreadMail gets the unread mail for the user doesn't require modhash for reading messages
func (*Redditor) IsLoggedIn ¶
IsLoggedIn returns true if the user is currently logged into reddit
func (*Redditor) PostComment ¶
func (r *Redditor) PostComment(parent *Submission, body string) error
PostComment posts a top level comment to a reddit submission
func (*Redditor) ReplyToComment ¶
ReplyToComment replies to a reddit comment on behalf of the user
func (*Redditor) SubmitLink ¶
SubmitLink submits a link to the subreddit
func (*Redditor) SubmitSelf ¶
SubmitSelf submits a self (non-link) submission to the subreddit of choice
func (*Redditor) UpdateEmailAndPass ¶
UpdateEmailAndPass updates the user's email and password. The user must provide their current password for this to succeed.
type Submission ¶
type Submission struct { Title string Url string NumComments int `json:"num_comments"` Author string IsSelf bool `json:"is_self"` IsNSFW bool `json:"over_18"` SelfText string Created float64 `json:"created_utc"` Score int Ups int Downs int Sub string `json:"subreddit"` AuthorFlairCSS string `json:"author_flair_css_class"` AuthorFlairText string `json:"author_flair_text"` LinkFlairCSS string `json:"link_flair_css_class"` LinkFlairText string `json:"link_flair_text"` Clicked bool Domain string Hidden bool Likes bool Permalink string Saved bool Edited int Distinguished string Stickied bool *Thing }
func (*Submission) GetComments ¶
func (r *Submission) GetComments(s sort, t period) []Comment
func (*Submission) GetUrl ¶
func (r *Submission) GetUrl() string
func (*Submission) PostComment ¶
func (r *Submission) PostComment(user *Redditor, body string) error
func (*Submission) String ¶
func (r *Submission) String() string
type Subreddit ¶
type Subreddit struct { AccountsActive int `json:"accounts_active"` HideDuration int `json:"comment_score_hide_mins"` Description string DisplayName string `json:"display_name"` HeaderImage string `json:"header_img"` HeaderSize []int `json:"header_size"` HeaderTitle string `json:"header_title"` Over18 bool `json:"over_18"` PublicDesc string `json:"public_description"` PublicTraffic bool `json:"public_traffic"` Subscribers int SubmissionType string `json:"submission_type"` SubredditType string `json:"subreddit_type"` Title string Url string // relative e.g. /r/pics UserIsBanned bool `json:"user_is_banned"` UserIsContrib bool `json:"user_is_contributor"` UserIsMod bool `json:"user_is_moderator"` UserIsSub bool `json:"user_is_subscriber"` Items []struct { Submission `json:"data"` } `json:"children"` *sync.RWMutex *Thing }
func GetFrontPage ¶
GetFrontPage currently gets the front page of *default* reddit TODO(Stringy): apply this to currently logged in user
func GetSubreddit ¶
GetSubreddit gets the front page of a named subreddit.
sub is the name of a valid subreddit
func NewSubreddit ¶
func NewSubreddit() *Subreddit
func (*Subreddit) GetControversial ¶
func (s *Subreddit) GetControversial(limit int) ([]Submission, error)
func (*Subreddit) GetHot ¶
func (s *Subreddit) GetHot(limit int) ([]Submission, error)
GetHot returns a list of "hot" submissions from the subreddit
func (*Subreddit) GetNew ¶
func (s *Subreddit) GetNew(limit int) ([]Submission, error)
GetNew returns a list of "new" submissions from the subreddit
type Thing ¶
type Thing struct { Id string Name string //fullname of a reddit thing (t1_, t2_, ...) Kind string //type }
func (*Thing) Hide ¶
Hide hides a Thing for user, so that it won't appear on any requests returns any errors from reddit
func (*Thing) MarkNsfw ¶
MarkNsfw marks a reddit thing as not safe for work for user returns errors from reddit
func (*Thing) Report ¶
Report reports a reddit Thing by user returns any errors recieved from reddit
func (*Thing) Unhide ¶
Unhide undoes Hide to allow a Thing to turn up in user's requests returns any errors from reddit
func (*Thing) UnmarkNsfw ¶
UnmarkNsfw unmarks a Thing as not safe for work returns errors recieved from reddit