reddit

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

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

Go to latest
Published: Dec 8, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MediaNone     = iota // 0: No usable media.
	MediaImageURL = iota // 1: An URL pointing to an image.
	MediaFileURL  = iota // 2: An URL pointing to a file.
	MediaVideoURL = iota // 3: An URL pointing to a video.
)

Media types

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client holds state about a Reddit client

func NewClient

func NewClient(username, password, clientID, clientSecret string) *Client

NewClient creates a new Reddit client using the passed credentials.

func (*Client) RandomMediaURL

func (c *Client) RandomMediaURL(subreddit string) (string, int, error)

RandomMediaURL returns the URL containing a random media from a given subreddit. The type specifies the type of media being returned (usually an URL pointing to an image or to a video). Returns the type empty string with type mediaNone if the random article does not contain any pictures.

type Credentials

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

Credentials holds all state require to authenticate a reddit request.

func NewCredentials

func NewCredentials(username, password, clientID, clientSecret string) *Credentials

NewCredentials returns a pointer to a new Credentials object.

func (*Credentials) RefreshToken

func (c *Credentials) RefreshToken() error

RefreshToken fetches a new authorization token (if needed).

func (*Credentials) Token

func (c *Credentials) Token() (*Token, error)

Token returns the latest token (or triggers a token fetch, if needed).

type CredentialsInterface

type CredentialsInterface interface {
	RefreshToken() error
	Token() (*Token, error)
}

CredentialsInterface defines the interface between the client and the Credentials routines.

type Token

type Token struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	ExpiresIn   int    `json:"expires_in"`
	Scope       string `json:"scope"`
	// contains filtered or unexported fields
}

Token holds the Oauth2 token from Reddit.

Jump to

Keyboard shortcuts

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