From 8424b2ac492540be07269cbb3f463c2c78330786 Mon Sep 17 00:00:00 2001 From: Vartan Benohanian Date: Thu, 2 Jul 2020 20:36:44 -0400 Subject: [PATCH] Rename Friendship struct to Relationship Signed-off-by: Vartan Benohanian --- account.go | 6 +++--- account_test.go | 18 +++++++++--------- user.go | 22 +++++++++++----------- user_test.go | 18 +++++++++--------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/account.go b/account.go index 5e22055..003c783 100644 --- a/account.go +++ b/account.go @@ -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) diff --git a/account_test.go b/account_test.go index 830336b..a4849a5 100644 --- a/account_test.go +++ b/account_test.go @@ -97,18 +97,18 @@ var expectedSettings = &Settings{ EnableVideoAutoplay: Bool(true), } -var expectedFriends = []Friendship{ +var expectedFriends = []Relationship{ { - ID: "r9_1r4879", - Friend: "test1", - FriendID: "t2_test1", - Created: &Timestamp{time.Date(2020, 6, 28, 16, 43, 55, 0, time.UTC)}, + ID: "r9_1r4879", + 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", - Created: &Timestamp{time.Date(2020, 6, 28, 16, 44, 2, 0, time.UTC)}, + ID: "r9_1re930", + User: "test2", + UserID: "t2_test2", + Created: &Timestamp{time.Date(2020, 6, 28, 16, 44, 2, 0, time.UTC)}, }, } diff --git a/user.go b/user.go index bbd6dae..afacd66 100644 --- a/user.go +++ b/user.go @@ -42,12 +42,12 @@ type UserShort struct { NSFW bool `json:"profile_over_18"` } -// Friendship represents a friend relationship. -type Friendship struct { - ID string `json:"rel_id,omitempty"` - Friend string `json:"name,omitempty"` - FriendID string `json:"id,omitempty"` - Created *Timestamp `json:"date,omitempty"` +// Relationship holds information about a relationship (friend/blocked). +type Relationship struct { + ID string `json:"rel_id,omitempty"` + User string `json:"name,omitempty"` + UserID string `json:"id,omitempty"` + Created *Timestamp `json:"date,omitempty"` } // Blocked represents a blocked relationship. @@ -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 diff --git a/user_test.go b/user_test.go index ccc34a4..aee5cf3 100644 --- a/user_test.go +++ b/user_test.go @@ -103,11 +103,11 @@ var expectedComment = Comment{ PostNumComments: 89751, } -var expectedFriendship = &Friendship{ - ID: "r9_tqfqp8", - Friend: "test123", - FriendID: "t2_7b8q1eob", - Created: &Timestamp{time.Date(2020, 6, 18, 20, 36, 34, 0, time.UTC)}, +var expectedRelationship = &Relationship{ + ID: "r9_tqfqp8", + User: "test123", + UserID: "t2_7b8q1eob", + Created: &Timestamp{time.Date(2020, 6, 18, 20, 36, 34, 0, time.UTC)}, } var expectedBlocked = &Blocked{ @@ -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) {