2017-04-14 16:59:43 +02:00
|
|
|
package mastodon
|
|
|
|
|
2017-04-17 04:10:29 +02:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
)
|
2017-04-14 21:23:36 +02:00
|
|
|
|
2022-11-13 22:14:40 +01:00
|
|
|
// Instance holds information for a mastodon instance.
|
2017-04-14 16:59:43 +02:00
|
|
|
type Instance struct {
|
2018-11-24 06:46:49 +01:00
|
|
|
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"`
|
2019-09-30 09:54:15 +02:00
|
|
|
ContactAccount *Account `json:"contact_account"`
|
2022-12-18 14:44:28 +01:00
|
|
|
Configuration *InstanceConfig `json:"configuration"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type InstanceConfigMap map[string]int
|
|
|
|
|
|
|
|
// InstanceConfig holds configuration accessible for clients.
|
|
|
|
type InstanceConfig struct {
|
|
|
|
Accounts *InstanceConfigMap `json:"accounts"`
|
|
|
|
Statuses *InstanceConfigMap `json:"statuses"`
|
|
|
|
MediaAttachments map[string]interface{} `json:"media_attachments"`
|
|
|
|
Polls *InstanceConfigMap `json:"polls"`
|
2018-01-29 05:09:30 +01:00
|
|
|
}
|
|
|
|
|
2022-11-13 22:14:40 +01:00
|
|
|
// InstanceStats holds information for mastodon instance stats.
|
2018-01-29 05:09:30 +01:00
|
|
|
type InstanceStats struct {
|
|
|
|
UserCount int64 `json:"user_count"`
|
|
|
|
StatusCount int64 `json:"status_count"`
|
|
|
|
DomainCount int64 `json:"domain_count"`
|
2017-04-14 16:59:43 +02:00
|
|
|
}
|
|
|
|
|
2022-11-13 22:14:40 +01:00
|
|
|
// GetInstance returns Instance.
|
2017-04-17 04:10:29 +02:00
|
|
|
func (c *Client) GetInstance(ctx context.Context) (*Instance, error) {
|
2017-04-14 16:59:43 +02:00
|
|
|
var instance Instance
|
2017-04-18 10:08:48 +02:00
|
|
|
err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance", nil, &instance, nil)
|
2017-04-14 16:59:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &instance, nil
|
|
|
|
}
|
2018-01-29 04:29:39 +01:00
|
|
|
|
2022-12-18 14:44:28 +01:00
|
|
|
// GetConfig returns InstanceConfig.
|
|
|
|
func (c *Instance) GetConfig() *InstanceConfig {
|
|
|
|
return c.Configuration
|
|
|
|
}
|
|
|
|
|
2022-11-13 22:14:40 +01:00
|
|
|
// WeeklyActivity holds information for mastodon weekly activity.
|
2018-01-29 04:29:39 +01:00
|
|
|
type WeeklyActivity struct {
|
|
|
|
Week Unixtime `json:"week"`
|
|
|
|
Statuses int64 `json:"statuses,string"`
|
|
|
|
Logins int64 `json:"logins,string"`
|
|
|
|
Registrations int64 `json:"registrations,string"`
|
|
|
|
}
|
|
|
|
|
2022-11-13 22:14:40 +01:00
|
|
|
// GetInstanceActivity returns instance activity.
|
2018-01-29 04:29:39 +01:00
|
|
|
func (c *Client) GetInstanceActivity(ctx context.Context) ([]*WeeklyActivity, error) {
|
|
|
|
var activity []*WeeklyActivity
|
|
|
|
err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance/activity", nil, &activity, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return activity, nil
|
|
|
|
}
|
|
|
|
|
2022-11-13 22:14:40 +01:00
|
|
|
// GetInstancePeers returns instance peers.
|
2018-01-29 04:29:39 +01:00
|
|
|
func (c *Client) GetInstancePeers(ctx context.Context) ([]string, error) {
|
|
|
|
var peers []string
|
|
|
|
err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance/peers", nil, &peers, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return peers, nil
|
|
|
|
}
|