reddit

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2025 License: Apache-2.0, MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRateLimited = fmt.Errorf("rate limited")
)

Functions

func NewOAuth2Client added in v0.1.1

func NewOAuth2Client(ctx context.Context, cfg Config) (*http.Client, error)

NewOAuth2Client creates and configures an OAuth2 HTTP client with retry logic for rate limiting.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

TODO: doc -2024-10-22

func NewClient

func NewClient(ctx context.Context, cfg Config) (*Client, error)

TODO: doc -2024-10-22

func (*Client) DeleteComment

func (c *Client) DeleteComment(id string) error

TODO: doc -2024-10-25

func (*Client) DeletePost

func (c *Client) DeletePost(id string) error

TODO: doc -2024-10-25

func (*Client) EditComment

func (c *Client) EditComment(id, body string) error

TODO: doc -2024-10-25

func (*Client) GetComments

func (c *Client) GetComments(username, after string) (*Listing[Comment], error)

TODO: doc -2024-10-22

func (*Client) GetPosts

func (c *Client) GetPosts(username, after string) (*Listing[Post], error)

TODO: doc -2024-10-30

func (*Client) GetSavedComments

func (c *Client) GetSavedComments(username, after string) (*Listing[Comment], error)

TODO: doc -2024-10-30

func (*Client) GetSavedPosts

func (c *Client) GetSavedPosts(username, after string) (*Listing[Comment], error)

TODO: doc -2024-10-30

func (*Client) UnsaveComment

func (c *Client) UnsaveComment(id string) error

TODO: doc -2024-10-30

func (*Client) UnsavePost

func (c *Client) UnsavePost(id string) error

TODO: doc -2024-10-30

type Comment

type Comment struct {
	ID         string `json:"id"`
	Body       string `json:"body"`
	Permalink  string `json:"permalink"`
	Subreddit  string `json:"subreddit"`
	Score      int    `json:"score"`
	CreatedUTC Time   `json:"created_utc"`
}

TODO: doc -2024-10-22

type Config

type Config struct {
	BaseURL      string
	ClientID     string
	ClientSecret string
	Username     string
	Password     string
	UserAgent    string
}

TODO: doc -2024-10-22

type EditResponse

type EditResponse struct {
	JQuery  []any `json:"jquery"` // ...wat?
	Success bool  `json:"success"`
}

EditResponse is the response from the Reddit API when editing a comment. It has a weird structure - see the tests for examples.

func (*EditResponse) IsRateLimited

func (resp *EditResponse) IsRateLimited() bool

IsRateLimited checks if the response indicates that the request was rate limited.

type Listing

type Listing[T any] struct {
	Data struct {
		Before   string `json:"before"`
		After    string `json:"after"`
		Children []struct {
			Data T `json:"data"`
		} `json:"children"`
	} `json:"data"`
}

TODO: doc -2024-10-22

func (*Listing[T]) Items

func (l *Listing[T]) Items() []T

TODO: doc -2024-10-22

type Post

type Post struct {
	ID         string `json:"id"`
	Title      string `json:"title"`
	Permalink  string `json:"permalink"`
	Subreddit  string `json:"subreddit"`
	Score      int    `json:"score"`
	CreatedUTC Time   `json:"created_utc"`
}

TODO: doc -2024-10-30

type Time

type Time struct {
	time.Time
}

Time is a type used to unmarshal Reddit's weird floating point timestamps. Reddit's API returns timestamps as Unix epoch timestamps, but as floating point numbers (for some reason). This type is used to unmarshal those timestamps into Go's time.Time type.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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