Documentation ¶
Index ¶
- Constants
- func GetOauthURL(endpoint string, formats ...interface{}) *url.URL
- func GetRedditURL(endpoint string, formats ...interface{}) *url.URL
- type BaseJSONResponse
- type BaseResponse
- type CommentResponse
- type CommentsByScore
- type CommentsByScoreDescending
- type ComposeMessageResponse
- type FloatTime
- type MeResponse
- type PostResponse
- type RedditAPI
- func (api *RedditAPI) ComposeMessage(to, subject, text string) error
- func (api *RedditAPI) Get(u *url.URL, query url.Values) (*http.Response, error)
- func (api *RedditAPI) NewRequest(method string, u *url.URL, body io.Reader) (*http.Request, error)
- func (api *RedditAPI) PostForm(u *url.URL, data url.Values) (*http.Response, error)
- func (api *RedditAPI) RequestContestMode(name string, state bool) error
- func (api *RedditAPI) RequestMe() (*MeResponse, error)
- func (api *RedditAPI) RequestPostJSON(u *url.URL) (*PostResponse, error)
- func (api *RedditAPI) RequestRemovePost(name string, spam bool) error
- func (api *RedditAPI) RequestSetStylesheet(subreddit, stylesheet, reason string) (*SetStylesheetResponse, error)
- func (api *RedditAPI) RequestSticky(subreddit string, name string, state bool, num int) error
- func (api *RedditAPI) RequestStylesheet(subreddit string) (string, error)
- func (api *RedditAPI) RequestStylesheetTemplate(subreddit string) (*StylesheetTemplateData, error)
- func (api *RedditAPI) RequestSubmitTextPost(subreddit, title, text string, ad, nsfw, spoiler, sendReplies bool) (*SubmitPostData, error)
- type RedditAccount
- type SetStylesheetResponse
- type StylesheetTemplateData
- type StylesheetTemplateImage
- type SubmitPostData
- type Token
- type TokenExpiresIn
Constants ¶
const ( HTTP = "http" HTTPS = "https" )
schemes
const ( OauthEndpointMe = "/api/v1/me" OauthEndpointStylesheet = "/r/%s/stylesheet" OauthEndpointSetStylesheet = "/r/%s/api/subreddit_stylesheet" OauthEndpointStylesheetTemplate = "/r/%s/about/stylesheet.json" OauthEndpointSubmitPost = "/api/submit" OauthEndpointRequestSticky = "/api/set_subreddit_sticky" OauthEndpointRequestContestMode = "/api/set_contest_mode" OauthEndpointRequestRemovePost = "/api/remove" OauthEndpointComposeMessage = "/api/compose" )
Oauth Endpoints
const (
GrantTypePassword = "password"
)
grant types
const (
RedditEndpointLogin = "/api/v1/access_token"
)
Reddit Endpoints
Variables ¶
This section is empty.
Functions ¶
func GetOauthURL ¶
GetOauthURL returns the URL for an Oauth endpoint
func GetRedditURL ¶
GetRedditURL returns the URL for a reddit endpoint
Types ¶
type BaseJSONResponse ¶
type BaseJSONResponse struct { JSON map[string][][]string `json:"json"` Message string `json:"message"` // indicates a different failure }
BaseJSONResponse is for the JSON API and provides the necessary Error function for it
func (*BaseJSONResponse) Error ¶
func (r *BaseJSONResponse) Error() error
type BaseResponse ¶
BaseResponse stores "error" and "message" and provides a function for validating a response based on these
func (*BaseResponse) Error ¶
func (r *BaseResponse) Error() error
type CommentResponse ¶
type CommentResponse struct { Subreddit string `json:"subreddit"` Saved bool `json:"saved"` GildCount int `json:"gilded"` Downvotes int64 `json:"downs"` Name string `json:"name"` SubredditType string `json:"subreddit_type"` Upvotes int64 `json:"ups"` AuthorName string `json:"author_fullname"` Score int64 `json:"score"` Edited FloatTime `json:"edited"` Archived bool `json:"archived"` Removed bool `json:"removed"` Spoiler bool `json:"spoiler"` Locked bool `json:"locked"` SubredditName string `json:"subreddit_id"` Author string `json:"author"` ContestMode bool `json:"contest_mode"` Approved bool `json:"approved"` Stickied bool `json:"stickied"` CreatedUTC FloatTime `json:"created_utc"` Body string `json:"body"` ParentID string `json:"parent_id"` RepliesListing json.RawMessage `json:"replies"` Replies []*CommentResponse }
func (*CommentResponse) DecodeReplies ¶
func (parentComment *CommentResponse) DecodeReplies() error
type CommentsByScore ¶
type CommentsByScore []CommentResponse
CommentsByScore implements a sort.Interface for sorting comments by score, from lowest to highest
func (CommentsByScore) Len ¶
func (a CommentsByScore) Len() int
func (CommentsByScore) Less ¶
func (a CommentsByScore) Less(i, j int) bool
func (CommentsByScore) Swap ¶
func (a CommentsByScore) Swap(i, j int)
type CommentsByScoreDescending ¶
type CommentsByScoreDescending CommentsByScore
CommentsByScoreDescending implements a sort.Interface for sorting comments by score, from highest to lowest
func (CommentsByScoreDescending) Len ¶
func (a CommentsByScoreDescending) Len() int
func (CommentsByScoreDescending) Less ¶
func (a CommentsByScoreDescending) Less(i, j int) bool
func (CommentsByScoreDescending) Swap ¶
func (a CommentsByScoreDescending) Swap(i, j int)
type ComposeMessageResponse ¶
type ComposeMessageResponse struct {
BaseJSONResponse
}
ComposeMessageResponse is the response from composing a message
type FloatTime ¶
FloatTime implements a custom unmarshaller for decoding the float time into a time.Time-compatible object
func (*FloatTime) UnmarshalJSON ¶
type MeResponse ¶
type MeResponse struct { BaseResponse Username string `json:"reddit_bot"` CommentKarma int `json:"comment_karma"` LinkKarma int `json:"link_karma"` Created FloatTime `json:"created"` CreatedUTC FloatTime `json:"created_utc"` HasMail bool `json:"has_mail"` HasModMail bool `json:"has_mod_mail"` HasVerifiedEmail bool `json:"has_verified_email"` ID string `json:"id"` HasGold bool `json:"is_gold"` IsMod bool `json:"is_mod"` Over18 bool `json:"over_18"` }
MeResponse is the response from a Me query
type PostResponse ¶
type PostResponse struct { Subreddit string `json:"subreddit"` Saved bool `json:"saved"` GildCount int `json:"gilded"` Hidden bool `json:"hidden"` Downvotes int64 `json:"downs"` Name string `json:"name"` ID string `json:"id"` Quarantined bool `json:"quarantine"` SubredditType string `json:"subreddit_type"` Upvotes int64 `json:"ups"` AuthorName string `json:"author_fullname"` CommentCount int64 `json:"num_comments"` Score int64 `json:"score"` Edited FloatTime `json:"edited"` IsSelf bool `json:"is_self"` Archived bool `json:"archived"` NSFW bool `json:"over_18"` Removed bool `json:"removed"` Spoiler bool `json:"spoiler"` Locked bool `json:"locked"` SubredditName string `json:"subreddit_id"` Author string `json:"author"` ContestMode bool `json:"contest_mode"` Approved bool `json:"approved"` Stickied bool `json:"stickied"` URL string `json:"url"` CreatedUTC FloatTime `json:"created_utc"` Body string `json:"selftext"` Replies []CommentResponse }
type RedditAPI ¶
type RedditAPI struct { ClientID string UserAgent string Account *RedditAccount Client http.Client DebugMode bool // contains filtered or unexported fields }
RedditAPI interfaces all the necessary functions to interact with Reddit via the official API
func NewRedditAPI ¶
NewRedditAPI creates a new API with a given ClientID and ClientSecret and with an unauthenticated account
func (*RedditAPI) ComposeMessage ¶
ComposeMessage sends a message to another user
func (*RedditAPI) Get ¶
Get performs a GET request to the specified URL with the specified query parameters Don't forget to close the response body
func (*RedditAPI) NewRequest ¶
func (*RedditAPI) PostForm ¶
PostForm posts form data to the specified URL with the required authentication Don't forget to close the response body
func (*RedditAPI) RequestContestMode ¶
RequestContestMode allows setting a post to contest mode
func (*RedditAPI) RequestMe ¶
func (api *RedditAPI) RequestMe() (*MeResponse, error)
RequestMe queries the "me" API endpoint
func (*RedditAPI) RequestPostJSON ¶
func (api *RedditAPI) RequestPostJSON(u *url.URL) (*PostResponse, error)
RequestPostJSON gets the JSON for a particular post
func (*RedditAPI) RequestRemovePost ¶
RequestRemovePost removes a post as a moderator. Spam specifies whether or not to remove it as spam
func (*RedditAPI) RequestSetStylesheet ¶
func (api *RedditAPI) RequestSetStylesheet(subreddit, stylesheet, reason string) (*SetStylesheetResponse, error)
RequestSetStylesheet sets the stylesheet for a subreddit
func (*RedditAPI) RequestSticky ¶
RequestSticky allows setting a post to sticky set num to -1 for bottom
func (*RedditAPI) RequestStylesheet ¶
RequestStylesheet gets the stylesheet of a particular subreddit
func (*RedditAPI) RequestStylesheetTemplate ¶
func (api *RedditAPI) RequestStylesheetTemplate(subreddit string) (*StylesheetTemplateData, error)
RequestStylesheetTemplate gets the stylesheet template (with e.g. %% %% for images instead of actual urls) for a particular subrededit
func (*RedditAPI) RequestSubmitTextPost ¶
func (api *RedditAPI) RequestSubmitTextPost(subreddit, title, text string, ad, nsfw, spoiler, sendReplies bool) (*SubmitPostData, error)
type RedditAccount ¶
RedditAccount holds the data pertaining to a reddit account
func (*RedditAccount) PasswordLogin ¶
func (a *RedditAccount) PasswordLogin(password string) error
PasswordLogin uses a password to authenticate, storing the access token in the RedditAccount. Returns an error.
type SetStylesheetResponse ¶
type SetStylesheetResponse struct {
BaseJSONResponse
}
type StylesheetTemplateData ¶
type StylesheetTemplateData struct { Images []StylesheetTemplateImage `json:"images"` Stylesheet string `json:"stylesheet"` }
StylesheetTemplateData is the data returned in the stylesheet template request
type StylesheetTemplateImage ¶
type StylesheetTemplateImage struct { URL string `json:"url"` Link string `json:"link"` Name string `json:"name"` }
StylesheetTemplateImage stores the data about an image that has been uploaded to a subreddit for use in the stylesheet
type SubmitPostData ¶
type Token ¶
type Token struct { Token string `json:"access_token"` TokenType string `json:"token_type"` Scope string `json:"scope"` ExpiresIn TokenExpiresIn `json:"expires_in"` // seconds Expiry time.Time Error string `json:"error"` }
Token stores the authentication token and expiry time so that the validity of the token can be automatically verified before requests.
type TokenExpiresIn ¶
TokenExpiresIn is a Duration with custom unmarshaller for unmarshalling the duration as seconds
func (*TokenExpiresIn) UnmarshalJSON ¶
func (t *TokenExpiresIn) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes the JSON into this