patreon

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

README

GoDoc Go Report Card

patreon-go

patreon-go is a Go client library for accessing the Patreon API.

This is largely inspired by https://github.com/mxpv/patreon-go, but handles authentication and updated to API V2

Documentation

Index

Constants

View Source
const PatreonAuthURL = "https://www.patreon.com/oauth2/authorize"
View Source
const PatreonBaseURL = "https://www.patreon.com/"
View Source
const PatreonTokenURL = "https://www.patreon.com/api/oauth2/token"

Variables

This section is empty.

Functions

func WithCursor

func WithCursor(cursor string) requestOption

WithCursor controls cursor-based pagination. Cursor will also be extracted from navigation links for convenience.

func WithFields

func WithFields(resource string, fields ...string) requestOption

WithFields specifies the resource attributes you want to be returned by API.

func WithIncludes

func WithIncludes(include ...string) requestOption

WithIncludes specifies the related resources you want to be returned by API.

func WithPageSize

func WithPageSize(size int) requestOption

WithPageSize specifies the number of items to return.

Types

type Error added in v0.0.3

type Error struct {
	Code     int    `json:"code"`
	CodeName string `json:"code_name"`
	Detail   string `json:"detail"`
	ID       string `json:"id"`
	Status   string `json:"status"`
	Title    string `json:"title"`
}

Error describes error details.

type ErrorResponse added in v0.0.3

type ErrorResponse struct {
	Errors []Error `json:"errors"`
}

ErrorResponse is a Patreon error response.

func (ErrorResponse) Error added in v0.0.3

func (e ErrorResponse) Error() string

type PatreonClient

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

PatreonClient is the access point of the patreon API You need one PatreonClient per user

func NewPatreonClient

func NewPatreonClient(patreonConfig *PatreonConfig) *PatreonClient

Creates a new PatreonClient from a PatreonConfig At this point the client is not usable, you need to either:

  • convert an authorization code into a token with Exchange()
  • set the token with SetToken()

func (*PatreonClient) Exchange

func (c *PatreonClient) Exchange(authCode string) error

Converts an authorization code into a token. The authorization code is available as the code param in the redirected url

func (*PatreonClient) FetchCampaigns

func (c *PatreonClient) FetchCampaigns(opts ...requestOption) (*resources.CampaignResponse, error)

func (*PatreonClient) FetchMember

func (c *PatreonClient) FetchMember(id string, opts ...requestOption) (*resources.MemberResponse, error)

func (*PatreonClient) FetchUser

func (c *PatreonClient) FetchUser(opts ...requestOption) (*resources.UserResponse, error)

func (*PatreonClient) GetMembership added in v0.0.4

func (c *PatreonClient) GetMembership() (*resources.User, *resources.Member, error)

Get the user and the membership of the user to your campaign If no error occurs:

  • user will always be returned
  • member will be returned if the user has a membership on your campaign otherwise it will be nil

func (*PatreonClient) GetToken

func (c *PatreonClient) GetToken() *oauth2.Token

Get the token associated with this client Use case: serialisation of the token (in a session for instance)

  • Note that the token has to be serialized at the end of your process cause it might be refreshed

func (*PatreonClient) SetToken

func (c *PatreonClient) SetToken(token *oauth2.Token)

Set the token associated with this client Use case: creating the client from a serialized token (in a session for instance)

type PatreonConfig

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

PatreonConfig is the configuration of an API client registered here: https://www.patreon.com/portal/registration/register-clients

func NewPatreonConfig

func NewPatreonConfig(clientID string, clientSecret string, redirectURL string, scopes []string) *PatreonConfig

Creates a new PatreonConfig

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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