Add method to get blocked users
Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
+25
@@ -367,3 +367,28 @@ func (s *AccountService) Friends(ctx context.Context) ([]Relationship, *Response
|
|||||||
|
|
||||||
return root.Friends, resp, nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
+19
-3
@@ -97,7 +97,7 @@ var expectedSettings = &Settings{
|
|||||||
EnableVideoAutoplay: Bool(true),
|
EnableVideoAutoplay: Bool(true),
|
||||||
}
|
}
|
||||||
|
|
||||||
var expectedFriends = []Relationship{
|
var expectedRelationships = []Relationship{
|
||||||
{
|
{
|
||||||
ID: "r9_1r4879",
|
ID: "r9_1r4879",
|
||||||
User: "test1",
|
User: "test1",
|
||||||
@@ -210,7 +210,23 @@ func TestAccountService_Friends(t *testing.T) {
|
|||||||
fmt.Fprint(w, blob)
|
fmt.Fprint(w, blob)
|
||||||
})
|
})
|
||||||
|
|
||||||
friends, _, err := client.Account.Friends(ctx)
|
relationships, _, err := client.Account.Friends(ctx)
|
||||||
assert.NoError(t, err)
|
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)
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+19
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user