Documentation ¶
Index ¶
- Constants
- func GetRedditAuthorizationUrl(user_id string, client_config RedditClientConfig) string
- type CollectorConfig
- type RedditAuthenticationResult
- type RedditClient
- func NewAuthenticatedRedditClient(user *RedditUser, client_config RedditClientConfig) *RedditClient
- func NewOauthRedditClient(user_id, code string, client_config RedditClientConfig) (*RedditClient, error)
- func NewRedditClient(user *RedditUser, client_config RedditClientConfig) (*RedditClient, error)
- func (client *RedditClient) Me() (RedditUser, error)
- func (client *RedditClient) Posts(subreddit *RedditItem, post_type string) ([]RedditItem, error)
- func (client *RedditClient) RetrieveComments(post *RedditItem) ([]RedditItem, error)
- func (client *RedditClient) SimilarSubreddits(subreddit *RedditItem) ([]RedditItem, error)
- func (client *RedditClient) SubredditSearch(search_query string) ([]RedditItem, error)
- func (client *RedditClient) Subreddits() ([]RedditItem, error)
- type RedditClientConfig
- type RedditCollector
- type RedditItem
- type RedditUser
Constants ¶
const ( JSON_BODY = "application/json" URL_ENCODED_BODY = "application/x-www-form-urlencoded" )
const ( DEFAULT_USERID = "__BLANK__" SCOPE = "identity read mysubreddits" )
const ( REDDIT_OAUTH_AUTHORIZE_URL = "https://www.reddit.com/api/v1/authorize" REDDIT_OAUTH_URL = "https://www.reddit.com/api/v1/access_token" REDDIT_DATA_URL = "https://oauth.reddit.com" )
const ( SUBREDDIT = "subreddit" POST = "post" COMMENT = "comment" )
const ( HOT = "hot" TOP = "top" BEST = "best" )
const ( REDDIT_URL = "https://www.reddit.com" REDDIT_SOURCE = "REDDIT" )
const ( MIN_SUBSCRIBER_LIMIT = 10000 MAX_POST_LIMIT = 10 )
const ( MAX_SUBREDDIT_TEXT_LENGTH = 1024 * 4 MAX_POST_TEXT_LENGTH = 3072 * 4 MAX_ARTICLE_TEXT_LENGTH = 4096 * 4 MAX_COMMENT_TEXT_LENGTH = 512 * 4 MAX_EXTRACTED_TEXT_LENGTH = 4096 * 4 MAX_CHILD_TEXT_LENGTH = 512 * 4 MIN_TEXT_LENGTH = 5 * 4 // anything below this text length, just ignore it MAX_DIGEST_TEXT_LENGTH = 6144 * 4 // 6144 tokens are roughly 6144*4 characters. This is around 7.5 pages full of content )
const ( // changing wait time since it takes while to publish all the messages MAX_WAIT_TIME = 10 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func GetRedditAuthorizationUrl ¶
func GetRedditAuthorizationUrl(user_id string, client_config RedditClientConfig) string
Types ¶
type CollectorConfig ¶
type CollectorConfig struct { MasterCollectorUsername string MasterCollectorPassword string RedditClientConfig // contains filtered or unexported fields }
func NewCollectorConfig ¶
func NewCollectorConfig(store_func func(beans []ds.Bean)) CollectorConfig
type RedditAuthenticationResult ¶
type RedditAuthenticationResult struct { AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` FailureMessage string `json:"message"` }
func (RedditAuthenticationResult) Error ¶
func (res RedditAuthenticationResult) Error() string
type RedditClient ¶
type RedditClient struct { User *RedditUser // contains filtered or unexported fields }
func NewAuthenticatedRedditClient ¶
func NewAuthenticatedRedditClient(user *RedditUser, client_config RedditClientConfig) *RedditClient
func NewOauthRedditClient ¶
func NewOauthRedditClient(user_id, code string, client_config RedditClientConfig) (*RedditClient, error)
func NewRedditClient ¶
func NewRedditClient(user *RedditUser, client_config RedditClientConfig) (*RedditClient, error)
func (*RedditClient) Me ¶
func (client *RedditClient) Me() (RedditUser, error)
func (*RedditClient) Posts ¶
func (client *RedditClient) Posts(subreddit *RedditItem, post_type string) ([]RedditItem, error)
gets posts: hot, best and top depending what is specified through post_type if sub_reddit display name is not specified it will pull from the overall list of posts instead of a specific subreddit TODO: deal with paging
func (*RedditClient) RetrieveComments ¶
func (client *RedditClient) RetrieveComments(post *RedditItem) ([]RedditItem, error)
retrieves comments for a specific post
func (*RedditClient) SimilarSubreddits ¶
func (client *RedditClient) SimilarSubreddits(subreddit *RedditItem) ([]RedditItem, error)
get subreddits based on a given does not return unique list of items and may have duplicates TODO: deal with paging
func (*RedditClient) SubredditSearch ¶
func (client *RedditClient) SubredditSearch(search_query string) ([]RedditItem, error)
uses the query string to look for sub-reddits min_users is used to filter for sub-reddits that has at least min_users number of users TODO: deal with paging
func (*RedditClient) Subreddits ¶
func (client *RedditClient) Subreddits() ([]RedditItem, error)
gets subreddits that the user in the client has already subscribed to
type RedditClientConfig ¶
type RedditCollector ¶
type RedditCollector struct {
// contains filtered or unexported fields
}
func NewCollector ¶
func NewCollector(config CollectorConfig) *RedditCollector
func (*RedditCollector) AddCollectionAccount ¶
func (collector *RedditCollector) AddCollectionAccount(user RedditUser)
func (*RedditCollector) Collect ¶
func (collector *RedditCollector) Collect()
COLLECTION RELATED FUNCTIONS
func (*RedditCollector) GetCollectionAccount ¶
func (collector *RedditCollector) GetCollectionAccount(userid string) *RedditUser
func (*RedditCollector) IsUserAuthenticated ¶
func (collector *RedditCollector) IsUserAuthenticated(userid string) (bool, string)
type RedditItem ¶
type RedditItem struct { Kind string // Subreddit, Post or Comment. This is not directly serialized ExtractedText string // This is the extracted text after stripping out the HTML tags and collecting contents in an URL. This is not directly serialized from Reddit but rather computed Name string `json:"name"` // unique identifier across media source. every reddit item has one DisplayName string `json:"display_name"` // url name for subreddits DisplayNamePrefixed string `json:"display_name_prefixed"` Id string `json:"id"` // unique identifier across item Kind Title string `json:"title"` // represents text title of the item. Applies to subreddits and posts but not comments Subreddit string `json:"subreddit"` // display_name of the subreddit where the post or comment is in SubredditPrefixed string `json:"subreddit_name_prefixed"` Parent string `json:"link_id"` // For comments: this represents which post or comment does this comment respond to. for posts: this is the same value as the channel CommentBodyHtml string `json:"body_html"` // comment body PostTextHtml string `json:"selftext_html"` // post text Url string `json:"url"` // for posts this is url posted by the post. for subreddit this is clickable link PublicDescriptionHtml string `json:"public_description_html"` //subreddit short description DescriptionHtml string `json:"description_html"` //subreddit long description SubredditCategory string `json:"advertiser_category"` //subreddit category PostCategory string `json:"link_flair_text"` // optional author or creator defined category of the post topic or subreddit topic Link string `json:"permalink"` // url or link to the post or comment. For subreddits this would be the URL field Author string `json:"author"` // author of posts or comments. Empty for subreddits CreatedDate float64 `json:"created"` // date of creation of the post or comment. Empty for subreddits Score int `json:"score,omitempty"` // Applies to posts and comments. Doesn't apply to subreddits NumComments int `json:"num_comments"` // Number of comments to a post or a comment. Doesn't apply to subreddit NumSubscribers int `json:"subscribers"` // Number of subscribers to a channel (subreddit). Doesn't apply to posts or comments SubredditSubscribers int `json:"subreddit_subscribers"` // this applies to posts and comments to indicate the same thing as above Ups int `json:"ups"` UpvoteRatio float64 `json:"upvote_ratio"` // Applies to subreddit posts and comments. Doesn't apply to subreddits // collecting user specific info for subreddits UserIsSubscriber bool `json:"user_is_subscriber"` UserIsModerator bool `json:"user_is_moderator"` UserIsContributor bool `json:"user_is_contributor"` }
represents Subreddit, Posts, Comments
type RedditUser ¶
type RedditUser struct { UserId string `json:"ignore_id,omitempty"` Username string `json:"name,omitempty"` Password string `json:"ignore_password,omitempty"` AccessToken string `json:"ignore_access_token,omitempty"` RefreshToken string `json:"ignore_refresh_token,omitempty"` }
the json tags are there to accommodate serialization directly from reddit api