minor spelling fixes
This commit is contained in:
parent
114537dcc0
commit
309dce6ff3
40
accounts.go
40
accounts.go
|
@ -9,7 +9,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Account hold information for mastodon account.
|
// Account holds information for a mastodon account.
|
||||||
type Account struct {
|
type Account struct {
|
||||||
ID ID `json:"id"`
|
ID ID `json:"id"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
|
@ -60,7 +60,7 @@ func (c *Client) GetAccount(ctx context.Context, id ID) (*Account, error) {
|
||||||
return &account, nil
|
return &account, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAccountCurrentUser return Account of current user.
|
// GetAccountCurrentUser returns the Account of current user.
|
||||||
func (c *Client) GetAccountCurrentUser(ctx context.Context) (*Account, error) {
|
func (c *Client) GetAccountCurrentUser(ctx context.Context) (*Account, error) {
|
||||||
var account Account
|
var account Account
|
||||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/accounts/verify_credentials", nil, &account, nil)
|
err := c.doAPI(ctx, http.MethodGet, "/api/v1/accounts/verify_credentials", nil, &account, nil)
|
||||||
|
@ -129,7 +129,7 @@ func (c *Client) AccountUpdate(ctx context.Context, profile *Profile) (*Account,
|
||||||
return &account, nil
|
return &account, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAccountStatuses return statuses by specified accuont.
|
// GetAccountStatuses return statuses by specified account.
|
||||||
func (c *Client) GetAccountStatuses(ctx context.Context, id ID, pg *Pagination) ([]*Status, error) {
|
func (c *Client) GetAccountStatuses(ctx context.Context, id ID, pg *Pagination) ([]*Status, error) {
|
||||||
var statuses []*Status
|
var statuses []*Status
|
||||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/statuses", url.PathEscape(string(id))), nil, &statuses, pg)
|
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/statuses", url.PathEscape(string(id))), nil, &statuses, pg)
|
||||||
|
@ -139,7 +139,7 @@ func (c *Client) GetAccountStatuses(ctx context.Context, id ID, pg *Pagination)
|
||||||
return statuses, nil
|
return statuses, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAccountPinnedStatuses return statuses pinned by specified accuont.
|
// GetAccountPinnedStatuses returns statuses pinned by specified accuont.
|
||||||
func (c *Client) GetAccountPinnedStatuses(ctx context.Context, id ID) ([]*Status, error) {
|
func (c *Client) GetAccountPinnedStatuses(ctx context.Context, id ID) ([]*Status, error) {
|
||||||
var statuses []*Status
|
var statuses []*Status
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
|
@ -151,7 +151,7 @@ func (c *Client) GetAccountPinnedStatuses(ctx context.Context, id ID) ([]*Status
|
||||||
return statuses, nil
|
return statuses, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAccountFollowers return followers list.
|
// GetAccountFollowers returns followers list.
|
||||||
func (c *Client) GetAccountFollowers(ctx context.Context, id ID, pg *Pagination) ([]*Account, error) {
|
func (c *Client) GetAccountFollowers(ctx context.Context, id ID, pg *Pagination) ([]*Account, error) {
|
||||||
var accounts []*Account
|
var accounts []*Account
|
||||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/followers", url.PathEscape(string(id))), nil, &accounts, pg)
|
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/followers", url.PathEscape(string(id))), nil, &accounts, pg)
|
||||||
|
@ -161,7 +161,7 @@ func (c *Client) GetAccountFollowers(ctx context.Context, id ID, pg *Pagination)
|
||||||
return accounts, nil
|
return accounts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAccountFollowing return following list.
|
// GetAccountFollowing returns following list.
|
||||||
func (c *Client) GetAccountFollowing(ctx context.Context, id ID, pg *Pagination) ([]*Account, error) {
|
func (c *Client) GetAccountFollowing(ctx context.Context, id ID, pg *Pagination) ([]*Account, error) {
|
||||||
var accounts []*Account
|
var accounts []*Account
|
||||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/following", url.PathEscape(string(id))), nil, &accounts, pg)
|
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/following", url.PathEscape(string(id))), nil, &accounts, pg)
|
||||||
|
@ -171,7 +171,7 @@ func (c *Client) GetAccountFollowing(ctx context.Context, id ID, pg *Pagination)
|
||||||
return accounts, nil
|
return accounts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBlocks return block list.
|
// GetBlocks returns block list.
|
||||||
func (c *Client) GetBlocks(ctx context.Context, pg *Pagination) ([]*Account, error) {
|
func (c *Client) GetBlocks(ctx context.Context, pg *Pagination) ([]*Account, error) {
|
||||||
var accounts []*Account
|
var accounts []*Account
|
||||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/blocks", nil, &accounts, pg)
|
err := c.doAPI(ctx, http.MethodGet, "/api/v1/blocks", nil, &accounts, pg)
|
||||||
|
@ -181,7 +181,7 @@ func (c *Client) GetBlocks(ctx context.Context, pg *Pagination) ([]*Account, err
|
||||||
return accounts, nil
|
return accounts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Relationship hold information for relation-ship to the account.
|
// Relationship holds information for relationship to the account.
|
||||||
type Relationship struct {
|
type Relationship struct {
|
||||||
ID ID `json:"id"`
|
ID ID `json:"id"`
|
||||||
Following bool `json:"following"`
|
Following bool `json:"following"`
|
||||||
|
@ -195,7 +195,7 @@ type Relationship struct {
|
||||||
Endorsed bool `json:"endorsed"`
|
Endorsed bool `json:"endorsed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// AccountFollow follow the account.
|
// AccountFollow follows the account.
|
||||||
func (c *Client) AccountFollow(ctx context.Context, id ID) (*Relationship, error) {
|
func (c *Client) AccountFollow(ctx context.Context, id ID) (*Relationship, error) {
|
||||||
var relationship Relationship
|
var relationship Relationship
|
||||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/follow", url.PathEscape(string(id))), nil, &relationship, nil)
|
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/follow", url.PathEscape(string(id))), nil, &relationship, nil)
|
||||||
|
@ -205,7 +205,7 @@ func (c *Client) AccountFollow(ctx context.Context, id ID) (*Relationship, error
|
||||||
return &relationship, nil
|
return &relationship, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AccountUnfollow unfollow the account.
|
// AccountUnfollow unfollows the account.
|
||||||
func (c *Client) AccountUnfollow(ctx context.Context, id ID) (*Relationship, error) {
|
func (c *Client) AccountUnfollow(ctx context.Context, id ID) (*Relationship, error) {
|
||||||
var relationship Relationship
|
var relationship Relationship
|
||||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/unfollow", url.PathEscape(string(id))), nil, &relationship, nil)
|
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/unfollow", url.PathEscape(string(id))), nil, &relationship, nil)
|
||||||
|
@ -215,7 +215,7 @@ func (c *Client) AccountUnfollow(ctx context.Context, id ID) (*Relationship, err
|
||||||
return &relationship, nil
|
return &relationship, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AccountBlock block the account.
|
// AccountBlock blocks the account.
|
||||||
func (c *Client) AccountBlock(ctx context.Context, id ID) (*Relationship, error) {
|
func (c *Client) AccountBlock(ctx context.Context, id ID) (*Relationship, error) {
|
||||||
var relationship Relationship
|
var relationship Relationship
|
||||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/block", url.PathEscape(string(id))), nil, &relationship, nil)
|
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/block", url.PathEscape(string(id))), nil, &relationship, nil)
|
||||||
|
@ -225,7 +225,7 @@ func (c *Client) AccountBlock(ctx context.Context, id ID) (*Relationship, error)
|
||||||
return &relationship, nil
|
return &relationship, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AccountUnblock unblock the account.
|
// AccountUnblock unblocks the account.
|
||||||
func (c *Client) AccountUnblock(ctx context.Context, id ID) (*Relationship, error) {
|
func (c *Client) AccountUnblock(ctx context.Context, id ID) (*Relationship, error) {
|
||||||
var relationship Relationship
|
var relationship Relationship
|
||||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/unblock", url.PathEscape(string(id))), nil, &relationship, nil)
|
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/unblock", url.PathEscape(string(id))), nil, &relationship, nil)
|
||||||
|
@ -235,7 +235,7 @@ func (c *Client) AccountUnblock(ctx context.Context, id ID) (*Relationship, erro
|
||||||
return &relationship, nil
|
return &relationship, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AccountMute mute the account.
|
// AccountMute mutes the account.
|
||||||
func (c *Client) AccountMute(ctx context.Context, id ID) (*Relationship, error) {
|
func (c *Client) AccountMute(ctx context.Context, id ID) (*Relationship, error) {
|
||||||
var relationship Relationship
|
var relationship Relationship
|
||||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/mute", url.PathEscape(string(id))), nil, &relationship, nil)
|
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/mute", url.PathEscape(string(id))), nil, &relationship, nil)
|
||||||
|
@ -245,7 +245,7 @@ func (c *Client) AccountMute(ctx context.Context, id ID) (*Relationship, error)
|
||||||
return &relationship, nil
|
return &relationship, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AccountUnmute unmute the account.
|
// AccountUnmute unmutes the account.
|
||||||
func (c *Client) AccountUnmute(ctx context.Context, id ID) (*Relationship, error) {
|
func (c *Client) AccountUnmute(ctx context.Context, id ID) (*Relationship, error) {
|
||||||
var relationship Relationship
|
var relationship Relationship
|
||||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/unmute", url.PathEscape(string(id))), nil, &relationship, nil)
|
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/unmute", url.PathEscape(string(id))), nil, &relationship, nil)
|
||||||
|
@ -255,7 +255,7 @@ func (c *Client) AccountUnmute(ctx context.Context, id ID) (*Relationship, error
|
||||||
return &relationship, nil
|
return &relationship, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAccountRelationships return relationship for the account.
|
// GetAccountRelationships returns relationship for the account.
|
||||||
func (c *Client) GetAccountRelationships(ctx context.Context, ids []string) ([]*Relationship, error) {
|
func (c *Client) GetAccountRelationships(ctx context.Context, ids []string) ([]*Relationship, error) {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
|
@ -270,7 +270,7 @@ func (c *Client) GetAccountRelationships(ctx context.Context, ids []string) ([]*
|
||||||
return relationships, nil
|
return relationships, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AccountsSearch search accounts by query.
|
// AccountsSearch searches accounts by query.
|
||||||
func (c *Client) AccountsSearch(ctx context.Context, q string, limit int64) ([]*Account, error) {
|
func (c *Client) AccountsSearch(ctx context.Context, q string, limit int64) ([]*Account, error) {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Set("q", q)
|
params.Set("q", q)
|
||||||
|
@ -284,7 +284,7 @@ func (c *Client) AccountsSearch(ctx context.Context, q string, limit int64) ([]*
|
||||||
return accounts, nil
|
return accounts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FollowRemoteUser send follow-request.
|
// FollowRemoteUser sends follow-request.
|
||||||
func (c *Client) FollowRemoteUser(ctx context.Context, uri string) (*Account, error) {
|
func (c *Client) FollowRemoteUser(ctx context.Context, uri string) (*Account, error) {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Set("uri", uri)
|
params.Set("uri", uri)
|
||||||
|
@ -297,7 +297,7 @@ func (c *Client) FollowRemoteUser(ctx context.Context, uri string) (*Account, er
|
||||||
return &account, nil
|
return &account, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFollowRequests return follow-requests.
|
// GetFollowRequests returns follow requests.
|
||||||
func (c *Client) GetFollowRequests(ctx context.Context, pg *Pagination) ([]*Account, error) {
|
func (c *Client) GetFollowRequests(ctx context.Context, pg *Pagination) ([]*Account, error) {
|
||||||
var accounts []*Account
|
var accounts []*Account
|
||||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/follow_requests", nil, &accounts, pg)
|
err := c.doAPI(ctx, http.MethodGet, "/api/v1/follow_requests", nil, &accounts, pg)
|
||||||
|
@ -307,12 +307,12 @@ func (c *Client) GetFollowRequests(ctx context.Context, pg *Pagination) ([]*Acco
|
||||||
return accounts, nil
|
return accounts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FollowRequestAuthorize is authorize the follow request of user with id.
|
// FollowRequestAuthorize authorizes the follow request of user with id.
|
||||||
func (c *Client) FollowRequestAuthorize(ctx context.Context, id ID) error {
|
func (c *Client) FollowRequestAuthorize(ctx context.Context, id ID) error {
|
||||||
return c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/follow_requests/%s/authorize", url.PathEscape(string(id))), nil, nil, nil)
|
return c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/follow_requests/%s/authorize", url.PathEscape(string(id))), nil, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FollowRequestReject is rejects the follow request of user with id.
|
// FollowRequestReject rejects the follow request of user with id.
|
||||||
func (c *Client) FollowRequestReject(ctx context.Context, id ID) error {
|
func (c *Client) FollowRequestReject(ctx context.Context, id ID) error {
|
||||||
return c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/follow_requests/%s/reject", url.PathEscape(string(id))), nil, nil, nil)
|
return c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/follow_requests/%s/reject", url.PathEscape(string(id))), nil, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
2
apps.go
2
apps.go
|
@ -27,7 +27,7 @@ type AppConfig struct {
|
||||||
Website string
|
Website string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Application is mastodon application.
|
// Application is a mastodon application.
|
||||||
type Application struct {
|
type Application struct {
|
||||||
ID ID `json:"id"`
|
ID ID `json:"id"`
|
||||||
RedirectURI string `json:"redirect_uri"`
|
RedirectURI string `json:"redirect_uri"`
|
||||||
|
|
12
instance.go
12
instance.go
|
@ -5,7 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Instance hold information for mastodon instance.
|
// Instance holds information for a mastodon instance.
|
||||||
type Instance struct {
|
type Instance struct {
|
||||||
URI string `json:"uri"`
|
URI string `json:"uri"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
|
@ -19,14 +19,14 @@ type Instance struct {
|
||||||
ContactAccount *Account `json:"contact_account"`
|
ContactAccount *Account `json:"contact_account"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InstanceStats hold information for mastodon instance stats.
|
// InstanceStats holds information for mastodon instance stats.
|
||||||
type InstanceStats struct {
|
type InstanceStats struct {
|
||||||
UserCount int64 `json:"user_count"`
|
UserCount int64 `json:"user_count"`
|
||||||
StatusCount int64 `json:"status_count"`
|
StatusCount int64 `json:"status_count"`
|
||||||
DomainCount int64 `json:"domain_count"`
|
DomainCount int64 `json:"domain_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetInstance return Instance.
|
// GetInstance returns Instance.
|
||||||
func (c *Client) GetInstance(ctx context.Context) (*Instance, error) {
|
func (c *Client) GetInstance(ctx context.Context) (*Instance, error) {
|
||||||
var instance Instance
|
var instance Instance
|
||||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance", nil, &instance, nil)
|
err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance", nil, &instance, nil)
|
||||||
|
@ -36,7 +36,7 @@ func (c *Client) GetInstance(ctx context.Context) (*Instance, error) {
|
||||||
return &instance, nil
|
return &instance, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WeeklyActivity hold information for mastodon weekly activity.
|
// WeeklyActivity holds information for mastodon weekly activity.
|
||||||
type WeeklyActivity struct {
|
type WeeklyActivity struct {
|
||||||
Week Unixtime `json:"week"`
|
Week Unixtime `json:"week"`
|
||||||
Statuses int64 `json:"statuses,string"`
|
Statuses int64 `json:"statuses,string"`
|
||||||
|
@ -44,7 +44,7 @@ type WeeklyActivity struct {
|
||||||
Registrations int64 `json:"registrations,string"`
|
Registrations int64 `json:"registrations,string"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetInstanceActivity return instance activity.
|
// GetInstanceActivity returns instance activity.
|
||||||
func (c *Client) GetInstanceActivity(ctx context.Context) ([]*WeeklyActivity, error) {
|
func (c *Client) GetInstanceActivity(ctx context.Context) ([]*WeeklyActivity, error) {
|
||||||
var activity []*WeeklyActivity
|
var activity []*WeeklyActivity
|
||||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance/activity", nil, &activity, nil)
|
err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance/activity", nil, &activity, nil)
|
||||||
|
@ -54,7 +54,7 @@ func (c *Client) GetInstanceActivity(ctx context.Context) ([]*WeeklyActivity, er
|
||||||
return activity, nil
|
return activity, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetInstancePeers return instance peers.
|
// GetInstancePeers returns instance peers.
|
||||||
func (c *Client) GetInstancePeers(ctx context.Context) ([]string, error) {
|
func (c *Client) GetInstancePeers(ctx context.Context) ([]string, error) {
|
||||||
var peers []string
|
var peers []string
|
||||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance/peers", nil, &peers, nil)
|
err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance/peers", nil, &peers, nil)
|
||||||
|
|
|
@ -128,7 +128,7 @@ func (c *Client) doAPI(ctx context.Context, method string, uri string, params in
|
||||||
return json.NewDecoder(resp.Body).Decode(&res)
|
return json.NewDecoder(resp.Body).Decode(&res)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient return new mastodon API client.
|
// NewClient returns a new mastodon API client.
|
||||||
func NewClient(config *Config) *Client {
|
func NewClient(config *Config) *Client {
|
||||||
return &Client{
|
return &Client{
|
||||||
Client: *http.DefaultClient,
|
Client: *http.DefaultClient,
|
||||||
|
@ -136,7 +136,7 @@ func NewClient(config *Config) *Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Authenticate get access-token to the API.
|
// Authenticate gets access-token to the API.
|
||||||
func (c *Client) Authenticate(ctx context.Context, username, password string) error {
|
func (c *Client) Authenticate(ctx context.Context, username, password string) error {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"client_id": {c.Config.ClientID},
|
"client_id": {c.Config.ClientID},
|
||||||
|
@ -222,7 +222,7 @@ const (
|
||||||
VisibilityDirectMessage = "direct"
|
VisibilityDirectMessage = "direct"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Toot is struct to post status.
|
// Toot is a struct to post status.
|
||||||
type Toot struct {
|
type Toot struct {
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
InReplyToID ID `json:"in_reply_to_id"`
|
InReplyToID ID `json:"in_reply_to_id"`
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Notification hold information for mastodon notification.
|
// Notification holds information for a mastodon notification.
|
||||||
type Notification struct {
|
type Notification struct {
|
||||||
ID ID `json:"id"`
|
ID ID `json:"id"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
@ -35,7 +35,7 @@ type PushAlerts struct {
|
||||||
Mention *Sbool `json:"mention"`
|
Mention *Sbool `json:"mention"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNotifications return notifications.
|
// GetNotifications returns notifications.
|
||||||
func (c *Client) GetNotifications(ctx context.Context, pg *Pagination) ([]*Notification, error) {
|
func (c *Client) GetNotifications(ctx context.Context, pg *Pagination) ([]*Notification, error) {
|
||||||
var notifications []*Notification
|
var notifications []*Notification
|
||||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/notifications", nil, ¬ifications, pg)
|
err := c.doAPI(ctx, http.MethodGet, "/api/v1/notifications", nil, ¬ifications, pg)
|
||||||
|
@ -45,7 +45,7 @@ func (c *Client) GetNotifications(ctx context.Context, pg *Pagination) ([]*Notif
|
||||||
return notifications, nil
|
return notifications, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNotification return notification.
|
// GetNotification returns notification.
|
||||||
func (c *Client) GetNotification(ctx context.Context, id ID) (*Notification, error) {
|
func (c *Client) GetNotification(ctx context.Context, id ID) (*Notification, error) {
|
||||||
var notification Notification
|
var notification Notification
|
||||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/notifications/%v", id), nil, ¬ification, nil)
|
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/notifications/%v", id), nil, ¬ification, nil)
|
||||||
|
@ -60,7 +60,7 @@ func (c *Client) DismissNotification(ctx context.Context, id ID) error {
|
||||||
return c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/notifications/%v/dismiss", id), nil, nil, nil)
|
return c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/notifications/%v/dismiss", id), nil, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearNotifications clear notifications.
|
// ClearNotifications clears notifications.
|
||||||
func (c *Client) ClearNotifications(ctx context.Context) error {
|
func (c *Client) ClearNotifications(ctx context.Context) error {
|
||||||
return c.doAPI(ctx, http.MethodPost, "/api/v1/notifications/clear", nil, nil, nil)
|
return c.doAPI(ctx, http.MethodPost, "/api/v1/notifications/clear", nil, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
6
polls.go
6
polls.go
|
@ -8,7 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Poll hold information for mastodon polls.
|
// Poll holds information for mastodon polls.
|
||||||
type Poll struct {
|
type Poll struct {
|
||||||
ID ID `json:"id"`
|
ID ID `json:"id"`
|
||||||
ExpiresAt time.Time `json:"expires_at"`
|
ExpiresAt time.Time `json:"expires_at"`
|
||||||
|
@ -22,13 +22,13 @@ type Poll struct {
|
||||||
Emojis []Emoji `json:"emojis"`
|
Emojis []Emoji `json:"emojis"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Poll hold information for a mastodon poll option.
|
// Poll holds information for a mastodon poll option.
|
||||||
type PollOption struct {
|
type PollOption struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
VotesCount int64 `json:"votes_count"`
|
VotesCount int64 `json:"votes_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPoll return poll specified by id.
|
// GetPoll returns poll specified by id.
|
||||||
func (c *Client) GetPoll(ctx context.Context, id ID) (*Poll, error) {
|
func (c *Client) GetPoll(ctx context.Context, id ID) (*Poll, error) {
|
||||||
var poll Poll
|
var poll Poll
|
||||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/polls/%s", id), nil, &poll, nil)
|
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/polls/%s", id), nil, &poll, nil)
|
||||||
|
|
|
@ -6,13 +6,13 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Report hold information for mastodon report.
|
// Report holds information for a mastodon report.
|
||||||
type Report struct {
|
type Report struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
ActionTaken bool `json:"action_taken"`
|
ActionTaken bool `json:"action_taken"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetReports return report of the current user.
|
// GetReports returns report of the current user.
|
||||||
func (c *Client) GetReports(ctx context.Context) ([]*Report, error) {
|
func (c *Client) GetReports(ctx context.Context) ([]*Report, error) {
|
||||||
var reports []*Report
|
var reports []*Report
|
||||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/reports", nil, &reports, nil)
|
err := c.doAPI(ctx, http.MethodGet, "/api/v1/reports", nil, &reports, nil)
|
||||||
|
|
26
status.go
26
status.go
|
@ -45,13 +45,13 @@ type Status struct {
|
||||||
Pinned interface{} `json:"pinned"`
|
Pinned interface{} `json:"pinned"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Context hold information for mastodon context.
|
// Context holds information for a mastodon context.
|
||||||
type Context struct {
|
type Context struct {
|
||||||
Ancestors []*Status `json:"ancestors"`
|
Ancestors []*Status `json:"ancestors"`
|
||||||
Descendants []*Status `json:"descendants"`
|
Descendants []*Status `json:"descendants"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Card hold information for mastodon card.
|
// Card holds information for a mastodon card.
|
||||||
type Card struct {
|
type Card struct {
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
|
@ -67,7 +67,7 @@ type Card struct {
|
||||||
Height int64 `json:"height"`
|
Height int64 `json:"height"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Conversation hold information for mastodon conversation.
|
// Conversation holds information for a mastodon conversation.
|
||||||
type Conversation struct {
|
type Conversation struct {
|
||||||
ID ID `json:"id"`
|
ID ID `json:"id"`
|
||||||
Accounts []*Account `json:"accounts"`
|
Accounts []*Account `json:"accounts"`
|
||||||
|
@ -140,7 +140,7 @@ func (m *Media) bodyAndContentType() (io.Reader, string, error) {
|
||||||
return &buf, mw.FormDataContentType(), nil
|
return &buf, mw.FormDataContentType(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFavourites return the favorite list of the current user.
|
// GetFavourites returns the favorite list of the current user.
|
||||||
func (c *Client) GetFavourites(ctx context.Context, pg *Pagination) ([]*Status, error) {
|
func (c *Client) GetFavourites(ctx context.Context, pg *Pagination) ([]*Status, error) {
|
||||||
var statuses []*Status
|
var statuses []*Status
|
||||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/favourites", nil, &statuses, pg)
|
err := c.doAPI(ctx, http.MethodGet, "/api/v1/favourites", nil, &statuses, pg)
|
||||||
|
@ -150,7 +150,7 @@ func (c *Client) GetFavourites(ctx context.Context, pg *Pagination) ([]*Status,
|
||||||
return statuses, nil
|
return statuses, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBookmarks return the bookmark list of the current user.
|
// GetBookmarks returns the bookmark list of the current user.
|
||||||
func (c *Client) GetBookmarks(ctx context.Context, pg *Pagination) ([]*Status, error) {
|
func (c *Client) GetBookmarks(ctx context.Context, pg *Pagination) ([]*Status, error) {
|
||||||
var statuses []*Status
|
var statuses []*Status
|
||||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/bookmarks", nil, &statuses, pg)
|
err := c.doAPI(ctx, http.MethodGet, "/api/v1/bookmarks", nil, &statuses, pg)
|
||||||
|
@ -160,7 +160,7 @@ func (c *Client) GetBookmarks(ctx context.Context, pg *Pagination) ([]*Status, e
|
||||||
return statuses, nil
|
return statuses, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStatus return status specified by id.
|
// GetStatus returns status specified by id.
|
||||||
func (c *Client) GetStatus(ctx context.Context, id ID) (*Status, error) {
|
func (c *Client) GetStatus(ctx context.Context, id ID) (*Status, error) {
|
||||||
var status Status
|
var status Status
|
||||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%s", id), nil, &status, nil)
|
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%s", id), nil, &status, nil)
|
||||||
|
@ -170,7 +170,7 @@ func (c *Client) GetStatus(ctx context.Context, id ID) (*Status, error) {
|
||||||
return &status, nil
|
return &status, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStatusContext return status specified by id.
|
// GetStatusContext returns status specified by id.
|
||||||
func (c *Client) GetStatusContext(ctx context.Context, id ID) (*Context, error) {
|
func (c *Client) GetStatusContext(ctx context.Context, id ID) (*Context, error) {
|
||||||
var context Context
|
var context Context
|
||||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%s/context", id), nil, &context, nil)
|
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%s/context", id), nil, &context, nil)
|
||||||
|
@ -180,7 +180,7 @@ func (c *Client) GetStatusContext(ctx context.Context, id ID) (*Context, error)
|
||||||
return &context, nil
|
return &context, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStatusCard return status specified by id.
|
// GetStatusCard returns status specified by id.
|
||||||
func (c *Client) GetStatusCard(ctx context.Context, id ID) (*Card, error) {
|
func (c *Client) GetStatusCard(ctx context.Context, id ID) (*Card, error) {
|
||||||
var card Card
|
var card Card
|
||||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%s/card", id), nil, &card, nil)
|
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%s/card", id), nil, &card, nil)
|
||||||
|
@ -210,7 +210,7 @@ func (c *Client) GetFavouritedBy(ctx context.Context, id ID, pg *Pagination) ([]
|
||||||
return accounts, nil
|
return accounts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reblog is reblog the toot of id and return status of reblog.
|
// Reblog reblogs the toot of id and returns status of reblog.
|
||||||
func (c *Client) Reblog(ctx context.Context, id ID) (*Status, error) {
|
func (c *Client) Reblog(ctx context.Context, id ID) (*Status, error) {
|
||||||
var status Status
|
var status Status
|
||||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/reblog", id), nil, &status, nil)
|
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/reblog", id), nil, &status, nil)
|
||||||
|
@ -220,7 +220,7 @@ func (c *Client) Reblog(ctx context.Context, id ID) (*Status, error) {
|
||||||
return &status, nil
|
return &status, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unreblog is unreblog the toot of id and return status of the original toot.
|
// Unreblog unreblogs the toot of id and returns status of the original toot.
|
||||||
func (c *Client) Unreblog(ctx context.Context, id ID) (*Status, error) {
|
func (c *Client) Unreblog(ctx context.Context, id ID) (*Status, error) {
|
||||||
var status Status
|
var status Status
|
||||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/unreblog", id), nil, &status, nil)
|
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/unreblog", id), nil, &status, nil)
|
||||||
|
@ -230,7 +230,7 @@ func (c *Client) Unreblog(ctx context.Context, id ID) (*Status, error) {
|
||||||
return &status, nil
|
return &status, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Favourite is favourite the toot of id and return status of the favourite toot.
|
// Favourite favourites the toot of id and returns status of the favourite toot.
|
||||||
func (c *Client) Favourite(ctx context.Context, id ID) (*Status, error) {
|
func (c *Client) Favourite(ctx context.Context, id ID) (*Status, error) {
|
||||||
var status Status
|
var status Status
|
||||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/favourite", id), nil, &status, nil)
|
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/favourite", id), nil, &status, nil)
|
||||||
|
@ -240,7 +240,7 @@ func (c *Client) Favourite(ctx context.Context, id ID) (*Status, error) {
|
||||||
return &status, nil
|
return &status, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unfavourite is unfavourite the toot of id and return status of the unfavourite toot.
|
// Unfavourite unfavourites the toot of id and returns status of the unfavourite toot.
|
||||||
func (c *Client) Unfavourite(ctx context.Context, id ID) (*Status, error) {
|
func (c *Client) Unfavourite(ctx context.Context, id ID) (*Status, error) {
|
||||||
var status Status
|
var status Status
|
||||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/unfavourite", id), nil, &status, nil)
|
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/unfavourite", id), nil, &status, nil)
|
||||||
|
@ -250,7 +250,7 @@ func (c *Client) Unfavourite(ctx context.Context, id ID) (*Status, error) {
|
||||||
return &status, nil
|
return &status, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bookmark is bookmark the toot of id and return status of the bookmark toot.
|
// Bookmark bookmarks the toot of id and returns status of the bookmark toot.
|
||||||
func (c *Client) Bookmark(ctx context.Context, id ID) (*Status, error) {
|
func (c *Client) Bookmark(ctx context.Context, id ID) (*Status, error) {
|
||||||
var status Status
|
var status Status
|
||||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/bookmark", id), nil, &status, nil)
|
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/bookmark", id), nil, &status, nil)
|
||||||
|
|
20
streaming.go
20
streaming.go
|
@ -13,32 +13,32 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UpdateEvent is struct for passing status event to app.
|
// UpdateEvent is a struct for passing status event to app.
|
||||||
type UpdateEvent struct {
|
type UpdateEvent struct {
|
||||||
Status *Status `json:"status"`
|
Status *Status `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *UpdateEvent) event() {}
|
func (e *UpdateEvent) event() {}
|
||||||
|
|
||||||
// NotificationEvent is struct for passing notification event to app.
|
// NotificationEvent is a struct for passing notification event to app.
|
||||||
type NotificationEvent struct {
|
type NotificationEvent struct {
|
||||||
Notification *Notification `json:"notification"`
|
Notification *Notification `json:"notification"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *NotificationEvent) event() {}
|
func (e *NotificationEvent) event() {}
|
||||||
|
|
||||||
// DeleteEvent is struct for passing deletion event to app.
|
// DeleteEvent is a struct for passing deletion event to app.
|
||||||
type DeleteEvent struct{ ID ID }
|
type DeleteEvent struct{ ID ID }
|
||||||
|
|
||||||
func (e *DeleteEvent) event() {}
|
func (e *DeleteEvent) event() {}
|
||||||
|
|
||||||
// ErrorEvent is struct for passing errors to app.
|
// ErrorEvent is a struct for passing errors to app.
|
||||||
type ErrorEvent struct{ err error }
|
type ErrorEvent struct{ err error }
|
||||||
|
|
||||||
func (e *ErrorEvent) event() {}
|
func (e *ErrorEvent) event() {}
|
||||||
func (e *ErrorEvent) Error() string { return e.err.Error() }
|
func (e *ErrorEvent) Error() string { return e.err.Error() }
|
||||||
|
|
||||||
// Event is interface passing events to app.
|
// Event is an interface passing events to app.
|
||||||
type Event interface {
|
type Event interface {
|
||||||
event()
|
event()
|
||||||
}
|
}
|
||||||
|
@ -150,12 +150,12 @@ func (c *Client) doStreaming(req *http.Request, q chan Event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// StreamingUser return channel to read events on home.
|
// StreamingUser returns a channel to read events on home.
|
||||||
func (c *Client) StreamingUser(ctx context.Context) (chan Event, error) {
|
func (c *Client) StreamingUser(ctx context.Context) (chan Event, error) {
|
||||||
return c.streaming(ctx, "user", nil)
|
return c.streaming(ctx, "user", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// StreamingPublic return channel to read events on public.
|
// StreamingPublic returns a channel to read events on public.
|
||||||
func (c *Client) StreamingPublic(ctx context.Context, isLocal bool) (chan Event, error) {
|
func (c *Client) StreamingPublic(ctx context.Context, isLocal bool) (chan Event, error) {
|
||||||
p := "public"
|
p := "public"
|
||||||
if isLocal {
|
if isLocal {
|
||||||
|
@ -165,7 +165,7 @@ func (c *Client) StreamingPublic(ctx context.Context, isLocal bool) (chan Event,
|
||||||
return c.streaming(ctx, p, nil)
|
return c.streaming(ctx, p, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// StreamingHashtag return channel to read events on tagged timeline.
|
// StreamingHashtag returns a channel to read events on tagged timeline.
|
||||||
func (c *Client) StreamingHashtag(ctx context.Context, tag string, isLocal bool) (chan Event, error) {
|
func (c *Client) StreamingHashtag(ctx context.Context, tag string, isLocal bool) (chan Event, error) {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Set("tag", tag)
|
params.Set("tag", tag)
|
||||||
|
@ -178,7 +178,7 @@ func (c *Client) StreamingHashtag(ctx context.Context, tag string, isLocal bool)
|
||||||
return c.streaming(ctx, p, params)
|
return c.streaming(ctx, p, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
// StreamingList return channel to read events on a list.
|
// StreamingList returns a channel to read events on a list.
|
||||||
func (c *Client) StreamingList(ctx context.Context, id ID) (chan Event, error) {
|
func (c *Client) StreamingList(ctx context.Context, id ID) (chan Event, error) {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Set("list", string(id))
|
params.Set("list", string(id))
|
||||||
|
@ -186,7 +186,7 @@ func (c *Client) StreamingList(ctx context.Context, id ID) (chan Event, error) {
|
||||||
return c.streaming(ctx, "list", params)
|
return c.streaming(ctx, "list", params)
|
||||||
}
|
}
|
||||||
|
|
||||||
// StreamingDirect return channel to read events on a direct messages.
|
// StreamingDirect returns a channel to read events on a direct messages.
|
||||||
func (c *Client) StreamingDirect(ctx context.Context) (chan Event, error) {
|
func (c *Client) StreamingDirect(ctx context.Context) (chan Event, error) {
|
||||||
return c.streaming(ctx, "direct", nil)
|
return c.streaming(ctx, "direct", nil)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user