Documentation ¶
Overview ¶
Package reddit implements an abstraction for the reddit.com API.
Index ¶
- Constants
- func NewLinkSubmission(sr, title, link string, replies bool, c *Captcha) *newSubmission
- func NewTextSubmission(sr, title, text string, replies bool, c *Captcha) *newSubmission
- type Captcha
- type Comment
- type Deleter
- type LoginSession
- func (s LoginSession) Clear() error
- func (s LoginSession) Delete(d Deleter) error
- func (s LoginSession) Frontpage() ([]*Submission, error)
- func (s LoginSession) Me() (*Redditor, error)
- func (s LoginSession) NeedsCaptcha() (bool, error)
- func (s LoginSession) NewCaptchaIden() (string, error)
- func (s LoginSession) Reply(r Replier, comment string) error
- func (s LoginSession) Submit(ns *newSubmission) error
- func (s LoginSession) Vote(v Voter, vote vote) error
- type Redditor
- type Replier
- type Session
- func (s Session) AboutRedditor(username string) (*Redditor, error)
- func (s Session) AboutSubreddit(subreddit string) (*Subreddit, error)
- func (s Session) CaptchaImage(iden string) (image.Image, error)
- func (s Session) Comments(h *Submission) ([]*Comment, error)
- func (s Session) DefaultFrontpage() ([]*Submission, error)
- func (s Session) SortedSubmissions(subreddit string, popularity popularitySort, age ageSort) ([]*Submission, error)
- func (s Session) SubredditSubmissions(subreddit string) ([]*Submission, error)
- type Submission
- type Subreddit
- type Voter
Constants ¶
const ( UpVote vote = "1" DownVote = "-1" RemoveVote = "0" )
const ( DefaultPopularity popularitySort = "" HotSubmissions = "hot" NewSubmissions = "new" RisingSubmissions = "rising" TopSubmissions = "top" ControversialSubmissions = "controversial" )
const ( DefaultAge ageSort = "" ThisHour = "hour" ThisMonth = "month" ThisYear = "year" AllTime = "all" )
Variables ¶
This section is empty.
Functions ¶
func NewLinkSubmission ¶
NewLinkSubmission returns a newSubmission with parameters appropriate for a link submission
func NewTextSubmission ¶
NewTextSubmission returns a newSubmission with parameters appropriate for a text submission
Types ¶
type Comment ¶
type Comment struct { Author string //`json:"author"` Body string //`json:"body"` BodyHTML string //`json:"body_html"` Subreddit string //`json:"subreddit"` LinkID string //`json:"link_id"` ParentID string //`json:"parent_id"` SubredditID string //`json:"subreddit_id"` FullID string //`json:"name"` UpVotes float64 //`json:"ups"` DownVotes float64 //`json:"downs"` Created float64 //`json:"created_utc"` Edited bool //`json:"edited"` BannedBy *string //`json:"banned_by"` ApprovedBy *string //`json:"approved_by"` AuthorFlairTxt *string //`json:"author_flair_text"` AuthorFlairCSSClass *string //`json:"author_flair_css_class"` NumReports *int //`json:"num_reports"` Likes *int //`json:"likes"` Replies []*Comment }
Comment represents a reddit comment.
type Deleter ¶
type Deleter interface {
// contains filtered or unexported methods
}
Deleter represents something that can be deleted on reddit.com.
type LoginSession ¶
type LoginSession struct { Session // contains filtered or unexported fields }
LoginSession represents an HTTP session with reddit.com -- all authenticated API calls are methods bound to this type.
func NewLoginSession ¶
func NewLoginSession(username, password, useragent string) (*LoginSession, error)
NewLoginSession creates a new session for those who want to log into a reddit account.
func (LoginSession) Clear ¶
func (s LoginSession) Clear() error
Clear clears all session cookies and updates the current session with a new one.
func (LoginSession) Delete ¶
func (s LoginSession) Delete(d Deleter) error
Delete deletes a Submission or Comment.
func (LoginSession) Frontpage ¶
func (s LoginSession) Frontpage() ([]*Submission, error)
Frontpage returns the submissions on the logged-in user's personal frontpage.
func (LoginSession) Me ¶
func (s LoginSession) Me() (*Redditor, error)
Me returns an up-to-date redditor object of the logged-in user.
func (LoginSession) NeedsCaptcha ¶
func (s LoginSession) NeedsCaptcha() (bool, error)
NeedsCaptcha returns true if captcha is required, false if it isn't
func (LoginSession) NewCaptchaIden ¶
func (s LoginSession) NewCaptchaIden() (string, error)
NewCaptchaIden gets a new captcha iden from reddit
func (LoginSession) Reply ¶
func (s LoginSession) Reply(r Replier, comment string) error
Reply posts a comment as a response to a Submission or Comment.
func (LoginSession) Submit ¶
func (s LoginSession) Submit(ns *newSubmission) error
func (LoginSession) Vote ¶
func (s LoginSession) Vote(v Voter, vote vote) error
Vote either votes or rescinds a vote for a Submission or Comment.
type Redditor ¶
type Redditor struct { ID string `json:"id"` Name string `json:"name"` LinkKarma int `json:"link_karma"` CommentKarma int `json:"comment_karma"` Created float32 `json:"created_utc"` Gold bool `json:"is_gold"` Mod bool `json:"is_mod"` Mail *bool `json:"has_mail"` ModMail *bool `json:"has_mod_mail"` }
type Replier ¶
type Replier interface {
// contains filtered or unexported methods
}
Replier represents something that can be replied to on reddit.com.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents an HTTP session with reddit.com without logging into an account.
func NewSession ¶
NewSession creates a new unauthenticated session to reddit.com.
func (Session) AboutRedditor ¶
AboutRedditor returns a Redditor for the given username.
func (Session) AboutSubreddit ¶
AboutSubreddit returns a subreddit for the given subreddit name.
func (Session) CaptchaImage ¶
CaptchaImage gets the png corresponding to the captcha iden and decodes it
func (Session) Comments ¶
func (s Session) Comments(h *Submission) ([]*Comment, error)
Comments returns the comments for a given Submission.
func (Session) DefaultFrontpage ¶
func (s Session) DefaultFrontpage() ([]*Submission, error)
DefaultFrontpage returns the submissions on the default reddit frontpage.
func (Session) SortedSubmissions ¶
func (s Session) SortedSubmissions(subreddit string, popularity popularitySort, age ageSort) ([]*Submission, error)
SortedSubmissions will return submissions from a subreddit (or homepage if "") by popularity and age TODO Review this
func (Session) SubredditSubmissions ¶
func (s Session) SubredditSubmissions(subreddit string) ([]*Submission, error)
SubredditSubmissions returns the submissions on the given subreddit.
type Submission ¶
type Submission struct { Author string `json:"author"` Title string `json:"title"` URL string `json:"url"` Domain string `json:"domain"` Subreddit string `json:"subreddit"` SubredditID string `json:"subreddit_id"` FullID string `json:"name"` ID string `json:"id"` Permalink string `json:"permalink"` Selftext string `json:"selftext"` ThumbnailURL string `json:"thumbnail"` DateCreated float32 `json:"created_utc"` NumComments int `json:"num_comments"` Score int `json:"score"` Ups int `json:"ups"` Downs int `json:"downs"` IsNSFW bool `json:"over_18"` IsSelf bool `json:"is_self"` WasClicked bool `json:"clicked"` IsSaved bool `json:"saved"` BannedBy *string `json:"banned_by"` }
Submission represents an individual post from the perspective of a subreddit. Remember to check for nil pointers before using any pointer fields.
func (*Submission) FullPermalink ¶
func (h *Submission) FullPermalink() string
FullPermalink returns the full URL of a submission.
func (*Submission) String ¶
func (h *Submission) String() string
String returns the string representation of a submission.
type Subreddit ¶
type Subreddit struct { Name string `json:"display_name"` Title string `json:"title"` Desc string `json:"description"` PublicDesc string `json:"public_description"` URL string `json:"url"` FullID string `json:"name"` ID string `json:"id"` HeaderImg string `json:"header_img"` DateCreated float32 `json:"created_utc"` NumSubs int `json:"subscribers"` IsNSFW bool `json:"over18"` }
Subreddit represents a subreddit from reddit.com.