pkg

package
v0.0.0-...-3d176a0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MergeCommentChannels

func MergeCommentChannels(channels ...<-chan models.Comment) chan models.Comment

MergeCommentChannels merges multiple input comments channels and returns a single comment channel

func MergeSubmissionChannels

func MergeSubmissionChannels(channels ...<-chan models.Submission) chan models.Submission

MergeSubmissionChannels merges multiple input submissions channels and returns a single submission channel

Types

type AuthConfig

type AuthConfig struct {
	ClientID     string
	ClientSecret string
	UserAgent    string
	Username     string
	Password     string
}

AuthConfig is the struct storing the reddit credentials

func GetConfigByEnv

func GetConfigByEnv() AuthConfig

GetConfigByEnv gets the reddit credentials from the env vars

func GetConfigByFile

func GetConfigByFile(filePath string) AuthConfig

GetConfigByFile gets the reddit credentials from a config file

type RedditClient

type RedditClient struct {
	Token            string  `json:"access_token"`
	Duration         float64 `json:"expires_in"`
	ExpirationTicker *time.Ticker
	Config           AuthConfig
	UserAgent        string
	Stream           Streaming
	Client           *http.Client
}

RedditClient is the client that makes requests to the api

func Authenticate

func Authenticate(config *AuthConfig) (*RedditClient, error)

Authenticate creates a new RedditClient from the provided config credentials

func Init

func Init(config AuthConfig) (*RedditClient, error)

Init initializes the client

func (*RedditClient) GetComment

func (c *RedditClient) GetComment(id string) (*models.Comment, error)

GetComment sends a request to get a specific comment

func (*RedditClient) GetCommentAnchor

func (c *RedditClient) GetCommentAnchor(subreddit string) (last *string, lastID *string, err error)

GetCommentAnchor gets latest comment in specified subreddit, returns its full Name (lastID), its id, and an error

func (*RedditClient) GetSubmission

func (c *RedditClient) GetSubmission(subreddit string, id string) (*models.Submission, error)

GetSubmission sends a request to get a specific submission

func (*RedditClient) GetSubmissionAnchor

func (c *RedditClient) GetSubmissionAnchor(subreddit string, sort string) (last *string, lastID *string, err error)

GetSubmissionAnchor gets latest submission in specified subreddit, returns its full Name (lastID), its id, and an error

func (*RedditClient) GetSubredditComments

func (c *RedditClient) GetSubredditComments(subreddit string, sort string, tdur string, limit int) ([]models.Comment, error)

GetSubredditComments sends a request for comments in specified subreddit, sort and limit

func (*RedditClient) GetSubredditCommentsAfter

func (c *RedditClient) GetSubredditCommentsAfter(subreddit string, sort string, last string, limit int) ([]models.Comment, error)

GetSubredditCommentsAfter sends a request for comments after last commment in specified subreddit, sort and limit

func (*RedditClient) GetSubredditSubmissions

func (c *RedditClient) GetSubredditSubmissions(subreddit string, sort string, tdur string, limit int) ([]models.Submission, error)

GetSubredditSubmissions sends a request for submissions in specified subreddit, sort and limit (number of items)

func (*RedditClient) GetSubredditSubmissionsAfter

func (c *RedditClient) GetSubredditSubmissionsAfter(subreddit string, last string, limit int) ([]models.Submission, error)

GetSubredditSubmissionsAfter sends a request for submissions after last submission (full name) in specified subreddit, sort and limit (number of items)

func (*RedditClient) IsDeletedComment

func (c *RedditClient) IsDeletedComment(id string) (bool, error)

IsDeletedComment checks if comment is deleted

func (*RedditClient) IsDeletedSubmission

func (c *RedditClient) IsDeletedSubmission(subreddit string, id string) (bool, error)

IsDeletedSubmission checks if submission is deleted

func (RedditClient) Request

func (c RedditClient) Request(request Request) ([]byte, error)

Request makes a request to the reddit api returns the body of the response

func (*RedditClient) StreamSubredditComments

func (r *RedditClient) StreamSubredditComments(subreddit string, refresh int) (<-chan models.Comment, error)

StreamSubredditComments streams comments from a specified subreddit Returns an output channel on which new comments are sent

func (*RedditClient) StreamSubredditSubmissions

func (r *RedditClient) StreamSubredditSubmissions(subreddit string, sort string, refresh int) (<-chan models.Submission, error)

StreamSubredditSubmissions streams comments from a specified subreddit Returns an output channel on which new submissions are sent

type RedditErr

type RedditErr struct {
	Message string `json:"message"`
	Error   string `json:"error"`
}

RedditErr is a struct to store reddit error messages

type Request

type Request struct {
	SubReddit string            // subreddit name
	Method    string            // http method
	Path      string            // url path
	Payload   map[string]string // request parameters
}

Request holds info for a request to the reddit api

type Streaming

type Streaming struct {
	RateLimit sync.WaitGroup
}

Streaming is for streaming parameters

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL