forked from carbocation/go-instagram
/
likes.go
58 lines (49 loc) · 1.47 KB
/
likes.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
// Copyright 2013 The go-instagram AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package instagram
import (
"fmt"
)
// LikesService handles communication with the likes related
// methods of the Instagram API.
//
// Instagram API docs: http://instagram.com/developer/endpoints/likes/
type LikesService struct {
client *Client
}
// MediaLikes gets a list of users who have liked mediaID.
//
// Instagram API docs: http://instagram.com/developer/endpoints/likes/#get_media_likes
func (s *LikesService) MediaLikes(mediaID string) ([]User, error) {
u := fmt.Sprintf("media/%v/likes", mediaID)
req, err := s.client.NewRequest("GET", u, "")
if err != nil {
return nil, err
}
users := new([]User)
_, err = s.client.Do(req, users)
return *users, err
}
// Like a media.
//
// Instagram API docs: http://instagram.com/developer/endpoints/likes/#post_likes
func (s *LikesService) Like(mediaID string) error {
return mediaLikesAction(s, mediaID, "POST")
}
// Unlike a media.
//
// Instagram API docs: http://instagram.com/developer/endpoints/likes/#delete_likes
func (s *LikesService) Unlike(mediaID string) error {
return mediaLikesAction(s, mediaID, "DELETE")
}
func mediaLikesAction(s *LikesService, mediaID, method string) error {
u := fmt.Sprintf("media/%v/likes", mediaID)
req, err := s.client.NewRequest(method, u, "")
if err != nil {
return err
}
_, err = s.client.Do(req, nil)
return err
}