Rename Friendship struct to Relationship

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian 2020-07-02 20:36:44 -04:00
parent f19965798c
commit 8424b2ac49
4 changed files with 32 additions and 32 deletions

View file

@ -305,7 +305,7 @@ func (s *AccountService) Trophies(ctx context.Context) ([]Trophy, *Response, err
}
type rootFriendList struct {
Friends []Friendship
Friends []Relationship
}
// UnmarshalJSON implements the json.Unmarshaler interface.
@ -340,7 +340,7 @@ func (l *rootFriendList) UnmarshalJSON(b []byte) error {
return nil
}
var friends []Friendship
var friends []Relationship
err = json.Unmarshal(byteValue, &friends)
if err != nil {
return err
@ -351,7 +351,7 @@ func (l *rootFriendList) UnmarshalJSON(b []byte) error {
}
// 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"
req, err := s.client.NewRequest(http.MethodGet, path, nil)

View file

@ -97,17 +97,17 @@ var expectedSettings = &Settings{
EnableVideoAutoplay: Bool(true),
}
var expectedFriends = []Friendship{
var expectedFriends = []Relationship{
{
ID: "r9_1r4879",
Friend: "test1",
FriendID: "t2_test1",
User: "test1",
UserID: "t2_test1",
Created: &Timestamp{time.Date(2020, 6, 28, 16, 43, 55, 0, time.UTC)},
},
{
ID: "r9_1re930",
Friend: "test2",
FriendID: "t2_test2",
User: "test2",
UserID: "t2_test2",
Created: &Timestamp{time.Date(2020, 6, 28, 16, 44, 2, 0, time.UTC)},
},
}

18
user.go
View file

@ -42,11 +42,11 @@ type UserShort struct {
NSFW bool `json:"profile_over_18"`
}
// Friendship represents a friend relationship.
type Friendship struct {
// Relationship holds information about a relationship (friend/blocked).
type Relationship struct {
ID string `json:"rel_id,omitempty"`
Friend string `json:"name,omitempty"`
FriendID string `json:"id,omitempty"`
User string `json:"name,omitempty"`
UserID string `json:"id,omitempty"`
Created *Timestamp `json:"date,omitempty"`
}
@ -329,9 +329,9 @@ func (s *UserService) Gilded(ctx context.Context, opts ...SearchOptionSetter) (*
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.
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)
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
}
root := new(Friendship)
root := new(Relationship)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
@ -349,7 +349,7 @@ func (s *UserService) GetFriendship(ctx context.Context, username string) (*Frie
}
// 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 {
Username string `json:"name"`
}
@ -362,7 +362,7 @@ func (s *UserService) Friend(ctx context.Context, username string) (*Friendship,
return nil, nil, err
}
root := new(Friendship)
root := new(Relationship)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err

View file

@ -103,10 +103,10 @@ var expectedComment = Comment{
PostNumComments: 89751,
}
var expectedFriendship = &Friendship{
var expectedRelationship = &Relationship{
ID: "r9_tqfqp8",
Friend: "test123",
FriendID: "t2_7b8q1eob",
User: "test123",
UserID: "t2_7b8q1eob",
Created: &Timestamp{time.Date(2020, 6, 18, 20, 36, 34, 0, time.UTC)},
}
@ -589,9 +589,9 @@ func TestUserService_GetFriendship(t *testing.T) {
fmt.Fprint(w, blob)
})
friendship, _, err := client.User.GetFriendship(ctx, "test123")
relationship, _, err := client.User.GetFriendship(ctx, "test123")
assert.NoError(t, err)
assert.Equal(t, expectedFriendship, friendship)
assert.Equal(t, expectedRelationship, relationship)
}
func TestUserService_Friend(t *testing.T) {
@ -615,9 +615,9 @@ func TestUserService_Friend(t *testing.T) {
fmt.Fprint(w, blob)
})
friendship, _, err := client.User.Friend(ctx, "test123")
relationship, _, err := client.User.Friend(ctx, "test123")
assert.NoError(t, err)
assert.Equal(t, expectedFriendship, friendship)
assert.Equal(t, expectedRelationship, relationship)
}
func TestUserService_Unfriend(t *testing.T) {