commit
e4826e97a1
17
accounts.go
17
accounts.go
|
@ -66,6 +66,16 @@ func (c *Client) GetAccountFollowing(id int64) ([]*Account, error) {
|
||||||
return accounts, nil
|
return accounts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetBlocks return block list.
|
||||||
|
func (c *Client) GetBlocks() ([]*Account, error) {
|
||||||
|
var accounts []*Account
|
||||||
|
err := c.doAPI(http.MethodGet, "/api/v1/blocks", nil, &accounts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return accounts, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Relationship hold information for relation-ship to the account.
|
// Relationship hold information for relation-ship to the account.
|
||||||
type Relationship struct {
|
type Relationship struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
|
@ -177,12 +187,9 @@ func (c *Client) FollowRemoteUser(uri string) (*Account, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFollowRequests return follow-requests.
|
// GetFollowRequests return follow-requests.
|
||||||
func (c *Client) GetFollowRequests(uri string) ([]*Account, error) {
|
func (c *Client) GetFollowRequests() ([]*Account, error) {
|
||||||
params := url.Values{}
|
|
||||||
params.Set("uri", uri)
|
|
||||||
|
|
||||||
var accounts []*Account
|
var accounts []*Account
|
||||||
err := c.doAPI(http.MethodGet, "/api/v1/follow_requests", params, &accounts)
|
err := c.doAPI(http.MethodGet, "/api/v1/follow_requests", nil, &accounts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,34 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestGetBlocks(t *testing.T) {
|
||||||
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
fmt.Fprintln(w, `[{"Username": "foo"}, {"Username": "bar"}]`)
|
||||||
|
return
|
||||||
|
}))
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
client := NewClient(&Config{
|
||||||
|
Server: ts.URL,
|
||||||
|
ClientID: "foo",
|
||||||
|
ClientSecret: "bar",
|
||||||
|
AccessToken: "zoo",
|
||||||
|
})
|
||||||
|
bl, err := client.GetBlocks()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not be fail: %v", err)
|
||||||
|
}
|
||||||
|
if len(bl) != 2 {
|
||||||
|
t.Fatalf("result should be two: %d", len(bl))
|
||||||
|
}
|
||||||
|
if bl[0].Username != "foo" {
|
||||||
|
t.Fatalf("want %q but %q", "foo", bl[0].Username)
|
||||||
|
}
|
||||||
|
if bl[1].Username != "bar" {
|
||||||
|
t.Fatalf("want %q but %q", "bar", bl[0].Username)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccountFollow(t *testing.T) {
|
func TestAccountFollow(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Path != "/api/v1/accounts/1234567/follow" {
|
if r.URL.Path != "/api/v1/accounts/1234567/follow" {
|
||||||
|
@ -72,3 +100,31 @@ func TestAccountUnfollow(t *testing.T) {
|
||||||
t.Fatalf("want %t but %t", false, rel.Following)
|
t.Fatalf("want %t but %t", false, rel.Following)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetFollowRequests(t *testing.T) {
|
||||||
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
fmt.Fprintln(w, `[{"Username": "foo"}, {"Username": "bar"}]`)
|
||||||
|
return
|
||||||
|
}))
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
client := NewClient(&Config{
|
||||||
|
Server: ts.URL,
|
||||||
|
ClientID: "foo",
|
||||||
|
ClientSecret: "bar",
|
||||||
|
AccessToken: "zoo",
|
||||||
|
})
|
||||||
|
fReqs, err := client.GetFollowRequests()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not be fail: %v", err)
|
||||||
|
}
|
||||||
|
if len(fReqs) != 2 {
|
||||||
|
t.Fatalf("result should be two: %d", len(fReqs))
|
||||||
|
}
|
||||||
|
if fReqs[0].Username != "foo" {
|
||||||
|
t.Fatalf("want %q but %q", "foo", fReqs[0].Username)
|
||||||
|
}
|
||||||
|
if fReqs[1].Username != "bar" {
|
||||||
|
t.Fatalf("want %q but %q", "bar", fReqs[0].Username)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
10
status.go
10
status.go
|
@ -45,6 +45,16 @@ type Card struct {
|
||||||
Image string `json:"image"`
|
Image string `json:"image"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetFavourites return the favorite list of the current user.
|
||||||
|
func (c *Client) GetFavourites() ([]*Status, error) {
|
||||||
|
var statuses []*Status
|
||||||
|
err := c.doAPI(http.MethodGet, "/api/v1/favourites", nil, &statuses)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return statuses, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetStatus return status specified by id.
|
// GetStatus return status specified by id.
|
||||||
func (c *Client) GetStatus(id string) (*Status, error) {
|
func (c *Client) GetStatus(id string) (*Status, error) {
|
||||||
var status Status
|
var status Status
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package mastodon
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetFavourites(t *testing.T) {
|
||||||
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
fmt.Fprintln(w, `[{"Content": "foo"}, {"Content": "bar"}]`)
|
||||||
|
return
|
||||||
|
}))
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
client := NewClient(&Config{
|
||||||
|
Server: ts.URL,
|
||||||
|
ClientID: "foo",
|
||||||
|
ClientSecret: "bar",
|
||||||
|
AccessToken: "zoo",
|
||||||
|
})
|
||||||
|
favs, err := client.GetFavourites()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not be fail: %v", err)
|
||||||
|
}
|
||||||
|
if len(favs) != 2 {
|
||||||
|
t.Fatalf("result should be two: %d", len(favs))
|
||||||
|
}
|
||||||
|
if favs[0].Content != "foo" {
|
||||||
|
t.Fatalf("want %q but %q", "foo", favs[0].Content)
|
||||||
|
}
|
||||||
|
if favs[1].Content != "bar" {
|
||||||
|
t.Fatalf("want %q but %q", "bar", favs[1].Content)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue