Add method to get blocked users
Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
parent
8424b2ac49
commit
12e801f83c
3 changed files with 63 additions and 3 deletions
25
account.go
25
account.go
|
@ -367,3 +367,28 @@ func (s *AccountService) Friends(ctx context.Context) ([]Relationship, *Response
|
|||
|
||||
return root.Friends, resp, nil
|
||||
}
|
||||
|
||||
type rootBlockedListing struct {
|
||||
Kind string `json:"kind,omitempty"`
|
||||
Data struct {
|
||||
Blocked []Relationship `json:"children"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
// Blocked returns a list of your blocked users.
|
||||
func (s *AccountService) Blocked(ctx context.Context) ([]Relationship, *Response, error) {
|
||||
path := "prefs/blocked"
|
||||
|
||||
req, err := s.client.NewRequest(http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(rootBlockedListing)
|
||||
resp, err := s.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return root.Data.Blocked, resp, nil
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ var expectedSettings = &Settings{
|
|||
EnableVideoAutoplay: Bool(true),
|
||||
}
|
||||
|
||||
var expectedFriends = []Relationship{
|
||||
var expectedRelationships = []Relationship{
|
||||
{
|
||||
ID: "r9_1r4879",
|
||||
User: "test1",
|
||||
|
@ -210,7 +210,23 @@ func TestAccountService_Friends(t *testing.T) {
|
|||
fmt.Fprint(w, blob)
|
||||
})
|
||||
|
||||
friends, _, err := client.Account.Friends(ctx)
|
||||
relationships, _, err := client.Account.Friends(ctx)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expectedFriends, friends)
|
||||
assert.Equal(t, expectedRelationships, relationships)
|
||||
}
|
||||
|
||||
func TestAccountService_Blocked(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
||||
blob := readFileContents(t, "testdata/account/blocked.json")
|
||||
|
||||
mux.HandleFunc("/prefs/blocked", func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, http.MethodGet, r.Method)
|
||||
fmt.Fprint(w, blob)
|
||||
})
|
||||
|
||||
relationships, _, err := client.Account.Blocked(ctx)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expectedRelationships, relationships)
|
||||
}
|
||||
|
|
19
testdata/account/blocked.json
vendored
Normal file
19
testdata/account/blocked.json
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"kind": "UserList",
|
||||
"data": {
|
||||
"children": [
|
||||
{
|
||||
"date": 1593362635,
|
||||
"rel_id": "r9_1r4879",
|
||||
"name": "test1",
|
||||
"id": "t2_test1"
|
||||
},
|
||||
{
|
||||
"date": 1593362642,
|
||||
"rel_id": "r9_1re930",
|
||||
"name": "test2",
|
||||
"id": "t2_test2"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue