Documentation ¶
Overview ¶
Package client provides a common interface for accessing the Mastodon API.
Index ¶
- func Post(ctx context.Context, cl Client, status string, visibility string, ...) (string, []string, error)
- func RegisterClient(ctx context.Context, scheme string, f ClientInitializeFunc) error
- func Schemes() []string
- func Upload(ctx context.Context, cl Client, media ...string) ([]string, error)
- type Client
- type ClientInitializeFunc
- type OAuth2Client
- func (cl *OAuth2Client) ExecuteMethod(ctx context.Context, http_method string, api_method string, args *url.Values) (io.ReadSeekCloser, error)
- func (cl *OAuth2Client) SetLogger(ctx context.Context, logger *log.Logger) error
- func (cl *OAuth2Client) UploadMedia(ctx context.Context, r io.Reader, args *url.Values) (io.ReadSeekCloser, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Post ¶
func Post(ctx context.Context, cl Client, status string, visibility string, media ...string) (string, []string, error)
Post is a helper method to use 'cl' to post a message to Mastodon with 'post' and 'visibility' and zero or more media files. It returns the ID of the post and of the IDs of any media uploads. If you need to post a message with more options you should use the `Client.ExecuteMethod` method instead.
func RegisterClient ¶
func RegisterClient(ctx context.Context, scheme string, f ClientInitializeFunc) error
Register a new URI scheme and ClientInitializeFunc function for a implementation of the Client interface.
func Schemes ¶
func Schemes() []string
Return a list of URI schemes for registered implementations of the Client interface.
Types ¶
type Client ¶
type Client interface { // Execute a Mastodon API method. ExecuteMethod(context.Context, string, string, *url.Values) (io.ReadSeekCloser, error) // Upload an io.Reader instance using the Mastodon API. UploadMedia(context.Context, io.Reader, *url.Values) (io.ReadSeekCloser, error) }
Client is the interface that defines common methods for all Mastodon API Client implementations. Currently there is only a single implementation that calls the Mastodon API using the OAuth2 authentication and authorization scheme but it is assumed that eventually there will be others.
func NewClient ¶
Create a new instance of the Client interface. Client instances are created by passing in a context.Context instance and a URI string. The form and substance of URI strings are specific to their implementations. For example to create a OAuth2Client you would write: cl, err := client.NewClient(ctx, "oauth2://:{ACCESS_TOKEN}@{MASTODON_HOST}")
type ClientInitializeFunc ¶
The initialization function signature for implementation of the Client interface.
type OAuth2Client ¶
type OAuth2Client struct {
// contains filtered or unexported fields
}
OAuth2Client implements the `Client` interface using OAuth2 access tokens for authentication and authorization.
func (*OAuth2Client) ExecuteMethod ¶
func (cl *OAuth2Client) ExecuteMethod(ctx context.Context, http_method string, api_method string, args *url.Values) (io.ReadSeekCloser, error)
ExecuteMethod will execute a Mastodon API method where 'api_method' is expected to be the relative URI for a given Mastodon API method.
func (*OAuth2Client) UploadMedia ¶
func (cl *OAuth2Client) UploadMedia(ctx context.Context, r io.Reader, args *url.Values) (io.ReadSeekCloser, error)
UploadMedia will upload the contents of 'r' as a media element using the Mastodon API.