Add Reblog and Unreblog
This commit is contained in:
parent
74901c994c
commit
6891f221bc
20
status.go
20
status.go
|
@ -105,6 +105,26 @@ func (c *Client) GetFavouritedBy(id int64) ([]*Account, error) {
|
||||||
return accounts, nil
|
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.
|
// GetTimelineHome return statuses from home timeline.
|
||||||
func (c *Client) GetTimelineHome() ([]*Status, error) {
|
func (c *Client) GetTimelineHome() ([]*Status, error) {
|
||||||
var statuses []*Status
|
var statuses []*Status
|
||||||
|
|
|
@ -106,3 +106,63 @@ func TestGetFavouritedBy(t *testing.T) {
|
||||||
t.Fatalf("want %q but %q", "bar", fbs[0].Username)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user