patreon

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2023 License: MIT Imports: 13 Imported by: 0

README

GoDoc MIT license Patreon

patreon-go-wrapper

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

Forked from patreon-go which has a great implementation for Patreon API V1

How to import

The patreon-go-wrapper package may be installed by running:

go get github.com/austinbspencer/patreon-go-wrapper

or

import "github.com/austinbspencer/patreon-go-wrapper"

Basic example

import (
	"fmt"

	"github.com/austinbspencer/patreon-go-wrapper"
)

func main() {
	client := patreon.NewClient(nil)

	user, err := client.FetchIdentity()
	if err != nil {
		// handle the error
	}

	fmt.Println(user.Data.Id)
}

Authentication

The patreon-go-wrapper library does not directly handle authentication. Instead, when creating a new client, pass an http.Client that can handle authentication for you, most likely you will need oauth2 package.

Here is an example with static token:

import (
	"github.com/austinbspencer/patreon-go-wrapper"
	"golang.org/x/oauth2"
)

func NewPatreonClient(ctx context.Context, token string) *patreon.Client {
	ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
	tc := oauth2.NewClient(ctx, ts)

	client := patreon.NewClient(tc)
	return client
}

Automatically refresh token:

Check the available scopes in the Patreon Docs

func NewPatreonClient() (*patreon.Client, error) {
	config := oauth2.Config{
		ClientID:     "<client_id>",
		ClientSecret: "<client_secret>",
		Endpoint: oauth2.Endpoint{
			AuthURL:  AuthorizationURL,
			TokenURL: AccessTokenURL,
		},
		Scopes: patreon.AllScopes,
	}

	token := oauth2.Token{
		AccessToken:  "<current_access_token>",
		RefreshToken: "<current_refresh_token>",
		// Must be non-nil, otherwise token will not be expired
		Expiry: time.Now().Add(-24 * time.Hour),
	}

	tc := config.Client(context.Background(), &token)

	client := NewClient(tc)
	_, err := client.FetchIdentity()

	return client, err
}

Real Example

package main

import (
	"context"
	"fmt"
	"os"
	"time"

	"github.com/austinbspencer/patreon-go-wrapper"
	_ "github.com/joho/godotenv/autoload"
	"golang.org/x/oauth2"
)

func main() {
	patreonConfig := oauth2.Config{
		ClientID:     os.Getenv("PATREON_CLIENT_ID"),
		ClientSecret: os.Getenv("PATREON_CLIENT_SECRET"),
		Endpoint: oauth2.Endpoint{
			AuthURL:  patreon.AuthorizationURL,
			TokenURL: patreon.AccessTokenURL,
		},
		Scopes: patreon.AllScopes,
	}

	token := oauth2.Token{
		AccessToken:  os.Getenv("PATREON_ACCESS_TOKEN"),
		RefreshToken: os.Getenv("PATREON_REFRESH_TOKEN"),
		// Must be non-nil, otherwise token will not be expired
		Expiry: time.Now().Add(2 * time.Hour),
	}

	tc := patreonConfig.Client(context.Background(), &token)

	client := patreon.NewClient(tc)

	fieldOpts := patreon.WithFields("user", patreon.UserFields...)
	campOpts := patreon.WithFields("campaign", patreon.CampaignFields...)
	includeOpts := patreon.WithIncludes("campaign")

	user, err := client.FetchIdentity(fieldOpts, campOpts, includeOpts)
	if err != nil {
		panic(err)
	}

	for _, item := range user.Included.Items {
		res, ok := item.(*patreon.Campaign)
		if !ok {
			fmt.Println("Not oke!")
			continue
		}
		fmt.Println(res.Attributes.Summary)
	}
}

Documentation

Overview

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

Example (RefreshToken)

Automatically refresh token

config := oauth2.Config{
	ClientID:     "<client_id>",
	ClientSecret: "<client_secret>",
	Endpoint: oauth2.Endpoint{
		AuthURL:  AuthorizationURL,
		TokenURL: AccessTokenURL,
	},
	Scopes: []string{"users", "pledges-to-me", "my-campaign"},
}

token := oauth2.Token{
	AccessToken:  "<current_access_token>",
	RefreshToken: "<current_refresh_token>",
	// Must be non-nil, otherwise token will not be expired
	Expiry: time.Now().Add(-24 * time.Hour),
}

tc := config.Client(context.Background(), &token)

client := NewClient(tc)
_, err := client.FetchIdentity()
if err != nil {
	panic(err)
}

print("OK")
Output:

Index

Examples

Constants

View Source
const (
	// AuthorizationURL specifies Patreon's OAuth2 authorization endpoint (see https://tools.ietf.org/html/rfc6749#section-3.1).
	// See Example_refreshToken for examples.
	AuthorizationURL = "https://www.patreon.com/oauth2/authorize"

	// AccessTokenURL specifies Patreon's OAuth2 token endpoint (see https://tools.ietf.org/html/rfc6749#section-3.2).
	// See Example_refreshToken for examples.
	AccessTokenURL = "https://api.patreon.com/oauth2/token"
)
View Source
const (
	// EventCreatePledge specifies a create pledge event
	EventCreatePledge = "pledges:create"

	// EventUpdatePledge specifies an update pledge event
	EventUpdatePledge = "pledges:update"

	// EventDeletePledge specifies a delete pledge event
	EventDeletePledge = "pledges:delete"
)
View Source
const (
	// HeaderEventType specifies an event type HTTP header name
	HeaderEventType = "X-Patreon-Event"

	// HeaderEventSignature specifies message signature HTTP header name to verify message body
	HeaderSignature = "X-Patreon-Signature"
)

Variables

View Source
var (
	// CampaignDefaultIncludes specifies default includes for Campaign.
	CampaignDefaultIncludes = []string{"tiers", "creator", "benefits", "goals"}
	// CampaignFields is all fields in the Campaign Attributes struct
	CampaignFields = getObjectFields(CampaignAttributes{})
)
View Source
var (
	// MemberDefaultIncludes specifies default includes for Member.
	MemberDefaultIncludes = []string{"address", "campaign", "currently_entitled_tiers", "user"}

	// MemberFields is all fields in the Member Attributes struct
	MemberFields = getObjectFields(Member{}.Attributes)
)
View Source
var (
	// PostDefaultIncludes specifies default includes for Post.
	PostDefaultIncludes = []string{"campaign", "user"}

	// PostFields is all fields in the Post Attributes struct
	PostFields = getObjectFields(Post{}.Attributes)
)
View Source
var (
	// UserDefaultIncludes specifies default includes for User.
	UserDefaultIncludes = []string{"campaign", "memberships"}

	// UserFields is all fields in the User Attributes struct
	UserFields = getObjectFields(UserAttributes{})
)
View Source
var (
	// WebhookDefaultIncludes specifies default includes for Webhook.
	WebhookDefaultIncludes = []string{"campaign", "client"}

	// WebhookFields is all fields in the Webhook Attributes struct
	WebhookFields = getObjectFields(Webhook{}.Attributes)
)
View Source
var AddressFields = getObjectFields(AddressAttributes{})

AddressFields is all fields in the Address Attributes struct

View Source
var AllScopes = []string{
	"identity", "identity[email]", "identity.memberships", "campaigns",
	"w:campaigns.webhook", "campaigns.members", "campaigns.members[email]",
	"campaigns.members.address", "campaigns.posts",
}

AllScopes is every scope possible for Oauth (see https://docs.patreon.com/#scopes).

View Source
var BenefitFields = getObjectFields(BenefitAttributes{})

BenefitFields is all fields in the Benefit Attributes struct

View Source
var DeliverableFields = getObjectFields(Deliverable{}.Attributes)

DeliverableFields is all fields in the Deliverable Attributes struct

View Source
var GoalFields = getObjectFields(Goal{}.Attributes)

GoalFields is all fields in the Goal Attributes struct

View Source
var MediaFields = getObjectFields(Media{}.Attributes)

MediaFields is all fields in the Media Attributes struct

View Source
var OauthClientFields = []string{
	"AuthorName", "ClientSecret", "DefaultScopes",
	"Description", "Domain", "IconURL", "Name",
	"PrivacyPolicyURL", "RedirectURIs", "TosURL", "Version",
}

OauthClientFields is all fields in the OauthClient Attributes struct

View Source
var PledgeEventFields = getObjectFields(PledgeEvent{}.Attributes)

PledgeEventFields is all fields in the PledgeEvent Attributes struct

View Source
var TierFields = getObjectFields(Tier{}.Attributes)

TierFields is all fields in the Tier Attributes struct

Functions

func VerifySignature

func VerifySignature(message []byte, secret string, signature string) (bool, error)

VerifySignature verifies the sender of the message

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 Address

type Address struct {
	Type          string            `json:"type"`
	ID            string            `json:"id"`
	Attributes    AddressAttributes `json:"attributes"`
	Relationships struct {
		Campaigns *CampaignsRelationship `json:"campaigns,omitempty"`
		User      *UserRelationship      `json:"user,omitempty"`
	} `json:"relationships"`
}

Address represents a Patreon's shipping address.

type AddressAttributes

type AddressAttributes struct {
	Addressee   string   `json:"addressee"`
	City        string   `json:"city"`
	Country     string   `json:"country"`
	CreatedAt   NullTime `json:"created_at"`
	Line1       string   `json:"line_1"`
	Line2       string   `json:"line_2"`
	PhoneNumber string   `json:"phone_number"`
	PostalCode  string   `json:"postal_code"`
	State       string   `json:"state"`
}

AddressAttributes is the attributes struct for the Address

type AddressRelationship

type AddressRelationship struct {
	Data  Data    `json:"data"`
	Links Related `json:"links"`
}

AddressRelationship represents 'address' include.

type Benefit

type Benefit struct {
	Type          string            `json:"type"`
	ID            string            `json:"id"`
	Attributes    BenefitAttributes `json:"attributes"`
	Relationships struct {
		Campaign              *CampaignRelationship     `json:"campaign,omitempty"`
		CampaignInstallations interface{}               `json:"campaign_installation"` // I don't know what this is.. Couldn't find any docs / examples
		Deliverables          *DeliverablesRelationship `json:"deliverables,omitempty"`
		Tiers                 *TiersRelationship        `json:"tiers,omitempty"`
	} `json:"relationships"`
}

Benefit is a benefit added to the campaign, which can be added to a tier to be delivered to the patron.

type BenefitAttributes

type BenefitAttributes struct {
	AppExternalID                 string                 `json:"app_external_id,omitempty"`
	AppMeta                       map[string]interface{} `json:"app_meta,omitempty"`
	BenefitType                   string                 `json:"benefit_type,omitempty"`
	CreatedAt                     NullTime               `json:"created_at,omitempty"`
	DeliverablesDueTodayCount     int                    `json:"deliverables_due_today_count,omitempty"`
	DeliveredDeliverablesCount    int                    `json:"delivered_deliverables_count,omitempty"`
	Description                   string                 `json:"description,omitempty"`
	IsDeleted                     bool                   `json:"is_deleted,omitempty"`
	IsEnded                       bool                   `json:"is_ended,omitempty"`
	IsPublished                   bool                   `json:"is_published,omitempty"`
	NextDeliverableDueDate        NullTime               `json:"next_deliverable_due_date,omitempty"`
	NotDeliveredDeliverablesCount int                    `json:"not_delivered_deliverables_count,omitempty"`
	RuleType                      bool                   `json:"rule_type,omitempty"`
	TiersCount                    int                    `json:"tiers_count,omitempty"`
	Title                         string                 `json:"title,omitempty"`
}

BenefitAttributes is the attributes struct for Benefit

type BenefitRelationship

type BenefitRelationship struct {
	Data  Data    `json:"data"`
	Links Related `json:"links"`
}

BenefitRelationship represents 'benefit' include.

type BenefitsRelationship

type BenefitsRelationship struct {
	Data  []Data  `json:"data"`
	Links Related `json:"links"`
}

BenefitsRelationship represents 'benefits' include.

type Campaign

type Campaign struct {
	Type          string             `json:"type"`
	ID            string             `json:"id"`
	Attributes    CampaignAttributes `json:"attributes"`
	Relationships struct {
		Benefits              *BenefitsRelationship   `json:"benefits,omitempty"`
		CampaignInstallations *interface{}            `json:"campaign_installations,omitempty"`
		Categories            *CategoriesRelationship `json:"categories,omitempty"`
		Creator               *CreatorRelationship    `json:"creator,omitempty"`
		Goals                 *GoalsRelationship      `json:"goals,omitempty"`
		Tiers                 *TiersRelationship      `json:"tiers,omitempty"`
	} `json:"relationships"`
}

Campaign is the creator's page, and the top-level object for accessing lists of members, tiers, etc.

type CampaignAttributes

type CampaignAttributes struct {
	CreatedAt            NullTime `json:"created_at"`
	CreationName         string   `json:"creation_name"`
	DiscordServerID      string   `json:"discord_server_id"`
	GoogleAnalyticsID    string   `json:"google_analytics_id"`
	HasRSS               bool     `json:"has_rss"`
	HasSentRSSNotify     bool     `json:"has_sent_rss_notify"`
	ImageSmallURL        string   `json:"image_small_url"`
	ImageURL             string   `json:"image_url"`
	IsChargedImmediately bool     `json:"is_charged_immediately"`
	IsMonthly            bool     `json:"is_monthly"`
	IsNsfw               bool     `json:"is_nsfw"`
	MainVideoEmbed       string   `json:"main_video_embed"`
	MainVideoURL         string   `json:"main_video_url"`
	OneLiner             string   `json:"one_liner"`
	PatronCount          int      `json:"patron_count"`
	PayPerName           string   `json:"pay_per_name"`
	PledgeURL            string   `json:"pledge_url"`
	PublishedAt          NullTime `json:"published_at"`
	RSSArtworkURL        bool     `json:"rss_artwork_url"`
	RSSFeedTitle         string   `json:"rss_feed_title"`
	ShowEarnings         bool     `json:"show_earnings"`
	Summary              string   `json:"summary"`
	ThanksEmbed          string   `json:"thanks_embed"`
	ThanksMsg            string   `json:"thanks_msg"`
	ThanksVideoURL       string   `json:"thanks_video_url"`
	URL                  string   `json:"url"`
	Vanity               string   `json:"vanity"`
}

CampaignAttributes is the attributes struct for Campaign

type CampaignRelationship

type CampaignRelationship struct {
	Data  Data    `json:"data"`
	Links Related `json:"links"`
}

CampaignRelationship represents 'campaign' include.

type CampaignResponse

type CampaignResponse struct {
	Data     Campaign `json:"data"`
	Included Includes `json:"included"`
}

CampaignV2Response wraps Patreon's campaign API response

type CampaignsRelationship

type CampaignsRelationship struct {
	Data  []Data  `json:"data"`
	Links Related `json:"links"`
}

CampaignsRelationship represents 'campaigns' include.

type CampaignsResponse

type CampaignsResponse struct {
	Data     []Campaign `json:"data"`
	Included Includes   `json:"included"`
}

CampaignsV2Response wraps Patreon's campaign API response

type CategoriesRelationship

type CategoriesRelationship struct {
	Data []Data `json:"data"`
}

CategoriesRelationship represents 'categories' include.

type Client

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

Client manages communication with Patreon API.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new Patreon API client. If a nil httpClient is provided, http.DefaultClient will be used. To use API methods which require authentication, provide an http.Client that will perform the authentication for you (such as that provided by the golang.org/x/oauth2 library).

func (*Client) Client

func (c *Client) Client() *http.Client

Client returns the HTTP client configured for this client.

func (*Client) FetchCampaign

func (c *Client) FetchCampaign(campaignID string, opts ...requestOption) (*CampaignResponse, error)

FetchCampaign is the single resource endpoint returns information about a single Campaign, fetched by campaign ID. Requires the campaigns scope.

func (*Client) FetchCampaignMember

func (c *Client) FetchCampaignMember(memberID string, opts ...requestOption) (*MemberResponse, error)

FetchCampaignMember gets a particular member by id. Requires the campaigns.members scope.

func (*Client) FetchCampaignMembers

func (c *Client) FetchCampaignMembers(campaignID string, opts ...requestOption) (*MembersResponse, error)

FetchCampaignMembers gets the Members for a given Campaign. Requires the campaigns.members scope.

func (*Client) FetchCampaignPost

func (c *Client) FetchCampaignPost(postID string, opts ...requestOption) (*PostResponse, error)

FetchCampaignPost gets a particular Post by ID. Requires the campaigns.posts scope.

func (*Client) FetchCampaignPosts

func (c *Client) FetchCampaignPosts(campaignID string, opts ...requestOption) (*PostsResponse, error)

FetchCampaignPosts gets a list of all the Posts on a given Campaign by campaign ID. Requires the campaigns.posts scope.

func (*Client) FetchCampaignWebhooks added in v1.0.0

func (c *Client) FetchCampaignWebhooks(opts ...requestOption) (*WebhookResponse, error)

FetchCampaignWebhooks gets the Webhooks for the current user's Campaign created by the API client. You will only be able to see webhooks created by your client. Requires the w:campaigns.webhook scope.

func (*Client) FetchCampaigns

func (c *Client) FetchCampaigns(opts ...requestOption) (*CampaignsResponse, error)

FetchCampaigns Returns a list of Campaigns owned by the authorized user. Requires the campaigns scope.

func (*Client) FetchIdentity

func (c *Client) FetchIdentity(opts ...requestOption) (*UserResponse, error)

FetchIdentity fetches a patron's profile info. This is the endpoint for accessing information about the current User with reference to the oauth token. It is most typically used in the OAuth "Log in with Patreon" flow to create or update the user's account on your site.

type CreatorRelationship

type CreatorRelationship struct {
	Data  Data    `json:"data"`
	Links Related `json:"links"`
}

CreatorRelationship represents 'creator' include.

type Data

type Data struct {
	ID   string `json:"id"`
	Type string `json:"type"`
}

Data represents a link to entity.

type Deliverable

type Deliverable struct {
	Type          string                `json:"type"`
	ID            string                `json:"id"`
	Attributes    DeliverableAttributes `json:"attributes"`
	Relationships struct {
		Benefit  *BenefitsRelationship `json:"benefit,omitempty"`
		Campaign *CampaignRelationship `json:"campaign,omitempty"`
		Member   *MemberRelationship   `json:"member,omitempty"`
		User     *UserRelationship     `json:"user,omitempty"`
	} `json:"relationships"`
}

Deliverable is the record of whether or not a patron has been delivered the benefit they are owed because of their member tier.

type DeliverableAttributes

type DeliverableAttributes struct {
	CompletedAt    NullTime `json:"completed_at"`
	DeliveryStatus string   `json:"delivery_status"`
	DueAt          NullTime `json:"due_at"`
}

DeliverableAttributes is the attributes struct for Deliverable

type DeliverablesRelationship

type DeliverablesRelationship struct {
	Data  []Data  `json:"data"`
	Links Related `json:"links"`
}

DeliverablesRelationship represents 'deliverables' include.

type Error

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

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

ErrorResponse is a Patreon error response.

func (ErrorResponse) Error

func (e ErrorResponse) Error() string

type Goal

type Goal struct {
	Type          string         `json:"type"`
	ID            string         `json:"id"`
	Attributes    GoalAttributes `json:"attributes"`
	Relationships struct {
		Campaign *CampaignRelationship `json:"campaign,omitempty"`
	} `json:"relationships"`
}

Goal is the funding goal in USD set by a creator on a campaign.

type GoalAttributes

type GoalAttributes struct {
	AmountCents         int      `json:"amount_cents"`
	CompletedPercentage int      `json:"completed_percentage"`
	CreatedAt           NullTime `json:"created_at"`
	Description         string   `json:"description"`
	ReachedAt           NullTime `json:"reached_at"`
	Title               string   `json:"title"`
}

GoalAttributes is the attributes struct for Goal

type GoalsRelationship

type GoalsRelationship struct {
	Data []Data `json:"data"`
}

GoalsRelationship represents 'goals' include.

type Includes

type Includes struct {
	Items []interface{}
}

Includes wraps 'includes' JSON field to handle objects of different type within an array.

func (*Includes) UnmarshalJSON

func (i *Includes) UnmarshalJSON(b []byte) error

UnmarshalJSON deserializes 'includes' field into the appropriate structs depending on the 'type' field. See http://gregtrowbridge.com/golang-json-serialization-with-interfaces/ for implementation details.

type Media

type Media struct {
	Type       string          `json:"type"`
	ID         string          `json:"id"`
	Attributes MediaAttributes `json:"attributes"`
}

Media is a file uploaded to patreon.com, usually an image.

type MediaAttributes

type MediaAttributes struct {
	CreatedAt         NullTime    `json:"created_at"`
	DownloadURL       string      `json:"download_url"`
	FileName          string      `json:"file_name"`
	ImageURLs         interface{} `json:"image_urls"`
	Metadata          interface{} `json:"metadata"`
	Mimetype          string      `json:"mimetype"`
	OwnerID           string      `json:"owner_id"`
	OwnerRelationship string      `json:"owner_relationship"`
	OwnerType         string      `json:"owner_type"`
	SizeBytes         int         `json:"size_bytes"`
	State             string      `json:"state"`
	UploadExpiresAt   NullTime    `json:"upload_expires_at"`
	UploadParameters  interface{} `json:"upload_parameters"`
	UploadUrl         string      `json:"upload_url"`
}

type MediaRelationship

type MediaRelationship struct {
	Data  Data    `json:"data"`
	Links Related `json:"links"`
}

MediaRelationship represents 'membership' include

type Member

type Member struct {
	Type          string           `json:"type"`
	ID            string           `json:"id"`
	Attributes    MemberAttributes `json:"attributes"`
	Relationships struct {
		Address                *AddressRelationship     `json:"address,omitempty"`
		Campaign               *CampaignRelationship    `json:"campaign,omitempty"`
		CurrentlyEntitledTiers *TiersRelationship       `json:"currently_entitled_tiers,omitempty"`
		PledgeHistory          *PledgeEventRelationship `json:"pledge_history,omitempty"`
		User                   *UserRelationship        `json:"user,omitempty"`
	} `json:"relationships"`
}

Member is the record of a user's membership to a campaign. Remains consistent across months of pledging.

type MemberAttributes

type MemberAttributes struct {
	CampaignLifetimeSupportCents int      `json:"campaign_lifetime_support_cents"`
	CurrentlyEntitledAmountCents int      `json:"currently_entitled_amount_cents"`
	Email                        string   `json:"email"`
	FullName                     string   `json:"full_name"`
	IsFollower                   bool     `json:"is_follower"`
	LastChargeDate               NullTime `json:"last_charge_date"`
	LastChargeStatus             string   `json:"last_charge_status"`
	LifetimeSupportCents         int      `json:"lifetime_support_cents"`
	NextChargeDate               NullTime `json:"next_charge_date"`
	Note                         string   `json:"note"`
	PatronStatus                 string   `json:"patron_status"`
	PledgeCadence                int      `json:"pledge_cadence"`
	PledgeRelationshipStart      NullTime `json:"pledge_relationship_start"`
	WillPayAmountCents           int      `json:"will_pay_amount_cents"`
}

MemberAttributes is the attributes struct for Member

type MemberRelationship

type MemberRelationship struct {
	Data  Data    `json:"data"`
	Links Related `json:"links"`
}

MemberRelationship represents 'member' include

type MemberResponse

type MemberResponse struct {
	Data     Member   `json:"data"`
	Included Includes `json:"included"`
	Links    struct {
		Self string `json:"self"`
	} `json:"links"`
}

MemberResponse wraps Patreon's fetch benefit API response

type MembersResponse

type MembersResponse struct {
	Data     []Member `json:"data"`
	Included Includes `json:"included"`
	Links    struct {
		First string `json:"first"`
		Last  string `json:"last"`
		Next  string `json:"next"`
		Prev  string `json:"prev"`
	} `json:"links"`
	Meta struct {
		Pagination struct {
			Cursors struct {
				First string `json:"first"`
				Last  string `json:"last"`
				Next  string `json:"next"`
				Prev  string `json:"prev"`
			} `json:"cursors"`
		} `json:"pagination"`
		Count int `json:"count"`
	} `json:"meta"`
}

MembersResponse wraps Patreon's fetch benefit API response

type MembershipsRelationship

type MembershipsRelationship struct {
	Data  []Data  `json:"data"`
	Links Related `json:"links"`
}

MembershipsRelationship represents 'membership' include

type Meta

type Meta struct {
	Count int `json:"count"`
}

Meta represents extra information about relationship.

type NullTime

type NullTime struct {
	time.Time
	Valid bool
}

NullTime represents a time.Time that may be JSON "null". golang prior 1.8 doesn't support this scenario (fails with error: parsing time "null" as ""2006-01-02T15:04:05Z07:00"": cannot parse "null" as """)

func (*NullTime) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler with JSON "null" support

type OauthClient

type OauthClient struct {
	Type          string                `json:"type"`
	ID            string                `json:"id"`
	Attributes    OauthClientAttributes `json:"attributes"`
	Relationships struct {
		// Apps *AppsRelationship  `json:"apps"`
		Campaign     *CampaignRelationship `json:"campaign,omitempty"`
		CreatorToken *oauth2.Token         `json:"creator_token,omitempty"`
		User         *UserRelationship     `json:"user,omitempty"`
	} `json:"relationships"`
}

OauthClient is a client created by a developer, used for getting OAuth2 access tokens.

type OauthClientAttributes

type OauthClientAttributes struct {
	AuthorName       string `json:"author_name"`
	ClientSecret     string `json:"client_secret"`
	DefaultScopes    string `json:"default_scopes"`
	Description      string `json:"description"`
	Domain           string `json:"domain"`
	IconURL          string `json:"icon_url"`
	Name             string `json:"name"`
	PrivacyPolicyURL string `json:"privacy_policy_url"`
	RedirectURIs     string `json:"redirect_uris"`
	TosURL           string `json:"tos_url"`
	Version          string `json:"version"`
}

OauthClientAttributes is the attributes struct for OauthClient

type PatronRelationship

type PatronRelationship struct {
	Data  Data    `json:"data"`
	Links Related `json:"links"`
}

PatronRelationship represents 'patron' include.

type PledgeEvent

type PledgeEvent struct {
	Type          string                `json:"type"`
	ID            string                `json:"id"`
	Attributes    PledgeEventAttributes `json:"attributes"`
	Relationships struct {
		Campaign *CampaignRelationship `json:"campaign,omitempty"`
		Patron   *PatronRelationship   `json:"patron"`
		Tier     *TierRelationship     `json:"tier,omitempty"`
	} `json:"relationships"`
}

PledgeEvent is the record of a pledging action taken by the user, or that action's failure.

type PledgeEventAttributes

type PledgeEventAttributes struct {
	AmountCents   int      `json:"amount_cents"`
	CurrencyCode  string   `json:"currency_code"`
	Date          NullTime `json:"date"`
	PaymentStatus string   `json:"payment_status"`
	TierID        string   `json:"tier_id"`
	TierTitle     string   `json:"tier_title"`
	Type          string   `json:"type"`
}

PledgeEventAttributes is the attributes struct for PledgeEvent

type PledgeEventRelationship

type PledgeEventRelationship struct {
	Data  Data    `json:"data"`
	Links Related `json:"links"`
}

PledgeEventRelationship represents 'pledge_history' include.

type Post

type Post struct {
	Type          string         `json:"type"`
	ID            string         `json:"id"`
	Attributes    PostAttributes `json:"attributes"`
	Relationships struct {
		User     *UserRelationship     `json:"user,omitempty"`
		Campaign *CampaignRelationship `json:"campaign,omitempty"`
	} `json:"relationships"`
}

Post is content posted by a creator on a campaign page.

type PostAggregationRelationship

type PostAggregationRelationship struct {
	Data  Data    `json:"data"`
	Links Related `json:"links"`
}

PostAggregationRelationship represents 'post_aggregation' include.

type PostAttributes

type PostAttributes struct {
	AppID       int         `json:"app_id"`
	AppStatus   string      `json:"app_status"`
	Content     string      `json:"content"`
	EmbedData   interface{} `json:"embed_data"`
	EmbedURL    string      `json:"embed_url"`
	IsPaid      bool        `json:"is_paid"`
	IsPublic    bool        `json:"is_public"`
	PublishedAt NullTime    `json:"published_at"`
	Title       string      `json:"title"`
	URL         string      `json:""`
}

PostAttributes is the attributes struct for Post

type PostResponse

type PostResponse struct {
	Data     Post     `json:"data"`
	Included Includes `json:"included"`
	Links    struct {
		Self string `json:"self"`
	} `json:"links"`
}

PostResponse wraps Patreon's fetch benefit API response

type PostsResponse

type PostsResponse struct {
	Data     []Post   `json:"data"`
	Included Includes `json:"included"`
	Links    struct {
		Self string `json:"self"`
	} `json:"links"`
}

PostsResponse wraps Patreon's fetch benefit API response

type Related struct {
	Related string `json:"related"`
}

Related is the string within Links

type RewardRelationship

type RewardRelationship struct {
	Data  Data    `json:"data"`
	Links Related `json:"links"`
}

RewardRelationship represents 'reward' include.

type RewardsRelationship

type RewardsRelationship struct {
	Data []Data `json:"data"`
}

RewardsRelationship represents 'rewards' include.

type Tier

type Tier struct {
	Type          string         `json:"type"`
	ID            string         `json:"id"`
	Attributes    TierAttributes `json:"attributes"`
	Relationships struct {
		Benefits  *BenefitsRelationship `json:"benefits,omitempty"`
		Campaign  *CampaignRelationship `json:"campaign,omitempty"`
		TierImage *MediaRelationship    `json:"tier_image,omitempty"`
	} `json:"relationships"`
}

Tier is a membership level on a campaign, which can have benefits attached to it.

type TierAttributes

type TierAttributes struct {
	AmountCents      int         `json:"amount_cents"`
	CreatedAt        NullTime    `json:"created_at"`
	Description      string      `json:"description"`
	DiscordRoleIds   interface{} `json:"discord_role_ids"`
	EditedAt         NullTime    `json:"edited_at"`
	ImageURL         string      `json:"image_url"`
	PatronCount      int         `json:"patron_count"`
	PostCount        int         `json:"post_count"`
	Published        bool        `json:"published"`
	PublishedAt      NullTime    `json:"published_at"`
	Remaining        int         `json:"remaining"`
	RequiresShipping bool        `json:"requires_shipping"`
	Title            string      `json:"title"`
	UnpublishedAt    NullTime    `json:"unpublished_at"`
	URL              string      `json:"url"`
	UserLimit        int         `json:"user_limit"`
}

TierAttributes is the attributes struct for Tier

type TierRelationship

type TierRelationship struct {
	Data  Data    `json:"data"`
	Links Related `json:"links"`
}

TierRelationship represents 'tier' include

type TiersRelationship

type TiersRelationship struct {
	Data  []Data  `json:"data"`
	Links Related `json:"links"`
}

TiersRelationship represents 'tiers' include

type User

type User struct {
	Type          string         `json:"type"`
	ID            string         `json:"id"`
	Attributes    UserAttributes `json:"attributes"`
	Relationships struct {
		Campaign    *CampaignRelationship    `json:"campaign,omitempty"`
		Memberships *MembershipsRelationship `json:"memberships,omitempty"`
	} `json:"relationships"`
}

User is the Patreon user, which can be both patron and creator.

type UserAttributes

type UserAttributes struct {
	About             string      `json:"about"`
	CanSeeNSFW        bool        `json:"can_see_nsfw"`
	Created           NullTime    `json:"created"`
	Email             string      `json:"email"`
	FirstName         string      `json:"first_name"`
	FullName          string      `json:"full_name"`
	HidePledges       bool        `json:"hide_pledges"`
	ImageURL          string      `json:"image_url"`
	IsEmailVerified   bool        `json:"is_email_verified"`
	LastName          string      `json:"last_name"`
	LikeCount         int         `json:"like_count"`
	SocialConnections interface{} `json:"social_connections"`
	ThumbURL          string      `json:"thumb_url"`
	URL               string      `json:"url"`
	Vanity            string      `json:"vanity"`
}

UserAttributes is the attributes struct for User

type UserRelationship

type UserRelationship struct {
	Data  Data    `json:"data"`
	Links Related `json:"links"`
}

UserRelationship represents 'user' include

type UserResponse

type UserResponse struct {
	Data     User     `json:"data"`
	Included Includes `json:"included"`
	Links    struct {
		Self string `json:"self"`
	} `json:"links"`
}

UserResponse wraps Patreon's fetch user API response

type Webhook

type Webhook struct {
	Type          string            `json:"type"`
	ID            string            `json:"id"`
	Attributes    WebhookAttributes `json:"attributes"`
	Relationships struct {
		Campaign    *CampaignRelationship    `json:"campaign,omitempty"`
		Memberships *MembershipsRelationship `json:"memberships,omitempty"`
	} `json:"relationships"`
}

Webhook is fired based on events happening on a particular campaign.

type WebhookAttributes

type WebhookAttributes struct {
	LastAttemptedAt           NullTime    `json:"last_attempted_at"`
	NumConsecutiveTimesFailed int         `json:"num_consecutive_times_failed"`
	Paused                    bool        `json:"paused"`
	Secret                    string      `json:"secret"`
	Triggers                  interface{} `json:"triggers"`
	URI                       string      `json:"uri"`
}

WebhookAttributes is the attributes struct for Webhook

type WebhookResponse

type WebhookResponse struct {
	Data     Webhook  `json:"data"`
	Included Includes `json:"included"`
	Links    struct {
		Self string `json:"self"`
	} `json:"links"`
}

WebhookResponse wraps Patreon's fetch user API response

Jump to

Keyboard shortcuts

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