Merge branch 'master' of github.com:mattn/go-mastodon

pull/44/head
Yasuhiro Matsumoto 2017-04-24 17:50:32 +09:00
commit def474a7a5
4 changed files with 63 additions and 10 deletions

View File

@ -14,8 +14,17 @@ func TestCmdFollow(t *testing.T) {
func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/api/v1/accounts/search":
q := r.URL.Query().Get("q")
if q == "mattn" {
fmt.Fprintln(w, `[{"id": 123}]`)
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":
fmt.Fprintln(w, `{"id": 123}`)
ok = true
@ -25,7 +34,34 @@ func TestCmdFollow(t *testing.T) {
return
},
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 {

View File

@ -9,7 +9,7 @@ import (
"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)
defer ts.Close()
@ -31,6 +31,10 @@ func testWithServer(h http.HandlerFunc, testFunc func(*cli.App)) string {
Server: "https://example.com",
},
}
testFunc(app)
for _, f := range testFuncs {
f(app)
}
return buf.String()
}

View File

@ -329,13 +329,13 @@ func run() int {
}
client := mastodon.NewClient(config)
if config.AccessToken == "" {
return authenticate(client, config, file)
}
app.Metadata = map[string]interface{}{
"client": client,
"config": config,
}
if config.AccessToken == "" {
return authenticate(client, config, file)
}
return nil
}

View File

@ -6,6 +6,7 @@ import (
"net/http"
"net/url"
"time"
"strconv"
)
// 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 {
params.Set("in_reply_to_id", fmt.Sprint(toot.InReplyToID))
}
// TODO: media_ids, senstitive, spoiler_text, visibility
//params.Set("visibility", "public")
if toot.MediaIDs != nil {
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
err := c.doAPI(ctx, http.MethodPost, "/api/v1/statuses", params, &status, nil)