Documentation
¶
Overview ¶
Package mira is fantastic reddit api wrapper
README at https://github.com/thecsw/mira
All function docs here
Index ¶
- Constants
- type ChainVals
- type Credentials
- type MiraInterface
- type Reddit
- func (c *Reddit) Approve() error
- func (c *Reddit) Comment(name string) *Reddit
- func (c *Reddit) Comments(sort string, tdur string, limit int) ([]models.Comment, error)
- func (c *Reddit) CommentsAfter(sort string, last string, limit int) ([]models.Comment, error)
- func (c *Reddit) Compose(subject, text string) error
- func (c *Reddit) Delete() error
- func (c *Reddit) Distinguish(how string, sticky bool) error
- func (c *Reddit) Edit(text string) (models.CommentWrap, error)
- func (c *Reddit) ExtractSubmission() (string, error)
- func (c *Reddit) Info() (MiraInterface, error)
- func (c *Reddit) ListUnreadMessages() ([]models.Comment, error)
- func (c *Reddit) Me() *Reddit
- func (c *Reddit) MiraRequest(method string, target string, payload map[string]string) ([]byte, error)
- func (c *Reddit) ModQueue(limit int) ([]models.ModQueueListingChild, error)
- func (c *Reddit) ModQueueAfter(last string, limit int) ([]models.ModQueueListingChild, error)
- func (c *Reddit) ReadAllMessages() error
- func (c *Reddit) ReadMessage(messageID string) error
- func (c *Reddit) Redditor(name string) *Reddit
- func (c *Reddit) Reply(text string) (models.CommentWrap, error)
- func (c *Reddit) ReplyWithID(name, text string) (models.CommentWrap, error)
- func (c *Reddit) Reports(limit int) ([]models.ModQueueListingChild, error)
- func (c *Reddit) ReportsAfter(last string, limit int) ([]models.ModQueueListingChild, error)
- func (c *Reddit) Root() (string, error)
- func (c *Reddit) Save(text string) (models.CommentWrap, error)
- func (c *Reddit) SaveWithID(name, text string) (models.CommentWrap, error)
- func (c *Reddit) SelectFlair(text string) error
- func (c *Reddit) SelectFlairWithID(name, text string) error
- func (c *Reddit) SetClient(client *http.Client)
- func (c *Reddit) SetDefault()
- func (c *Reddit) StreamCommentReplies() <-chan models.Comment
- func (c *Reddit) StreamComments() (<-chan models.Comment, error)
- func (c *Reddit) StreamMentions() <-chan models.Comment
- func (c *Reddit) StreamModQueue() (<-chan models.PostListingChild, error)
- func (c *Reddit) StreamReports() (<-chan models.ReportListingChild, error)
- func (c *Reddit) StreamSubmissions() (<-chan models.PostListingChild, error)
- func (c *Reddit) Submission(name string) *Reddit
- func (c *Reddit) Submissions(sort string, tdur string, limit int) ([]models.PostListingChild, error)
- func (c *Reddit) SubmissionsAfter(last string, limit int) ([]models.PostListingChild, error)
- func (c *Reddit) Submit(title string, text string) (models.Submission, error)
- func (c *Reddit) Subreddit(name ...string) *Reddit
- func (c *Reddit) UpdateSidebar(text string) error
- func (c *Reddit) UserFlair(user, text string) error
- func (c *Reddit) UserFlairWithID(name, user, text string) error
- type RedditErr
- type RedditVals
- type Streaming
Constants ¶
const ( // RedditBase is the basic reddit base URL, authed is the base URL for use once authenticated RedditBase = "https://www.reddit.com/" // RedditOauth is the oauth url to pass the tokens to RedditOauth = "https://oauth.reddit.com" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Credentials ¶
type Credentials struct { ClientID string ClientSecret string Username string Password string UserAgent string }
func ReadCredsFromEnv ¶
func ReadCredsFromEnv() Credentials
ReadCredsFromEnv reads mira credentials from environment
func ReadCredsFromFile ¶
func ReadCredsFromFile(file string) Credentials
ReadCredsFromFile reads mira credentials from a given file path
type MiraInterface ¶
type MiraInterface interface { GetId() string GetParentId() string GetTitle() string GetBody() string GetAuthor() string GetName() string GetKarma() float64 GetUps() float64 GetDowns() float64 GetSubreddit() string GetCreated() float64 GetFlair() string GetUrl() string IsRoot() bool }
MiraInterface is the interface that unites most of the reddit objects that mira uses and exposes some of the most used methods
type Reddit ¶
type Reddit struct { Token string `json:"access_token"` Duration float64 `json:"expires_in"` Creds Credentials Chain chan *ChainVals Stream Streaming Values RedditVals Client *http.Client }
Reddit is the main mira struct that practically does everything
func Authenticate ¶
func Authenticate(c *Credentials) (*Reddit, error)
Authenticate returns *Reddit object that has been authed
func Init ¶
func Init(c Credentials) (*Reddit, error)
Init is used when we initialize the Reddit instance, automatically start a goroutine that will update the token every 45 minutes. The auto_refresh should not be accessible to the end user as it is an internal method
func (*Reddit) Approve ¶
Approve is a mod tool to approve a comment or a submission Will fail if not a mod.
func (*Reddit) Comments ¶
Comments returns comments from a subreddit up to a specified limit sorted by the given parameters
Sorting options: "hot", "new", "top", "rising", "controversial", "random"
Duration options: "hour", "day", "week", "year", "all"
Limit is any numerical value, so 0 <= limit <= 100.
func (*Reddit) CommentsAfter ¶
CommentsAfter returns new comments from a subreddit
Last is the anchor of a comment id ¶
Limit is any numerical value, so 0 <= limit <= 100.
func (*Reddit) Distinguish ¶
Distinguish is a mod tool to distinguish a comment or a submission Will fail if not a mod.
func (*Reddit) Edit ¶
func (c *Reddit) Edit(text string) (models.CommentWrap, error)
Edit will edit the next queued comment.
func (*Reddit) ExtractSubmission ¶
ExtractSubmission extracts submission id from last pushed object does not make an api call like .Root(), use this instead.
func (*Reddit) Info ¶
func (c *Reddit) Info() (MiraInterface, error)
Info returns MiraInterface of last pushed object.
func (*Reddit) ListUnreadMessages ¶
ListUnreadMessages returns a list of all unread messages.
func (*Reddit) MiraRequest ¶
func (c *Reddit) MiraRequest(method string, target string, payload map[string]string) ([]byte, error)
MiraRequest Reddit API is always developing and I can't implement all endpoints; It will be a bit of a bloat; Instead, you have accessto *Reddit.MiraRequest method that will let you to do any custom reddit api calls!
Here is the signature:
func (c *Reddit) MiraRequest(method string, target string, payload map[string]string) ([]byte, error) {...}
It is pretty straight-forward, the return is a slice of bytes; Parse it yourself.
func (*Reddit) ModQueue ¶
func (c *Reddit) ModQueue(limit int) ([]models.ModQueueListingChild, error)
ModQueue returns modqueue entries from a subreddit up to a specified limit sorted by the given parameters Limit is any numerical value, so 0 <= limit <= 100.
func (*Reddit) ModQueueAfter ¶
ModQueueAfter returns new modqueue entries from a subreddit
Last is the anchor of a modqueue entry id ¶
Limit is any numerical value, so 0 <= limit <= 100.
func (*Reddit) ReadAllMessages ¶
ReadAllMessages uses ReadMessage on all unread messages.
func (*Reddit) ReadMessage ¶
ReadMessage marks the next comment/message as read.
func (*Reddit) Reply ¶
func (c *Reddit) Reply(text string) (models.CommentWrap, error)
Reply replies to a comment with text.
func (*Reddit) ReplyWithID ¶
func (c *Reddit) ReplyWithID(name, text string) (models.CommentWrap, error)
ReplyWithID is the same as Reply but with explicit passing comment id.
func (*Reddit) Reports ¶
func (c *Reddit) Reports(limit int) ([]models.ModQueueListingChild, error)
Reports returns report entries from a subreddit up to a specified limit sorted by the given parameters Limit is any numerical value, so 0 <= limit <= 100.
func (*Reddit) ReportsAfter ¶
ReportsAfter returns new report entries from a subreddit
Last is the anchor of a modqueue entry id ¶
Limit is any numerical value, so 0 <= limit <= 100.
func (*Reddit) Root ¶
Root will return the submission id of a comment Very expensive on API calls, please use .ExtractSubmission() instead.
func (*Reddit) Save ¶
func (c *Reddit) Save(text string) (models.CommentWrap, error)
Save posts a comment to a submission.
func (*Reddit) SaveWithID ¶
func (c *Reddit) SaveWithID(name, text string) (models.CommentWrap, error)
SaveWithID is the same as Save but with explicitely passing.
func (*Reddit) SelectFlair ¶
SelectFlair sets a submission flair.
func (*Reddit) SelectFlairWithID ¶
SelectFlairWithID sets submission flair with explicit ID.
func (*Reddit) StreamCommentReplies ¶
StreamCommentReplies streams comment replies c is the channel with all unread messages
func (*Reddit) StreamComments ¶
StreamComments streams comments from a redditor or a subreddit c is the channel with all comments
func (*Reddit) StreamMentions ¶
StreamMentions streams recent mentions c is the channel with all unread messages
func (*Reddit) StreamModQueue ¶
func (c *Reddit) StreamModQueue() (<-chan models.PostListingChild, error)
StreamModQueue streams modqueue entries from a subreddit c is the channel with all modqueue entries.
func (*Reddit) StreamReports ¶
func (c *Reddit) StreamReports() (<-chan models.ReportListingChild, error)
StreamReports streams reports entries from a subreddit c is the channel with all report entries.
func (*Reddit) StreamSubmissions ¶
func (c *Reddit) StreamSubmissions() (<-chan models.PostListingChild, error)
StreamSubmissions streams submissions from a redditor or a subreddit c is the channel with all submissions.
func (*Reddit) Submission ¶
Submission pushes a new submission value to the internal queue.
func (*Reddit) Submissions ¶
func (c *Reddit) Submissions(sort string, tdur string, limit int) ([]models.PostListingChild, error)
Submissions returns submissions from a subreddit up to a specified limit sorted by the given parameters
Sorting options: "hot", "new", "top", "rising", "controversial", "random"
Duration options: "hour", "day", "week", "year", "all"
Limit is any numerical value, so 0 <= limit <= 100.
func (*Reddit) SubmissionsAfter ¶
SubmissionsAfter returns new submissions from a subreddit
Last is the anchor of a submission id ¶
Limit is any numerical value, so 0 <= limit <= 100.
func (*Reddit) UpdateSidebar ¶
UpdateSidebar updates subreddit's sidebar, Needs mod privileges.
func (*Reddit) UserFlairWithID ¶
UserFlairWithID is the same as UserFlair but explicit redditor name.
type RedditVals ¶
type RedditVals struct {
GetSubmissionFromCommentTries int
}
RedditVals is just some values to backoff