Merge branch 'master' into resolve

pull/150/head
mattn 2022-11-30 08:15:33 +09:00 committed by GitHub
commit 18f084c012
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 155 additions and 186 deletions

View File

@ -153,8 +153,8 @@ func main() {
## Installation
```
$ go get github.com/mattn/go-mastodon
```shell
go install github.com/mattn/go-mastodon@latest
```
## License

View File

@ -9,7 +9,7 @@ import (
"time"
)
// Account hold information for mastodon account.
// Account holds information for a mastodon account.
type Account struct {
ID ID `json:"id"`
Username string `json:"username"`
@ -60,7 +60,7 @@ func (c *Client) GetAccount(ctx context.Context, id ID) (*Account, error) {
return &account, nil
}
// GetAccountCurrentUser return Account of current user.
// GetAccountCurrentUser returns the Account of current user.
func (c *Client) GetAccountCurrentUser(ctx context.Context) (*Account, error) {
var account Account
err := c.doAPI(ctx, http.MethodGet, "/api/v1/accounts/verify_credentials", nil, &account, nil)
@ -129,7 +129,7 @@ func (c *Client) AccountUpdate(ctx context.Context, profile *Profile) (*Account,
return &account, nil
}
// GetAccountStatuses return statuses by specified accuont.
// GetAccountStatuses return statuses by specified account.
func (c *Client) GetAccountStatuses(ctx context.Context, id ID, pg *Pagination) ([]*Status, error) {
var statuses []*Status
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/statuses", url.PathEscape(string(id))), nil, &statuses, pg)
@ -139,7 +139,7 @@ func (c *Client) GetAccountStatuses(ctx context.Context, id ID, pg *Pagination)
return statuses, nil
}
// GetAccountPinnedStatuses return statuses pinned by specified accuont.
// GetAccountPinnedStatuses returns statuses pinned by specified accuont.
func (c *Client) GetAccountPinnedStatuses(ctx context.Context, id ID) ([]*Status, error) {
var statuses []*Status
params := url.Values{}
@ -151,7 +151,7 @@ func (c *Client) GetAccountPinnedStatuses(ctx context.Context, id ID) ([]*Status
return statuses, nil
}
// GetAccountFollowers return followers list.
// GetAccountFollowers returns followers list.
func (c *Client) GetAccountFollowers(ctx context.Context, id ID, pg *Pagination) ([]*Account, error) {
var accounts []*Account
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/followers", url.PathEscape(string(id))), nil, &accounts, pg)
@ -161,7 +161,7 @@ func (c *Client) GetAccountFollowers(ctx context.Context, id ID, pg *Pagination)
return accounts, nil
}
// GetAccountFollowing return following list.
// GetAccountFollowing returns following list.
func (c *Client) GetAccountFollowing(ctx context.Context, id ID, pg *Pagination) ([]*Account, error) {
var accounts []*Account
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/following", url.PathEscape(string(id))), nil, &accounts, pg)
@ -171,7 +171,7 @@ func (c *Client) GetAccountFollowing(ctx context.Context, id ID, pg *Pagination)
return accounts, nil
}
// GetBlocks return block list.
// GetBlocks returns block list.
func (c *Client) GetBlocks(ctx context.Context, pg *Pagination) ([]*Account, error) {
var accounts []*Account
err := c.doAPI(ctx, http.MethodGet, "/api/v1/blocks", nil, &accounts, pg)
@ -181,7 +181,7 @@ func (c *Client) GetBlocks(ctx context.Context, pg *Pagination) ([]*Account, err
return accounts, nil
}
// Relationship hold information for relation-ship to the account.
// Relationship holds information for relationship to the account.
type Relationship struct {
ID ID `json:"id"`
Following bool `json:"following"`
@ -195,7 +195,7 @@ type Relationship struct {
Endorsed bool `json:"endorsed"`
}
// AccountFollow follow the account.
// AccountFollow follows the account.
func (c *Client) AccountFollow(ctx context.Context, id ID) (*Relationship, error) {
var relationship Relationship
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/follow", url.PathEscape(string(id))), nil, &relationship, nil)
@ -205,7 +205,7 @@ func (c *Client) AccountFollow(ctx context.Context, id ID) (*Relationship, error
return &relationship, nil
}
// AccountUnfollow unfollow the account.
// AccountUnfollow unfollows the account.
func (c *Client) AccountUnfollow(ctx context.Context, id ID) (*Relationship, error) {
var relationship Relationship
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/unfollow", url.PathEscape(string(id))), nil, &relationship, nil)
@ -215,7 +215,7 @@ func (c *Client) AccountUnfollow(ctx context.Context, id ID) (*Relationship, err
return &relationship, nil
}
// AccountBlock block the account.
// AccountBlock blocks the account.
func (c *Client) AccountBlock(ctx context.Context, id ID) (*Relationship, error) {
var relationship Relationship
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/block", url.PathEscape(string(id))), nil, &relationship, nil)
@ -225,7 +225,7 @@ func (c *Client) AccountBlock(ctx context.Context, id ID) (*Relationship, error)
return &relationship, nil
}
// AccountUnblock unblock the account.
// AccountUnblock unblocks the account.
func (c *Client) AccountUnblock(ctx context.Context, id ID) (*Relationship, error) {
var relationship Relationship
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/unblock", url.PathEscape(string(id))), nil, &relationship, nil)
@ -235,7 +235,7 @@ func (c *Client) AccountUnblock(ctx context.Context, id ID) (*Relationship, erro
return &relationship, nil
}
// AccountMute mute the account.
// AccountMute mutes the account.
func (c *Client) AccountMute(ctx context.Context, id ID) (*Relationship, error) {
var relationship Relationship
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/mute", url.PathEscape(string(id))), nil, &relationship, nil)
@ -245,7 +245,7 @@ func (c *Client) AccountMute(ctx context.Context, id ID) (*Relationship, error)
return &relationship, nil
}
// AccountUnmute unmute the account.
// AccountUnmute unmutes the account.
func (c *Client) AccountUnmute(ctx context.Context, id ID) (*Relationship, error) {
var relationship Relationship
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/unmute", url.PathEscape(string(id))), nil, &relationship, nil)
@ -255,7 +255,7 @@ func (c *Client) AccountUnmute(ctx context.Context, id ID) (*Relationship, error
return &relationship, nil
}
// GetAccountRelationships return relationship for the account.
// GetAccountRelationships returns relationship for the account.
func (c *Client) GetAccountRelationships(ctx context.Context, ids []string) ([]*Relationship, error) {
params := url.Values{}
for _, id := range ids {
@ -270,7 +270,7 @@ func (c *Client) GetAccountRelationships(ctx context.Context, ids []string) ([]*
return relationships, nil
}
// AccountsSearch search accounts by query.
// AccountsSearch searches accounts by query.
func (c *Client) AccountsSearch(ctx context.Context, q string, limit int64) ([]*Account, error) {
params := url.Values{}
params.Set("q", q)
@ -298,7 +298,7 @@ func (c *Client) AccountsSearchResolve(ctx context.Context, q string, limit int6
return accounts, nil
}
// FollowRemoteUser send follow-request.
// FollowRemoteUser sends follow-request.
func (c *Client) FollowRemoteUser(ctx context.Context, uri string) (*Account, error) {
params := url.Values{}
params.Set("uri", uri)
@ -311,7 +311,7 @@ func (c *Client) FollowRemoteUser(ctx context.Context, uri string) (*Account, er
return &account, nil
}
// GetFollowRequests return follow-requests.
// GetFollowRequests returns follow requests.
func (c *Client) GetFollowRequests(ctx context.Context, pg *Pagination) ([]*Account, error) {
var accounts []*Account
err := c.doAPI(ctx, http.MethodGet, "/api/v1/follow_requests", nil, &accounts, pg)
@ -321,12 +321,12 @@ func (c *Client) GetFollowRequests(ctx context.Context, pg *Pagination) ([]*Acco
return accounts, nil
}
// FollowRequestAuthorize is authorize the follow request of user with id.
// FollowRequestAuthorize authorizes the follow request of user with id.
func (c *Client) FollowRequestAuthorize(ctx context.Context, id ID) error {
return c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/follow_requests/%s/authorize", url.PathEscape(string(id))), nil, nil, nil)
}
// FollowRequestReject is rejects the follow request of user with id.
// FollowRequestReject rejects the follow request of user with id.
func (c *Client) FollowRequestReject(ctx context.Context, id ID) error {
return c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/follow_requests/%s/reject", url.PathEscape(string(id))), nil, nil, nil)
}

View File

@ -118,7 +118,6 @@ func TestGetAccountStatuses(t *testing.T) {
return
}
fmt.Fprintln(w, `[{"content": "foo"}, {"content": "bar"}]`)
return
}))
defer ts.Close()
@ -156,7 +155,6 @@ func TestGetAccountPinnedStatuses(t *testing.T) {
return
}
fmt.Fprintln(w, `[{"content": "foo"}, {"content": "bar"}]`)
return
}))
defer ts.Close()
@ -189,7 +187,6 @@ func TestGetAccountFollowers(t *testing.T) {
return
}
fmt.Fprintln(w, `[{"username": "foo"}, {"username": "bar"}]`)
return
}))
defer ts.Close()
@ -225,7 +222,6 @@ func TestGetAccountFollowing(t *testing.T) {
return
}
fmt.Fprintln(w, `[{"username": "foo"}, {"username": "bar"}]`)
return
}))
defer ts.Close()
@ -263,7 +259,6 @@ func TestGetBlocks(t *testing.T) {
return
}
fmt.Fprintln(w, `[{"username": "foo"}, {"username": "bar"}]`)
return
}))
defer ts.Close()
@ -299,7 +294,6 @@ func TestAccountFollow(t *testing.T) {
return
}
fmt.Fprintln(w, `{"id":1234567,"following":true}`)
return
}))
defer ts.Close()
@ -309,11 +303,11 @@ func TestAccountFollow(t *testing.T) {
ClientSecret: "bar",
AccessToken: "zoo",
})
rel, err := client.AccountFollow(context.Background(), "123")
_, err := client.AccountFollow(context.Background(), "123")
if err == nil {
t.Fatalf("should be fail: %v", err)
}
rel, err = client.AccountFollow(context.Background(), "1234567")
rel, err := client.AccountFollow(context.Background(), "1234567")
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
@ -332,7 +326,6 @@ func TestAccountUnfollow(t *testing.T) {
return
}
fmt.Fprintln(w, `{"id":1234567,"following":false}`)
return
}))
defer ts.Close()
@ -342,11 +335,11 @@ func TestAccountUnfollow(t *testing.T) {
ClientSecret: "bar",
AccessToken: "zoo",
})
rel, err := client.AccountUnfollow(context.Background(), "123")
_, err := client.AccountUnfollow(context.Background(), "123")
if err == nil {
t.Fatalf("should be fail: %v", err)
}
rel, err = client.AccountUnfollow(context.Background(), "1234567")
rel, err := client.AccountUnfollow(context.Background(), "1234567")
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
@ -365,7 +358,6 @@ func TestAccountBlock(t *testing.T) {
return
}
fmt.Fprintln(w, `{"id":1234567,"blocking":true}`)
return
}))
defer ts.Close()
@ -398,7 +390,6 @@ func TestAccountUnblock(t *testing.T) {
return
}
fmt.Fprintln(w, `{"id":1234567,"blocking":false}`)
return
}))
defer ts.Close()
@ -431,7 +422,6 @@ func TestAccountMute(t *testing.T) {
return
}
fmt.Fprintln(w, `{"id":1234567,"muting":true}`)
return
}))
defer ts.Close()
@ -464,7 +454,6 @@ func TestAccountUnmute(t *testing.T) {
return
}
fmt.Fprintln(w, `{"id":1234567,"muting":false}`)
return
}))
defer ts.Close()
@ -530,7 +519,6 @@ func TestAccountsSearch(t *testing.T) {
return
}
fmt.Fprintln(w, `[{"username": "foobar"}, {"username": "barfoo"}]`)
return
}))
defer ts.Close()
@ -601,7 +589,6 @@ func TestFollowRemoteUser(t *testing.T) {
return
}
fmt.Fprintln(w, `{"username": "zzz"}`)
return
}))
defer ts.Close()
@ -633,7 +620,6 @@ func TestGetFollowRequests(t *testing.T) {
return
}
fmt.Fprintln(w, `[{"username": "foo"}, {"username": "bar"}]`)
return
}))
defer ts.Close()
@ -719,7 +705,6 @@ func TestGetMutes(t *testing.T) {
return
}
fmt.Fprintln(w, `[{"username": "foo"}, {"username": "bar"}]`)
return
}))
defer ts.Close()

View File

@ -27,7 +27,7 @@ type AppConfig struct {
Website string
}
// Application is mastodon application.
// Application is a mastodon application.
type Application struct {
ID ID `json:"id"`
RedirectURI string `json:"redirect_uri"`

View File

@ -27,7 +27,6 @@ func TestRegisterApp(t *testing.T) {
return
}
fmt.Fprintln(w, `{"id": 123, "client_id": "foo", "client_secret": "bar"}`)
return
}))
defer ts.Close()
@ -79,7 +78,6 @@ func TestRegisterAppWithCancel(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(3 * time.Second)
fmt.Fprintln(w, `{"client_id": "foo", "client_secret": "bar"}`)
return
}))
defer ts.Close()

View File

@ -5,7 +5,7 @@ import (
"fmt"
"github.com/mattn/go-mastodon"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func cmdAccount(c *cli.Context) error {

View File

@ -6,7 +6,7 @@ import (
"strings"
"testing"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func TestCmdAccount(t *testing.T) {

View File

@ -5,7 +5,7 @@ import (
"errors"
"github.com/mattn/go-mastodon"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func cmdDelete(c *cli.Context) error {

View File

@ -5,7 +5,7 @@ import (
"net/http"
"testing"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func TestCmdDelete(t *testing.T) {

View File

@ -5,7 +5,7 @@ import (
"errors"
"github.com/mattn/go-mastodon"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func cmdFollow(c *cli.Context) error {

View File

@ -5,7 +5,7 @@ import (
"net/http"
"testing"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func TestCmdFollow(t *testing.T) {

View File

@ -6,7 +6,7 @@ import (
"time"
"github.com/mattn/go-mastodon"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func cmdFollowers(c *cli.Context) error {

View File

@ -6,7 +6,7 @@ import (
"strings"
"testing"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func TestCmdFollowers(t *testing.T) {

View File

@ -6,7 +6,7 @@ import (
"sort"
"github.com/mattn/go-mastodon"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func cmdInstance(c *cli.Context) error {

View File

@ -5,7 +5,7 @@ import (
"fmt"
"github.com/mattn/go-mastodon"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func cmdInstanceActivity(c *cli.Context) error {

View File

@ -5,7 +5,7 @@ import (
"fmt"
"github.com/mattn/go-mastodon"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func cmdInstancePeers(c *cli.Context) error {

View File

@ -6,7 +6,7 @@ import (
"strings"
"testing"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func TestCmdInstance(t *testing.T) {

View File

@ -1,7 +1,7 @@
package main
import (
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func cmdMikami(c *cli.Context) error {

View File

@ -7,7 +7,7 @@ import (
"strings"
"testing"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func TestCmdMikami(t *testing.T) {

View File

@ -6,7 +6,7 @@ import (
"github.com/fatih/color"
"github.com/mattn/go-mastodon"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func cmdNotification(c *cli.Context) error {

View File

@ -6,7 +6,7 @@ import (
"strings"
"testing"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func TestCmdNotification(t *testing.T) {

View File

@ -6,7 +6,7 @@ import (
"fmt"
"github.com/mattn/go-mastodon"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func cmdSearch(c *cli.Context) error {

View File

@ -6,7 +6,7 @@ import (
"strings"
"testing"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func TestCmdSearch(t *testing.T) {

View File

@ -10,7 +10,7 @@ import (
"text/template"
"github.com/mattn/go-mastodon"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
// SimpleJSON is a struct for output JSON for data to be simple used

View File

@ -6,7 +6,7 @@ import (
"net/http/httptest"
"github.com/mattn/go-mastodon"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func testWithServer(h http.HandlerFunc, testFuncs ...func(*cli.App)) string {

View File

@ -4,7 +4,7 @@ import (
"context"
"github.com/mattn/go-mastodon"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func cmdTimeline(c *cli.Context) error {

View File

@ -6,7 +6,7 @@ import (
"strings"
"testing"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func TestCmdTimeline(t *testing.T) {

View File

@ -6,7 +6,7 @@ import (
"fmt"
"github.com/mattn/go-mastodon"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func cmdToot(c *cli.Context) error {

View File

@ -5,7 +5,7 @@ import (
"net/http"
"testing"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func TestCmdToot(t *testing.T) {

View File

@ -6,7 +6,7 @@ import (
"fmt"
"github.com/mattn/go-mastodon"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func cmdUpload(c *cli.Context) error {

View File

@ -6,7 +6,7 @@ import (
"strings"
"testing"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func TestCmdUpload(t *testing.T) {

View File

@ -6,7 +6,7 @@ import (
"net/url"
"github.com/PuerkitoBio/goquery"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func cmdXSearch(c *cli.Context) error {

View File

@ -8,7 +8,7 @@ import (
"strings"
"testing"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func TestCmdXSearch(t *testing.T) {

View File

@ -9,6 +9,7 @@ require (
github.com/fatih/color v1.13.0
github.com/mattn/go-mastodon v0.0.4
github.com/mattn/go-tty v0.0.4
github.com/urfave/cli v1.22.9
github.com/urfave/cli v1.13.0
github.com/urfave/cli/v2 v2.23.5 // indirect
golang.org/x/net v0.0.0-20220531201128-c960675eff93
)

View File

@ -1,9 +1,8 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U=
github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI=
github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c=
github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
@ -11,9 +10,8 @@ github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYF
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
@ -22,15 +20,16 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-tty v0.0.4 h1:NVikla9X8MN0SQAqCYzpGyXv0jY7MNl3HOWD2dkle7E=
github.com/mattn/go-tty v0.0.4/go.mod h1:u5GGXBtZU6RQoKV8gY5W6UhMudbR5vXnUe7j3pxse28=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 h1:nrZ3ySNYwJbSpD6ce9duiP+QkD3JuLCcWkdaehUS/3Y=
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80/go.mod h1:iFyPdL66DjUD96XmzVL3ZntbzcflLnznH0fr99w5VqE=
github.com/urfave/cli v1.22.9 h1:cv3/KhXGBGjEXLC4bH0sLuJ9BewaAbpk5oyMOveu4pw=
github.com/urfave/cli v1.22.9/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli v1.13.0 h1:kkpCmfxnnnWIie2rCljcvaVrNYmsFq1ynTJH5kn1Ip4=
github.com/urfave/cli v1.13.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli/v2 v2.23.5 h1:xbrU7tAYviSpqeR3X4nEFWUdB/uDZ6DE+HxmRU7Xtyw=
github.com/urfave/cli/v2 v2.23.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220531201128-c960675eff93 h1:MYimHLfoXEpOhqd/zgoA/uoXzHB86AEky4LAx5ij9xA=
golang.org/x/net v0.0.0-20220531201128-c960675eff93/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
@ -43,7 +42,6 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
@ -52,4 +50,4 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -17,7 +17,7 @@ import (
"github.com/fatih/color"
"github.com/mattn/go-mastodon"
"github.com/mattn/go-tty"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
"golang.org/x/net/html"
)
@ -183,23 +183,23 @@ func makeApp() *cli.App {
app.Usage = "mastodon client"
app.Version = "0.0.1"
app.Flags = []cli.Flag{
cli.StringFlag{
&cli.StringFlag{
Name: "profile",
Usage: "profile name",
Value: "",
},
}
app.Commands = []cli.Command{
app.Commands = []*cli.Command{
{
Name: "toot",
Usage: "post toot",
Flags: []cli.Flag{
cli.StringFlag{
&cli.StringFlag{
Name: "ff",
Usage: "post utf-8 string from a file(\"-\" means STDIN)",
Value: "",
},
cli.StringFlag{
&cli.StringFlag{
Name: "i",
Usage: "in-reply-to",
Value: "",
@ -211,19 +211,19 @@ func makeApp() *cli.App {
Name: "stream",
Usage: "stream statuses",
Flags: []cli.Flag{
cli.StringFlag{
&cli.StringFlag{
Name: "type",
Usage: "stream type (public,public/local,user:NAME,hashtag:TAG)",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "json",
Usage: "output JSON",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "simplejson",
Usage: "output simple JSON",
},
cli.StringFlag{
&cli.StringFlag{
Name: "template",
Usage: "output with tamplate format",
},

View File

@ -7,7 +7,7 @@ import (
"os"
"testing"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
func TestReadFileFile(t *testing.T) {

View File

@ -5,7 +5,7 @@ import (
"net/http"
)
// Instance hold information for mastodon instance.
// Instance holds information for a mastodon instance.
type Instance struct {
URI string `json:"uri"`
Title string `json:"title"`
@ -19,14 +19,14 @@ type Instance struct {
ContactAccount *Account `json:"contact_account"`
}
// InstanceStats hold information for mastodon instance stats.
// InstanceStats holds information for mastodon instance stats.
type InstanceStats struct {
UserCount int64 `json:"user_count"`
StatusCount int64 `json:"status_count"`
DomainCount int64 `json:"domain_count"`
}
// GetInstance return Instance.
// GetInstance returns 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)
@ -36,7 +36,7 @@ func (c *Client) GetInstance(ctx context.Context) (*Instance, error) {
return &instance, nil
}
// WeeklyActivity hold information for mastodon weekly activity.
// WeeklyActivity holds information for mastodon weekly activity.
type WeeklyActivity struct {
Week Unixtime `json:"week"`
Statuses int64 `json:"statuses,string"`
@ -44,7 +44,7 @@ type WeeklyActivity struct {
Registrations int64 `json:"registrations,string"`
}
// GetInstanceActivity return instance activity.
// GetInstanceActivity returns instance activity.
func (c *Client) GetInstanceActivity(ctx context.Context) ([]*WeeklyActivity, error) {
var activity []*WeeklyActivity
err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance/activity", nil, &activity, nil)
@ -54,7 +54,7 @@ func (c *Client) GetInstanceActivity(ctx context.Context) ([]*WeeklyActivity, er
return activity, nil
}
// GetInstancePeers return instance peers.
// GetInstancePeers returns instance peers.
func (c *Client) GetInstancePeers(ctx context.Context) ([]string, error) {
var peers []string
err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance/peers", nil, &peers, nil)

View File

@ -15,7 +15,6 @@ func TestGetLists(t *testing.T) {
return
}
fmt.Fprintln(w, `[{"id": "1", "title": "foo"}, {"id": "2", "title": "bar"}]`)
return
}))
defer ts.Close()
@ -47,7 +46,6 @@ func TestGetAccountLists(t *testing.T) {
return
}
fmt.Fprintln(w, `[{"id": "1", "title": "foo"}, {"id": "2", "title": "bar"}]`)
return
}))
defer ts.Close()
@ -83,7 +81,6 @@ func TestGetListAccounts(t *testing.T) {
return
}
fmt.Fprintln(w, `[{"username": "foo"}, {"username": "bar"}]`)
return
}))
defer ts.Close()
@ -119,7 +116,6 @@ func TestGetList(t *testing.T) {
return
}
fmt.Fprintln(w, `{"id": "1", "title": "foo"}`)
return
}))
defer ts.Close()
@ -129,11 +125,11 @@ func TestGetList(t *testing.T) {
ClientSecret: "bar",
AccessToken: "zoo",
})
list, err := client.GetList(context.Background(), "2")
_, err := client.GetList(context.Background(), "2")
if err == nil {
t.Fatalf("should be fail: %v", err)
}
list, err = client.GetList(context.Background(), "1")
list, err := client.GetList(context.Background(), "1")
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
@ -149,7 +145,6 @@ func TestCreateList(t *testing.T) {
return
}
fmt.Fprintln(w, `{"id": "1", "title": "foo"}`)
return
}))
defer ts.Close()
@ -159,11 +154,11 @@ func TestCreateList(t *testing.T) {
ClientSecret: "bar",
AccessToken: "zoo",
})
list, err := client.CreateList(context.Background(), "")
_, err := client.CreateList(context.Background(), "")
if err == nil {
t.Fatalf("should be fail: %v", err)
}
list, err = client.CreateList(context.Background(), "foo")
list, err := client.CreateList(context.Background(), "foo")
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
@ -183,7 +178,6 @@ func TestRenameList(t *testing.T) {
return
}
fmt.Fprintln(w, `{"id": "1", "title": "bar"}`)
return
}))
defer ts.Close()
@ -193,11 +187,11 @@ func TestRenameList(t *testing.T) {
ClientSecret: "bar",
AccessToken: "zoo",
})
list, err := client.RenameList(context.Background(), "2", "bar")
_, err := client.RenameList(context.Background(), "2", "bar")
if err == nil {
t.Fatalf("should be fail: %v", err)
}
list, err = client.RenameList(context.Background(), "1", "bar")
list, err := client.RenameList(context.Background(), "1", "bar")
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
@ -216,7 +210,6 @@ func TestDeleteList(t *testing.T) {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusMethodNotAllowed)
return
}
return
}))
defer ts.Close()
@ -246,7 +239,6 @@ func TestAddToList(t *testing.T) {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
return
}))
defer ts.Close()
@ -272,7 +264,6 @@ func TestRemoveFromList(t *testing.T) {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusMethodNotAllowed)
return
}
return
}))
defer ts.Close()

View File

@ -128,7 +128,7 @@ func (c *Client) doAPI(ctx context.Context, method string, uri string, params in
return json.NewDecoder(resp.Body).Decode(&res)
}
// NewClient return new mastodon API client.
// NewClient returns a new mastodon API client.
func NewClient(config *Config) *Client {
return &Client{
Client: *http.DefaultClient,
@ -136,7 +136,7 @@ func NewClient(config *Config) *Client {
}
}
// Authenticate get access-token to the API.
// Authenticate gets access-token to the API.
func (c *Client) Authenticate(ctx context.Context, username, password string) error {
params := url.Values{
"client_id": {c.Config.ClientID},
@ -222,7 +222,7 @@ const (
VisibilityDirectMessage = "direct"
)
// Toot is struct to post status.
// Toot is a struct to post status.
type Toot struct {
Status string `json:"status"`
InReplyToID ID `json:"in_reply_to_id"`
@ -230,6 +230,7 @@ type Toot struct {
Sensitive bool `json:"sensitive"`
SpoilerText string `json:"spoiler_text"`
Visibility string `json:"visibility"`
Language string `json:"language"`
ScheduledAt *time.Time `json:"scheduled_at,omitempty"`
Poll *TootPoll `json:"poll"`
}

View File

@ -96,7 +96,6 @@ func TestAuthenticate(t *testing.T) {
return
}
fmt.Fprintln(w, `{"access_token": "zoo"}`)
return
}))
defer ts.Close()
@ -124,7 +123,6 @@ func TestAuthenticate(t *testing.T) {
func TestAuthenticateWithCancel(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(3 * time.Second)
return
}))
defer ts.Close()
@ -151,7 +149,6 @@ func TestAuthenticateApp(t *testing.T) {
return
}
fmt.Fprintln(w, `{"name":"zzz","website":"yyy","vapid_key":"xxx"}`)
return
}))
defer ts.Close()
@ -183,7 +180,6 @@ func TestPostStatus(t *testing.T) {
return
}
fmt.Fprintln(w, `{"access_token": "zoo"}`)
return
}))
defer ts.Close()
@ -216,7 +212,6 @@ func TestPostStatus(t *testing.T) {
func TestPostStatusWithCancel(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(3 * time.Second)
return
}))
defer ts.Close()
@ -257,6 +252,9 @@ func TestPostStatusParams(t *testing.T) {
if r.FormValue("visibility") != "" {
s.Visibility = (r.FormValue("visibility"))
}
if r.FormValue("language") != "" {
s.Language = (r.FormValue("language"))
}
if r.FormValue("sensitive") == "true" {
s.Sensitive = true
s.SpoilerText = fmt.Sprintf("<p>%s</p>", r.FormValue("spoiler_text"))
@ -293,6 +291,7 @@ func TestPostStatusParams(t *testing.T) {
Status: "foobar",
InReplyToID: ID("2"),
Visibility: "unlisted",
Language: "sv",
Sensitive: true,
SpoilerText: "bar",
MediaIDs: []ID{"1", "2"},
@ -315,6 +314,9 @@ func TestPostStatusParams(t *testing.T) {
if s.Visibility != "unlisted" {
t.Fatalf("want %q but %q", "unlisted", s.Visibility)
}
if s.Language != "sv" {
t.Fatalf("want %q but %q", "sv", s.Language)
}
if s.Sensitive != true {
t.Fatalf("want %t but %t", true, s.Sensitive)
}
@ -351,7 +353,6 @@ func TestPostStatusParams(t *testing.T) {
func TestGetTimelineHome(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `[{"content": "foo"}, {"content": "bar"}]`)
return
}))
defer ts.Close()
@ -391,7 +392,6 @@ func TestGetTimelineHome(t *testing.T) {
func TestGetTimelineHomeWithCancel(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(3 * time.Second)
return
}))
defer ts.Close()

View File

@ -12,7 +12,7 @@ import (
"time"
)
// Notification hold information for mastodon notification.
// Notification holds information for a mastodon notification.
type Notification struct {
ID ID `json:"id"`
Type string `json:"type"`
@ -35,7 +35,7 @@ type PushAlerts struct {
Mention *Sbool `json:"mention"`
}
// GetNotifications return notifications.
// GetNotifications returns notifications.
func (c *Client) GetNotifications(ctx context.Context, pg *Pagination) ([]*Notification, error) {
var notifications []*Notification
err := c.doAPI(ctx, http.MethodGet, "/api/v1/notifications", nil, &notifications, pg)
@ -45,7 +45,7 @@ func (c *Client) GetNotifications(ctx context.Context, pg *Pagination) ([]*Notif
return notifications, nil
}
// GetNotification return notification.
// GetNotification returns notification.
func (c *Client) GetNotification(ctx context.Context, id ID) (*Notification, error) {
var notification Notification
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/notifications/%v", id), nil, &notification, nil)
@ -60,7 +60,7 @@ func (c *Client) DismissNotification(ctx context.Context, id ID) error {
return c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/notifications/%v/dismiss", id), nil, nil, nil)
}
// ClearNotifications clear notifications.
// ClearNotifications clears notifications.
func (c *Client) ClearNotifications(ctx context.Context) error {
return c.doAPI(ctx, http.MethodPost, "/api/v1/notifications/clear", nil, nil, nil)
}

View File

@ -28,7 +28,6 @@ func TestGetNotifications(t *testing.T) {
return
}
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}))
defer ts.Close()
@ -76,7 +75,6 @@ func TestPushSubscription(t *testing.T) {
return
}
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}))
defer ts.Close()

View File

@ -8,7 +8,7 @@ import (
"time"
)
// Poll hold information for mastodon polls.
// Poll holds information for mastodon polls.
type Poll struct {
ID ID `json:"id"`
ExpiresAt time.Time `json:"expires_at"`
@ -22,13 +22,13 @@ type Poll struct {
Emojis []Emoji `json:"emojis"`
}
// Poll hold information for a mastodon poll option.
// Poll holds information for a mastodon poll option.
type PollOption struct {
Title string `json:"title"`
VotesCount int64 `json:"votes_count"`
}
// GetPoll return poll specified by id.
// GetPoll returns poll specified by id.
func (c *Client) GetPoll(ctx context.Context, id ID) (*Poll, error) {
var poll Poll
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/polls/%s", id), nil, &poll, nil)

View File

@ -6,13 +6,13 @@ import (
"net/url"
)
// Report hold information for mastodon report.
// Report holds information for a mastodon report.
type Report struct {
ID int64 `json:"id"`
ActionTaken bool `json:"action_taken"`
}
// GetReports return report of the current user.
// GetReports returns report of the current user.
func (c *Client) GetReports(ctx context.Context) ([]*Report, error) {
var reports []*Report
err := c.doAPI(ctx, http.MethodGet, "/api/v1/reports", nil, &reports, nil)

View File

@ -15,7 +15,6 @@ func TestGetReports(t *testing.T) {
return
}
fmt.Fprintln(w, `[{"id": 122, "action_taken": false}, {"id": 123, "action_taken": true}]`)
return
}))
defer ts.Close()
@ -55,7 +54,6 @@ func TestReport(t *testing.T) {
} else {
fmt.Fprintln(w, `{"id": 1234, "action_taken": true}`)
}
return
}))
defer ts.Close()
@ -65,11 +63,11 @@ func TestReport(t *testing.T) {
ClientSecret: "bar",
AccessToken: "zoo",
})
rp, err := client.Report(context.Background(), "121", nil, "")
_, err := client.Report(context.Background(), "121", nil, "")
if err == nil {
t.Fatalf("should be fail: %v", err)
}
rp, err = client.Report(context.Background(), "122", nil, "")
rp, err := client.Report(context.Background(), "122", nil, "")
if err != nil {
t.Fatalf("should not be fail: %v", err)
}

View File

@ -45,13 +45,13 @@ type Status struct {
Pinned interface{} `json:"pinned"`
}
// Context hold information for mastodon context.
// Context holds information for a mastodon context.
type Context struct {
Ancestors []*Status `json:"ancestors"`
Descendants []*Status `json:"descendants"`
}
// Card hold information for mastodon card.
// Card holds information for a mastodon card.
type Card struct {
URL string `json:"url"`
Title string `json:"title"`
@ -67,7 +67,7 @@ type Card struct {
Height int64 `json:"height"`
}
// Conversation hold information for mastodon conversation.
// Conversation holds information for a mastodon conversation.
type Conversation struct {
ID ID `json:"id"`
Accounts []*Account `json:"accounts"`
@ -140,7 +140,7 @@ func (m *Media) bodyAndContentType() (io.Reader, string, error) {
return &buf, mw.FormDataContentType(), nil
}
// GetFavourites return the favorite list of the current user.
// GetFavourites returns the favorite list of the current user.
func (c *Client) GetFavourites(ctx context.Context, pg *Pagination) ([]*Status, error) {
var statuses []*Status
err := c.doAPI(ctx, http.MethodGet, "/api/v1/favourites", nil, &statuses, pg)
@ -150,7 +150,7 @@ func (c *Client) GetFavourites(ctx context.Context, pg *Pagination) ([]*Status,
return statuses, nil
}
// GetBookmarks return the bookmark list of the current user.
// GetBookmarks returns the bookmark list of the current user.
func (c *Client) GetBookmarks(ctx context.Context, pg *Pagination) ([]*Status, error) {
var statuses []*Status
err := c.doAPI(ctx, http.MethodGet, "/api/v1/bookmarks", nil, &statuses, pg)
@ -160,7 +160,7 @@ func (c *Client) GetBookmarks(ctx context.Context, pg *Pagination) ([]*Status, e
return statuses, nil
}
// GetStatus return status specified by id.
// GetStatus returns status specified by id.
func (c *Client) GetStatus(ctx context.Context, id ID) (*Status, error) {
var status Status
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%s", id), nil, &status, nil)
@ -170,7 +170,7 @@ func (c *Client) GetStatus(ctx context.Context, id ID) (*Status, error) {
return &status, nil
}
// GetStatusContext return status specified by id.
// GetStatusContext returns status specified by id.
func (c *Client) GetStatusContext(ctx context.Context, id ID) (*Context, error) {
var context Context
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%s/context", id), nil, &context, nil)
@ -180,7 +180,7 @@ func (c *Client) GetStatusContext(ctx context.Context, id ID) (*Context, error)
return &context, nil
}
// GetStatusCard return status specified by id.
// GetStatusCard returns status specified by id.
func (c *Client) GetStatusCard(ctx context.Context, id ID) (*Card, error) {
var card Card
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%s/card", id), nil, &card, nil)
@ -210,7 +210,7 @@ func (c *Client) GetFavouritedBy(ctx context.Context, id ID, pg *Pagination) ([]
return accounts, nil
}
// Reblog is reblog the toot of id and return status of reblog.
// Reblog reblogs the toot of id and returns status of reblog.
func (c *Client) Reblog(ctx context.Context, id ID) (*Status, error) {
var status Status
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/reblog", id), nil, &status, nil)
@ -220,7 +220,7 @@ func (c *Client) Reblog(ctx context.Context, id ID) (*Status, error) {
return &status, nil
}
// Unreblog is unreblog the toot of id and return status of the original toot.
// Unreblog unreblogs the toot of id and returns status of the original toot.
func (c *Client) Unreblog(ctx context.Context, id ID) (*Status, error) {
var status Status
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/unreblog", id), nil, &status, nil)
@ -230,7 +230,7 @@ func (c *Client) Unreblog(ctx context.Context, id ID) (*Status, error) {
return &status, nil
}
// Favourite is favourite the toot of id and return status of the favourite toot.
// Favourite favourites the toot of id and returns status of the favourite toot.
func (c *Client) Favourite(ctx context.Context, id ID) (*Status, error) {
var status Status
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/favourite", id), nil, &status, nil)
@ -240,7 +240,7 @@ func (c *Client) Favourite(ctx context.Context, id ID) (*Status, error) {
return &status, nil
}
// Unfavourite is unfavourite the toot of id and return status of the unfavourite toot.
// Unfavourite unfavourites the toot of id and returns status of the unfavourite toot.
func (c *Client) Unfavourite(ctx context.Context, id ID) (*Status, error) {
var status Status
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/unfavourite", id), nil, &status, nil)
@ -250,7 +250,7 @@ func (c *Client) Unfavourite(ctx context.Context, id ID) (*Status, error) {
return &status, nil
}
// Bookmark is bookmark the toot of id and return status of the bookmark toot.
// Bookmark bookmarks the toot of id and returns status of the bookmark toot.
func (c *Client) Bookmark(ctx context.Context, id ID) (*Status, error) {
var status Status
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/bookmark", id), nil, &status, nil)
@ -365,6 +365,9 @@ func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) {
if toot.Visibility != "" {
params.Set("visibility", fmt.Sprint(toot.Visibility))
}
if toot.Language != "" {
params.Set("language", fmt.Sprint(toot.Language))
}
if toot.Sensitive {
params.Set("sensitive", "true")
}
@ -409,7 +412,12 @@ func (c *Client) UploadMedia(ctx context.Context, file string) (*Attachment, err
return c.UploadMediaFromMedia(ctx, &Media{File: f})
}
// UploadMediaFromReader uploads a media attachment from a io.Reader.
// UploadMediaFromBytes uploads a media attachment from a byte slice.
func (c *Client) UploadMediaFromBytes(ctx context.Context, b []byte) (*Attachment, error) {
return c.UploadMediaFromReader(ctx, bytes.NewReader(b))
}
// UploadMediaFromReader uploads a media attachment from an io.Reader.
func (c *Client) UploadMediaFromReader(ctx context.Context, reader io.Reader) (*Attachment, error) {
return c.UploadMediaFromMedia(ctx, &Media{File: reader})
}

View File

@ -3,6 +3,7 @@ package mastodon
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
@ -12,7 +13,6 @@ import (
func TestGetFavourites(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `[{"content": "foo"}, {"content": "bar"}]`)
return
}))
defer ts.Close()
@ -40,7 +40,6 @@ func TestGetFavourites(t *testing.T) {
func TestGetBookmarks(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `[{"content": "foo"}, {"content": "bar"}]`)
return
}))
defer ts.Close()
@ -72,7 +71,6 @@ func TestGetStatus(t *testing.T) {
return
}
fmt.Fprintln(w, `{"content": "zzz", "emojis":[{"shortcode":"💩", "url":"http://example.com", "static_url": "http://example.com/static"}]}`)
return
}))
defer ts.Close()
@ -114,7 +112,6 @@ func TestGetStatusCard(t *testing.T) {
return
}
fmt.Fprintln(w, `{"title": "zzz"}`)
return
}))
defer ts.Close()
@ -144,7 +141,6 @@ func TestGetStatusContext(t *testing.T) {
return
}
fmt.Fprintln(w, `{"ancestors": [{"content": "zzz"},{"content": "bbb"}]}`)
return
}))
defer ts.Close()
@ -183,7 +179,6 @@ func TestGetRebloggedBy(t *testing.T) {
return
}
fmt.Fprintln(w, `[{"username": "foo"}, {"username": "bar"}]`)
return
}))
defer ts.Close()
@ -219,7 +214,6 @@ func TestGetFavouritedBy(t *testing.T) {
return
}
fmt.Fprintln(w, `[{"username": "foo"}, {"username": "bar"}]`)
return
}))
defer ts.Close()
@ -255,7 +249,6 @@ func TestReblog(t *testing.T) {
return
}
fmt.Fprintln(w, `{"content": "zzz"}`)
return
}))
defer ts.Close()
@ -285,7 +278,6 @@ func TestUnreblog(t *testing.T) {
return
}
fmt.Fprintln(w, `{"content": "zzz"}`)
return
}))
defer ts.Close()
@ -315,7 +307,6 @@ func TestFavourite(t *testing.T) {
return
}
fmt.Fprintln(w, `{"content": "zzz"}`)
return
}))
defer ts.Close()
@ -345,7 +336,6 @@ func TestUnfavourite(t *testing.T) {
return
}
fmt.Fprintln(w, `{"content": "zzz"}`)
return
}))
defer ts.Close()
@ -375,7 +365,6 @@ func TestBookmark(t *testing.T) {
return
}
fmt.Fprintln(w, `{"content": "zzz"}`)
return
}))
defer ts.Close()
@ -405,7 +394,6 @@ func TestUnbookmark(t *testing.T) {
return
}
fmt.Fprintln(w, `{"content": "zzz"}`)
return
}))
defer ts.Close()
@ -487,7 +475,6 @@ func TestGetTimelineHashtag(t *testing.T) {
return
}
fmt.Fprintln(w, `[{"content": "zzz"},{"content": "yyy"}]`)
return
}))
defer ts.Close()
@ -523,7 +510,6 @@ func TestGetTimelineList(t *testing.T) {
return
}
fmt.Fprintln(w, `[{"content": "zzz"},{"content": "yyy"}]`)
return
}))
defer ts.Close()
@ -559,7 +545,6 @@ func TestGetTimelineMedia(t *testing.T) {
return
}
fmt.Fprintln(w, `[{"content": "zzz"},{"content": "yyy"}]`)
return
}))
defer ts.Close()
@ -598,7 +583,6 @@ func TestDeleteStatus(t *testing.T) {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusMethodNotAllowed)
return
}
return
}))
defer ts.Close()
@ -634,7 +618,6 @@ func TestSearch(t *testing.T) {
"statuses":[{"content": "aaa"}],
"hashtags":[{"name": "tag"},{"name": "tag2"},{"name": "tag3"}]
}`)
return
}))
defer ts.Close()
@ -679,7 +662,6 @@ func TestUploadMedia(t *testing.T) {
return
}
fmt.Fprintln(w, `{"id": 123}`)
return
}))
defer ts.Close()
@ -708,6 +690,18 @@ func TestUploadMedia(t *testing.T) {
if writerAttachment.ID != "123" {
t.Fatalf("want %q but %q", "123", attachment.ID)
}
bytes, err := ioutil.ReadFile("testdata/logo.png")
if err != nil {
t.Fatalf("could not open file: %v", err)
}
byteAttachment, err := client.UploadMediaFromBytes(context.Background(), bytes)
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
if byteAttachment.ID != "123" {
t.Fatalf("want %q but got %q", "123", attachment.ID)
}
}
func TestGetConversations(t *testing.T) {
@ -716,7 +710,6 @@ func TestGetConversations(t *testing.T) {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
}
fmt.Fprintln(w, `[{"id": "4", "unread":false, "last_status" : {"content": "zzz"}}, {"id": "3", "unread":true, "last_status" : {"content": "bar"}}]`)
return
}))
defer ts.Close()
@ -754,7 +747,6 @@ func TestDeleteConversation(t *testing.T) {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusMethodNotAllowed)
return
}
return
}))
defer ts.Close()
@ -780,7 +772,6 @@ func TestMarkConversationsAsRead(t *testing.T) {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
return
}))
defer ts.Close()

View File

@ -13,32 +13,32 @@ import (
"strings"
)
// UpdateEvent is struct for passing status event to app.
// UpdateEvent is a struct for passing status event to app.
type UpdateEvent struct {
Status *Status `json:"status"`
}
func (e *UpdateEvent) event() {}
// NotificationEvent is struct for passing notification event to app.
// NotificationEvent is a struct for passing notification event to app.
type NotificationEvent struct {
Notification *Notification `json:"notification"`
}
func (e *NotificationEvent) event() {}
// DeleteEvent is struct for passing deletion event to app.
// DeleteEvent is a struct for passing deletion event to app.
type DeleteEvent struct{ ID ID }
func (e *DeleteEvent) event() {}
// ErrorEvent is struct for passing errors to app.
// ErrorEvent is a struct for passing errors to app.
type ErrorEvent struct{ err error }
func (e *ErrorEvent) event() {}
func (e *ErrorEvent) Error() string { return e.err.Error() }
// Event is interface passing events to app.
// Event is an interface passing events to app.
type Event interface {
event()
}
@ -150,12 +150,12 @@ func (c *Client) doStreaming(req *http.Request, q chan Event) {
}
}
// StreamingUser return channel to read events on home.
// StreamingUser returns a channel to read events on home.
func (c *Client) StreamingUser(ctx context.Context) (chan Event, error) {
return c.streaming(ctx, "user", nil)
}
// StreamingPublic return channel to read events on public.
// StreamingPublic returns a channel to read events on public.
func (c *Client) StreamingPublic(ctx context.Context, isLocal bool) (chan Event, error) {
p := "public"
if isLocal {
@ -165,7 +165,7 @@ func (c *Client) StreamingPublic(ctx context.Context, isLocal bool) (chan Event,
return c.streaming(ctx, p, nil)
}
// StreamingHashtag return channel to read events on tagged timeline.
// StreamingHashtag returns a channel to read events on tagged timeline.
func (c *Client) StreamingHashtag(ctx context.Context, tag string, isLocal bool) (chan Event, error) {
params := url.Values{}
params.Set("tag", tag)
@ -178,7 +178,7 @@ func (c *Client) StreamingHashtag(ctx context.Context, tag string, isLocal bool)
return c.streaming(ctx, p, params)
}
// StreamingList return channel to read events on a list.
// StreamingList returns a channel to read events on a list.
func (c *Client) StreamingList(ctx context.Context, id ID) (chan Event, error) {
params := url.Values{}
params.Set("list", string(id))
@ -186,7 +186,7 @@ func (c *Client) StreamingList(ctx context.Context, id ID) (chan Event, error) {
return c.streaming(ctx, "list", params)
}
// StreamingDirect return channel to read events on a direct messages.
// StreamingDirect returns a channel to read events on a direct messages.
func (c *Client) StreamingDirect(ctx context.Context) (chan Event, error) {
return c.streaming(ctx, "direct", nil)
}