aboutsummaryrefslogtreecommitdiff
path: root/mastodon/instance.go
blob: 32174506ce152c1405a815e86ccb38e28eb9b628 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package mastodon

import (
	"context"
	"net/http"
)

// Instance hold information for mastodon 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:"account"`
}

// InstanceStats hold information for mastodon instance stats.
type InstanceStats struct {
	UserCount   int64 `json:"user_count"`
	StatusCount int64 `json:"status_count"`
	DomainCount int64 `json:"domain_count"`
}

// GetInstance return Instance.
func (c *Client) GetInstance(ctx context.Context) (*Instance, error) {
	var instance Instance
	err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance", nil, &instance, nil)
	if err != nil {
		return nil, err
	}
	return &instance, nil
}

// WeeklyActivity hold information for mastodon weekly activity.
type WeeklyActivity struct {
	Week          Unixtime `json:"week"`
	Statuses      int64    `json:"statuses,string"`
	Logins        int64    `json:"logins,string"`
	Registrations int64    `json:"registrations,string"`
}

// GetInstanceActivity return instance activity.
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
}

// GetInstancePeers return instance peers.
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
}