remove context.Context

This commit is contained in:
gutmet 2022-11-20 18:03:36 +01:00
parent cf574831cc
commit ac39fb12dd
10 changed files with 162 additions and 169 deletions

View File

@ -1,7 +1,6 @@
package mastodon package mastodon
import ( import (
"context"
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
@ -51,9 +50,9 @@ type AccountSource struct {
} }
// GetAccount return Account. // GetAccount return Account.
func (c *Client) GetAccount(ctx context.Context, id ID) (*Account, error) { func (c *Client) GetAccount(id ID) (*Account, error) {
var account Account var account Account
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s", url.PathEscape(string(id))), nil, &account, nil) err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s", url.PathEscape(string(id))), nil, &account, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -61,9 +60,9 @@ func (c *Client) GetAccount(ctx context.Context, id ID) (*Account, error) {
} }
// GetAccountCurrentUser returns the Account of current user. // GetAccountCurrentUser returns the Account of current user.
func (c *Client) GetAccountCurrentUser(ctx context.Context) (*Account, error) { func (c *Client) GetAccountCurrentUser() (*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(http.MethodGet, "/api/v1/accounts/verify_credentials", nil, &account, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -86,7 +85,7 @@ type Profile struct {
} }
// AccountUpdate updates the information of the current user. // AccountUpdate updates the information of the current user.
func (c *Client) AccountUpdate(ctx context.Context, profile *Profile) (*Account, error) { func (c *Client) AccountUpdate(profile *Profile) (*Account, error) {
params := url.Values{} params := url.Values{}
if profile.DisplayName != nil { if profile.DisplayName != nil {
params.Set("display_name", *profile.DisplayName) params.Set("display_name", *profile.DisplayName)
@ -122,7 +121,7 @@ func (c *Client) AccountUpdate(ctx context.Context, profile *Profile) (*Account,
} }
var account Account var account Account
err := c.doAPI(ctx, http.MethodPatch, "/api/v1/accounts/update_credentials", params, &account, nil) err := c.doAPI(http.MethodPatch, "/api/v1/accounts/update_credentials", params, &account, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -130,9 +129,9 @@ func (c *Client) AccountUpdate(ctx context.Context, profile *Profile) (*Account,
} }
// GetAccountStatuses return statuses by specified account. // GetAccountStatuses return statuses by specified account.
func (c *Client) GetAccountStatuses(ctx context.Context, id ID, pg *Pagination) ([]*Status, error) { func (c *Client) GetAccountStatuses(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(http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/statuses", url.PathEscape(string(id))), nil, &statuses, pg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -140,11 +139,11 @@ func (c *Client) GetAccountStatuses(ctx context.Context, id ID, pg *Pagination)
} }
// GetAccountPinnedStatuses returns 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(id ID) ([]*Status, error) {
var statuses []*Status var statuses []*Status
params := url.Values{} params := url.Values{}
params.Set("pinned", "true") params.Set("pinned", "true")
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/statuses", url.PathEscape(string(id))), params, &statuses, nil) err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/statuses", url.PathEscape(string(id))), params, &statuses, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -152,9 +151,9 @@ func (c *Client) GetAccountPinnedStatuses(ctx context.Context, id ID) ([]*Status
} }
// GetAccountFollowers returns followers list. // GetAccountFollowers returns followers list.
func (c *Client) GetAccountFollowers(ctx context.Context, id ID, pg *Pagination) ([]*Account, error) { func (c *Client) GetAccountFollowers(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(http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/followers", url.PathEscape(string(id))), nil, &accounts, pg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -162,9 +161,9 @@ func (c *Client) GetAccountFollowers(ctx context.Context, id ID, pg *Pagination)
} }
// GetAccountFollowing returns following list. // GetAccountFollowing returns following list.
func (c *Client) GetAccountFollowing(ctx context.Context, id ID, pg *Pagination) ([]*Account, error) { func (c *Client) GetAccountFollowing(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(http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/following", url.PathEscape(string(id))), nil, &accounts, pg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -172,9 +171,9 @@ func (c *Client) GetAccountFollowing(ctx context.Context, id ID, pg *Pagination)
} }
// GetBlocks returns block list. // GetBlocks returns block list.
func (c *Client) GetBlocks(ctx context.Context, pg *Pagination) ([]*Account, error) { func (c *Client) GetBlocks(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(http.MethodGet, "/api/v1/blocks", nil, &accounts, pg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -196,9 +195,9 @@ type Relationship struct {
} }
// AccountFollow follows the account. // AccountFollow follows the account.
func (c *Client) AccountFollow(ctx context.Context, id ID) (*Relationship, error) { func (c *Client) AccountFollow(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(http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/follow", url.PathEscape(string(id))), nil, &relationship, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -206,9 +205,9 @@ func (c *Client) AccountFollow(ctx context.Context, id ID) (*Relationship, error
} }
// AccountUnfollow unfollows the account. // AccountUnfollow unfollows the account.
func (c *Client) AccountUnfollow(ctx context.Context, id ID) (*Relationship, error) { func (c *Client) AccountUnfollow(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(http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/unfollow", url.PathEscape(string(id))), nil, &relationship, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -216,9 +215,9 @@ func (c *Client) AccountUnfollow(ctx context.Context, id ID) (*Relationship, err
} }
// AccountBlock blocks the account. // AccountBlock blocks the account.
func (c *Client) AccountBlock(ctx context.Context, id ID) (*Relationship, error) { func (c *Client) AccountBlock(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(http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/block", url.PathEscape(string(id))), nil, &relationship, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -226,9 +225,9 @@ func (c *Client) AccountBlock(ctx context.Context, id ID) (*Relationship, error)
} }
// AccountUnblock unblocks the account. // AccountUnblock unblocks the account.
func (c *Client) AccountUnblock(ctx context.Context, id ID) (*Relationship, error) { func (c *Client) AccountUnblock(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(http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/unblock", url.PathEscape(string(id))), nil, &relationship, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -236,9 +235,9 @@ func (c *Client) AccountUnblock(ctx context.Context, id ID) (*Relationship, erro
} }
// AccountMute mutes the account. // AccountMute mutes the account.
func (c *Client) AccountMute(ctx context.Context, id ID) (*Relationship, error) { func (c *Client) AccountMute(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(http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/mute", url.PathEscape(string(id))), nil, &relationship, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -246,9 +245,9 @@ func (c *Client) AccountMute(ctx context.Context, id ID) (*Relationship, error)
} }
// AccountUnmute unmutes the account. // AccountUnmute unmutes the account.
func (c *Client) AccountUnmute(ctx context.Context, id ID) (*Relationship, error) { func (c *Client) AccountUnmute(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(http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/unmute", url.PathEscape(string(id))), nil, &relationship, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -256,14 +255,14 @@ func (c *Client) AccountUnmute(ctx context.Context, id ID) (*Relationship, error
} }
// GetAccountRelationships returns 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(ids []string) ([]*Relationship, error) {
params := url.Values{} params := url.Values{}
for _, id := range ids { for _, id := range ids {
params.Add("id[]", id) params.Add("id[]", id)
} }
var relationships []*Relationship var relationships []*Relationship
err := c.doAPI(ctx, http.MethodGet, "/api/v1/accounts/relationships", params, &relationships, nil) err := c.doAPI(http.MethodGet, "/api/v1/accounts/relationships", params, &relationships, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -271,13 +270,13 @@ func (c *Client) GetAccountRelationships(ctx context.Context, ids []string) ([]*
} }
// AccountsSearch searches 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(q string, limit int64) ([]*Account, error) {
params := url.Values{} params := url.Values{}
params.Set("q", q) params.Set("q", q)
params.Set("limit", fmt.Sprint(limit)) params.Set("limit", fmt.Sprint(limit))
var accounts []*Account var accounts []*Account
err := c.doAPI(ctx, http.MethodGet, "/api/v1/accounts/search", params, &accounts, nil) err := c.doAPI(http.MethodGet, "/api/v1/accounts/search", params, &accounts, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -285,12 +284,12 @@ func (c *Client) AccountsSearch(ctx context.Context, q string, limit int64) ([]*
} }
// FollowRemoteUser sends follow-request. // FollowRemoteUser sends follow-request.
func (c *Client) FollowRemoteUser(ctx context.Context, uri string) (*Account, error) { func (c *Client) FollowRemoteUser(uri string) (*Account, error) {
params := url.Values{} params := url.Values{}
params.Set("uri", uri) params.Set("uri", uri)
var account Account var account Account
err := c.doAPI(ctx, http.MethodPost, "/api/v1/follows", params, &account, nil) err := c.doAPI(http.MethodPost, "/api/v1/follows", params, &account, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -298,9 +297,9 @@ func (c *Client) FollowRemoteUser(ctx context.Context, uri string) (*Account, er
} }
// GetFollowRequests returns follow requests. // GetFollowRequests returns follow requests.
func (c *Client) GetFollowRequests(ctx context.Context, pg *Pagination) ([]*Account, error) { func (c *Client) GetFollowRequests(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(http.MethodGet, "/api/v1/follow_requests", nil, &accounts, pg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -308,19 +307,19 @@ func (c *Client) GetFollowRequests(ctx context.Context, pg *Pagination) ([]*Acco
} }
// FollowRequestAuthorize authorizes 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(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(http.MethodPost, fmt.Sprintf("/api/v1/follow_requests/%s/authorize", url.PathEscape(string(id))), nil, nil, nil)
} }
// FollowRequestReject 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(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(http.MethodPost, fmt.Sprintf("/api/v1/follow_requests/%s/reject", url.PathEscape(string(id))), nil, nil, nil)
} }
// GetMutes returns the list of users muted by the current user. // GetMutes returns the list of users muted by the current user.
func (c *Client) GetMutes(ctx context.Context, pg *Pagination) ([]*Account, error) { func (c *Client) GetMutes(pg *Pagination) ([]*Account, error) {
var accounts []*Account var accounts []*Account
err := c.doAPI(ctx, http.MethodGet, "/api/v1/mutes", nil, &accounts, pg) err := c.doAPI(http.MethodGet, "/api/v1/mutes", nil, &accounts, pg)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -103,9 +103,9 @@ type ApplicationVerification struct {
} }
// VerifyAppCredentials returns the mastodon application. // VerifyAppCredentials returns the mastodon application.
func (c *Client) VerifyAppCredentials(ctx context.Context) (*ApplicationVerification, error) { func (c *Client) VerifyAppCredentials() (*ApplicationVerification, error) {
var application ApplicationVerification var application ApplicationVerification
err := c.doAPI(ctx, http.MethodGet, "/api/v1/apps/verify_credentials", nil, &application, nil) err := c.doAPI(http.MethodGet, "/api/v1/apps/verify_credentials", nil, &application, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -1,7 +1,6 @@
package mastodon package mastodon
import ( import (
"context"
"errors" "errors"
"fmt" "fmt"
"net/http" "net/http"
@ -20,9 +19,9 @@ type Filter struct {
} }
// GetFilters returns all the filters on the current account. // GetFilters returns all the filters on the current account.
func (c *Client) GetFilters(ctx context.Context) ([]*Filter, error) { func (c *Client) GetFilters() ([]*Filter, error) {
var filters []*Filter var filters []*Filter
err := c.doAPI(ctx, http.MethodGet, "/api/v1/filters", nil, &filters, nil) err := c.doAPI(http.MethodGet, "/api/v1/filters", nil, &filters, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -30,9 +29,9 @@ func (c *Client) GetFilters(ctx context.Context) ([]*Filter, error) {
} }
// GetFilter retrieves a filter by ID. // GetFilter retrieves a filter by ID.
func (c *Client) GetFilter(ctx context.Context, id ID) (*Filter, error) { func (c *Client) GetFilter(id ID) (*Filter, error) {
var filter Filter var filter Filter
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/filters/%s", url.PathEscape(string(id))), nil, &filter, nil) err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/filters/%s", url.PathEscape(string(id))), nil, &filter, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -40,7 +39,7 @@ func (c *Client) GetFilter(ctx context.Context, id ID) (*Filter, error) {
} }
// CreateFilter creates a new filter. // CreateFilter creates a new filter.
func (c *Client) CreateFilter(ctx context.Context, filter *Filter) (*Filter, error) { func (c *Client) CreateFilter(filter *Filter) (*Filter, error) {
if filter == nil { if filter == nil {
return nil, errors.New("filter can't be nil") return nil, errors.New("filter can't be nil")
} }
@ -67,7 +66,7 @@ func (c *Client) CreateFilter(ctx context.Context, filter *Filter) (*Filter, err
} }
var f Filter var f Filter
err := c.doAPI(ctx, http.MethodPost, "/api/v1/filters", params, &f, nil) err := c.doAPI(http.MethodPost, "/api/v1/filters", params, &f, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -75,7 +74,7 @@ func (c *Client) CreateFilter(ctx context.Context, filter *Filter) (*Filter, err
} }
// UpdateFilter updates a filter. // UpdateFilter updates a filter.
func (c *Client) UpdateFilter(ctx context.Context, id ID, filter *Filter) (*Filter, error) { func (c *Client) UpdateFilter(id ID, filter *Filter) (*Filter, error) {
if filter == nil { if filter == nil {
return nil, errors.New("filter can't be nil") return nil, errors.New("filter can't be nil")
} }
@ -111,7 +110,7 @@ func (c *Client) UpdateFilter(ctx context.Context, id ID, filter *Filter) (*Filt
} }
var f Filter var f Filter
err := c.doAPI(ctx, http.MethodPut, fmt.Sprintf("/api/v1/filters/%s", url.PathEscape(string(id))), params, &f, nil) err := c.doAPI(http.MethodPut, fmt.Sprintf("/api/v1/filters/%s", url.PathEscape(string(id))), params, &f, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -119,6 +118,6 @@ func (c *Client) UpdateFilter(ctx context.Context, id ID, filter *Filter) (*Filt
} }
// DeleteFilter removes a filter. // DeleteFilter removes a filter.
func (c *Client) DeleteFilter(ctx context.Context, id ID) error { func (c *Client) DeleteFilter(id ID) error {
return c.doAPI(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/filters/%s", url.PathEscape(string(id))), nil, nil, nil) return c.doAPI(http.MethodDelete, fmt.Sprintf("/api/v1/filters/%s", url.PathEscape(string(id))), nil, nil, nil)
} }

View File

@ -1,7 +1,6 @@
package mastodon package mastodon
import ( import (
"context"
"net/http" "net/http"
) )
@ -27,9 +26,9 @@ type InstanceStats struct {
} }
// GetInstance returns Instance. // GetInstance returns Instance.
func (c *Client) GetInstance(ctx context.Context) (*Instance, error) { func (c *Client) GetInstance() (*Instance, error) {
var instance Instance var instance Instance
err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance", nil, &instance, nil) err := c.doAPI(http.MethodGet, "/api/v1/instance", nil, &instance, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -45,9 +44,9 @@ type WeeklyActivity struct {
} }
// GetInstanceActivity returns instance activity. // GetInstanceActivity returns instance activity.
func (c *Client) GetInstanceActivity(ctx context.Context) ([]*WeeklyActivity, error) { func (c *Client) GetInstanceActivity() ([]*WeeklyActivity, error) {
var activity []*WeeklyActivity var activity []*WeeklyActivity
err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance/activity", nil, &activity, nil) err := c.doAPI(http.MethodGet, "/api/v1/instance/activity", nil, &activity, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -55,9 +54,9 @@ func (c *Client) GetInstanceActivity(ctx context.Context) ([]*WeeklyActivity, er
} }
// GetInstancePeers returns instance peers. // GetInstancePeers returns instance peers.
func (c *Client) GetInstancePeers(ctx context.Context) ([]string, error) { func (c *Client) GetInstancePeers() ([]string, error) {
var peers []string var peers []string
err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance/peers", nil, &peers, nil) err := c.doAPI(http.MethodGet, "/api/v1/instance/peers", nil, &peers, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -1,7 +1,6 @@
package mastodon package mastodon
import ( import (
"context"
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
@ -14,9 +13,9 @@ type List struct {
} }
// GetLists returns all the lists on the current account. // GetLists returns all the lists on the current account.
func (c *Client) GetLists(ctx context.Context) ([]*List, error) { func (c *Client) GetLists() ([]*List, error) {
var lists []*List var lists []*List
err := c.doAPI(ctx, http.MethodGet, "/api/v1/lists", nil, &lists, nil) err := c.doAPI(http.MethodGet, "/api/v1/lists", nil, &lists, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -24,9 +23,9 @@ func (c *Client) GetLists(ctx context.Context) ([]*List, error) {
} }
// GetAccountLists returns the lists containing a given account. // GetAccountLists returns the lists containing a given account.
func (c *Client) GetAccountLists(ctx context.Context, id ID) ([]*List, error) { func (c *Client) GetAccountLists(id ID) ([]*List, error) {
var lists []*List var lists []*List
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/lists", url.PathEscape(string(id))), nil, &lists, nil) err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/lists", url.PathEscape(string(id))), nil, &lists, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -34,9 +33,9 @@ func (c *Client) GetAccountLists(ctx context.Context, id ID) ([]*List, error) {
} }
// GetListAccounts returns the accounts in a given list. // GetListAccounts returns the accounts in a given list.
func (c *Client) GetListAccounts(ctx context.Context, id ID) ([]*Account, error) { func (c *Client) GetListAccounts(id ID) ([]*Account, error) {
var accounts []*Account var accounts []*Account
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/lists/%s/accounts", url.PathEscape(string(id))), url.Values{"limit": {"0"}}, &accounts, nil) err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/lists/%s/accounts", url.PathEscape(string(id))), url.Values{"limit": {"0"}}, &accounts, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -44,9 +43,9 @@ func (c *Client) GetListAccounts(ctx context.Context, id ID) ([]*Account, error)
} }
// GetList retrieves a list by ID. // GetList retrieves a list by ID.
func (c *Client) GetList(ctx context.Context, id ID) (*List, error) { func (c *Client) GetList(id ID) (*List, error) {
var list List var list List
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/lists/%s", url.PathEscape(string(id))), nil, &list, nil) err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/lists/%s", url.PathEscape(string(id))), nil, &list, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -54,12 +53,12 @@ func (c *Client) GetList(ctx context.Context, id ID) (*List, error) {
} }
// CreateList creates a new list with a given title. // CreateList creates a new list with a given title.
func (c *Client) CreateList(ctx context.Context, title string) (*List, error) { func (c *Client) CreateList(title string) (*List, error) {
params := url.Values{} params := url.Values{}
params.Set("title", title) params.Set("title", title)
var list List var list List
err := c.doAPI(ctx, http.MethodPost, "/api/v1/lists", params, &list, nil) err := c.doAPI(http.MethodPost, "/api/v1/lists", params, &list, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -67,12 +66,12 @@ func (c *Client) CreateList(ctx context.Context, title string) (*List, error) {
} }
// RenameList assigns a new title to a list. // RenameList assigns a new title to a list.
func (c *Client) RenameList(ctx context.Context, id ID, title string) (*List, error) { func (c *Client) RenameList(id ID, title string) (*List, error) {
params := url.Values{} params := url.Values{}
params.Set("title", title) params.Set("title", title)
var list List var list List
err := c.doAPI(ctx, http.MethodPut, fmt.Sprintf("/api/v1/lists/%s", url.PathEscape(string(id))), params, &list, nil) err := c.doAPI(http.MethodPut, fmt.Sprintf("/api/v1/lists/%s", url.PathEscape(string(id))), params, &list, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -80,28 +79,28 @@ func (c *Client) RenameList(ctx context.Context, id ID, title string) (*List, er
} }
// DeleteList removes a list. // DeleteList removes a list.
func (c *Client) DeleteList(ctx context.Context, id ID) error { func (c *Client) DeleteList(id ID) error {
return c.doAPI(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/lists/%s", url.PathEscape(string(id))), nil, nil, nil) return c.doAPI(http.MethodDelete, fmt.Sprintf("/api/v1/lists/%s", url.PathEscape(string(id))), nil, nil, nil)
} }
// AddToList adds accounts to a list. // AddToList adds accounts to a list.
// //
// Only accounts already followed by the user can be added to a list. // Only accounts already followed by the user can be added to a list.
func (c *Client) AddToList(ctx context.Context, list ID, accounts ...ID) error { func (c *Client) AddToList(list ID, accounts ...ID) error {
params := url.Values{} params := url.Values{}
for _, acct := range accounts { for _, acct := range accounts {
params.Add("account_ids", string(acct)) params.Add("account_ids", string(acct))
} }
return c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/lists/%s/accounts", url.PathEscape(string(list))), params, nil, nil) return c.doAPI(http.MethodPost, fmt.Sprintf("/api/v1/lists/%s/accounts", url.PathEscape(string(list))), params, nil, nil)
} }
// RemoveFromList removes accounts from a list. // RemoveFromList removes accounts from a list.
func (c *Client) RemoveFromList(ctx context.Context, list ID, accounts ...ID) error { func (c *Client) RemoveFromList(list ID, accounts ...ID) error {
params := url.Values{} params := url.Values{}
for _, acct := range accounts { for _, acct := range accounts {
params.Add("account_ids", string(acct)) params.Add("account_ids", string(acct))
} }
return c.doAPI(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/lists/%s/accounts", url.PathEscape(string(list))), params, nil, nil) return c.doAPI(http.MethodDelete, fmt.Sprintf("/api/v1/lists/%s/accounts", url.PathEscape(string(list))), params, nil, nil)
} }

View File

@ -29,7 +29,8 @@ type Client struct {
UserAgent string UserAgent string
} }
func (c *Client) doAPI(ctx context.Context, method string, uri string, params interface{}, res interface{}, pg *Pagination) error { func (c *Client) doAPI(method string, uri string, params interface{}, res interface{}, pg *Pagination) error {
ctx := context.Background()
u, err := url.Parse(c.Config.Server) u, err := url.Parse(c.Config.Server)
if err != nil { if err != nil {
return err return err

View File

@ -1,7 +1,6 @@
package mastodon package mastodon
import ( import (
"context"
"crypto/ecdsa" "crypto/ecdsa"
"crypto/elliptic" "crypto/elliptic"
"encoding/base64" "encoding/base64"
@ -36,9 +35,9 @@ type PushAlerts struct {
} }
// GetNotifications returns notifications. // GetNotifications returns notifications.
func (c *Client) GetNotifications(ctx context.Context, pg *Pagination) ([]*Notification, error) { func (c *Client) GetNotifications(pg *Pagination) ([]*Notification, error) {
var notifications []*Notification var notifications []*Notification
err := c.doAPI(ctx, http.MethodGet, "/api/v1/notifications", nil, &notifications, pg) err := c.doAPI(http.MethodGet, "/api/v1/notifications", nil, &notifications, pg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -46,9 +45,9 @@ func (c *Client) GetNotifications(ctx context.Context, pg *Pagination) ([]*Notif
} }
// GetNotification returns notification. // GetNotification returns notification.
func (c *Client) GetNotification(ctx context.Context, id ID) (*Notification, error) { func (c *Client) GetNotification(id ID) (*Notification, error) {
var notification Notification var notification Notification
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/notifications/%v", id), nil, &notification, nil) err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/notifications/%v", id), nil, &notification, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -56,17 +55,17 @@ func (c *Client) GetNotification(ctx context.Context, id ID) (*Notification, err
} }
// DismissNotification deletes a single notification. // DismissNotification deletes a single notification.
func (c *Client) DismissNotification(ctx context.Context, id ID) error { func (c *Client) DismissNotification(id ID) error {
return c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/notifications/%v/dismiss", id), nil, nil, nil) return c.doAPI(http.MethodPost, fmt.Sprintf("/api/v1/notifications/%v/dismiss", id), nil, nil, nil)
} }
// ClearNotifications clears notifications. // ClearNotifications clears notifications.
func (c *Client) ClearNotifications(ctx context.Context) error { func (c *Client) ClearNotifications() error {
return c.doAPI(ctx, http.MethodPost, "/api/v1/notifications/clear", nil, nil, nil) return c.doAPI(http.MethodPost, "/api/v1/notifications/clear", nil, nil, nil)
} }
// AddPushSubscription adds a new push subscription. // AddPushSubscription adds a new push subscription.
func (c *Client) AddPushSubscription(ctx context.Context, endpoint string, public ecdsa.PublicKey, shared []byte, alerts PushAlerts) (*PushSubscription, error) { func (c *Client) AddPushSubscription(endpoint string, public ecdsa.PublicKey, shared []byte, alerts PushAlerts) (*PushSubscription, error) {
var subscription PushSubscription var subscription PushSubscription
pk := elliptic.Marshal(public.Curve, public.X, public.Y) pk := elliptic.Marshal(public.Curve, public.X, public.Y)
params := url.Values{} params := url.Values{}
@ -85,7 +84,7 @@ func (c *Client) AddPushSubscription(ctx context.Context, endpoint string, publi
if alerts.Mention != nil { if alerts.Mention != nil {
params.Add("data[alerts][mention]", strconv.FormatBool(bool(*alerts.Mention))) params.Add("data[alerts][mention]", strconv.FormatBool(bool(*alerts.Mention)))
} }
err := c.doAPI(ctx, http.MethodPost, "/api/v1/push/subscription", params, &subscription, nil) err := c.doAPI(http.MethodPost, "/api/v1/push/subscription", params, &subscription, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -93,7 +92,7 @@ func (c *Client) AddPushSubscription(ctx context.Context, endpoint string, publi
} }
// UpdatePushSubscription updates which type of notifications are sent for the active push subscription. // UpdatePushSubscription updates which type of notifications are sent for the active push subscription.
func (c *Client) UpdatePushSubscription(ctx context.Context, alerts *PushAlerts) (*PushSubscription, error) { func (c *Client) UpdatePushSubscription(alerts *PushAlerts) (*PushSubscription, error) {
var subscription PushSubscription var subscription PushSubscription
params := url.Values{} params := url.Values{}
if alerts.Follow != nil { if alerts.Follow != nil {
@ -108,7 +107,7 @@ func (c *Client) UpdatePushSubscription(ctx context.Context, alerts *PushAlerts)
if alerts.Mention != nil { if alerts.Mention != nil {
params.Add("data[alerts][mention]", strconv.FormatBool(bool(*alerts.Mention))) params.Add("data[alerts][mention]", strconv.FormatBool(bool(*alerts.Mention)))
} }
err := c.doAPI(ctx, http.MethodPut, "/api/v1/push/subscription", params, &subscription, nil) err := c.doAPI(http.MethodPut, "/api/v1/push/subscription", params, &subscription, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -116,14 +115,14 @@ func (c *Client) UpdatePushSubscription(ctx context.Context, alerts *PushAlerts)
} }
// RemovePushSubscription deletes the active push subscription. // RemovePushSubscription deletes the active push subscription.
func (c *Client) RemovePushSubscription(ctx context.Context) error { func (c *Client) RemovePushSubscription() error {
return c.doAPI(ctx, http.MethodDelete, "/api/v1/push/subscription", nil, nil, nil) return c.doAPI(http.MethodDelete, "/api/v1/push/subscription", nil, nil, nil)
} }
// GetPushSubscription retrieves information about the active push subscription. // GetPushSubscription retrieves information about the active push subscription.
func (c *Client) GetPushSubscription(ctx context.Context) (*PushSubscription, error) { func (c *Client) GetPushSubscription() (*PushSubscription, error) {
var subscription PushSubscription var subscription PushSubscription
err := c.doAPI(ctx, http.MethodGet, "/api/v1/push/subscription", nil, &subscription, nil) err := c.doAPI(http.MethodGet, "/api/v1/push/subscription", nil, &subscription, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -1,7 +1,6 @@
package mastodon package mastodon
import ( import (
"context"
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
@ -29,9 +28,9 @@ type PollOption struct {
} }
// GetPoll returns 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(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(http.MethodGet, fmt.Sprintf("/api/v1/polls/%s", id), nil, &poll, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -39,14 +38,14 @@ func (c *Client) GetPoll(ctx context.Context, id ID) (*Poll, error) {
} }
// PollVote votes on a poll specified by id, choices is the Poll.Options index to vote on // PollVote votes on a poll specified by id, choices is the Poll.Options index to vote on
func (c *Client) PollVote(ctx context.Context, id ID, choices ...int) (*Poll, error) { func (c *Client) PollVote(id ID, choices ...int) (*Poll, error) {
params := url.Values{} params := url.Values{}
for _, c := range choices { for _, c := range choices {
params.Add("choices[]", fmt.Sprintf("%d", c)) params.Add("choices[]", fmt.Sprintf("%d", c))
} }
var poll Poll var poll Poll
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/polls/%s/votes", url.PathEscape(string(id))), params, &poll, nil) err := c.doAPI(http.MethodPost, fmt.Sprintf("/api/v1/polls/%s/votes", url.PathEscape(string(id))), params, &poll, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -1,7 +1,6 @@
package mastodon package mastodon
import ( import (
"context"
"net/http" "net/http"
"net/url" "net/url"
) )
@ -13,9 +12,9 @@ type Report struct {
} }
// GetReports returns 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() ([]*Report, error) {
var reports []*Report var reports []*Report
err := c.doAPI(ctx, http.MethodGet, "/api/v1/reports", nil, &reports, nil) err := c.doAPI(http.MethodGet, "/api/v1/reports", nil, &reports, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -23,7 +22,7 @@ func (c *Client) GetReports(ctx context.Context) ([]*Report, error) {
} }
// Report reports the report // Report reports the report
func (c *Client) Report(ctx context.Context, accountID ID, ids []ID, comment string) (*Report, error) { func (c *Client) Report(accountID ID, ids []ID, comment string) (*Report, error) {
params := url.Values{} params := url.Values{}
params.Set("account_id", string(accountID)) params.Set("account_id", string(accountID))
for _, id := range ids { for _, id := range ids {
@ -31,7 +30,7 @@ func (c *Client) Report(ctx context.Context, accountID ID, ids []ID, comment str
} }
params.Set("comment", comment) params.Set("comment", comment)
var report Report var report Report
err := c.doAPI(ctx, http.MethodPost, "/api/v1/reports", params, &report, nil) err := c.doAPI(http.MethodPost, "/api/v1/reports", params, &report, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }

117
status.go
View File

@ -2,7 +2,6 @@ package mastodon
import ( import (
"bytes" "bytes"
"context"
"fmt" "fmt"
"io" "io"
"mime/multipart" "mime/multipart"
@ -141,9 +140,9 @@ func (m *Media) bodyAndContentType() (io.Reader, string, error) {
} }
// GetFavourites returns 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(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(http.MethodGet, "/api/v1/favourites", nil, &statuses, pg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -151,9 +150,9 @@ func (c *Client) GetFavourites(ctx context.Context, pg *Pagination) ([]*Status,
} }
// GetBookmarks returns 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(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(http.MethodGet, "/api/v1/bookmarks", nil, &statuses, pg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -161,9 +160,9 @@ func (c *Client) GetBookmarks(ctx context.Context, pg *Pagination) ([]*Status, e
} }
// GetStatus returns 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(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(http.MethodGet, fmt.Sprintf("/api/v1/statuses/%s", id), nil, &status, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -171,9 +170,9 @@ func (c *Client) GetStatus(ctx context.Context, id ID) (*Status, error) {
} }
// GetStatusContext returns 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(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(http.MethodGet, fmt.Sprintf("/api/v1/statuses/%s/context", id), nil, &context, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -181,9 +180,9 @@ func (c *Client) GetStatusContext(ctx context.Context, id ID) (*Context, error)
} }
// GetStatusCard returns 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(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(http.MethodGet, fmt.Sprintf("/api/v1/statuses/%s/card", id), nil, &card, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -191,9 +190,9 @@ func (c *Client) GetStatusCard(ctx context.Context, id ID) (*Card, error) {
} }
// GetRebloggedBy returns the account list of the user who reblogged the toot of id. // GetRebloggedBy returns the account list of the user who reblogged the toot of id.
func (c *Client) GetRebloggedBy(ctx context.Context, id ID, pg *Pagination) ([]*Account, error) { func (c *Client) GetRebloggedBy(id ID, pg *Pagination) ([]*Account, error) {
var accounts []*Account var accounts []*Account
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%s/reblogged_by", id), nil, &accounts, pg) err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/statuses/%s/reblogged_by", id), nil, &accounts, pg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -201,9 +200,9 @@ func (c *Client) GetRebloggedBy(ctx context.Context, id ID, pg *Pagination) ([]*
} }
// GetFavouritedBy returns the account list of the user who liked the toot of id. // GetFavouritedBy returns the account list of the user who liked the toot of id.
func (c *Client) GetFavouritedBy(ctx context.Context, id ID, pg *Pagination) ([]*Account, error) { func (c *Client) GetFavouritedBy(id ID, pg *Pagination) ([]*Account, error) {
var accounts []*Account var accounts []*Account
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%s/favourited_by", id), nil, &accounts, pg) err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/statuses/%s/favourited_by", id), nil, &accounts, pg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -211,9 +210,9 @@ func (c *Client) GetFavouritedBy(ctx context.Context, id ID, pg *Pagination) ([]
} }
// Reblog reblogs the toot of id and returns 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(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(http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/reblog", id), nil, &status, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -221,9 +220,9 @@ func (c *Client) Reblog(ctx context.Context, id ID) (*Status, error) {
} }
// Unreblog unreblogs the toot of id and returns 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(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(http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/unreblog", id), nil, &status, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -231,9 +230,9 @@ func (c *Client) Unreblog(ctx context.Context, id ID) (*Status, error) {
} }
// Favourite favourites the toot of id and returns 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(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(http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/favourite", id), nil, &status, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -241,9 +240,9 @@ func (c *Client) Favourite(ctx context.Context, id ID) (*Status, error) {
} }
// Unfavourite unfavourites the toot of id and returns 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(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(http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/unfavourite", id), nil, &status, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -251,9 +250,9 @@ func (c *Client) Unfavourite(ctx context.Context, id ID) (*Status, error) {
} }
// Bookmark bookmarks the toot of id and returns 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(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(http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/bookmark", id), nil, &status, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -261,9 +260,9 @@ func (c *Client) Bookmark(ctx context.Context, id ID) (*Status, error) {
} }
// Unbookmark is unbookmark the toot of id and return status of the unbookmark toot. // Unbookmark is unbookmark the toot of id and return status of the unbookmark toot.
func (c *Client) Unbookmark(ctx context.Context, id ID) (*Status, error) { func (c *Client) Unbookmark(id ID) (*Status, error) {
var status Status var status Status
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/unbookmark", id), nil, &status, nil) err := c.doAPI(http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/unbookmark", id), nil, &status, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -271,9 +270,9 @@ func (c *Client) Unbookmark(ctx context.Context, id ID) (*Status, error) {
} }
// GetTimelineHome return statuses from home timeline. // GetTimelineHome return statuses from home timeline.
func (c *Client) GetTimelineHome(ctx context.Context, pg *Pagination) ([]*Status, error) { func (c *Client) GetTimelineHome(pg *Pagination) ([]*Status, error) {
var statuses []*Status var statuses []*Status
err := c.doAPI(ctx, http.MethodGet, "/api/v1/timelines/home", nil, &statuses, pg) err := c.doAPI(http.MethodGet, "/api/v1/timelines/home", nil, &statuses, pg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -281,14 +280,14 @@ func (c *Client) GetTimelineHome(ctx context.Context, pg *Pagination) ([]*Status
} }
// GetTimelinePublic return statuses from public timeline. // GetTimelinePublic return statuses from public timeline.
func (c *Client) GetTimelinePublic(ctx context.Context, isLocal bool, pg *Pagination) ([]*Status, error) { func (c *Client) GetTimelinePublic(isLocal bool, pg *Pagination) ([]*Status, error) {
params := url.Values{} params := url.Values{}
if isLocal { if isLocal {
params.Set("local", "t") params.Set("local", "t")
} }
var statuses []*Status var statuses []*Status
err := c.doAPI(ctx, http.MethodGet, "/api/v1/timelines/public", params, &statuses, pg) err := c.doAPI(http.MethodGet, "/api/v1/timelines/public", params, &statuses, pg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -296,14 +295,14 @@ func (c *Client) GetTimelinePublic(ctx context.Context, isLocal bool, pg *Pagina
} }
// GetTimelineHashtag return statuses from tagged timeline. // GetTimelineHashtag return statuses from tagged timeline.
func (c *Client) GetTimelineHashtag(ctx context.Context, tag string, isLocal bool, pg *Pagination) ([]*Status, error) { func (c *Client) GetTimelineHashtag(tag string, isLocal bool, pg *Pagination) ([]*Status, error) {
params := url.Values{} params := url.Values{}
if isLocal { if isLocal {
params.Set("local", "t") params.Set("local", "t")
} }
var statuses []*Status var statuses []*Status
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/timelines/tag/%s", url.PathEscape(tag)), params, &statuses, pg) err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/timelines/tag/%s", url.PathEscape(tag)), params, &statuses, pg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -311,9 +310,9 @@ func (c *Client) GetTimelineHashtag(ctx context.Context, tag string, isLocal boo
} }
// GetTimelineList return statuses from a list timeline. // GetTimelineList return statuses from a list timeline.
func (c *Client) GetTimelineList(ctx context.Context, id ID, pg *Pagination) ([]*Status, error) { func (c *Client) GetTimelineList(id ID, pg *Pagination) ([]*Status, error) {
var statuses []*Status var statuses []*Status
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/timelines/list/%s", url.PathEscape(string(id))), nil, &statuses, pg) err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/timelines/list/%s", url.PathEscape(string(id))), nil, &statuses, pg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -322,7 +321,7 @@ func (c *Client) GetTimelineList(ctx context.Context, id ID, pg *Pagination) ([]
// GetTimelineMedia return statuses from media timeline. // GetTimelineMedia return statuses from media timeline.
// NOTE: This is an experimental feature of pawoo.net. // NOTE: This is an experimental feature of pawoo.net.
func (c *Client) GetTimelineMedia(ctx context.Context, isLocal bool, pg *Pagination) ([]*Status, error) { func (c *Client) GetTimelineMedia(isLocal bool, pg *Pagination) ([]*Status, error) {
params := url.Values{} params := url.Values{}
params.Set("media", "t") params.Set("media", "t")
if isLocal { if isLocal {
@ -330,7 +329,7 @@ func (c *Client) GetTimelineMedia(ctx context.Context, isLocal bool, pg *Paginat
} }
var statuses []*Status var statuses []*Status
err := c.doAPI(ctx, http.MethodGet, "/api/v1/timelines/public", params, &statuses, pg) err := c.doAPI(http.MethodGet, "/api/v1/timelines/public", params, &statuses, pg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -338,7 +337,7 @@ func (c *Client) GetTimelineMedia(ctx context.Context, isLocal bool, pg *Paginat
} }
// PostStatus post the toot. // PostStatus post the toot.
func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) { func (c *Client) PostStatus(toot *Toot) (*Status, error) {
params := url.Values{} params := url.Values{}
params.Set("status", toot.Status) params.Set("status", toot.Status)
if toot.InReplyToID != "" { if toot.InReplyToID != "" {
@ -376,7 +375,7 @@ func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) {
} }
var status Status var status Status
err := c.doAPI(ctx, http.MethodPost, "/api/v1/statuses", params, &status, nil) err := c.doAPI(http.MethodPost, "/api/v1/statuses", params, &status, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -384,17 +383,17 @@ func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) {
} }
// DeleteStatus delete the toot. // DeleteStatus delete the toot.
func (c *Client) DeleteStatus(ctx context.Context, id ID) error { func (c *Client) DeleteStatus(id ID) error {
return c.doAPI(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/statuses/%s", id), nil, nil, nil) return c.doAPI(http.MethodDelete, fmt.Sprintf("/api/v1/statuses/%s", id), nil, nil, nil)
} }
// Search search content with query. // Search search content with query.
func (c *Client) Search(ctx context.Context, q string, resolve bool) (*Results, error) { func (c *Client) Search(q string, resolve bool) (*Results, error) {
params := url.Values{} params := url.Values{}
params.Set("q", q) params.Set("q", q)
params.Set("resolve", fmt.Sprint(resolve)) params.Set("resolve", fmt.Sprint(resolve))
var results Results var results Results
err := c.doAPI(ctx, http.MethodGet, "/api/v2/search", params, &results, nil) err := c.doAPI(http.MethodGet, "/api/v2/search", params, &results, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -402,41 +401,41 @@ func (c *Client) Search(ctx context.Context, q string, resolve bool) (*Results,
} }
// UploadMedia upload a media attachment from a file. // UploadMedia upload a media attachment from a file.
func (c *Client) UploadMedia(ctx context.Context, file string) (*Attachment, error) { func (c *Client) UploadMedia(file string) (*Attachment, error) {
f, err := os.Open(file) f, err := os.Open(file)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer f.Close() defer f.Close()
return c.UploadMediaFromMedia(ctx, &Media{File: f}) return c.UploadMediaFromMedia(&Media{File: f})
} }
// UploadMediaFromBytes uploads a media attachment from a byte slice. // UploadMediaFromBytes uploads a media attachment from a byte slice.
func (c *Client) UploadMediaFromBytes(ctx context.Context, b []byte) (*Attachment, error) { func (c *Client) UploadMediaFromBytes(b []byte) (*Attachment, error) {
return c.UploadMediaFromReader(ctx, bytes.NewReader(b)) return c.UploadMediaFromReader(bytes.NewReader(b))
} }
// UploadMediaFromReader uploads a media attachment from an io.Reader. // UploadMediaFromReader uploads a media attachment from an io.Reader.
func (c *Client) UploadMediaFromReader(ctx context.Context, reader io.Reader) (*Attachment, error) { func (c *Client) UploadMediaFromReader(reader io.Reader) (*Attachment, error) {
return c.UploadMediaFromMedia(ctx, &Media{File: reader}) return c.UploadMediaFromMedia(&Media{File: reader})
} }
// UploadMediaFromMedia uploads a media attachment from a Media struct. // UploadMediaFromMedia uploads a media attachment from a Media struct.
func (c *Client) UploadMediaFromMedia(ctx context.Context, media *Media) (*Attachment, error) { func (c *Client) UploadMediaFromMedia(media *Media) (*Attachment, error) {
var attachment Attachment var attachment Attachment
if err := c.doAPI(ctx, http.MethodPost, "/api/v1/media", media, &attachment, nil); err != nil { if err := c.doAPI(http.MethodPost, "/api/v1/media", media, &attachment, nil); err != nil {
return nil, err return nil, err
} }
return &attachment, nil return &attachment, nil
} }
// GetTimelineDirect return statuses from direct timeline. // GetTimelineDirect return statuses from direct timeline.
func (c *Client) GetTimelineDirect(ctx context.Context, pg *Pagination) ([]*Status, error) { func (c *Client) GetTimelineDirect(pg *Pagination) ([]*Status, error) {
params := url.Values{} params := url.Values{}
var conversations []*Conversation var conversations []*Conversation
err := c.doAPI(ctx, http.MethodGet, "/api/v1/conversations", params, &conversations, pg) err := c.doAPI(http.MethodGet, "/api/v1/conversations", params, &conversations, pg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -452,11 +451,11 @@ func (c *Client) GetTimelineDirect(ctx context.Context, pg *Pagination) ([]*Stat
} }
// GetConversations return direct conversations. // GetConversations return direct conversations.
func (c *Client) GetConversations(ctx context.Context, pg *Pagination) ([]*Conversation, error) { func (c *Client) GetConversations(pg *Pagination) ([]*Conversation, error) {
params := url.Values{} params := url.Values{}
var conversations []*Conversation var conversations []*Conversation
err := c.doAPI(ctx, http.MethodGet, "/api/v1/conversations", params, &conversations, pg) err := c.doAPI(http.MethodGet, "/api/v1/conversations", params, &conversations, pg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -464,11 +463,11 @@ func (c *Client) GetConversations(ctx context.Context, pg *Pagination) ([]*Conve
} }
// DeleteConversation delete the conversation specified by id. // DeleteConversation delete the conversation specified by id.
func (c *Client) DeleteConversation(ctx context.Context, id ID) error { func (c *Client) DeleteConversation(id ID) error {
return c.doAPI(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/conversations/%s", id), nil, nil, nil) return c.doAPI(http.MethodDelete, fmt.Sprintf("/api/v1/conversations/%s", id), nil, nil, nil)
} }
// MarkConversationAsRead mark the conversation as read. // MarkConversationAsRead mark the conversation as read.
func (c *Client) MarkConversationAsRead(ctx context.Context, id ID) error { func (c *Client) MarkConversationAsRead(id ID) error {
return c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/conversations/%s/read", id), nil, nil, nil) return c.doAPI(http.MethodPost, fmt.Sprintf("/api/v1/conversations/%s/read", id), nil, nil, nil)
} }