forked from ahmedash95/go-twitter
/
friendships.go
134 lines (117 loc) · 5 KB
/
friendships.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package twitter
import (
"net/http"
"github.com/dghubble/sling"
)
// FriendshipService provides methods for accessing Twitter friendship API
// endpoints.
type FriendshipService struct {
sling *sling.Sling
}
// newFriendshipService returns a new FriendshipService.
func newFriendshipService(sling *sling.Sling) *FriendshipService {
return &FriendshipService{
sling: sling.Path("friendships/"),
}
}
// FriendshipCreateParams are parameters for FriendshipService.Create
type FriendshipCreateParams struct {
ScreenName string `url:"screen_name,omitempty"`
UserID int64 `url:"user_id,omitempty"`
Follow *bool `url:"follow,omitempty"`
}
// Create creates a friendship to (i.e. follows) the specified user and
// returns the followed user.
// Requires a user auth context.
// https://dev.twitter.com/rest/reference/post/friendships/create
func (s *FriendshipService) Create(params *FriendshipCreateParams) (*User, *http.Response, error) {
user := new(User)
apiError := new(APIError)
resp, err := s.sling.New().Post("create.json").QueryStruct(params).Receive(user, apiError)
return user, resp, relevantError(err, *apiError)
}
// FriendshipShowParams are paramenters for FriendshipService.Show
type FriendshipShowParams struct {
SourceID int64 `url:"source_id,omitempty"`
SourceScreenName string `url:"source_screen_name,omitempty"`
TargetID int64 `url:"target_id,omitempty"`
TargetScreenName string `url:"target_screen_name,omitempty"`
}
// Show returns the relationship between two arbitrary users.
// Requires a user auth or an app context.
// https://dev.twitter.com/rest/reference/get/friendships/show
func (s *FriendshipService) Show(params *FriendshipShowParams) (*Relationship, *http.Response, error) {
response := new(RelationshipResponse)
apiError := new(APIError)
resp, err := s.sling.New().Get("show.json").QueryStruct(params).Receive(response, apiError)
return response.Relationship, resp, relevantError(err, *apiError)
}
// RelationshipResponse contains a relationship.
type RelationshipResponse struct {
Relationship *Relationship `json:"relationship"`
}
// Relationship represents the relation between a source user and target user.
type Relationship struct {
Source RelationshipSource `json:"source"`
Target RelationshipTarget `json:"target"`
}
// RelationshipSource represents the source user.
type RelationshipSource struct {
ID int64 `json:"id"`
IDStr string `json:"id_str"`
ScreenName string `json:"screen_name"`
Following bool `json:"following"`
FollowedBy bool `json:"followed_by"`
CanDM bool `json:"can_dm"`
Blocking bool `json:"blocking"`
Muting bool `json:"muting"`
AllReplies bool `json:"all_replies"`
WantRetweets bool `json:"want_retweets"`
MarkedSpam bool `json:"marked_spam"`
NotificationsEnabled bool `json:"notifications_enabled"`
}
// RelationshipTarget represents the target user.
type RelationshipTarget struct {
ID int64 `json:"id"`
IDStr string `json:"id_str"`
ScreenName string `json:"screen_name"`
Following bool `json:"following"`
FollowedBy bool `json:"followed_by"`
}
// FriendshipDestroyParams are paramenters for FriendshipService.Destroy
type FriendshipDestroyParams struct {
ScreenName string `url:"screen_name,omitempty"`
UserID int64 `url:"user_id,omitempty"`
}
// Destroy destroys a friendship to (i.e. unfollows) the specified user and
// returns the unfollowed user.
// Requires a user auth context.
// https://dev.twitter.com/rest/reference/post/friendships/destroy
func (s *FriendshipService) Destroy(params *FriendshipDestroyParams) (*User, *http.Response, error) {
user := new(User)
apiError := new(APIError)
resp, err := s.sling.New().Post("destroy.json").QueryStruct(params).Receive(user, apiError)
return user, resp, relevantError(err, *apiError)
}
// FriendshipPendingParams are paramenters for FriendshipService.Outgoing
type FriendshipPendingParams struct {
Cursor int64 `url:"cursor,omitempty"`
}
// Outgoing returns a collection of numeric IDs for every protected user for whom the authenticating
// user has a pending follow request.
// https://dev.twitter.com/rest/reference/get/friendships/outgoing
func (s *FriendshipService) Outgoing(params *FriendshipPendingParams) (*FriendIDs, *http.Response, error) {
ids := new(FriendIDs)
apiError := new(APIError)
resp, err := s.sling.New().Get("outgoing.json").QueryStruct(params).Receive(ids, apiError)
return ids, resp, relevantError(err, *apiError)
}
// Incoming returns a collection of numeric IDs for every user who has a pending request to
// follow the authenticating user.
// https://dev.twitter.com/rest/reference/get/friendships/incoming
func (s *FriendshipService) Incoming(params *FriendshipPendingParams) (*FriendIDs, *http.Response, error) {
ids := new(FriendIDs)
apiError := new(APIError)
resp, err := s.sling.New().Get("incoming.json").QueryStruct(params).Receive(ids, apiError)
return ids, resp, relevantError(err, *apiError)
}