mastodon

package module
v0.0.0-...-04581fb Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: MIT Imports: 20 Imported by: 0

README

go-mastodon

Build Status Codecov Go Reference Go Report Card

Usage

Application
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/mattn/go-mastodon"
)

func main() {
	app, err := mastodon.RegisterApp(context.Background(), &mastodon.AppConfig{
		Server:     "https://mstdn.jp",
		ClientName: "client-name",
		Scopes:     "read write follow",
		Website:    "https://github.com/mattn/go-mastodon",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("client-id    : %s\n", app.ClientID)
	fmt.Printf("client-secret: %s\n", app.ClientSecret)
}
Client
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/mattn/go-mastodon"
)

func main() {
	c := mastodon.NewClient(&mastodon.Config{
		Server:       "https://mstdn.jp",
		ClientID:     "client-id",
		ClientSecret: "client-secret",
	})
	err := c.Authenticate(context.Background(), "your-email", "your-password")
	if err != nil {
		log.Fatal(err)
	}
	timeline, err := c.GetTimelineHome(context.Background(), nil)
	if err != nil {
		log.Fatal(err)
	}
	for i := len(timeline) - 1; i >= 0; i-- {
		fmt.Println(timeline[i])
	}
}

Status of implementations

  • GET /api/v1/accounts/:id
  • GET /api/v1/accounts/verify_credentials
  • PATCH /api/v1/accounts/update_credentials
  • GET /api/v1/accounts/:id/followers
  • GET /api/v1/accounts/:id/following
  • GET /api/v1/accounts/:id/statuses
  • POST /api/v1/accounts/:id/follow
  • POST /api/v1/accounts/:id/unfollow
  • GET /api/v1/accounts/:id/block
  • GET /api/v1/accounts/:id/unblock
  • GET /api/v1/accounts/:id/mute
  • GET /api/v1/accounts/:id/unmute
  • GET /api/v1/accounts/:id/lists
  • GET /api/v1/accounts/relationships
  • GET /api/v1/accounts/search
  • GET /api/v1/apps/verify_credentials
  • GET /api/v1/bookmarks
  • POST /api/v1/apps
  • GET /api/v1/blocks
  • GET /api/v1/conversations
  • DELETE /api/v1/conversations/:id
  • POST /api/v1/conversations/:id/read
  • GET /api/v1/favourites
  • GET /api/v1/filters
  • POST /api/v1/filters
  • GET /api/v1/filters/:id
  • PUT /api/v1/filters/:id
  • DELETE /api/v1/filters/:id
  • GET /api/v1/follow_requests
  • POST /api/v1/follow_requests/:id/authorize
  • POST /api/v1/follow_requests/:id/reject
  • POST /api/v1/follows
  • GET /api/v1/instance
  • GET /api/v1/instance/activity
  • GET /api/v1/instance/peers
  • GET /api/v1/lists
  • GET /api/v1/lists/:id/accounts
  • GET /api/v1/lists/:id
  • POST /api/v1/lists
  • PUT /api/v1/lists/:id
  • DELETE /api/v1/lists/:id
  • POST /api/v1/lists/:id/accounts
  • DELETE /api/v1/lists/:id/accounts
  • POST /api/v1/media
  • GET /api/v1/mutes
  • GET /api/v1/notifications
  • GET /api/v1/notifications/:id
  • POST /api/v1/notifications/:id/dismiss
  • POST /api/v1/notifications/clear
  • POST /api/v1/push/subscription
  • GET /api/v1/push/subscription
  • PUT /api/v1/push/subscription
  • DELETE /api/v1/push/subscription
  • GET /api/v1/reports
  • POST /api/v1/reports
  • GET /api/v2/search
  • GET /api/v1/statuses/:id
  • GET /api/v1/statuses/:id/context
  • GET /api/v1/statuses/:id/card
  • GET /api/v1/statuses/:id/history
  • GET /api/v1/statuses/:id/reblogged_by
  • GET /api/v1/statuses/:id/source
  • GET /api/v1/statuses/:id/favourited_by
  • POST /api/v1/statuses
  • PUT /api/v1/statuses/:id
  • DELETE /api/v1/statuses/:id
  • POST /api/v1/statuses/:id/reblog
  • POST /api/v1/statuses/:id/unreblog
  • POST /api/v1/statuses/:id/favourite
  • POST /api/v1/statuses/:id/unfavourite
  • POST /api/v1/statuses/:id/bookmark
  • POST /api/v1/statuses/:id/unbookmark
  • GET /api/v1/timelines/home
  • GET /api/v1/timelines/public
  • GET /api/v1/timelines/tag/:hashtag
  • GET /api/v1/timelines/list/:id
  • GET /api/v1/streaming/user
  • GET /api/v1/streaming/public
  • GET /api/v1/streaming/hashtag?tag=:hashtag
  • GET /api/v1/streaming/hashtag/local?tag=:hashtag
  • GET /api/v1/streaming/list?list=:list_id
  • GET /api/v1/streaming/direct

Installation

go install github.com/mattn/go-mastodon@latest

License

MIT

Author

Yasuhiro Matsumoto (a.k.a. mattn)

Documentation

Overview

Package mastodon provides functions and structs for accessing the mastodon API.

Index

Examples

Constants

View Source
const (
	VisibilityPublic        = "public"
	VisibilityUnlisted      = "unlisted"
	VisibilityFollowersOnly = "private"
	VisibilityDirectMessage = "direct"
)

Convenience constants for Toot.Visibility

Variables

This section is empty.

Functions

func Base64Encode

func Base64Encode(file *os.File) (string, error)

Base64Encode returns the base64 data URI format string of the file.

func Base64EncodeFileName

func Base64EncodeFileName(filename string) (string, error)

Base64EncodeFileName returns the base64 data URI format string of the file with the file name.

func String

func String(v string) *string

String is a helper function to get the pointer value of a string.

Types

type Account

type Account struct {
	ID             ID             `json:"id"`
	Username       string         `json:"username"`
	Acct           string         `json:"acct"`
	DisplayName    string         `json:"display_name"`
	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"`
	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"`
	Emojis         []Emoji        `json:"emojis"`
	Moved          *Account       `json:"moved"`
	Fields         []Field        `json:"fields"`
	Bot            bool           `json:"bot"`
	Discoverable   bool           `json:"discoverable"`
	Source         *AccountSource `json:"source"`
}

Account holds information for a mastodon account.

type AccountSource

type AccountSource struct {
	Privacy   *string  `json:"privacy"`
	Sensitive *bool    `json:"sensitive"`
	Language  *string  `json:"language"`
	Note      *string  `json:"note"`
	Fields    *[]Field `json:"fields"`
}

AccountSource is a Mastodon account profile field.

type AppConfig

type AppConfig struct {
	http.Client
	Server     string
	ClientName string

	// Where the user should be redirected after authorization (for no redirect, use urn:ietf:wg:oauth:2.0:oob)
	RedirectURIs string

	// This can be a space-separated list of items listed on the /settings/applications/new page of any Mastodon
	// instance. "read", "write", and "follow" are top-level scopes that include all the permissions of the more
	// specific scopes like "read:favourites", "write:statuses", and "write:follows".
	Scopes string

	// Optional.
	Website string
}

AppConfig is a setting for registering applications.

type Application

type Application struct {
	ID           ID     `json:"id"`
	RedirectURI  string `json:"redirect_uri"`
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`

	// AuthURI is not part of the Mastodon API; it is generated by go-mastodon.
	AuthURI string `json:"auth_uri,omitempty"`
}

Application is a mastodon application.

func RegisterApp

func RegisterApp(ctx context.Context, appConfig *AppConfig) (*Application, error)

RegisterApp returns the mastodon application.

Example
app, err := mastodon.RegisterApp(context.Background(), &mastodon.AppConfig{
	Server:     "https://mstdn.jp",
	ClientName: "client-name",
	Scopes:     "read write follow",
	Website:    "https://github.com/mattn/go-mastodon",
})
if err != nil {
	log.Fatal(err)
}
fmt.Printf("client-id    : %s\n", app.ClientID)
fmt.Printf("client-secret: %s\n", app.ClientSecret)
Output:

type ApplicationVerification

type ApplicationVerification struct {
	Name     string `json:"name"`
	Website  string `json:"website"`
	VapidKey string `json:"vapid_key"`
}

ApplicationVerification is mastodon application.

type Attachment

type Attachment struct {
	ID          ID             `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"`
	Description string         `json:"description"`
	Meta        AttachmentMeta `json:"meta"`
}

Attachment hold information for attachment.

type AttachmentMeta

type AttachmentMeta struct {
	Original AttachmentSize `json:"original"`
	Small    AttachmentSize `json:"small"`
}

AttachmentMeta holds information for attachment metadata.

type AttachmentSize

type AttachmentSize struct {
	Width  int64   `json:"width"`
	Height int64   `json:"height"`
	Size   string  `json:"size"`
	Aspect float64 `json:"aspect"`
}

AttachmentSize holds information for attatchment size.

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"`
	HTML         string `json:"html"`
	Width        int64  `json:"width"`
	Height       int64  `json:"height"`
}

Card holds information for a mastodon card.

type Client

type Client struct {
	http.Client
	Config    *Config
	UserAgent string
}

Client is a API client for mastodon.

Example
c := mastodon.NewClient(&mastodon.Config{
	Server:       "https://mstdn.jp",
	ClientID:     "client-id",
	ClientSecret: "client-secret",
})
err := c.Authenticate(context.Background(), "your-email", "your-password")
if err != nil {
	log.Fatal(err)
}
timeline, err := c.GetTimelineHome(context.Background(), nil)
if err != nil {
	log.Fatal(err)
}
for i := len(timeline) - 1; i >= 0; i-- {
	fmt.Println(timeline[i])
}
Output:

func NewClient

func NewClient(config *Config) *Client

NewClient returns a new mastodon API client.

func (*Client) AccountBlock

func (c *Client) AccountBlock(ctx context.Context, id ID) (*Relationship, error)

AccountBlock blocks the account.

func (*Client) AccountFollow

func (c *Client) AccountFollow(ctx context.Context, id ID) (*Relationship, error)

AccountFollow follows the account.

func (*Client) AccountMute

func (c *Client) AccountMute(ctx context.Context, id ID) (*Relationship, error)

AccountMute mutes the account.

func (*Client) AccountUnblock

func (c *Client) AccountUnblock(ctx context.Context, id ID) (*Relationship, error)

AccountUnblock unblocks the account.

func (*Client) AccountUnfollow

func (c *Client) AccountUnfollow(ctx context.Context, id ID) (*Relationship, error)

AccountUnfollow unfollows the account.

func (*Client) AccountUnmute

func (c *Client) AccountUnmute(ctx context.Context, id ID) (*Relationship, error)

AccountUnmute unmutes the account.

func (*Client) AccountUpdate

func (c *Client) AccountUpdate(ctx context.Context, profile *Profile) (*Account, error)

AccountUpdate updates the information of the current user.

func (*Client) AccountsSearch

func (c *Client) AccountsSearch(ctx context.Context, q string, limit int64) ([]*Account, error)

AccountsSearch searches accounts by query.

func (*Client) AddPushSubscription

func (c *Client) AddPushSubscription(ctx context.Context, endpoint string, public ecdsa.PublicKey, shared []byte, alerts PushAlerts) (*PushSubscription, error)

AddPushSubscription adds a new push subscription.

func (*Client) AddToList

func (c *Client) AddToList(ctx context.Context, list ID, accounts ...ID) error

AddToList adds accounts to a list.

Only accounts already followed by the user can be added to a list.

func (*Client) Authenticate

func (c *Client) Authenticate(ctx context.Context, username, password string) error

Authenticate gets access-token to the API.

func (*Client) AuthenticateApp

func (c *Client) AuthenticateApp(ctx context.Context) error

AuthenticateApp logs in using client credentials.

func (*Client) AuthenticateToken

func (c *Client) AuthenticateToken(ctx context.Context, authCode, redirectURI string) error

AuthenticateToken logs in using a grant token returned by Application.AuthURI.

redirectURI should be the same as Application.RedirectURI.

func (*Client) Bookmark

func (c *Client) Bookmark(ctx context.Context, id ID) (*Status, error)

Bookmark bookmarks the toot of id and returns status of the bookmark toot.

func (*Client) ClearNotifications

func (c *Client) ClearNotifications(ctx context.Context) error

ClearNotifications clears notifications.

func (*Client) CreateFilter

func (c *Client) CreateFilter(ctx context.Context, filter *Filter) (*Filter, error)

CreateFilter creates a new filter.

func (*Client) CreateList

func (c *Client) CreateList(ctx context.Context, title string) (*List, error)

CreateList creates a new list with a given title.

func (*Client) DeleteConversation

func (c *Client) DeleteConversation(ctx context.Context, id ID) error

DeleteConversation delete the conversation specified by id.

func (*Client) DeleteFilter

func (c *Client) DeleteFilter(ctx context.Context, id ID) error

DeleteFilter removes a filter.

func (*Client) DeleteList

func (c *Client) DeleteList(ctx context.Context, id ID) error

DeleteList removes a list.

func (*Client) DeleteStatus

func (c *Client) DeleteStatus(ctx context.Context, id ID) error

DeleteStatus delete the toot.

func (*Client) DismissNotification

func (c *Client) DismissNotification(ctx context.Context, id ID) error

DismissNotification deletes a single notification.

func (*Client) Favourite

func (c *Client) Favourite(ctx context.Context, id ID) (*Status, error)

Favourite favourites the toot of id and returns status of the favourite toot.

func (*Client) FollowRemoteUser

func (c *Client) FollowRemoteUser(ctx context.Context, uri string) (*Account, error)

FollowRemoteUser sends follow-request.

func (*Client) FollowRequestAuthorize

func (c *Client) FollowRequestAuthorize(ctx context.Context, id ID) error

FollowRequestAuthorize authorizes the follow request of user with id.

func (*Client) FollowRequestReject

func (c *Client) FollowRequestReject(ctx context.Context, id ID) error

FollowRequestReject rejects the follow request of user with id.

func (*Client) GetAccount

func (c *Client) GetAccount(ctx context.Context, id ID) (*Account, error)

GetAccount return Account.

func (*Client) GetAccountCurrentUser

func (c *Client) GetAccountCurrentUser(ctx context.Context) (*Account, error)

GetAccountCurrentUser returns the Account of current user.

func (*Client) GetAccountFollowers

func (c *Client) GetAccountFollowers(ctx context.Context, id ID, pg *Pagination) ([]*Account, error)

GetAccountFollowers returns followers list.

func (*Client) GetAccountFollowing

func (c *Client) GetAccountFollowing(ctx context.Context, id ID, pg *Pagination) ([]*Account, error)

GetAccountFollowing returns following list.

func (*Client) GetAccountLists

func (c *Client) GetAccountLists(ctx context.Context, id ID) ([]*List, error)

GetAccountLists returns the lists containing a given account.

func (*Client) GetAccountPinnedStatuses

func (c *Client) GetAccountPinnedStatuses(ctx context.Context, id ID) ([]*Status, error)

GetAccountPinnedStatuses returns statuses pinned by specified accuont.

func (*Client) GetAccountRelationships

func (c *Client) GetAccountRelationships(ctx context.Context, ids []string) ([]*Relationship, error)

GetAccountRelationships returns relationship for the account.

func (*Client) GetAccountStatuses

func (c *Client) GetAccountStatuses(ctx context.Context, id ID, pg *Pagination) ([]*Status, error)

GetAccountStatuses return statuses by specified account.

func (*Client) GetBlocks

func (c *Client) GetBlocks(ctx context.Context, pg *Pagination) ([]*Account, error)

GetBlocks returns block list.

func (*Client) GetBookmarks

func (c *Client) GetBookmarks(ctx context.Context, pg *Pagination) ([]*Status, error)

GetBookmarks returns the bookmark list of the current user.

func (*Client) GetConversations

func (c *Client) GetConversations(ctx context.Context, pg *Pagination) ([]*Conversation, error)

GetConversations return direct conversations.

func (*Client) GetFavouritedBy

func (c *Client) GetFavouritedBy(ctx context.Context, id ID, pg *Pagination) ([]*Account, error)

GetFavouritedBy returns the account list of the user who liked the toot of id.

func (*Client) GetFavourites

func (c *Client) GetFavourites(ctx context.Context, pg *Pagination) ([]*Status, error)

GetFavourites returns the favorite list of the current user.

func (*Client) GetFilter

func (c *Client) GetFilter(ctx context.Context, id ID) (*Filter, error)

GetFilter retrieves a filter by ID.

func (*Client) GetFilters

func (c *Client) GetFilters(ctx context.Context) ([]*Filter, error)

GetFilters returns all the filters on the current account.

func (*Client) GetFollowRequests

func (c *Client) GetFollowRequests(ctx context.Context, pg *Pagination) ([]*Account, error)

GetFollowRequests returns follow requests.

func (*Client) GetInstance

func (c *Client) GetInstance(ctx context.Context) (*Instance, error)

GetInstance returns Instance.

func (*Client) GetInstanceActivity

func (c *Client) GetInstanceActivity(ctx context.Context) ([]*WeeklyActivity, error)

GetInstanceActivity returns instance activity.

func (*Client) GetInstancePeers

func (c *Client) GetInstancePeers(ctx context.Context) ([]string, error)

GetInstancePeers returns instance peers.

func (*Client) GetList

func (c *Client) GetList(ctx context.Context, id ID) (*List, error)

GetList retrieves a list by ID.

func (*Client) GetListAccounts

func (c *Client) GetListAccounts(ctx context.Context, id ID) ([]*Account, error)

GetListAccounts returns the accounts in a given list.

func (*Client) GetLists

func (c *Client) GetLists(ctx context.Context) ([]*List, error)

GetLists returns all the lists on the current account.

func (*Client) GetMutes

func (c *Client) GetMutes(ctx context.Context, pg *Pagination) ([]*Account, error)

GetMutes returns the list of users muted by the current user.

func (*Client) GetNotification

func (c *Client) GetNotification(ctx context.Context, id ID) (*Notification, error)

GetNotification returns notification.

func (*Client) GetNotifications

func (c *Client) GetNotifications(ctx context.Context, pg *Pagination) ([]*Notification, error)

GetNotifications returns notifications.

func (*Client) GetPoll

func (c *Client) GetPoll(ctx context.Context, id ID) (*Poll, error)

GetPoll returns poll specified by id.

func (*Client) GetPushSubscription

func (c *Client) GetPushSubscription(ctx context.Context) (*PushSubscription, error)

GetPushSubscription retrieves information about the active push subscription.

func (*Client) GetRebloggedBy

func (c *Client) GetRebloggedBy(ctx context.Context, id ID, pg *Pagination) ([]*Account, error)

GetRebloggedBy returns the account list of the user who reblogged the toot of id.

func (*Client) GetReports

func (c *Client) GetReports(ctx context.Context) ([]*Report, error)

GetReports returns report of the current user.

func (*Client) GetStatus

func (c *Client) GetStatus(ctx context.Context, id ID) (*Status, error)

GetStatus returns status specified by id.

func (*Client) GetStatusCard

func (c *Client) GetStatusCard(ctx context.Context, id ID) (*Card, error)

GetStatusCard returns status specified by id.

func (*Client) GetStatusContext

func (c *Client) GetStatusContext(ctx context.Context, id ID) (*Context, error)

GetStatusContext returns status specified by id.

func (*Client) GetStatusHistory

func (c *Client) GetStatusHistory(ctx context.Context, id ID) ([]*StatusHistory, error)

GetStatusHistory returns the status history specified by id.

func (*Client) GetStatusSource

func (c *Client) GetStatusSource(ctx context.Context, id ID) (*Source, error)

GetStatusSource returns source data specified by id.

func (*Client) GetTimelineDirect

func (c *Client) GetTimelineDirect(ctx context.Context, pg *Pagination) ([]*Status, error)

GetTimelineDirect return statuses from direct timeline.

func (*Client) GetTimelineHashtag

func (c *Client) GetTimelineHashtag(ctx context.Context, tag string, isLocal bool, pg *Pagination) ([]*Status, error)

GetTimelineHashtag return statuses from tagged timeline.

func (*Client) GetTimelineHome

func (c *Client) GetTimelineHome(ctx context.Context, pg *Pagination) ([]*Status, error)

GetTimelineHome return statuses from home timeline.

func (*Client) GetTimelineList

func (c *Client) GetTimelineList(ctx context.Context, id ID, pg *Pagination) ([]*Status, error)

GetTimelineList return statuses from a list timeline.

func (*Client) GetTimelineMedia

func (c *Client) GetTimelineMedia(ctx context.Context, isLocal bool, pg *Pagination) ([]*Status, error)

GetTimelineMedia return statuses from media timeline. NOTE: This is an experimental feature of pawoo.net.

func (*Client) GetTimelinePublic

func (c *Client) GetTimelinePublic(ctx context.Context, isLocal bool, pg *Pagination) ([]*Status, error)

GetTimelinePublic return statuses from public timeline.

func (*Client) MarkConversationAsRead

func (c *Client) MarkConversationAsRead(ctx context.Context, id ID) error

MarkConversationAsRead mark the conversation as read.

func (*Client) NewWSClient

func (c *Client) NewWSClient() *WSClient

NewWSClient return WebSocket client.

func (*Client) PollVote

func (c *Client) PollVote(ctx context.Context, id ID, choices ...int) (*Poll, error)

PollVote votes on a poll specified by id, choices is the Poll.Options index to vote on

func (*Client) PostStatus

func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error)

PostStatus post the toot.

func (*Client) Reblog

func (c *Client) Reblog(ctx context.Context, id ID) (*Status, error)

Reblog reblogs the toot of id and returns status of reblog.

func (*Client) RemoveFromList

func (c *Client) RemoveFromList(ctx context.Context, list ID, accounts ...ID) error

RemoveFromList removes accounts from a list.

func (*Client) RemovePushSubscription

func (c *Client) RemovePushSubscription(ctx context.Context) error

RemovePushSubscription deletes the active push subscription.

func (*Client) RenameList

func (c *Client) RenameList(ctx context.Context, id ID, title string) (*List, error)

RenameList assigns a new title to a list.

func (*Client) Report

func (c *Client) Report(ctx context.Context, accountID ID, ids []ID, comment string) (*Report, error)

Report reports the report

func (*Client) Search

func (c *Client) Search(ctx context.Context, q string, resolve bool) (*Results, error)

Search search content with query.

func (*Client) StreamingDirect

func (c *Client) StreamingDirect(ctx context.Context) (chan Event, error)

StreamingDirect returns a channel to read events on a direct messages.

func (*Client) StreamingHashtag

func (c *Client) StreamingHashtag(ctx context.Context, tag string, isLocal bool) (chan Event, error)

StreamingHashtag returns a channel to read events on tagged timeline.

func (*Client) StreamingList

func (c *Client) StreamingList(ctx context.Context, id ID) (chan Event, error)

StreamingList returns a channel to read events on a list.

func (*Client) StreamingPublic

func (c *Client) StreamingPublic(ctx context.Context, isLocal bool) (chan Event, error)

StreamingPublic returns a channel to read events on public.

func (*Client) StreamingUser

func (c *Client) StreamingUser(ctx context.Context) (chan Event, error)

StreamingUser returns a channel to read events on home.

func (*Client) Unbookmark

func (c *Client) Unbookmark(ctx context.Context, id ID) (*Status, error)

Unbookmark is unbookmark the toot of id and return status of the unbookmark toot.

func (*Client) Unfavourite

func (c *Client) Unfavourite(ctx context.Context, id ID) (*Status, error)

Unfavourite unfavourites the toot of id and returns status of the unfavourite toot.

func (*Client) Unreblog

func (c *Client) Unreblog(ctx context.Context, id ID) (*Status, error)

Unreblog unreblogs the toot of id and returns status of the original toot.

func (*Client) UpdateFilter

func (c *Client) UpdateFilter(ctx context.Context, id ID, filter *Filter) (*Filter, error)

UpdateFilter updates a filter.

func (*Client) UpdatePushSubscription

func (c *Client) UpdatePushSubscription(ctx context.Context, alerts *PushAlerts) (*PushSubscription, error)

UpdatePushSubscription updates which type of notifications are sent for the active push subscription.

func (*Client) UpdateStatus

func (c *Client) UpdateStatus(ctx context.Context, toot *Toot, id ID) (*Status, error)

UpdateStatus updates the toot.

func (*Client) UploadMedia

func (c *Client) UploadMedia(ctx context.Context, file string) (*Attachment, error)

UploadMedia upload a media attachment from a file.

func (*Client) UploadMediaFromBytes

func (c *Client) UploadMediaFromBytes(ctx context.Context, b []byte) (*Attachment, error)

UploadMediaFromBytes uploads a media attachment from a byte slice.

func (*Client) UploadMediaFromMedia

func (c *Client) UploadMediaFromMedia(ctx context.Context, media *Media) (*Attachment, error)

UploadMediaFromMedia uploads a media attachment from a Media struct.

func (*Client) UploadMediaFromReader

func (c *Client) UploadMediaFromReader(ctx context.Context, reader io.Reader) (*Attachment, error)

UploadMediaFromReader uploads a media attachment from an io.Reader.

func (*Client) VerifyAppCredentials

func (c *Client) VerifyAppCredentials(ctx context.Context) (*ApplicationVerification, error)

VerifyAppCredentials returns the mastodon application.

type Config

type Config struct {
	Server       string
	ClientID     string
	ClientSecret string
	AccessToken  string
}

Config is a setting for access mastodon APIs.

type Context

type Context struct {
	Ancestors   []*Status `json:"ancestors"`
	Descendants []*Status `json:"descendants"`
}

Context holds information for a mastodon context.

type Conversation

type Conversation struct {
	ID         ID         `json:"id"`
	Accounts   []*Account `json:"accounts"`
	Unread     bool       `json:"unread"`
	LastStatus *Status    `json:"last_status"`
}

Conversation holds information for a mastodon conversation.

type DeleteEvent

type DeleteEvent struct{ ID ID }

DeleteEvent is a struct for passing deletion event to app.

type Emoji

type Emoji struct {
	ShortCode       string `json:"shortcode"`
	StaticURL       string `json:"static_url"`
	URL             string `json:"url"`
	VisibleInPicker bool   `json:"visible_in_picker"`
}

Emoji hold information for CustomEmoji.

type ErrorEvent

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

ErrorEvent is a struct for passing errors to app.

func (*ErrorEvent) Error

func (e *ErrorEvent) Error() string

type Event

type Event interface {
	// contains filtered or unexported methods
}

Event is an interface passing events to app.

type Field

type Field struct {
	Name       string    `json:"name"`
	Value      string    `json:"value"`
	VerifiedAt time.Time `json:"verified_at"`
}

Field is a Mastodon account profile field.

type Filter

type Filter struct {
	ID           ID        `json:"id"`
	Phrase       string    `json:"phrase"`
	Context      []string  `json:"context"`
	WholeWord    bool      `json:"whole_word"`
	ExpiresAt    time.Time `json:"expires_at"`
	Irreversible bool      `json:"irreversible"`
}

Filter is metadata for a filter of users.

type History

type History struct {
	Day      string `json:"day"`
	Uses     string `json:"uses"`
	Accounts string `json:"accounts"`
}

History hold information for history.

type ID

type ID string

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) error

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,omitempty"`
	Thumbnail      string            `json:"thumbnail,omitempty"`
	URLs           map[string]string `json:"urls,omitempty"`
	Stats          *InstanceStats    `json:"stats,omitempty"`
	Languages      []string          `json:"languages"`
	ContactAccount *Account          `json:"contact_account"`
	Configuration  *InstanceConfig   `json:"configuration"`
}

Instance holds information for a mastodon instance.

func (*Instance) GetConfig

func (c *Instance) GetConfig() *InstanceConfig

GetConfig returns InstanceConfig.

type InstanceConfig

type InstanceConfig struct {
	Accounts         *InstanceConfigMap     `json:"accounts"`
	Statuses         *InstanceConfigMap     `json:"statuses"`
	MediaAttachments map[string]interface{} `json:"media_attachments"`
	Polls            *InstanceConfigMap     `json:"polls"`
}

InstanceConfig holds configuration accessible for clients.

type InstanceConfigMap

type InstanceConfigMap map[string]int

type InstanceStats

type InstanceStats struct {
	UserCount   int64 `json:"user_count"`
	StatusCount int64 `json:"status_count"`
	DomainCount int64 `json:"domain_count"`
}

InstanceStats holds information for mastodon instance stats.

type List

type List struct {
	ID    ID     `json:"id"`
	Title string `json:"title"`
}

List is metadata for a list of users.

type Media

type Media struct {
	File        io.Reader
	Thumbnail   io.Reader
	Description string
	Focus       string
}

Media is struct to hold media.

type Mention

type Mention struct {
	URL      string `json:"url"`
	Username string `json:"username"`
	Acct     string `json:"acct"`
	ID       ID     `json:"id"`
}

Mention hold information for mention.

type Notification

type Notification struct {
	ID        ID        `json:"id"`
	Type      string    `json:"type"`
	CreatedAt time.Time `json:"created_at"`
	Account   Account   `json:"account"`
	Status    *Status   `json:"status"`
}

Notification holds information for a mastodon notification.

type NotificationEvent

type NotificationEvent struct {
	Notification *Notification `json:"notification"`
}

NotificationEvent is a struct for passing notification event to app.

type Pagination

type Pagination struct {
	MaxID   ID
	SinceID ID
	MinID   ID
	Limit   int64
}

Pagination is a struct for specifying the get range.

Example
c := mastodon.NewClient(&mastodon.Config{
	Server:       "https://mstdn.jp",
	ClientID:     "client-id",
	ClientSecret: "client-secret",
})
var followers []*mastodon.Account
var pg mastodon.Pagination
for {
	fs, err := c.GetAccountFollowers(context.Background(), "1", &pg)
	if err != nil {
		log.Fatal(err)
	}
	followers = append(followers, fs...)
	if pg.MaxID == "" {
		break
	}
	time.Sleep(10 * time.Second)
}
for _, f := range followers {
	fmt.Println(f.Acct)
}
Output:

type Poll

type Poll struct {
	ID          ID           `json:"id"`
	ExpiresAt   time.Time    `json:"expires_at"`
	Expired     bool         `json:"expired"`
	Multiple    bool         `json:"multiple"`
	VotesCount  int64        `json:"votes_count"`
	VotersCount int64        `json:"voters_count"`
	Options     []PollOption `json:"options"`
	Voted       bool         `json:"voted"`
	OwnVotes    []int        `json:"own_votes"`
	Emojis      []Emoji      `json:"emojis"`
}

Poll holds information for mastodon polls.

type PollOption

type PollOption struct {
	Title      string `json:"title"`
	VotesCount int64  `json:"votes_count"`
}

Poll holds information for a mastodon poll option.

type Profile

type Profile struct {
	// If it is nil it will not be updated.
	// If it is empty, update it with empty.
	DisplayName *string
	Note        *string
	Locked      *bool
	Fields      *[]Field
	Source      *AccountSource

	// Set the base64 encoded character string of the image.
	Avatar string
	Header string
}

Profile is a struct for updating profiles.

type PushAlerts

type PushAlerts struct {
	Follow    *Sbool `json:"follow"`
	Favourite *Sbool `json:"favourite"`
	Reblog    *Sbool `json:"reblog"`
	Mention   *Sbool `json:"mention"`
}

type PushSubscription

type PushSubscription struct {
	ID        ID          `json:"id"`
	Endpoint  string      `json:"endpoint"`
	ServerKey string      `json:"server_key"`
	Alerts    *PushAlerts `json:"alerts"`
}

type Relationship

type Relationship struct {
	ID                  ID   `json:"id"`
	Following           bool `json:"following"`
	FollowedBy          bool `json:"followed_by"`
	Blocking            bool `json:"blocking"`
	Muting              bool `json:"muting"`
	MutingNotifications bool `json:"muting_notifications"`
	Requested           bool `json:"requested"`
	DomainBlocking      bool `json:"domain_blocking"`
	ShowingReblogs      bool `json:"showing_reblogs"`
	Endorsed            bool `json:"endorsed"`
}

Relationship holds information for relationship to the account.

type Report

type Report struct {
	ID          int64 `json:"id"`
	ActionTaken bool  `json:"action_taken"`
}

Report holds information for a mastodon report.

type Results

type Results struct {
	Accounts []*Account `json:"accounts"`
	Statuses []*Status  `json:"statuses"`
	Hashtags []*Tag     `json:"hashtags"`
}

Results hold information for search result.

type Sbool

type Sbool bool

func (*Sbool) UnmarshalJSON

func (s *Sbool) UnmarshalJSON(data []byte) error

type Source

type Source struct {
	ID          ID     `json:"id"`
	Text        string `json:"text"`
	SpoilerText string `json:"spoiler_text"`
}

Source holds source properties so a status can be edited.

type Status

type Status struct {
	ID                 ID           `json:"id"`
	URI                string       `json:"uri"`
	URL                string       `json:"url"`
	Account            Account      `json:"account"`
	InReplyToID        interface{}  `json:"in_reply_to_id"`
	InReplyToAccountID interface{}  `json:"in_reply_to_account_id"`
	Reblog             *Status      `json:"reblog"`
	Content            string       `json:"content"`
	CreatedAt          time.Time    `json:"created_at"`
	EditedAt           time.Time    `json:"edited_at"`
	Emojis             []Emoji      `json:"emojis"`
	RepliesCount       int64        `json:"replies_count"`
	ReblogsCount       int64        `json:"reblogs_count"`
	FavouritesCount    int64        `json:"favourites_count"`
	Reblogged          interface{}  `json:"reblogged"`
	Favourited         interface{}  `json:"favourited"`
	Bookmarked         interface{}  `json:"bookmarked"`
	Muted              interface{}  `json:"muted"`
	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"`
	Card               *Card        `json:"card"`
	Poll               *Poll        `json:"poll"`
	Application        Application  `json:"application"`
	Language           string       `json:"language"`
	Pinned             interface{}  `json:"pinned"`
}

Status is struct to hold status.

type StatusHistory

type StatusHistory struct {
	Content          string       `json:"content"`
	SpoilerText      string       `json:"spoiler_text"`
	Account          Account      `json:"account"`
	Sensitive        bool         `json:"sensitive"`
	CreatedAt        time.Time    `json:"created_at"`
	Emojis           []Emoji      `json:"emojis"`
	MediaAttachments []Attachment `json:"media_attachments"`
}

StatusHistory is a struct to hold status history data.

type Stream

type Stream struct {
	Event   string      `json:"event"`
	Payload interface{} `json:"payload"`
}

Stream is a struct of data that flows in streaming.

type Tag

type Tag struct {
	Name    string    `json:"name"`
	URL     string    `json:"url"`
	History []History `json:"history"`
}

Tag hold information for tag.

type Toot

type Toot struct {
	Status      string     `json:"status"`
	InReplyToID ID         `json:"in_reply_to_id"`
	MediaIDs    []ID       `json:"media_ids"`
	Sensitive   bool       `json:"sensitive"`
	SpoilerText string     `json:"spoiler_text"`
	Visibility  string     `json:"visibility"`
	Language    string     `json:"language"`
	ScheduledAt *time.Time `json:"scheduled_at,omitempty"`
	Poll        *TootPoll  `json:"poll"`
}

Toot is a struct to post status.

type TootPoll

type TootPoll struct {
	Options          []string `json:"options"`
	ExpiresInSeconds int64    `json:"expires_in"`
	Multiple         bool     `json:"multiple"`
	HideTotals       bool     `json:"hide_totals"`
}

TootPoll holds information for creating a poll in Toot.

type Unixtime

type Unixtime time.Time

func (*Unixtime) UnmarshalJSON

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

type UpdateEditEvent

type UpdateEditEvent struct {
	Status *Status `json:"status"`
}

UpdateEditEvent is a struct for passing status edit event to app.

type UpdateEvent

type UpdateEvent struct {
	Status *Status `json:"status"`
}

UpdateEvent is a struct for passing status event to app.

type WSClient

type WSClient struct {
	websocket.Dialer
	// contains filtered or unexported fields
}

WSClient is a WebSocket client.

func (*WSClient) StreamingWSHashtag

func (c *WSClient) StreamingWSHashtag(ctx context.Context, tag string, isLocal bool) (chan Event, error)

StreamingWSHashtag return channel to read events on tagged timeline using WebSocket.

func (*WSClient) StreamingWSList

func (c *WSClient) StreamingWSList(ctx context.Context, id ID) (chan Event, error)

StreamingWSList return channel to read events on a list using WebSocket.

func (*WSClient) StreamingWSPublic

func (c *WSClient) StreamingWSPublic(ctx context.Context, isLocal bool) (chan Event, error)

StreamingWSPublic return channel to read events on public using WebSocket.

func (*WSClient) StreamingWSUser

func (c *WSClient) StreamingWSUser(ctx context.Context) (chan Event, error)

StreamingWSUser return channel to read events on home using WebSocket.

type WeeklyActivity

type WeeklyActivity struct {
	Week          Unixtime `json:"week"`
	Statuses      int64    `json:"statuses,string"`
	Logins        int64    `json:"logins,string"`
	Registrations int64    `json:"registrations,string"`
}

WeeklyActivity holds information for mastodon weekly activity.

Jump to

Keyboard shortcuts

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