Fix to not return *Pagination
parent
dd0b467062
commit
134128cb56
78
accounts.go
78
accounts.go
|
@ -30,7 +30,7 @@ type Account struct {
|
|||
// GetAccount return Account.
|
||||
func (c *Client) GetAccount(ctx context.Context, id int) (*Account, error) {
|
||||
var account Account
|
||||
_, err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%d", id), nil, &account, nil)
|
||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%d", id), nil, &account, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ func (c *Client) GetAccount(ctx context.Context, id int) (*Account, error) {
|
|||
// GetAccountCurrentUser return Account of current user.
|
||||
func (c *Client) GetAccountCurrentUser(ctx context.Context) (*Account, error) {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ func (c *Client) AccountUpdate(ctx context.Context, profile *Profile) (*Account,
|
|||
}
|
||||
|
||||
var account Account
|
||||
_, err := c.doAPI(ctx, http.MethodPatch, "/api/v1/accounts/update_credentials", params, &account, nil)
|
||||
err := c.doAPI(ctx, http.MethodPatch, "/api/v1/accounts/update_credentials", params, &account, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -84,43 +84,43 @@ func (c *Client) AccountUpdate(ctx context.Context, profile *Profile) (*Account,
|
|||
}
|
||||
|
||||
// GetAccountStatuses return statuses by specified accuont.
|
||||
func (c *Client) GetAccountStatuses(ctx context.Context, id int64, pg *Pagination) ([]*Status, *Pagination, error) {
|
||||
func (c *Client) GetAccountStatuses(ctx context.Context, id int64, pg *Pagination) ([]*Status, error) {
|
||||
var statuses []*Status
|
||||
retPG, err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%d/statuses", id), nil, &statuses, pg)
|
||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%d/statuses", id), nil, &statuses, pg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
return statuses, retPG, nil
|
||||
return statuses, nil
|
||||
}
|
||||
|
||||
// GetAccountFollowers return followers list.
|
||||
func (c *Client) GetAccountFollowers(ctx context.Context, id int64, pg *Pagination) ([]*Account, *Pagination, error) {
|
||||
func (c *Client) GetAccountFollowers(ctx context.Context, id int64, pg *Pagination) ([]*Account, error) {
|
||||
var accounts []*Account
|
||||
retPG, err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%d/followers", id), nil, &accounts, pg)
|
||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%d/followers", id), nil, &accounts, pg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
return accounts, retPG, nil
|
||||
return accounts, nil
|
||||
}
|
||||
|
||||
// GetAccountFollowing return following list.
|
||||
func (c *Client) GetAccountFollowing(ctx context.Context, id int64, pg *Pagination) ([]*Account, *Pagination, error) {
|
||||
func (c *Client) GetAccountFollowing(ctx context.Context, id int64, pg *Pagination) ([]*Account, error) {
|
||||
var accounts []*Account
|
||||
retPG, err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%d/following", id), nil, &accounts, pg)
|
||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%d/following", id), nil, &accounts, pg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
return accounts, retPG, nil
|
||||
return accounts, nil
|
||||
}
|
||||
|
||||
// GetBlocks return block list.
|
||||
func (c *Client) GetBlocks(ctx context.Context, pg *Pagination) ([]*Account, *Pagination, error) {
|
||||
func (c *Client) GetBlocks(ctx context.Context, pg *Pagination) ([]*Account, error) {
|
||||
var accounts []*Account
|
||||
retPG, err := c.doAPI(ctx, http.MethodGet, "/api/v1/blocks", nil, &accounts, pg)
|
||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/blocks", nil, &accounts, pg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
return accounts, retPG, nil
|
||||
return accounts, nil
|
||||
}
|
||||
|
||||
// Relationship hold information for relation-ship to the account.
|
||||
|
@ -136,7 +136,7 @@ type Relationship struct {
|
|||
// AccountFollow follow the account.
|
||||
func (c *Client) AccountFollow(ctx context.Context, id int64) (*Relationship, error) {
|
||||
var relationship Relationship
|
||||
_, err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/follow", id), nil, &relationship, nil)
|
||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/follow", id), nil, &relationship, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ func (c *Client) AccountFollow(ctx context.Context, id int64) (*Relationship, er
|
|||
// AccountUnfollow unfollow the account.
|
||||
func (c *Client) AccountUnfollow(ctx context.Context, id int64) (*Relationship, error) {
|
||||
var relationship Relationship
|
||||
_, err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/unfollow", id), nil, &relationship, nil)
|
||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/unfollow", id), nil, &relationship, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ func (c *Client) AccountUnfollow(ctx context.Context, id int64) (*Relationship,
|
|||
// AccountBlock block the account.
|
||||
func (c *Client) AccountBlock(ctx context.Context, id int64) (*Relationship, error) {
|
||||
var relationship Relationship
|
||||
_, err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/block", id), nil, &relationship, nil)
|
||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/block", id), nil, &relationship, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ func (c *Client) AccountBlock(ctx context.Context, id int64) (*Relationship, err
|
|||
// AccountUnblock unblock the account.
|
||||
func (c *Client) AccountUnblock(ctx context.Context, id int64) (*Relationship, error) {
|
||||
var relationship Relationship
|
||||
_, err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/unblock", id), nil, &relationship, nil)
|
||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/unblock", id), nil, &relationship, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ func (c *Client) AccountUnblock(ctx context.Context, id int64) (*Relationship, e
|
|||
// AccountMute mute the account.
|
||||
func (c *Client) AccountMute(ctx context.Context, id int64) (*Relationship, error) {
|
||||
var relationship Relationship
|
||||
_, err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/mute", id), nil, &relationship, nil)
|
||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/mute", id), nil, &relationship, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ func (c *Client) AccountMute(ctx context.Context, id int64) (*Relationship, erro
|
|||
// AccountUnmute unmute the account.
|
||||
func (c *Client) AccountUnmute(ctx context.Context, id int64) (*Relationship, error) {
|
||||
var relationship Relationship
|
||||
_, err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/unmute", id), nil, &relationship, nil)
|
||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/unmute", id), nil, &relationship, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ func (c *Client) GetAccountRelationships(ctx context.Context, ids []int64) ([]*R
|
|||
}
|
||||
|
||||
var relationships []*Relationship
|
||||
_, err := c.doAPI(ctx, http.MethodGet, "/api/v1/accounts/relationships", params, &relationships, nil)
|
||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/accounts/relationships", params, &relationships, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ func (c *Client) AccountsSearch(ctx context.Context, q string, limit int64) ([]*
|
|||
params.Set("limit", fmt.Sprint(limit))
|
||||
|
||||
var accounts []*Account
|
||||
_, err := c.doAPI(ctx, http.MethodGet, "/api/v1/accounts/search", params, &accounts, nil)
|
||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/accounts/search", params, &accounts, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ func (c *Client) FollowRemoteUser(ctx context.Context, uri string) (*Account, er
|
|||
params.Set("uri", uri)
|
||||
|
||||
var account Account
|
||||
_, err := c.doAPI(ctx, http.MethodPost, "/api/v1/follows", params, &account, nil)
|
||||
err := c.doAPI(ctx, http.MethodPost, "/api/v1/follows", params, &account, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -236,33 +236,31 @@ func (c *Client) FollowRemoteUser(ctx context.Context, uri string) (*Account, er
|
|||
}
|
||||
|
||||
// GetFollowRequests return follow-requests.
|
||||
func (c *Client) GetFollowRequests(ctx context.Context, pg *Pagination) ([]*Account, *Pagination, error) {
|
||||
func (c *Client) GetFollowRequests(ctx context.Context, pg *Pagination) ([]*Account, error) {
|
||||
var accounts []*Account
|
||||
retPG, 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)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
return accounts, retPG, nil
|
||||
return accounts, nil
|
||||
}
|
||||
|
||||
// FollowRequestAuthorize is authorize the follow request of user with id.
|
||||
func (c *Client) FollowRequestAuthorize(ctx context.Context, id int64) error {
|
||||
_, err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/follow_requests/%d/authorize", id), nil, nil, nil)
|
||||
return err
|
||||
return c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/follow_requests/%d/authorize", id), nil, nil, nil)
|
||||
}
|
||||
|
||||
// FollowRequestReject is rejects the follow request of user with id.
|
||||
func (c *Client) FollowRequestReject(ctx context.Context, id int64) error {
|
||||
_, err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/follow_requests/%d/reject", id), nil, nil, nil)
|
||||
return err
|
||||
return c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/follow_requests/%d/reject", id), nil, nil, nil)
|
||||
}
|
||||
|
||||
// GetMutes returns the list of users muted by the current user.
|
||||
func (c *Client) GetMutes(ctx context.Context, pg *Pagination) ([]*Account, *Pagination, error) {
|
||||
func (c *Client) GetMutes(ctx context.Context, pg *Pagination) ([]*Account, error) {
|
||||
var accounts []*Account
|
||||
retPG, err := c.doAPI(ctx, http.MethodGet, "/api/v1/mutes", nil, &accounts, pg)
|
||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/mutes", nil, &accounts, pg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
return accounts, retPG, nil
|
||||
return accounts, nil
|
||||
}
|
||||
|
|
|
@ -124,11 +124,11 @@ func TestGetAccountStatuses(t *testing.T) {
|
|||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
_, _, err := client.GetAccountStatuses(context.Background(), 123, nil)
|
||||
_, err := client.GetAccountStatuses(context.Background(), 123, nil)
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
ss, _, err := client.GetAccountStatuses(context.Background(), 1234567, nil)
|
||||
ss, err := client.GetAccountStatuses(context.Background(), 1234567, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
|
@ -157,11 +157,11 @@ func TestGetAccountFollowers(t *testing.T) {
|
|||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
_, _, err := client.GetAccountFollowers(context.Background(), 123, nil)
|
||||
_, err := client.GetAccountFollowers(context.Background(), 123, nil)
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
fl, _, err := client.GetAccountFollowers(context.Background(), 1234567, nil)
|
||||
fl, err := client.GetAccountFollowers(context.Background(), 1234567, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
|
@ -193,11 +193,11 @@ func TestGetAccountFollowing(t *testing.T) {
|
|||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
_, _, err := client.GetAccountFollowing(context.Background(), 123, nil)
|
||||
_, err := client.GetAccountFollowing(context.Background(), 123, nil)
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
fl, _, err := client.GetAccountFollowing(context.Background(), 1234567, nil)
|
||||
fl, err := client.GetAccountFollowing(context.Background(), 1234567, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
|
@ -231,11 +231,11 @@ func TestGetBlocks(t *testing.T) {
|
|||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
_, _, err := client.GetBlocks(context.Background(), nil)
|
||||
_, err := client.GetBlocks(context.Background(), nil)
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
bl, _, err := client.GetBlocks(context.Background(), nil)
|
||||
bl, err := client.GetBlocks(context.Background(), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
|
@ -566,11 +566,11 @@ func TestGetFollowRequests(t *testing.T) {
|
|||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
_, _, err := client.GetFollowRequests(context.Background(), nil)
|
||||
_, err := client.GetFollowRequests(context.Background(), nil)
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
fReqs, _, err := client.GetFollowRequests(context.Background(), nil)
|
||||
fReqs, err := client.GetFollowRequests(context.Background(), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
|
@ -652,11 +652,11 @@ func TestGetMutes(t *testing.T) {
|
|||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
_, _, err := client.GetMutes(context.Background(), nil)
|
||||
_, err := client.GetMutes(context.Background(), nil)
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
mutes, _, err := client.GetMutes(context.Background(), nil)
|
||||
mutes, err := client.GetMutes(context.Background(), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ func ExampleClient() {
|
|||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
timeline, _, err := c.GetTimelineHome(context.Background(), nil)
|
||||
timeline, err := c.GetTimelineHome(context.Background(), nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ type Instance struct {
|
|||
// GetInstance return Instance.
|
||||
func (c *Client) GetInstance(ctx context.Context) (*Instance, error) {
|
||||
var instance Instance
|
||||
_, err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance", nil, &instance, nil)
|
||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance", nil, &instance, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
32
mastodon.go
32
mastodon.go
|
@ -33,10 +33,10 @@ type Client struct {
|
|||
config *Config
|
||||
}
|
||||
|
||||
func (c *Client) doAPI(ctx context.Context, method string, uri string, params interface{}, res interface{}, pg *Pagination) (*Pagination, error) {
|
||||
func (c *Client) doAPI(ctx context.Context, method string, uri string, params interface{}, res interface{}, pg *Pagination) error {
|
||||
u, err := url.Parse(c.config.Server)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
u.Path = path.Join(u.Path, uri)
|
||||
|
||||
|
@ -54,12 +54,12 @@ func (c *Client) doAPI(ctx context.Context, method string, uri string, params in
|
|||
}
|
||||
req, err = http.NewRequest(method, u.String(), body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
} else if file, ok := params.(string); ok {
|
||||
f, err := os.Open(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
|
@ -67,19 +67,19 @@ func (c *Client) doAPI(ctx context.Context, method string, uri string, params in
|
|||
mw := multipart.NewWriter(&buf)
|
||||
part, err := mw.CreateFormFile("file", filepath.Base(file))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
_, err = io.Copy(part, f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
err = mw.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
req, err = http.NewRequest(method, u.String(), &buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
ct = mw.FormDataContentType()
|
||||
} else {
|
||||
|
@ -88,7 +88,7 @@ func (c *Client) doAPI(ctx context.Context, method string, uri string, params in
|
|||
}
|
||||
req, err = http.NewRequest(method, u.String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
}
|
||||
req = req.WithContext(ctx)
|
||||
|
@ -99,25 +99,25 @@ func (c *Client) doAPI(ctx context.Context, method string, uri string, params in
|
|||
|
||||
resp, err := c.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
lh := resp.Header.Get("Link")
|
||||
var retPG *Pagination
|
||||
if lh != "" {
|
||||
retPG, err = newPagination(lh)
|
||||
retPG, err := newPagination(lh)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
*pg = *retPG
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, parseAPIError("bad request", resp)
|
||||
return parseAPIError("bad request", resp)
|
||||
} else if res == nil {
|
||||
return nil, nil
|
||||
return nil
|
||||
}
|
||||
return retPG, json.NewDecoder(resp.Body).Decode(&res)
|
||||
return json.NewDecoder(resp.Body).Decode(&res)
|
||||
}
|
||||
|
||||
// NewClient return new mastodon API client.
|
||||
|
|
|
@ -23,7 +23,7 @@ func TestDoAPI(t *testing.T) {
|
|||
defer ts.Close()
|
||||
|
||||
c := NewClient(&Config{Server: ts.URL})
|
||||
_, err := c.doAPI(context.Background(), http.MethodGet, "/", nil, nil, &Pagination{
|
||||
err := c.doAPI(context.Background(), http.MethodGet, "/", nil, nil, &Pagination{
|
||||
MaxID: Int64(999),
|
||||
})
|
||||
if err == nil {
|
||||
|
@ -31,11 +31,12 @@ func TestDoAPI(t *testing.T) {
|
|||
}
|
||||
|
||||
var accounts []Account
|
||||
pg, err := c.doAPI(context.Background(), http.MethodGet, "/", url.Values{}, &accounts, &Pagination{
|
||||
pg := &Pagination{
|
||||
MaxID: Int64(123),
|
||||
SinceID: Int64(789),
|
||||
Limit: Int64(10),
|
||||
})
|
||||
}
|
||||
err = c.doAPI(context.Background(), http.MethodGet, "/", url.Values{}, &accounts, pg)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
|
@ -52,11 +53,12 @@ func TestDoAPI(t *testing.T) {
|
|||
t.Fatalf("want %q but %q", "bar", accounts[1].Username)
|
||||
}
|
||||
|
||||
pg, err = c.doAPI(context.Background(), http.MethodGet, "/", nil, &accounts, &Pagination{
|
||||
pg = &Pagination{
|
||||
MaxID: Int64(123),
|
||||
SinceID: Int64(789),
|
||||
Limit: Int64(10),
|
||||
})
|
||||
}
|
||||
err = c.doAPI(context.Background(), http.MethodGet, "/", nil, &accounts, pg)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
|
@ -216,7 +218,7 @@ func TestGetTimelineHome(t *testing.T) {
|
|||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
tl, _, err := client.GetTimelineHome(context.Background(), nil)
|
||||
tl, err := client.GetTimelineHome(context.Background(), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
|
@ -246,7 +248,7 @@ func TestGetTimelineHomeWithCancel(t *testing.T) {
|
|||
})
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
_, _, err := client.GetTimelineHome(ctx, nil)
|
||||
_, err := client.GetTimelineHome(ctx, nil)
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
|
|
|
@ -17,19 +17,19 @@ type Notification struct {
|
|||
}
|
||||
|
||||
// GetNotifications return notifications.
|
||||
func (c *Client) GetNotifications(ctx context.Context, pg *Pagination) ([]*Notification, *Pagination, error) {
|
||||
func (c *Client) GetNotifications(ctx context.Context, pg *Pagination) ([]*Notification, error) {
|
||||
var notifications []*Notification
|
||||
retPG, err := c.doAPI(ctx, http.MethodGet, "/api/v1/notifications", nil, ¬ifications, pg)
|
||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/notifications", nil, ¬ifications, pg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
return notifications, retPG, nil
|
||||
return notifications, nil
|
||||
}
|
||||
|
||||
// GetNotification return notification.
|
||||
func (c *Client) GetNotification(ctx context.Context, id int64) (*Notification, error) {
|
||||
var notification Notification
|
||||
_, err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/notifications/%d", id), nil, ¬ification, nil)
|
||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/notifications/%d", id), nil, ¬ification, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -38,6 +38,5 @@ func (c *Client) GetNotification(ctx context.Context, id int64) (*Notification,
|
|||
|
||||
// ClearNotifications clear notifications.
|
||||
func (c *Client) ClearNotifications(ctx context.Context) error {
|
||||
_, err := c.doAPI(ctx, http.MethodPost, "/api/v1/notifications/clear", nil, nil, nil)
|
||||
return err
|
||||
return c.doAPI(ctx, http.MethodPost, "/api/v1/notifications/clear", nil, nil, nil)
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ func TestGetNotifications(t *testing.T) {
|
|||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
ns, _, err := client.GetNotifications(context.Background(), nil)
|
||||
ns, err := client.GetNotifications(context.Background(), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ type Report struct {
|
|||
// GetReports return report of the current user.
|
||||
func (c *Client) GetReports(ctx context.Context) ([]*Report, error) {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ func (c *Client) Report(ctx context.Context, accountID int64, ids []int64, comme
|
|||
}
|
||||
params.Set("comment", comment)
|
||||
var report Report
|
||||
_, err := c.doAPI(ctx, http.MethodPost, "/api/v1/reports", params, &report, nil)
|
||||
err := c.doAPI(ctx, http.MethodPost, "/api/v1/reports", params, &report, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
79
status.go
79
status.go
|
@ -48,19 +48,19 @@ type Card struct {
|
|||
}
|
||||
|
||||
// GetFavourites return the favorite list of the current user.
|
||||
func (c *Client) GetFavourites(ctx context.Context, pg *Pagination) ([]*Status, *Pagination, error) {
|
||||
func (c *Client) GetFavourites(ctx context.Context, pg *Pagination) ([]*Status, error) {
|
||||
var statuses []*Status
|
||||
retPG, err := c.doAPI(ctx, http.MethodGet, "/api/v1/favourites", nil, &statuses, pg)
|
||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/favourites", nil, &statuses, pg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
return statuses, retPG, nil
|
||||
return statuses, nil
|
||||
}
|
||||
|
||||
// GetStatus return status specified by id.
|
||||
func (c *Client) GetStatus(ctx context.Context, id int64) (*Status, error) {
|
||||
var status Status
|
||||
_, err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%d", id), nil, &status, nil)
|
||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%d", id), nil, &status, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ func (c *Client) GetStatus(ctx context.Context, id int64) (*Status, error) {
|
|||
// GetStatusContext return status specified by id.
|
||||
func (c *Client) GetStatusContext(ctx context.Context, id int64) (*Context, error) {
|
||||
var context Context
|
||||
_, err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%d/context", id), nil, &context, nil)
|
||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%d/context", id), nil, &context, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ func (c *Client) GetStatusContext(ctx context.Context, id int64) (*Context, erro
|
|||
// GetStatusCard return status specified by id.
|
||||
func (c *Client) GetStatusCard(ctx context.Context, id int64) (*Card, error) {
|
||||
var card Card
|
||||
_, err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%d/card", id), nil, &card, nil)
|
||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%d/card", id), nil, &card, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -88,29 +88,29 @@ func (c *Client) GetStatusCard(ctx context.Context, id int64) (*Card, error) {
|
|||
}
|
||||
|
||||
// GetRebloggedBy returns the account list of the user who reblogged the toot of id.
|
||||
func (c *Client) GetRebloggedBy(ctx context.Context, id int64, pg *Pagination) ([]*Account, *Pagination, error) {
|
||||
func (c *Client) GetRebloggedBy(ctx context.Context, id int64, pg *Pagination) ([]*Account, error) {
|
||||
var accounts []*Account
|
||||
retPG, err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%d/reblogged_by", id), nil, &accounts, pg)
|
||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%d/reblogged_by", id), nil, &accounts, pg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
return accounts, retPG, nil
|
||||
return accounts, nil
|
||||
}
|
||||
|
||||
// GetFavouritedBy returns the account list of the user who liked the toot of id.
|
||||
func (c *Client) GetFavouritedBy(ctx context.Context, id int64, pg *Pagination) ([]*Account, *Pagination, error) {
|
||||
func (c *Client) GetFavouritedBy(ctx context.Context, id int64, pg *Pagination) ([]*Account, error) {
|
||||
var accounts []*Account
|
||||
retPG, err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%d/favourited_by", id), nil, &accounts, pg)
|
||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%d/favourited_by", id), nil, &accounts, pg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
return accounts, retPG, nil
|
||||
return accounts, nil
|
||||
}
|
||||
|
||||
// Reblog is reblog the toot of id and return status of reblog.
|
||||
func (c *Client) Reblog(ctx context.Context, id int64) (*Status, error) {
|
||||
var status Status
|
||||
_, err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%d/reblog", id), nil, &status, nil)
|
||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%d/reblog", id), nil, &status, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ func (c *Client) Reblog(ctx context.Context, id int64) (*Status, error) {
|
|||
// Unreblog is unreblog the toot of id and return status of the original toot.
|
||||
func (c *Client) Unreblog(ctx context.Context, id int64) (*Status, error) {
|
||||
var status Status
|
||||
_, err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%d/unreblog", id), nil, &status, nil)
|
||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%d/unreblog", id), nil, &status, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ func (c *Client) Unreblog(ctx context.Context, id int64) (*Status, error) {
|
|||
// Favourite is favourite the toot of id and return status of the favourite toot.
|
||||
func (c *Client) Favourite(ctx context.Context, id int64) (*Status, error) {
|
||||
var status Status
|
||||
_, err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%d/favourite", id), nil, &status, nil)
|
||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%d/favourite", id), nil, &status, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ func (c *Client) Favourite(ctx context.Context, id int64) (*Status, error) {
|
|||
// Unfavourite is unfavourite the toot of id and return status of the unfavourite toot.
|
||||
func (c *Client) Unfavourite(ctx context.Context, id int64) (*Status, error) {
|
||||
var status Status
|
||||
_, err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%d/unfavourite", id), nil, &status, nil)
|
||||
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%d/unfavourite", id), nil, &status, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -148,48 +148,48 @@ func (c *Client) Unfavourite(ctx context.Context, id int64) (*Status, error) {
|
|||
}
|
||||
|
||||
// GetTimelineHome return statuses from home timeline.
|
||||
func (c *Client) GetTimelineHome(ctx context.Context, pg *Pagination) ([]*Status, *Pagination, error) {
|
||||
func (c *Client) GetTimelineHome(ctx context.Context, pg *Pagination) ([]*Status, error) {
|
||||
var statuses []*Status
|
||||
retPG, err := c.doAPI(ctx, http.MethodGet, "/api/v1/timelines/home", nil, &statuses, pg)
|
||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/timelines/home", nil, &statuses, pg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
return statuses, retPG, nil
|
||||
return statuses, nil
|
||||
}
|
||||
|
||||
// GetTimelinePublic return statuses from public timeline.
|
||||
func (c *Client) GetTimelinePublic(ctx context.Context, isLocal bool, pg *Pagination) ([]*Status, *Pagination, error) {
|
||||
func (c *Client) GetTimelinePublic(ctx context.Context, isLocal bool, pg *Pagination) ([]*Status, error) {
|
||||
params := url.Values{}
|
||||
if isLocal {
|
||||
params.Set("local", "t")
|
||||
}
|
||||
|
||||
var statuses []*Status
|
||||
retPG, err := c.doAPI(ctx, http.MethodGet, "/api/v1/timelines/public", params, &statuses, pg)
|
||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/timelines/public", params, &statuses, pg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
return statuses, retPG, nil
|
||||
return statuses, nil
|
||||
}
|
||||
|
||||
// GetTimelineHashtag return statuses from tagged timeline.
|
||||
func (c *Client) GetTimelineHashtag(ctx context.Context, tag string, isLocal bool, pg *Pagination) ([]*Status, *Pagination, error) {
|
||||
func (c *Client) GetTimelineHashtag(ctx context.Context, tag string, isLocal bool, pg *Pagination) ([]*Status, error) {
|
||||
params := url.Values{}
|
||||
if isLocal {
|
||||
params.Set("local", "t")
|
||||
}
|
||||
|
||||
var statuses []*Status
|
||||
retPG, err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/timelines/tag/%s", url.PathEscape(tag)), params, &statuses, pg)
|
||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/timelines/tag/%s", url.PathEscape(tag)), params, &statuses, pg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
return statuses, retPG, nil
|
||||
return statuses, nil
|
||||
}
|
||||
|
||||
// GetTimelineMedia return statuses from media timeline.
|
||||
// NOTE: This is an experimental feature of pawoo.net.
|
||||
func (c *Client) GetTimelineMedia(ctx context.Context, isLocal bool, pg *Pagination) ([]*Status, *Pagination, error) {
|
||||
func (c *Client) GetTimelineMedia(ctx context.Context, isLocal bool, pg *Pagination) ([]*Status, error) {
|
||||
params := url.Values{}
|
||||
params.Set("media", "t")
|
||||
if isLocal {
|
||||
|
@ -197,11 +197,11 @@ func (c *Client) GetTimelineMedia(ctx context.Context, isLocal bool, pg *Paginat
|
|||
}
|
||||
|
||||
var statuses []*Status
|
||||
retPG, err := c.doAPI(ctx, http.MethodGet, "/api/v1/timelines/public", params, &statuses, pg)
|
||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/timelines/public", params, &statuses, pg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
return statuses, retPG, nil
|
||||
return statuses, nil
|
||||
}
|
||||
|
||||
// PostStatus post the toot.
|
||||
|
@ -227,7 +227,7 @@ func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) {
|
|||
}
|
||||
|
||||
var status Status
|
||||
_, err := c.doAPI(ctx, http.MethodPost, "/api/v1/statuses", params, &status, nil)
|
||||
err := c.doAPI(ctx, http.MethodPost, "/api/v1/statuses", params, &status, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -236,8 +236,7 @@ func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) {
|
|||
|
||||
// DeleteStatus delete the toot.
|
||||
func (c *Client) DeleteStatus(ctx context.Context, id int64) error {
|
||||
_, err := c.doAPI(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/statuses/%d", id), nil, nil, nil)
|
||||
return err
|
||||
return c.doAPI(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/statuses/%d", id), nil, nil, nil)
|
||||
}
|
||||
|
||||
// Search search content with query.
|
||||
|
@ -246,7 +245,7 @@ func (c *Client) Search(ctx context.Context, q string, resolve bool) (*Results,
|
|||
params.Set("q", q)
|
||||
params.Set("resolve", fmt.Sprint(resolve))
|
||||
var results Results
|
||||
_, err := c.doAPI(ctx, http.MethodGet, "/api/v1/search", params, &results, nil)
|
||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/search", params, &results, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -256,7 +255,7 @@ func (c *Client) Search(ctx context.Context, q string, resolve bool) (*Results,
|
|||
// UploadMedia upload a media attachment.
|
||||
func (c *Client) UploadMedia(ctx context.Context, file string) (*Attachment, error) {
|
||||
var attachment Attachment
|
||||
_, err := c.doAPI(ctx, http.MethodPost, "/api/v1/media", file, &attachment, nil)
|
||||
err := c.doAPI(ctx, http.MethodPost, "/api/v1/media", file, &attachment, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ func TestGetFavourites(t *testing.T) {
|
|||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
favs, _, err := client.GetFavourites(context.Background(), nil)
|
||||
favs, err := client.GetFavourites(context.Background(), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
|
@ -152,11 +152,11 @@ func TestGetRebloggedBy(t *testing.T) {
|
|||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
_, _, err := client.GetRebloggedBy(context.Background(), 123, nil)
|
||||
_, err := client.GetRebloggedBy(context.Background(), 123, nil)
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
rbs, _, err := client.GetRebloggedBy(context.Background(), 1234567, nil)
|
||||
rbs, err := client.GetRebloggedBy(context.Background(), 1234567, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
|
@ -188,11 +188,11 @@ func TestGetFavouritedBy(t *testing.T) {
|
|||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
_, _, err := client.GetFavouritedBy(context.Background(), 123, nil)
|
||||
_, err := client.GetFavouritedBy(context.Background(), 123, nil)
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
fbs, _, err := client.GetFavouritedBy(context.Background(), 1234567, nil)
|
||||
fbs, err := client.GetFavouritedBy(context.Background(), 1234567, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
|
@ -338,11 +338,11 @@ func TestGetTimelinePublic(t *testing.T) {
|
|||
defer ts.Close()
|
||||
|
||||
client := NewClient(&Config{Server: ts.URL})
|
||||
_, _, err := client.GetTimelinePublic(context.Background(), false, nil)
|
||||
_, err := client.GetTimelinePublic(context.Background(), false, nil)
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
tl, _, err := client.GetTimelinePublic(context.Background(), true, nil)
|
||||
tl, err := client.GetTimelinePublic(context.Background(), true, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
|
@ -374,11 +374,11 @@ func TestGetTimelineHashtag(t *testing.T) {
|
|||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
_, _, err := client.GetTimelineHashtag(context.Background(), "notfound", false, nil)
|
||||
_, err := client.GetTimelineHashtag(context.Background(), "notfound", false, nil)
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
tags, _, err := client.GetTimelineHashtag(context.Background(), "zzz", true, nil)
|
||||
tags, err := client.GetTimelineHashtag(context.Background(), "zzz", true, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
|
@ -410,11 +410,11 @@ func TestGetTimelineMedia(t *testing.T) {
|
|||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
_, _, err := client.GetTimelineMedia(context.Background(), false, nil)
|
||||
_, err := client.GetTimelineMedia(context.Background(), false, nil)
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
tags, _, err := client.GetTimelineMedia(context.Background(), true, nil)
|
||||
tags, err := client.GetTimelineMedia(context.Background(), true, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue