Documentation ¶
Overview ¶
Package mastodon is an API client for Mastodon1, specifically designed for making bots.
Index ¶
- type Account
- type Announcement
- type Application
- type Attachment
- type Card
- type Client
- func (c *Client) AuthorizeURL(app *OAuth2Application, scope string) (string, error)
- func (c *Client) CreateApplication(ctx context.Context, car CreateApplicationRequest) (*OAuth2Application, error)
- func (c *Client) CreateStatus(ctx context.Context, csp CreateStatusParams) (*Status, error)
- func (c *Client) FetchToken(ctx context.Context, app *OAuth2Application, code, scope string) (*TokenInfo, error)
- func (c *Client) StreamMessages(ctx context.Context, subreq ...WSSubscribeRequest) (chan WSMessage, error)
- func (c *Client) UploadMedia(ctx context.Context, fin io.Reader, fname, description, focus string) (*Attachment, error)
- func (c *Client) VerifyCredentials(ctx context.Context) error
- type Context
- type Conversation
- type CreateApplicationRequest
- type CreateStatusParams
- type DomainName
- type Emoji
- type EmojiReaction
- type Error
- type Field
- type Instance
- type InstancePeer
- type List
- type MastodonDate
- type Mention
- type Notification
- type OAuth2Application
- type Relationship
- type Report
- type Results
- type SourceParams
- type Status
- type Tag
- type TokenInfo
- type WSMessage
- type WSSubscribeRequest
- type WeekActivity
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct { ID string `json:"id"` Username string `json:"username"` Acct string `json:"acct"` DisplayName string `json:"display_name"` Note string `json:"note"` URL string `json:"url"` Avatar string `json:"avatar"` AvatarStatic string `json:"avatar_static"` Header string `json:"header"` HeaderStatic string `json:"header_static"` Locked bool `json:"locked"` CreatedAt time.Time `json:"created_at"` FollowersCount int64 `json:"followers_count"` FollowingCount int64 `json:"following_count"` StatusesCount int64 `json:"statuses_count"` Moved *Account `json:"moved"` Bot bool `json:"bot"` Emojis []Emoji `json:"emojis"` Fields *[]Field `json:"fields"` Source *SourceParams `json:"source"` }
Account represents a Mastodon account entity
type Announcement ¶
type Announcement struct { ID string `json:"id"` Content string `json:"content"` StartsAt *time.Time `json:"starts_at"` EndsAt *time.Time `json:"ends_at"` AllDay bool `json:"all_day"` PublishedAt time.Time `json:"published_at"` UpdatedAt *time.Time `json:"updated_at"` Read bool `json:"read"` }
Announcement is a single server announcement.
type Application ¶
Application represents a Mastodon application entity
type Attachment ¶
type Attachment struct { ID string `json:"id"` Type string `json:"type"` URL string `json:"url"` RemoteURL *string `json:"remote_url"` PreviewURL string `json:"preview_url"` TextURL *string `json:"text_url"` Meta *struct { Original struct { Size string `json:"size"` Aspect float64 `json:"aspect"` Width int `json:"width"` Height int `json:"height"` } `json:"original"` Small struct { Size string `json:"size"` Aspect float64 `json:"aspect"` Width int `json:"width"` Height int `json:"height"` } `json:"small"` } `json:"meta"` Description *string `json:"description"` }
Attachment represents a Mastodon media attachment entity
type Card ¶
type Card struct { URL string `json:"url"` Title string `json:"title"` Description string `json:"description"` Image string `json:"image"` Type *string `json:"type"` AuthorName *string `json:"author_name"` AuthorURL *string `json:"author_url"` ProviderName *string `json:"provider_name"` ProviderURL *string `json:"provider_url"` EmbedURL *string `json:"embed_url"` HTML *string `json:"html"` Width *int `json:"width"` Height *int `json:"height"` }
Card represents a Mastodon preview card entity
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the client for Mastodon
func Authenticated ¶
Authenticated makes a new authenticated Mastodon client.
func Unauthenticated ¶
Unauthenticated makes a new unauthenticated Mastodon client.
func (*Client) AuthorizeURL ¶
func (c *Client) AuthorizeURL(app *OAuth2Application, scope string) (string, error)
func (*Client) CreateApplication ¶
func (c *Client) CreateApplication(ctx context.Context, car CreateApplicationRequest) (*OAuth2Application, error)
func (*Client) CreateStatus ¶
func (*Client) FetchToken ¶
func (*Client) StreamMessages ¶
func (c *Client) StreamMessages(ctx context.Context, subreq ...WSSubscribeRequest) (chan WSMessage, error)
StreamMessages is a low-level message streaming facility.
func (*Client) UploadMedia ¶
type Context ¶
type Context struct { Ancestors []Status `json:"ancestors"` Descendants []Status `json:"descendants"` }
Context represents a Mastodon context entity
type Conversation ¶
type Conversation struct { ID string `json:"id"` Unread bool `json:"unread"` Accounts []Account `json:"accounts"` LastStatus *Status `json:"status"` }
Conversation represents a conversation with "direct message" visibility.
type CreateStatusParams ¶
type CreateStatusParams struct { Status string `json:"status"` InReplyTo string `json:"in_reply_to_id"` MediaIDs []string `json:"media_ids"` SpoilerText string `json:"spoiler_text"` Visibility string `json:"visibility"` ScheduledAt *time.Time `json:"scheduled_at,omitempty"` }
func (CreateStatusParams) Values ¶
func (csp CreateStatusParams) Values() url.Values
type DomainName ¶
type DomainName string
DomainName is a domain name string, as returned by the domain_blocks API
type Emoji ¶
type Emoji struct { ShortCode string `json:"shortcode"` URL string `json:"url"` StaticURL string `json:"static_url"` VisibleInPicker bool `json:"visible_in_picker"` }
Emoji represents a Mastodon emoji entity
type EmojiReaction ¶
type EmojiReaction struct { Name string `json:"name"` Count int `json:"count"` AnnouncementID string `json:"announcement_id"` }
EmojiReaction represents an emoji reaction to an announcement.
type Error ¶
type Error struct {
Text string `json:"error"`
}
Error represents a Mastodon error entity
type Instance ¶
type Instance struct { URI string `json:"uri"` Title string `json:"title"` Description string `json:"description"` Email string `json:"email"` Version string `json:"version"` URLs struct { SteamingAPI string `json:"streaming_api"` } `json:"urls"` Stats struct { UserCount int64 `json:"user_count"` StatusCount int64 `json:"status_count"` DomainCount int64 `json:"domain_count"` } `json:"stats"` Thumbnail *string `json:"thumbnail"` Languages []string `json:"languages"` ContactAccount *Account `json:"contact_account"` }
Instance represents a Mastodon instance entity
type InstancePeer ¶
type InstancePeer string
InstancePeer is a peer name, as returned by the instance/peers API
type MastodonDate ¶
MastodonDate is a custom type for the timestamps returned by some API calls It is used, for example, by 'v1/instance/activity' and 'v2/search'. The date returned by those Mastodon API calls is a string containing a timestamp in seconds
func (*MastodonDate) MarshalJSON ¶
func (act *MastodonDate) MarshalJSON() ([]byte, error)
MarshalJSON handles serialization for custom MastodonDate type
func (*MastodonDate) UnmarshalJSON ¶
func (act *MastodonDate) UnmarshalJSON(b []byte) error
UnmarshalJSON handles deserialization for custom MastodonDate type
type Mention ¶
type Mention struct { ID string `json:"id"` URL string `json:"url"` Username string `json:"username"` Acct string `json:"acct"` }
Mention represents a Mastodon mention entity
type Notification ¶
type Notification struct { ID string `json:"id"` Type string `json:"type"` CreatedAt time.Time `json:"created_at"` Account *Account `json:"account"` Status *Status `json:"status"` }
Notification represents a Mastodon notification entity
type OAuth2Application ¶
type Relationship ¶
type Relationship struct { ID string `json:"id"` Following bool `json:"following"` //ShowingReblogs bool `json:"showing_reblogs"` // Incoherent type FollowedBy bool `json:"followed_by"` Blocking bool `json:"blocking"` Muting bool `json:"muting"` Requested bool `json:"requested"` DomainBlocking bool `jsin:"domain_blocking"` MutingNotifications bool `json:"muting_notifications"` ShowingReblogs bool `json:"showing_reblogs"` Endorsed bool `json:"endorsed"` }
Relationship represents a Mastodon relationship entity
type SourceParams ¶
type SourceParams struct { Privacy *string `json:"privacy,omitempty"` Language *string `json:"language,omitempty"` Sensitive *bool `json:"sensitive,omitempty"` Note *string `json:"note,omitempty"` Fields *[]Field `json:"fields,omitempty"` }
SourceParams is a source params structure
type Status ¶
type Status struct { ID string `json:"id"` URI string `json:"uri"` URL string `json:"url"` Account *Account `json:"account"` InReplyToID *string `json:"in_reply_to_id"` InReplyToAccountID *string `json:"in_reply_to_account_id"` Reblog *Status `json:"reblog"` Content string `json:"content"` CreatedAt time.Time `json:"created_at"` ReblogsCount int64 `json:"reblogs_count"` FavouritesCount int64 `json:"favourites_count"` RepliesCount int64 `json:"replies_count"` Reblogged bool `json:"reblogged"` Favourited bool `json:"favourited"` Muted bool `json:"muted"` Pinned bool `json:"pinned"` Sensitive bool `json:"sensitive"` SpoilerText string `json:"spoiler_text"` Visibility string `json:"visibility"` MediaAttachments []Attachment `json:"media_attachments"` Mentions []Mention `json:"mentions"` Tags []Tag `json:"tags"` Emojis []Emoji `json:"emojis"` Application *Application `json:"application"` Language *string `json:"language"` }
Status represents a Mastodon status entity
func FetchStatus ¶
FetchStatus fetches a Mastodon status over the internet using the federation protocol.
This will not work if the target server has "secure" mode enabled.
type Tag ¶
type Tag struct { Name string `json:"name"` URL string `json:"url"` History []struct { Day MastodonDate `json:"day"` Uses int64 `json:"uses,string"` Accounts int64 `json:"accounts,string"` } `json:"history"` }
Tag represents a Mastodon tag entity
type TokenInfo ¶
type TokenInfo struct { AccessToken string `json:"access_token"` TokenType string `json:"token_type"` Scope string `json:"scope"` CreatedAt MastodonDate `json:"created_at"` }
type WSMessage ¶
type WSMessage struct { Stream []string `json:"stream"` Event string `json:"event"` Payload string `json:"payload"` // json string }
WSMessage is a websocket message. Whenever you get something from the streaming service, it will fit into this box.
type WSSubscribeRequest ¶
type WSSubscribeRequest struct { Type string `json:"type"` // should be "subscribe" or "unsubscribe" Stream string `json:"stream"` Hashtag string `json:"hashtag,omitempty"` }
WSSubscribeRequest is a websocket instruction to subscribe to a streaming feed.
type WeekActivity ¶
type WeekActivity struct { Week MastodonDate `json:"week"` Statuses int64 `json:"statuses,string"` Logins int64 `json:"logins,string"` Registrations int64 `json:"registrations,string"` }
WeekActivity represents a Mastodon instance activity "week" entity