Documentation
¶
Overview ¶
Package mastodon provides functions and structs for accessing the mastodon API.
Index ¶
- func Base64Encode(file *os.File) (string, error)
- func Base64EncodeFileName(filename string) (string, error)
- func String(v string) *string
- type Account
- type AppConfig
- type Application
- type Attachment
- type Card
- type Client
- func (c *Client) AccountBlock(ctx context.Context, id ID) (*Relationship, error)
- func (c *Client) AccountFollow(ctx context.Context, id ID) (*Relationship, error)
- func (c *Client) AccountMute(ctx context.Context, id ID) (*Relationship, error)
- func (c *Client) AccountUnblock(ctx context.Context, id ID) (*Relationship, error)
- func (c *Client) AccountUnfollow(ctx context.Context, id ID) (*Relationship, error)
- func (c *Client) AccountUnmute(ctx context.Context, id ID) (*Relationship, error)
- func (c *Client) AccountUpdate(ctx context.Context, profile *Profile) (*Account, error)
- func (c *Client) AccountsSearch(ctx context.Context, q string, limit int64) ([]*Account, error)
- func (c *Client) Authenticate(ctx context.Context, username, password string) error
- func (c *Client) ClearNotifications(ctx context.Context) error
- func (c *Client) DeleteStatus(ctx context.Context, id int64) error
- func (c *Client) Favourite(ctx context.Context, id int64) (*Status, error)
- func (c *Client) FollowRemoteUser(ctx context.Context, uri string) (*Account, error)
- func (c *Client) FollowRequestAuthorize(ctx context.Context, id ID) error
- func (c *Client) FollowRequestReject(ctx context.Context, id ID) error
- func (c *Client) GetAccount(ctx context.Context, id ID) (*Account, error)
- func (c *Client) GetAccountCurrentUser(ctx context.Context) (*Account, error)
- func (c *Client) GetAccountFollowers(ctx context.Context, id ID, pg *Pagination) ([]*Account, error)
- func (c *Client) GetAccountFollowing(ctx context.Context, id ID, pg *Pagination) ([]*Account, error)
- func (c *Client) GetAccountRelationships(ctx context.Context, ids []string) ([]*Relationship, error)
- func (c *Client) GetAccountStatuses(ctx context.Context, id ID, pg *Pagination) ([]*Status, error)
- func (c *Client) GetBlocks(ctx context.Context, pg *Pagination) ([]*Account, error)
- func (c *Client) GetFavouritedBy(ctx context.Context, id int64, pg *Pagination) ([]*Account, error)
- func (c *Client) GetFavourites(ctx context.Context, pg *Pagination) ([]*Status, error)
- func (c *Client) GetFollowRequests(ctx context.Context, pg *Pagination) ([]*Account, error)
- func (c *Client) GetInstance(ctx context.Context) (*Instance, error)
- func (c *Client) GetMutes(ctx context.Context, pg *Pagination) ([]*Account, error)
- func (c *Client) GetNotification(ctx context.Context, id int64) (*Notification, error)
- func (c *Client) GetNotifications(ctx context.Context, pg *Pagination) ([]*Notification, error)
- func (c *Client) GetRebloggedBy(ctx context.Context, id int64, pg *Pagination) ([]*Account, error)
- func (c *Client) GetReports(ctx context.Context) ([]*Report, error)
- func (c *Client) GetStatus(ctx context.Context, id int64) (*Status, error)
- func (c *Client) GetStatusCard(ctx context.Context, id int64) (*Card, error)
- func (c *Client) GetStatusContext(ctx context.Context, id int64) (*Context, error)
- func (c *Client) GetTimelineHashtag(ctx context.Context, tag string, isLocal bool, pg *Pagination) ([]*Status, error)
- func (c *Client) GetTimelineHome(ctx context.Context, pg *Pagination) ([]*Status, error)
- func (c *Client) GetTimelineMedia(ctx context.Context, isLocal bool, pg *Pagination) ([]*Status, error)
- func (c *Client) GetTimelinePublic(ctx context.Context, isLocal bool, pg *Pagination) ([]*Status, error)
- func (c *Client) NewWSClient() *WSClient
- func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error)
- func (c *Client) Reblog(ctx context.Context, id int64) (*Status, error)
- func (c *Client) Report(ctx context.Context, accountID int64, ids []int64, comment string) (*Report, error)
- func (c *Client) Search(ctx context.Context, q string, resolve bool) (*Results, error)
- func (c *Client) StreamingHashtag(ctx context.Context, tag string, isLocal bool) (chan Event, error)
- func (c *Client) StreamingPublic(ctx context.Context, isLocal bool) (chan Event, error)
- func (c *Client) StreamingUser(ctx context.Context) (chan Event, error)
- func (c *Client) Unfavourite(ctx context.Context, id int64) (*Status, error)
- func (c *Client) Unreblog(ctx context.Context, id int64) (*Status, error)
- func (c *Client) UploadMedia(ctx context.Context, file string) (*Attachment, error)
- type Config
- type Context
- type DeleteEvent
- type ErrorEvent
- type Event
- type ID
- type Instance
- type Mention
- type Notification
- type NotificationEvent
- type Pagination
- type Profile
- type Relationship
- type Report
- type Results
- type Status
- type Stream
- type Tag
- type Toot
- type UpdateEvent
- type WSClient
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Base64Encode ¶
Base64Encode returns the base64 data URI format string of the file.
func Base64EncodeFileName ¶
Base64EncodeFileName returns the base64 data URI format string of the file with the file name.
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"`
}
Account hold information for mastodon account.
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 the following items: "read", "write" and "follow".
Scopes string
// Optional.
Website string
}
AppConfig is a setting for registering applications.
type Application ¶
type Application struct {
ID int64 `json:"id"`
RedirectURI string `json:"redirect_uri"`
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
}
Application is 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)
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"`
}
Attachment hold information for attachment.
type Card ¶
type Card struct {
URL string `json:"url"`
Title string `json:"title"`
Description string `json:"description"`
Image string `json:"image"`
}
Card hold information for mastodon card.
type Client ¶
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])
}
func (*Client) AccountBlock ¶
AccountBlock block the account.
func (*Client) AccountFollow ¶
AccountFollow follow the account.
func (*Client) AccountMute ¶
AccountMute mute the account.
func (*Client) AccountUnblock ¶
AccountUnblock unblock the account.
func (*Client) AccountUnfollow ¶
AccountUnfollow unfollow the account.
func (*Client) AccountUnmute ¶
AccountUnmute unmute the account.
func (*Client) AccountUpdate ¶
AccountUpdate updates the information of the current user.
func (*Client) AccountsSearch ¶
AccountsSearch search accounts by query.
func (*Client) Authenticate ¶
Authenticate get access-token to the API.
func (*Client) ClearNotifications ¶
ClearNotifications clear notifications.
func (*Client) DeleteStatus ¶
DeleteStatus delete the toot.
func (*Client) Favourite ¶
Favourite is favourite the toot of id and return status of the favourite toot.
func (*Client) FollowRemoteUser ¶
FollowRemoteUser send follow-request.
func (*Client) FollowRequestAuthorize ¶
FollowRequestAuthorize is authorize the follow request of user with id.
func (*Client) FollowRequestReject ¶
FollowRequestReject is rejects the follow request of user with id.
func (*Client) GetAccount ¶
GetAccount return Account.
func (*Client) GetAccountCurrentUser ¶
GetAccountCurrentUser return Account of current user.
func (*Client) GetAccountFollowers ¶
func (c *Client) GetAccountFollowers(ctx context.Context, id ID, pg *Pagination) ([]*Account, error)
GetAccountFollowers return followers list.
func (*Client) GetAccountFollowing ¶
func (c *Client) GetAccountFollowing(ctx context.Context, id ID, pg *Pagination) ([]*Account, error)
GetAccountFollowing return following list.
func (*Client) GetAccountRelationships ¶
func (c *Client) GetAccountRelationships(ctx context.Context, ids []string) ([]*Relationship, error)
GetAccountRelationships return relationship for the account.
func (*Client) GetAccountStatuses ¶
GetAccountStatuses return statuses by specified accuont.
func (*Client) GetFavouritedBy ¶
GetFavouritedBy returns the account list of the user who liked the toot of id.
func (*Client) GetFavourites ¶
GetFavourites return the favorite list of the current user.
func (*Client) GetFollowRequests ¶
GetFollowRequests return follow-requests.
func (*Client) GetInstance ¶
GetInstance return Instance.
func (*Client) GetNotification ¶
GetNotification return notification.
func (*Client) GetNotifications ¶
func (c *Client) GetNotifications(ctx context.Context, pg *Pagination) ([]*Notification, error)
GetNotifications return notifications.
func (*Client) GetRebloggedBy ¶
GetRebloggedBy returns the account list of the user who reblogged the toot of id.
func (*Client) GetReports ¶
GetReports return report of the current user.
func (*Client) GetStatusCard ¶
GetStatusCard return status specified by id.
func (*Client) GetStatusContext ¶
GetStatusContext return status specified by id.
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 ¶
GetTimelineHome return statuses from home 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) NewWSClient ¶
NewWSClient return WebSocket client.
func (*Client) PostStatus ¶
PostStatus post the toot.
func (*Client) Report ¶
func (c *Client) Report(ctx context.Context, accountID int64, ids []int64, comment string) (*Report, error)
Report reports the report
func (*Client) StreamingHashtag ¶
func (c *Client) StreamingHashtag(ctx context.Context, tag string, isLocal bool) (chan Event, error)
StreamingHashtag return channel to read events on tagged timeline.
func (*Client) StreamingPublic ¶
StreamingPublic return channel to read events on public.
func (*Client) StreamingUser ¶
StreamingUser return channel to read events on home.
func (*Client) Unfavourite ¶
Unfavourite is unfavourite the toot of id and return status of the unfavourite toot.
func (*Client) Unreblog ¶
Unreblog is unreblog the toot of id and return status of the original toot.
func (*Client) UploadMedia ¶
UploadMedia upload a media attachment.
type Context ¶
type Context struct {
Ancestors []*Status `json:"ancestors"`
Descendants []*Status `json:"descendants"`
}
Context hold information for mastodon context.
type DeleteEvent ¶
type DeleteEvent struct{ ID int64 }
DeleteEvent is struct for passing deletion event to app.
type ErrorEvent ¶
type ErrorEvent struct {
// contains filtered or unexported fields
}
ErrorEvent is 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 interface passing events to app.
type Instance ¶
type Instance struct {
URI string `json:"uri"`
Title string `json:"title"`
Description string `json:"description"`
EMail string `json:"email"`
}
Instance hold information for mastodon instance.
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 int64 `json:"id"`
Type string `json:"type"`
CreatedAt time.Time `json:"created_at"`
Account Account `json:"account"`
Status *Status `json:"status"`
}
Notification hold information for mastodon notification.
type NotificationEvent ¶
type NotificationEvent struct {
Notification *Notification `json:"notification"`
}
NotificationEvent is struct for passing notification event to app.
type Pagination ¶
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)
}
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
// Set the base64 encoded character string of the image.
Avatar string
Header string
}
Profile is a struct for updating profiles.
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"`
Requested bool `json:"requested"`
}
Relationship hold information for relation-ship to the account.
type Status ¶
type Status struct {
ID ID `json:"id"`
CreatedAt time.Time `json:"created_at"`
InReplyToID interface{} `json:"in_reply_to_id"`
InReplyToAccountID interface{} `json:"in_reply_to_account_id"`
Sensitive bool `json:"sensitive"`
SpoilerText string `json:"spoiler_text"`
Visibility string `json:"visibility"`
Application Application `json:"application"`
Account Account `json:"account"`
MediaAttachments []Attachment `json:"media_attachments"`
Mentions []Mention `json:"mentions"`
Tags []Tag `json:"tags"`
URI string `json:"uri"`
Content string `json:"content"`
URL string `json:"url"`
ReblogsCount int64 `json:"reblogs_count"`
FavouritesCount int64 `json:"favourites_count"`
Reblog *Status `json:"reblog"`
Favourited interface{} `json:"favourited"`
Reblogged interface{} `json:"reblogged"`
}
Status is struct to hold status.
type Stream ¶
type Stream struct {
Event string `json:"event"`
Payload interface{} `json:"payload"`
}
Stream is a struct of data that flows in streaming.
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"`
}
Toot is struct to post status.
type UpdateEvent ¶
type UpdateEvent struct {
Status *Status `json:"status"`
}
UpdateEvent is struct for passing status event to app.
type WSClient ¶
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) StreamingWSPublic ¶
StreamingWSPublic return channel to read events on public using WebSocket.