forked from ahmdrz/goinsta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profiles.go
69 lines (62 loc) · 1.38 KB
/
profiles.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
package goinsta
import (
"encoding/json"
"fmt"
)
// Profiles allows user function interactions
type Profiles struct {
inst *Instagram
}
func newProfiles(inst *Instagram) *Profiles {
profiles := &Profiles{
inst: inst,
}
return profiles
}
// ByName return a *User structure parsed by username
func (prof *Profiles) ByName(name string) (*User, error) {
body, err := prof.inst.sendSimpleRequest(urlUserByName, name)
if err == nil {
resp := userResp{}
err = json.Unmarshal(body, &resp)
if err == nil {
user := &resp.User
user.inst = prof.inst
return user, err
}
}
return nil, err
}
// ByID returns a *User structure parsed by user id
func (prof *Profiles) ByID(id int64) (*User, error) {
data, err := prof.inst.prepareData()
if err != nil {
return nil, err
}
body, err := prof.inst.sendRequest(
&reqOptions{
Endpoint: fmt.Sprintf(urlUserByID, id),
Query: generateSignature(data),
},
)
if err == nil {
resp := userResp{}
err = json.Unmarshal(body, &resp)
if err == nil {
user := &resp.User
user.inst = prof.inst
return user, err
}
}
return nil, err
}
// Blocked returns a list of blocked profiles.
func (prof *Profiles) Blocked() ([]BlockedUser, error) {
body, err := prof.inst.sendSimpleRequest(urlBlockedList)
if err == nil {
resp := blockedListResp{}
err = json.Unmarshal(body, &resp)
return resp.BlockedList, err
}
return nil, err
}