Add Reblog and Unreblog

pull/15/head
178inaba 2017-04-16 14:53:15 +09:00
parent 74901c994c
commit 6891f221bc
2 changed files with 80 additions and 0 deletions

View File

@ -105,6 +105,26 @@ func (c *Client) GetFavouritedBy(id int64) ([]*Account, error) {
return accounts, nil
}
// Reblog is reblog the toot of id.
func (c *Client) Reblog(id int64) (*Status, error) {
var status Status
err := c.doAPI(http.MethodPost, fmt.Sprintf("/api/v1/statuses/%d/reblog", id), nil, &status)
if err != nil {
return nil, err
}
return &status, nil
}
// Unreblog is unreblog the toot of id.
func (c *Client) Unreblog(id int64) (*Status, error) {
var status Status
err := c.doAPI(http.MethodPost, fmt.Sprintf("/api/v1/statuses/%d/unreblog", id), nil, &status)
if err != nil {
return nil, err
}
return &status, nil
}
// GetTimelineHome return statuses from home timeline.
func (c *Client) GetTimelineHome() ([]*Status, error) {
var statuses []*Status

View File

@ -106,3 +106,63 @@ func TestGetFavouritedBy(t *testing.T) {
t.Fatalf("want %q but %q", "bar", fbs[0].Username)
}
}
func TestReblog(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/statuses/1234567/reblog" {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
fmt.Fprintln(w, `{"Content": "zzz"}`)
return
}))
defer ts.Close()
client := NewClient(&Config{
Server: ts.URL,
ClientID: "foo",
ClientSecret: "bar",
AccessToken: "zoo",
})
_, err := client.Reblog(123)
if err == nil {
t.Fatalf("should be fail: %v", err)
}
status, err := client.Reblog(1234567)
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
if status.Content != "zzz" {
t.Fatalf("want %q but %q", "zzz", status.Content)
}
}
func TestUnreblog(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/statuses/1234567/unreblog" {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
fmt.Fprintln(w, `{"Content": "zzz"}`)
return
}))
defer ts.Close()
client := NewClient(&Config{
Server: ts.URL,
ClientID: "foo",
ClientSecret: "bar",
AccessToken: "zoo",
})
_, err := client.Unreblog(123)
if err == nil {
t.Fatalf("should be fail: %v", err)
}
status, err := client.Unreblog(1234567)
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
if status.Content != "zzz" {
t.Fatalf("want %q but %q", "zzz", status.Content)
}
}