flannel

package module
v0.0.0-...-afa984f Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2020 License: MIT Imports: 10 Imported by: 0

README

flannel

GoDoc

Facebook API wrapper for charities

To run the tests:

Add a local ./.env file containing:

ACCESS_TOKEN=<facebook user access token>

CHARITY_ID=<facebook charity id>

Run make test

Documentation

Index

Constants

View Source
const (
	CreateFundraiserEndpoint = "https://graph.facebook.com/v2.8/me/fundraisers"
)

Facebook API endpoints.

View Source
const FundraiserCoverPhotoImageMaxSize = (4 * 1024 * 1024) - 1

FundraiserCoverPhotoImageMaxSize defines the maximum size for fundraiser cover photo images.

Variables

This section is empty.

Functions

func ErrorCodes

func ErrorCodes(err error) (code int, subcode int)

ErrorCodes extracts any Facebook error codes from err. See https://developers.facebook.com/docs/graph-api/using-graph-api/error-handling/

func ErrorMessages

func ErrorMessages(err error) (message string, errorusertitle string, errorusermsg string)

ErrorMessages extracts any Facebook error messages from err. See https://developers.facebook.com/docs/graph-api/using-graph-api/error-handling/

func IsErrorWithFundraiserCoverPhoto

func IsErrorWithFundraiserCoverPhoto(err error) bool

IsErrorWithFundraiserCoverPhoto returns true if err was returned from WithFundraiserCoverPhotoURL option.

func WithFundraiserCoverPhotoImage

func WithFundraiserCoverPhotoImage(name string, content io.Reader) func(*multipart.Writer) error

WithFundraiserCoverPhotoImage adds an optional cover photo image when creating a new Facebook Fundraiser.

func WithFundraiserCoverPhotoURL

func WithFundraiserCoverPhotoURL(name string, content url.URL) func(*multipart.Writer) error

WithFundraiserCoverPhotoURL adds an optional cover photo when creating a new Facebook Fundraiser.

func WithFundraiserField

func WithFundraiserField(name string, value string) func(*multipart.Writer) error

WithFundraiserField adds an optional field when creating a new Facebook Fundraiser.

The Facebook Fundraiser API supports the following optional fields:

external_fundraiser_uri - URI of the fundraiser on the external site

external_event_name - Name of the event this fundraiser belongs to

external_event_uri - URI of the event this fundraiser belongs to

external_event_start_time - Unix timestamp of the day when the event takes place

func WithLogger

func WithLogger(logger Logger, debug bool) func(*APIClient) error

WithLogger adds logging of API calls on error to the APIClient. If the debug flag is set all API calls are logged.

Types

type APIClient

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

APIClient represents a HTTP client to the Facebook APIs.

func CreateAPIClient

func CreateAPIClient(options ...func(*APIClient) error) (APIClient, error)

CreateAPIClient creates a new HTTP client to the Facebook APIs with the provided options.

func (APIClient) CreateFundraiser

func (c APIClient) CreateFundraiser(params CreateFundraiserParams, options ...func(*multipart.Writer) error) (status int, result map[string]interface{}, err error)

CreateFundraiser creates a new Facebook Fundraiser. Required parameters are set with params. Optional parameters are set with options.

type CreateFundraiserParams

type CreateFundraiserParams struct {

	// AccessToken as provided by Facebook Login for the user creating the fundraiser.
	AccessToken string

	// Charity ID is the Facebook Charity ID
	CharityID string

	// Title of the Facebook Fundraiser, can be up to 70 characters long.
	Title string

	// Description of the Facebook Fundraiser, can be up to 50k characters long.
	Description string

	// Goal in currency’s smallest unit. Fundraisers currently support only whole values, so for currencies with cents like USD,
	// you must round to an integer number and then multiply by 100 to get the value in cents. For zero-decimal currencies like JPY,
	// simply provide the integer amount without multiplying by 100.
	Goal int

	// Currency ISO 4127 code for the goal amount.
	Currency string

	// EndTime is a timestamp of when the fundraiser will stop accepting donations. Must be within 5 years from now.
	// Facebook converts this to 11:59pm in the timezone of the facebook user (as identified by the AccessToken)
	EndTime time.Time

	// ExternalID is generated by you to identify the fundraiser in your system.
	ExternalID string
}

CreateFundraiserParams is the set of parameters required to create a Facebook Fundraiser.

type Logger

type Logger interface {
	Logf(format string, args ...interface{})
}

Logger is the interface implemented by the APIClient when logging API calls.

type LoggerFunc

type LoggerFunc func(format string, args ...interface{})

The LoggerFunc type is an adapter to allow the use of ordinary functions as Loggers. If f is a function with the appropriate signature, LoggerFunc(f) is a Logger that calls f.

func (LoggerFunc) Logf

func (f LoggerFunc) Logf(format string, args ...interface{})

Logf calls f(format, args...).

type RestrictedReader

type RestrictedReader struct {
	Reader    io.Reader
	MaxSize   int
	BytesRead int
}

A RestrictedReader wraps the provided Reader restricting the amount of data read to the specified MaxSize of bytes. Each call to Read updates BytesRead to reflect the new total. If the MaxSize is exceeded an error is returned.

func (*RestrictedReader) IsMaxSizeExceeded

func (r *RestrictedReader) IsMaxSizeExceeded(err error) bool

IsMaxSizeExceeded returns true if err is max size exceeded.

func (*RestrictedReader) Read

func (r *RestrictedReader) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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