Add Favourite and Unfavourite
parent
7719f511aa
commit
bbb4df76ca
20
status.go
20
status.go
|
@ -125,6 +125,26 @@ func (c *Client) Unreblog(id int64) (*Status, error) {
|
|||
return &status, nil
|
||||
}
|
||||
|
||||
// Favourite is favourite the toot of id and return status of the favourite toot.
|
||||
func (c *Client) Favourite(id int64) (*Status, error) {
|
||||
var status Status
|
||||
err := c.doAPI(http.MethodPost, fmt.Sprintf("/api/v1/statuses/%d/favourite", id), nil, &status)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &status, nil
|
||||
}
|
||||
|
||||
// Unfavourite is unfavourite the toot of id and return status of the unfavourite toot.
|
||||
func (c *Client) Unfavourite(id int64) (*Status, error) {
|
||||
var status Status
|
||||
err := c.doAPI(http.MethodPost, fmt.Sprintf("/api/v1/statuses/%d/unfavourite", 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
|
||||
|
|
|
@ -166,3 +166,63 @@ func TestUnreblog(t *testing.T) {
|
|||
t.Fatalf("want %q but %q", "zzz", status.Content)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFavourite(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/v1/statuses/1234567/favourite" {
|
||||
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.Favourite(123)
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
status, err := client.Favourite(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 TestUnfavourite(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/v1/statuses/1234567/unfavourite" {
|
||||
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.Unfavourite(123)
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
status, err := client.Unfavourite(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