Rename Friendship struct to Relationship
Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
+3
-3
@@ -305,7 +305,7 @@ func (s *AccountService) Trophies(ctx context.Context) ([]Trophy, *Response, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
type rootFriendList struct {
|
type rootFriendList struct {
|
||||||
Friends []Friendship
|
Friends []Relationship
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalJSON implements the json.Unmarshaler interface.
|
// UnmarshalJSON implements the json.Unmarshaler interface.
|
||||||
@@ -340,7 +340,7 @@ func (l *rootFriendList) UnmarshalJSON(b []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var friends []Friendship
|
var friends []Relationship
|
||||||
err = json.Unmarshal(byteValue, &friends)
|
err = json.Unmarshal(byteValue, &friends)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -351,7 +351,7 @@ func (l *rootFriendList) UnmarshalJSON(b []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Friends returns a list of your friends.
|
// Friends returns a list of your friends.
|
||||||
func (s *AccountService) Friends(ctx context.Context) ([]Friendship, *Response, error) {
|
func (s *AccountService) Friends(ctx context.Context) ([]Relationship, *Response, error) {
|
||||||
path := "prefs/friends"
|
path := "prefs/friends"
|
||||||
|
|
||||||
req, err := s.client.NewRequest(http.MethodGet, path, nil)
|
req, err := s.client.NewRequest(http.MethodGet, path, nil)
|
||||||
|
|||||||
+9
-9
@@ -97,18 +97,18 @@ var expectedSettings = &Settings{
|
|||||||
EnableVideoAutoplay: Bool(true),
|
EnableVideoAutoplay: Bool(true),
|
||||||
}
|
}
|
||||||
|
|
||||||
var expectedFriends = []Friendship{
|
var expectedFriends = []Relationship{
|
||||||
{
|
{
|
||||||
ID: "r9_1r4879",
|
ID: "r9_1r4879",
|
||||||
Friend: "test1",
|
User: "test1",
|
||||||
FriendID: "t2_test1",
|
UserID: "t2_test1",
|
||||||
Created: &Timestamp{time.Date(2020, 6, 28, 16, 43, 55, 0, time.UTC)},
|
Created: &Timestamp{time.Date(2020, 6, 28, 16, 43, 55, 0, time.UTC)},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: "r9_1re930",
|
ID: "r9_1re930",
|
||||||
Friend: "test2",
|
User: "test2",
|
||||||
FriendID: "t2_test2",
|
UserID: "t2_test2",
|
||||||
Created: &Timestamp{time.Date(2020, 6, 28, 16, 44, 2, 0, time.UTC)},
|
Created: &Timestamp{time.Date(2020, 6, 28, 16, 44, 2, 0, time.UTC)},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,12 +42,12 @@ type UserShort struct {
|
|||||||
NSFW bool `json:"profile_over_18"`
|
NSFW bool `json:"profile_over_18"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Friendship represents a friend relationship.
|
// Relationship holds information about a relationship (friend/blocked).
|
||||||
type Friendship struct {
|
type Relationship struct {
|
||||||
ID string `json:"rel_id,omitempty"`
|
ID string `json:"rel_id,omitempty"`
|
||||||
Friend string `json:"name,omitempty"`
|
User string `json:"name,omitempty"`
|
||||||
FriendID string `json:"id,omitempty"`
|
UserID string `json:"id,omitempty"`
|
||||||
Created *Timestamp `json:"date,omitempty"`
|
Created *Timestamp `json:"date,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Blocked represents a blocked relationship.
|
// Blocked represents a blocked relationship.
|
||||||
@@ -329,9 +329,9 @@ func (s *UserService) Gilded(ctx context.Context, opts ...SearchOptionSetter) (*
|
|||||||
return root.getPosts(), resp, nil
|
return root.getPosts(), resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFriendship returns friendship details with the specified user.
|
// GetFriendship returns relationship details with the specified user.
|
||||||
// If the user is not your friend, it will return an error.
|
// If the user is not your friend, it will return an error.
|
||||||
func (s *UserService) GetFriendship(ctx context.Context, username string) (*Friendship, *Response, error) {
|
func (s *UserService) GetFriendship(ctx context.Context, username string) (*Relationship, *Response, error) {
|
||||||
path := fmt.Sprintf("api/v1/me/friends/%s", username)
|
path := fmt.Sprintf("api/v1/me/friends/%s", username)
|
||||||
|
|
||||||
req, err := s.client.NewRequest(http.MethodGet, path, nil)
|
req, err := s.client.NewRequest(http.MethodGet, path, nil)
|
||||||
@@ -339,7 +339,7 @@ func (s *UserService) GetFriendship(ctx context.Context, username string) (*Frie
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
root := new(Friendship)
|
root := new(Relationship)
|
||||||
resp, err := s.client.Do(ctx, req, root)
|
resp, err := s.client.Do(ctx, req, root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, resp, err
|
return nil, resp, err
|
||||||
@@ -349,7 +349,7 @@ func (s *UserService) GetFriendship(ctx context.Context, username string) (*Frie
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Friend friends a user.
|
// Friend friends a user.
|
||||||
func (s *UserService) Friend(ctx context.Context, username string) (*Friendship, *Response, error) {
|
func (s *UserService) Friend(ctx context.Context, username string) (*Relationship, *Response, error) {
|
||||||
type request struct {
|
type request struct {
|
||||||
Username string `json:"name"`
|
Username string `json:"name"`
|
||||||
}
|
}
|
||||||
@@ -362,7 +362,7 @@ func (s *UserService) Friend(ctx context.Context, username string) (*Friendship,
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
root := new(Friendship)
|
root := new(Relationship)
|
||||||
resp, err := s.client.Do(ctx, req, root)
|
resp, err := s.client.Do(ctx, req, root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, resp, err
|
return nil, resp, err
|
||||||
|
|||||||
+9
-9
@@ -103,11 +103,11 @@ var expectedComment = Comment{
|
|||||||
PostNumComments: 89751,
|
PostNumComments: 89751,
|
||||||
}
|
}
|
||||||
|
|
||||||
var expectedFriendship = &Friendship{
|
var expectedRelationship = &Relationship{
|
||||||
ID: "r9_tqfqp8",
|
ID: "r9_tqfqp8",
|
||||||
Friend: "test123",
|
User: "test123",
|
||||||
FriendID: "t2_7b8q1eob",
|
UserID: "t2_7b8q1eob",
|
||||||
Created: &Timestamp{time.Date(2020, 6, 18, 20, 36, 34, 0, time.UTC)},
|
Created: &Timestamp{time.Date(2020, 6, 18, 20, 36, 34, 0, time.UTC)},
|
||||||
}
|
}
|
||||||
|
|
||||||
var expectedBlocked = &Blocked{
|
var expectedBlocked = &Blocked{
|
||||||
@@ -589,9 +589,9 @@ func TestUserService_GetFriendship(t *testing.T) {
|
|||||||
fmt.Fprint(w, blob)
|
fmt.Fprint(w, blob)
|
||||||
})
|
})
|
||||||
|
|
||||||
friendship, _, err := client.User.GetFriendship(ctx, "test123")
|
relationship, _, err := client.User.GetFriendship(ctx, "test123")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, expectedFriendship, friendship)
|
assert.Equal(t, expectedRelationship, relationship)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUserService_Friend(t *testing.T) {
|
func TestUserService_Friend(t *testing.T) {
|
||||||
@@ -615,9 +615,9 @@ func TestUserService_Friend(t *testing.T) {
|
|||||||
fmt.Fprint(w, blob)
|
fmt.Fprint(w, blob)
|
||||||
})
|
})
|
||||||
|
|
||||||
friendship, _, err := client.User.Friend(ctx, "test123")
|
relationship, _, err := client.User.Friend(ctx, "test123")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, expectedFriendship, friendship)
|
assert.Equal(t, expectedRelationship, relationship)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUserService_Unfriend(t *testing.T) {
|
func TestUserService_Unfriend(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user