Merge branch 'master' of github.com:mattn/go-mastodon
This commit is contained in:
commit
def474a7a5
|
@ -14,8 +14,17 @@ func TestCmdFollow(t *testing.T) {
|
||||||
func(w http.ResponseWriter, r *http.Request) {
|
func(w http.ResponseWriter, r *http.Request) {
|
||||||
switch r.URL.Path {
|
switch r.URL.Path {
|
||||||
case "/api/v1/accounts/search":
|
case "/api/v1/accounts/search":
|
||||||
|
q := r.URL.Query().Get("q")
|
||||||
|
if q == "mattn" {
|
||||||
fmt.Fprintln(w, `[{"id": 123}]`)
|
fmt.Fprintln(w, `[{"id": 123}]`)
|
||||||
return
|
return
|
||||||
|
} else if q == "different_id" {
|
||||||
|
fmt.Fprintln(w, `[{"id": 1234567}]`)
|
||||||
|
return
|
||||||
|
} else if q == "empty" {
|
||||||
|
fmt.Fprintln(w, `[]`)
|
||||||
|
return
|
||||||
|
}
|
||||||
case "/api/v1/accounts/123/follow":
|
case "/api/v1/accounts/123/follow":
|
||||||
fmt.Fprintln(w, `{"id": 123}`)
|
fmt.Fprintln(w, `{"id": 123}`)
|
||||||
ok = true
|
ok = true
|
||||||
|
@ -25,7 +34,34 @@ func TestCmdFollow(t *testing.T) {
|
||||||
return
|
return
|
||||||
},
|
},
|
||||||
func(app *cli.App) {
|
func(app *cli.App) {
|
||||||
app.Run([]string{"mstdn", "follow", "mattn"})
|
err := app.Run([]string{"mstdn", "follow", "mattn"})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not be fail: %v", err)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
func(app *cli.App) {
|
||||||
|
err := app.Run([]string{"mstdn", "follow"})
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("should be fail: %v", err)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
func(app *cli.App) {
|
||||||
|
err := app.Run([]string{"mstdn", "follow", "fail"})
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("should be fail: %v", err)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
func(app *cli.App) {
|
||||||
|
err := app.Run([]string{"mstdn", "follow", "empty"})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not be fail: %v", err)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
func(app *cli.App) {
|
||||||
|
err := app.Run([]string{"mstdn", "follow", "different_id"})
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("should not be fail: %v", err)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testWithServer(h http.HandlerFunc, testFunc func(*cli.App)) string {
|
func testWithServer(h http.HandlerFunc, testFuncs ...func(*cli.App)) string {
|
||||||
ts := httptest.NewServer(h)
|
ts := httptest.NewServer(h)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
|
@ -31,6 +31,10 @@ func testWithServer(h http.HandlerFunc, testFunc func(*cli.App)) string {
|
||||||
Server: "https://example.com",
|
Server: "https://example.com",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
testFunc(app)
|
|
||||||
|
for _, f := range testFuncs {
|
||||||
|
f(app)
|
||||||
|
}
|
||||||
|
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
|
@ -329,13 +329,13 @@ func run() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
client := mastodon.NewClient(config)
|
client := mastodon.NewClient(config)
|
||||||
if config.AccessToken == "" {
|
|
||||||
return authenticate(client, config, file)
|
|
||||||
}
|
|
||||||
app.Metadata = map[string]interface{}{
|
app.Metadata = map[string]interface{}{
|
||||||
"client": client,
|
"client": client,
|
||||||
"config": config,
|
"config": config,
|
||||||
}
|
}
|
||||||
|
if config.AccessToken == "" {
|
||||||
|
return authenticate(client, config, file)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
status.go
17
status.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Status is struct to hold status.
|
// Status is struct to hold status.
|
||||||
|
@ -173,8 +174,20 @@ func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) {
|
||||||
if toot.InReplyToID > 0 {
|
if toot.InReplyToID > 0 {
|
||||||
params.Set("in_reply_to_id", fmt.Sprint(toot.InReplyToID))
|
params.Set("in_reply_to_id", fmt.Sprint(toot.InReplyToID))
|
||||||
}
|
}
|
||||||
// TODO: media_ids, senstitive, spoiler_text, visibility
|
if toot.MediaIDs != nil {
|
||||||
//params.Set("visibility", "public")
|
for _, media := range toot.MediaIDs {
|
||||||
|
params.Add("media_ids[]", strconv.FormatInt(media, 10))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if toot.Visibility != "" {
|
||||||
|
params.Set("visibility", fmt.Sprint(toot.Visibility))
|
||||||
|
}
|
||||||
|
if toot.Sensitive {
|
||||||
|
params.Set("senstitive", "true")
|
||||||
|
}
|
||||||
|
if toot.SpoilerText != "" {
|
||||||
|
params.Set("spoiler_text", toot.SpoilerText)
|
||||||
|
}
|
||||||
|
|
||||||
var status Status
|
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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user