Documentation
¶
Overview ¶
Package reddit implements an abstraction for the reddit.com API.
Index ¶
- Constants
- type Captcha
- type Comment
- type Deleter
- type ListingOptions
- type LoginSession
- func (s LoginSession) Clear() error
- func (s LoginSession) Delete(d Deleter) error
- func (s LoginSession) Frontpage(sort popularitySort, params ListingOptions) ([]*Submission, error)
- func (s LoginSession) Listing(username, listing string, sort popularitySort, after string) ([]*Submission, error)
- func (s LoginSession) Me() (*Redditor, error)
- func (s LoginSession) MyComments(sort popularitySort, after string) ([]*Submission, error)
- func (s LoginSession) MyDisliked(sort popularitySort, after string) ([]*Submission, error)
- func (s LoginSession) MyGilded(sort popularitySort, after string) ([]*Submission, error)
- func (s LoginSession) MyHidden(sort popularitySort, after string) ([]*Submission, error)
- func (s LoginSession) MyLiked(sort popularitySort, after string) ([]*Submission, error)
- func (s LoginSession) MyOverview(sort popularitySort, after string) ([]*Submission, error)
- func (s LoginSession) MySaved(sort popularitySort, after string) ([]*Submission, error)
- func (s LoginSession) MySubmitted(sort popularitySort, after string) ([]*Submission, 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 NewSubmission
- 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(sort popularitySort, params ListingOptions) ([]*Submission, error)
- func (s Session) SubredditSubmissions(subreddit string, sort popularitySort, params ListingOptions) ([]*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" ThisDay = "day" ThisMonth = "month" ThisYear = "year" AllTime = "all" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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 ListingOptions ¶
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(sort popularitySort, params ListingOptions) ([]*Submission, error)
Frontpage returns the submissions on the logged-in user's personal frontpage.
func (LoginSession) Listing ¶
func (s LoginSession) Listing(username, listing string, sort popularitySort, after string) ([]*Submission, error)
Listing returns a listing for an user
func (LoginSession) Me ¶
func (s LoginSession) Me() (*Redditor, error)
Me returns an up-to-date redditor object of the logged-in user.
func (LoginSession) MyComments ¶
func (s LoginSession) MyComments(sort popularitySort, after string) ([]*Submission, error)
Fetch the Comments listing for the logged-in user
func (LoginSession) MyDisliked ¶
func (s LoginSession) MyDisliked(sort popularitySort, after string) ([]*Submission, error)
Fetch the Disliked listing for the logged-in user
func (LoginSession) MyGilded ¶
func (s LoginSession) MyGilded(sort popularitySort, after string) ([]*Submission, error)
Fetch the Gilded listing for the logged-in user
func (LoginSession) MyHidden ¶
func (s LoginSession) MyHidden(sort popularitySort, after string) ([]*Submission, error)
Fetch the Hidden listing for the logged-in user
func (LoginSession) MyLiked ¶
func (s LoginSession) MyLiked(sort popularitySort, after string) ([]*Submission, error)
Fetch the Liked listing for the logged-in user
func (LoginSession) MyOverview ¶
func (s LoginSession) MyOverview(sort popularitySort, after string) ([]*Submission, error)
Fetch the Overview listing for the logged-in user
func (LoginSession) MySaved ¶
func (s LoginSession) MySaved(sort popularitySort, after string) ([]*Submission, error)
Fetch the Saved listing for the logged-in user
func (LoginSession) MySubmitted ¶
func (s LoginSession) MySubmitted(sort popularitySort, after string) ([]*Submission, error)
Fetch the Submitted listing for 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 NewSubmission ¶
type NewSubmission struct {
Subreddit string
Title string
Content string
Self bool
SendReplies bool
Resubmit bool
Save bool
Captcha *Captcha
}
NewSubmission contains the data needed to submit
func NewLinkSubmission ¶
func NewLinkSubmission(sr, title, link string, replies bool, c *Captcha) *NewSubmission
NewLinkSubmission returns a NewSubmission with parameters appropriate for a link submission
func NewTextSubmission ¶
func NewTextSubmission(sr, title, text string, replies bool, c *Captcha) *NewSubmission
NewTextSubmission returns a NewSubmission with parameters appropriate for a text submission
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(sort popularitySort, params ListingOptions) ([]*Submission, error)
DefaultFrontpage returns the submissions on the default reddit frontpage.
func (Session) SubredditSubmissions ¶
func (s Session) SubredditSubmissions(subreddit string, sort popularitySort, params ListingOptions) ([]*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.