Add method to include accounts resolve param
parent
7dfe81e233
commit
f61059815d
14
accounts.go
14
accounts.go
|
@ -284,6 +284,20 @@ func (c *Client) AccountsSearch(ctx context.Context, q string, limit int64) ([]*
|
||||||
return accounts, nil
|
return accounts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) AccountsSearchResolve(ctx context.Context, q string, limit int64) ([]*Account, error) {
|
||||||
|
params := url.Values{}
|
||||||
|
params.Set("q", q)
|
||||||
|
params.Set("limit", fmt.Sprint(limit))
|
||||||
|
params.Set("resolve", "true")
|
||||||
|
|
||||||
|
var accounts []*Account
|
||||||
|
err := c.doAPI(ctx, http.MethodGet, "/api/v1/accounts/search", params, &accounts, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return accounts, nil
|
||||||
|
}
|
||||||
|
|
||||||
// FollowRemoteUser send follow-request.
|
// FollowRemoteUser send follow-request.
|
||||||
func (c *Client) FollowRemoteUser(ctx context.Context, uri string) (*Account, error) {
|
func (c *Client) FollowRemoteUser(ctx context.Context, uri string) (*Account, error) {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
|
|
|
@ -559,6 +559,41 @@ func TestAccountsSearch(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccountsSearchResolve(t *testing.T) {
|
||||||
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.URL.Query()["q"][0] != "foo" {
|
||||||
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Fprintln(w, `[{"username": "foobar"}, {"username": "barfoo"}]`)
|
||||||
|
}))
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
client := NewClient(&Config{
|
||||||
|
Server: ts.URL,
|
||||||
|
ClientID: "foo",
|
||||||
|
ClientSecret: "bar",
|
||||||
|
AccessToken: "zoo",
|
||||||
|
})
|
||||||
|
_, err := client.AccountsSearchResolve(context.Background(), "zzz", 2)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("should be fail: %v", err)
|
||||||
|
}
|
||||||
|
res, err := client.AccountsSearchResolve(context.Background(), "foo", 2)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not be fail: %v", err)
|
||||||
|
}
|
||||||
|
if len(res) != 2 {
|
||||||
|
t.Fatalf("result should be two: %d", len(res))
|
||||||
|
}
|
||||||
|
if res[0].Username != "foobar" {
|
||||||
|
t.Fatalf("want %q but %q", "foobar", res[0].Username)
|
||||||
|
}
|
||||||
|
if res[1].Username != "barfoo" {
|
||||||
|
t.Fatalf("want %q but %q", "barfoo", res[1].Username)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestFollowRemoteUser(t *testing.T) {
|
func TestFollowRemoteUser(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.PostFormValue("uri") != "foo@success.social" {
|
if r.PostFormValue("uri") != "foo@success.social" {
|
||||||
|
|
Loading…
Reference in New Issue