mastodon

package module
v0.0.0-...-8ddbe98 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2018 License: GPL-3.0 Imports: 10 Imported by: 0

README

mastodon-go

A Go library for Mastodon.

Go Report Card GoDoc

$ go get github.com/BakeRolls/mastodon-go

See example/main.go for an example on how to use this library.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	Base        string
	Prefix      string
	AccessToken string
}

API contains necessary informations to work with Mastodons API.

func (API) Delete

func (api API) Delete(endpoint string, values url.Values, dest interface{}) error

Delete request

func (API) Do

func (api API) Do(method string, endpoint string, values url.Values) (io.ReadCloser, error)

Do executes an API request. The method is a HTTP method, e.g. GET or POST.

func (API) Get

func (api API) Get(endpoint string, values url.Values, dest interface{}) error

Get request

func (API) Post

func (api API) Post(endpoint string, values url.Values, dest interface{}) error

Post request

type Account

type Account struct {
	ID          string `json:"id"`              // The ID of the account
	Username    string `json:"username"`        // The username of the account
	Acct        string `json:"acct"`            // Equals username for local users, includes @domain for remote ones
	DisplayName string `json:"display_name"`    // The account's display name
	Note        string `json:"note"`            // Biography of user
	URL         string `json:"url"`             // URL of the user's profile page (can be remote)
	Avatar      string `json:"avatar"`          // URL to the avatar image
	Header      string `json:"header"`          // URL to the header image
	Locked      bool   `json:"locked"`          // Boolean for when the account cannot be followed without waiting for approval first
	CreatedAt   string `json:"created_at"`      // The time the account was created
	Followers   int    `json:"followers_count"` // The number of followers for the account
	Following   int    `json:"following_count"` // The number of accounts the given account is following
	Statuses    int    `json:"statuses_count"`  // The number of statuses the account has made
}

Account holds informations about an account.

type Accounts

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

Accounts implements methods under /accounts.

func (Accounts) Block

func (accounts Accounts) Block(id string) (Account, error)

Block an account

func (Accounts) Follow

func (accounts Accounts) Follow(id string) (Account, error)

Follow an user.

func (Accounts) Followers

func (accounts Accounts) Followers(id string) ([]Account, error)

Followers returns an slice of following accounts.

func (Accounts) Following

func (accounts Accounts) Following(id string) ([]Account, error)

Following returns an slice of followed accounts.

func (Accounts) Get

func (accounts Accounts) Get(id string) (Account, error)

Get returns an account.

func (Accounts) Mute

func (accounts Accounts) Mute(id string) (Account, error)

Mute an account.

func (Accounts) Relationships

func (accounts Accounts) Relationships(ids ...int) ([]Relationship, error)

Relationships returns an slice of Relationships of the current user to a list of given accounts.

func (Accounts) Search

func (accounts Accounts) Search(q string, limit int) ([]Account, error)

Search returns an slice of matching Accounts. Will lookup an account remotely if the search term is in the username@domain format and not yet in the database.

func (Accounts) Statuses

func (accounts Accounts) Statuses(id string, params url.Values) ([]Status, error)

Statuses returns an slice of statuses. Accepted params are: only_media: Only return statuses that have media attachments exclude_replies: Skip statuses that reply to other statuses

func (Accounts) Unblock

func (accounts Accounts) Unblock(id string) (Account, error)

Unblock an account.

func (Accounts) Unfollow

func (accounts Accounts) Unfollow(id string) (Account, error)

Unfollow an account

func (Accounts) Unmute

func (accounts Accounts) Unmute(id string) (Account, error)

Unmute an user.

func (Accounts) VerifyCredentials

func (accounts Accounts) VerifyCredentials() (Account, error)

VerifyCredentials returns the authenticated user's account.

type App

type App struct {
	Token          *oauth2.Token
	Config         *oauth2.Config
	API            *API
	Accounts       *Accounts
	Blocks         *Blocks
	Favourites     *Favourites
	FollowRequests *FollowRequests
	Follows        *Follows
	Instances      *Instances
	Mutes          *Mutes
	Notifications  *Notifications
	Reports        *Reports
	Search         *Search
	Statuses       *Statuses
	Timelines      *Timelines
}

App holds the AccessToken and the OAuth2 config.

func NewApp

func NewApp(base, name, uris string, scopes []string, website string) (*App, error)

NewApp tries to register a new app.

func (App) AuthCodeURL

func (app App) AuthCodeURL() string

AuthCodeURL builds a URL to obtain an AccessCode.

func (App) Exchange

func (app App) Exchange(code string) (string, error)

Exchange swaps an AccessCode with an AccessToken which can be used to authenticate an user.

func (App) SetToken

func (app App) SetToken(token string)

SetToken saves the AccessToken in struct.

type Application

type Application struct {
	ID           string `json:"id"`
	Name         string `json:"name"`    // Name of the app
	Website      string `json:"website"` // Homepage URL of the app
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
}

Application holds informations about an application.

type Attachment

type Attachment struct {
	ID         string `json:"id"`          // ID of the attachment
	Type       string `json:"type"`        // One of: "image", "video", "gifv"
	URL        string `json:"url"`         // URL of the locally hosted version of the image
	RemoteURL  string `json:"remote_url"`  // For remote images, the remote URL of the original image
	PreviewURL string `json:"preview_url"` // URL of the preview image
	TextURL    string `json:"text_url"`    // Shorter URL for the image, for insertion into text (only present on local images)
}

Attachment holds informations about an attachment.

type Blocks

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

Blocks implements methods under /blocks.

func (Blocks) Get

func (blocks Blocks) Get() ([]Account, error)

Get returns an slice of accounts blocked by the authenticated user.

type Card

type Card struct {
	URL         string `json:"url"`         // The url associated with the card
	Title       string `json:"title"`       // The title of the card
	Description string `json:"description"` // The card description
	Image       string `json:"image"`       // The image associated with the card, if any
}

Card holds informations about a card.

type Context

type Context struct {
	Ancestors   []Status `json:"ancestors"`   // The ancestors of the status in the conversation, as a list of Statuses
	Descendants []Status `json:"descendants"` // The descendants of the status in the conversation, as a list of Statuses
}

Context holds informations about a statuses context.

type Error

type Error struct {
	Error string `json:"error"` // A textual description of the error
}

Error holds informations about an error.

type Favourites

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

Favourites implements methods under /favourites.

func (Favourites) Get

func (favourites Favourites) Get() ([]Status, error)

Get returns an slice of statuses favourited by the authenticated user.

type FollowRequests

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

FollowRequests implements methods under /follow_requests.

func (FollowRequests) Authorize

func (followRequests FollowRequests) Authorize(id string) error

Authorize authorizes a follow request.

func (FollowRequests) Get

func (followRequests FollowRequests) Get() ([]Account, error)

Get returns an slice of accounts which have requested to follow the authenticated user.

func (FollowRequests) Reject

func (followRequests FollowRequests) Reject(id string) error

Reject rejects a follow request.

func (FollowRequests) RejectFalseIcons

func (followRequests FollowRequests) RejectFalseIcons(id string) error

RejectFalseIcons rejects a follow request.

type Follows

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

Follows implements methods under /follows.

func (Follows) Follow

func (follows Follows) Follow(uri string) (Account, error)

Follow a remote user.

type Instance

type Instance struct {
	URI         string `json:"uri"`         // URI of the current instance
	Title       string `json:"title"`       // The instance's title
	Description string `json:"description"` // A description for the instance
	Email       string `json:"email"`       // An email address which can be used to contact the instance administrator
}

Instance holds informations about an instance.

type Instances

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

Instances implements methods under /instance.

func (Instances) Get

func (instances Instances) Get() (Instance, error)

Get returns the current instance. Does not require authentication.

type Mention

type Mention struct {
	ID       string `json:"id"`       // Account ID
	URL      string `json:"url"`      // URL of user's profile (can be remote)
	Username string `json:"username"` // The username of the account
	Acct     string `json:"acct"`     // Equals username for local users, includes @domain for remote ones
}

Mention holds informations about a mention.

type Mutes

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

Mutes implements methods under /mutes.

func (Mutes) Get

func (mutes Mutes) Get() ([]Account, error)

Get returns an attachment that can be used when creating a status.

type Notification

type Notification struct {
	ID        string   `json:"id"`         // The notification ID
	Type      string   `json:"type"`       // One of: "mention", "reblog", "favourite", "follow"
	CreatedAt string   `json:"created_at"` // The time the notification was created
	Account   *Account `json:"account"`    // The Account sending the notification to the user
	Status    *Status  `json:"status"`     // The Status associated with the notification, if applicable
}

Notification holds informations about a notification.

type Notifications

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

Notifications implements methods under /notifications.

func (Notifications) Clear

func (notifications Notifications) Clear() error

Clear deletes all notifications from the Mastodon server for the authenticated user.

func (Notifications) Get

func (notifications Notifications) Get() ([]Notification, error)

Get returns a list of notifications for the authenticated user.

func (Notifications) GetSingle

func (notifications Notifications) GetSingle(id string) (Notification, error)

GetSingle returns the notification.

type Relationship

type Relationship struct {
	Following  bool `json:"following"`   // Whether the user is currently following the account
	FollowedBy bool `json:"followed_by"` // Whether the user is currently being followed by the account
	Blocking   bool `json:"blocking"`    // Whether the user is currently blocking the account
	Muting     bool `json:"muting"`      // Whether the user is currently muting the account
	Requested  bool `json:"requested"`   // Whether the user has requested to follow the account
}

Relationship holds informations about a relationship.

type Report

type Report struct {
	ID          string `json:"id"`           // The ID of the report
	ActionTaken string `json:"action_taken"` // The action taken in response to the report
}

Report holds informations about a report.

type Reports

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

Reports implements methods under /reports.

func (Reports) Get

func (reports Reports) Get() ([]Report, error)

Get returns a list of reports made by the authenticated user.

func (Reports) Report

func (reports Reports) Report(account, status string, comment string) (Report, error)

Report reports a user and returns the finished report.

type Results

type Results struct {
	Accounts []Account `json:"accounts"` // An array of matched Accounts
	Statuses []Status  `json:"statuses"` // An array of matchhed Statuses
	Hashtags []string  `json:"hashtags"` // An array of matched hashtags, as strings
}

Results holds informations about results.

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

Search implements methods under /search.

func (Search) Search

func (search Search) Search(q string, resolve bool) (Results, error)

Search returns results. If q is a URL, Mastodon will attempt to fetch the provided account or status. Otherwise, it will do a local account and hashtag search.

type Status

type Status struct {
	ID                 string       `json:"id"`                     // The ID of the status
	URI                string       `json:"uri"`                    // A Fediverse-unique resource ID
	URL                string       `json:"url"`                    // URL to the status page (can be remote)
	Account            *Account     `json:"account"`                // The Account which posted the status
	InReplyToID        string       `json:"in_reply_to_id"`         // null or the ID of the status it replies to
	InReplyToAccountID string       `json:"in_reply_to_account_id"` // null or the ID of the account it replies to
	Reblog             *Status      `json:"reblog"`                 // null or the reblogged Status
	Content            string       `json:"content"`                // Body of the status; this will contain HTML (remote HTML already sanitized)
	CreatedAt          string       `json:"created_at"`             // The time the status was created
	Reblogs            int          `json:"reblogs_count"`          // The number of reblogs for the status
	Favourites         int          `json:"favourites_count"`       // The number of favourites for the status
	Reblogged          bool         `json:"reblogged"`              // Whether the authenticated user has reblogged the status
	Favourited         bool         `json:"favourited"`             // Whether the authenticated user has favourited the status
	Sensitive          bool         `json:"sensitive"`              // Whether media attachments should be hidden by default
	SpoilerText        string       `json:"spoiler_text"`           // If not empty, warning text that should be displayed before the actual content
	Visibility         string       `json:"visibility"`             // One of: public, unlisted, private, direct
	MediaAttachments   []Attachment `json:"media_attachments"`      // An array of Attachments
	Mentions           []Mention    `json:"mentions"`               // An array of Mentions
	Tags               []Tag        `json:"tags"`                   // An array of Tags
	Application        *Application `json:"application"`            // Application from which the status was posted
}

Status holds informations about a status.

type Statuses

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

Statuses implements methods under /statuses.

func (Statuses) Card

func (statuses Statuses) Card(id string) (Card, error)

Card returns a card.

func (Statuses) Context

func (statuses Statuses) Context(id string) (Context, error)

Context returns a context.

func (Statuses) Delete

func (statuses Statuses) Delete(id string) error

Delete deletes a status.

func (Statuses) Favourite

func (statuses Statuses) Favourite(id string) (Status, error)

Favourite favourites a status.

func (Statuses) Favourites

func (statuses Statuses) Favourites(id string) ([]Account, error)

Favourites returns an array of accounts.

func (Statuses) Get

func (statuses Statuses) Get(id string) (Status, error)

Get returns a status.

func (Statuses) Reblog

func (statuses Statuses) Reblog(id string) (Status, error)

Reblog rebloggs a status.

func (Statuses) Reblogs

func (statuses Statuses) Reblogs(id string) ([]Account, error)

Reblogs returns an array of accounts.

func (Statuses) Unfavourite

func (statuses Statuses) Unfavourite(id string) (Status, error)

Unfavourite deletes a favourited status.

func (Statuses) Unreblog

func (statuses Statuses) Unreblog(id string) (Status, error)

Unreblog deletes a reblogged status.

func (Statuses) Update

func (statuses Statuses) Update(status string, v url.Values) (Status, error)

Update posts and returns a new status. Accepted params are: in_reply_to_id: local ID of the status you want to reply to media_ids: array of media IDs to attach to the status (maximum 4) sensitive: set this to mark the media of the status as NSFW spoiler_text: text to be shown as a warning before the actual content visibility: either "direct", "private", "unlisted" or "public"

type Tag

type Tag struct {
	Name string `json:"name"` // The hashtag, not including the preceding #
	URL  string `json:"url"`  // The URL of the hashtag
}

Tag holds informations about a tag.

type Timelines

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

Timelines implements methods under /timelines.

func (Timelines) Hashtag

func (timelines Timelines) Hashtag(hashtag string, v url.Values) ([]Status, error)

Hashtag returns an array of statuses, most recent ones first.

func (Timelines) Home

func (timelines Timelines) Home() ([]Status, error)

Home returns an array of statuses, most recent ones first.

func (Timelines) Public

func (timelines Timelines) Public(v url.Values) ([]Status, error)

Public returns an array of statuses, most recent ones first.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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