-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
api.go
63 lines (52 loc) · 2.35 KB
/
api.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
package like
import (
"context"
"github.com/michimani/gotwi"
"github.com/michimani/gotwi/tweet/like/types"
)
const (
listUsersEndpoint = "https://api.twitter.com/2/tweets/:id/liking_users"
listEndpoint = "https://api.twitter.com/2/users/:id/liked_tweets"
createEndpoint = "https://api.twitter.com/2/users/:id/likes"
deleteEndpoint = "https://api.twitter.com/2/users/:id/likes/:tweet_id"
)
// Allows you to get information about a Tweet’s liking users.
// You will receive the most recent 100 users who liked the specified Tweet.
// https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/get-tweets-id-liking_users
func ListUsers(ctx context.Context, c *gotwi.Client, p *types.ListUsersInput) (*types.ListUsersOutput, error) {
res := &types.ListUsersOutput{}
if err := c.CallAPI(ctx, listUsersEndpoint, "GET", p, res); err != nil {
return nil, err
}
return res, nil
}
// Allows you to get information about a user’s liked Tweets.
// The Tweets returned by this endpoint count towards the Project-level Tweet cap.
// https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/get-users-id-liked_tweets
func List(ctx context.Context, c *gotwi.Client, p *types.ListInput) (*types.ListOutput, error) {
res := &types.ListOutput{}
if err := c.CallAPI(ctx, listEndpoint, "GET", p, res); err != nil {
return nil, err
}
return res, nil
}
// Causes the user ID identified in the path parameter to Like the target Tweet.
// https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/post-users-id-likes
func Create(ctx context.Context, c *gotwi.Client, p *types.CreateInput) (*types.CreateOutput, error) {
res := &types.CreateOutput{}
if err := c.CallAPI(ctx, createEndpoint, "POST", p, res); err != nil {
return nil, err
}
return res, nil
}
// Allows a user or authenticated user ID to unlike a Tweet.
// The request succeeds with no action when the user sends
// a request to a user they're not liking the Tweet or have already unliked the Tweet.
// https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/delete-users-id-likes-tweet_id
func Delete(ctx context.Context, c *gotwi.Client, p *types.DeleteInput) (*types.DeleteOutput, error) {
res := &types.DeleteOutput{}
if err := c.CallAPI(ctx, deleteEndpoint, "DELETE", p, res); err != nil {
return nil, err
}
return res, nil
}