-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathuser.go
90 lines (78 loc) · 2.54 KB
/
user.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
package vkapi
import (
"encoding/json"
"net/url"
)
// last seen device
const (
_ = iota
PlatformMobile
PlatformIPhone
PlatfromIPad
PlatformAndroid
PlatformWPhone
PlatformWindows
PlatformWeb
)
var (
userFields = "nickname,screen_name,sex,bdate,city,country," +
"photo,photo_medium,photo_big,has_mobile,contacts," +
"education,online,relation,last_seen,activity," +
"can_write_private_message,can_see_all_posts,can_post,universities"
)
type User struct {
UID int `json:"id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Sex int `json:"sex"`
Nickname string `json:"nickname"`
ScreenName string `json:"screen_name"`
BDate string `json:"bdate"`
City *UserCity `json:"city"`
Country *UserCountry `json:"country"`
Photo string `json:"photo"`
PhotoMedium string `json:"photo_medium"`
PhotoBig string `json:"photo_big"`
Photo50 string `json:"photo_50"`
Photo100 string `json:"photo_100"`
HasMobile int `json:"has_mobile"`
Online int `json:"online"`
OnlineInfo *OnlineInfo `json:"online_info"`
CanPost int `json:"can_post"`
CanSeeAllPosts int `json:"can_see_all_posts"`
CanWritePrivateMessages int `json:"can_write_private_message"`
Status string `json:"activity"`
LastOnline *LastSeen `json:"last_seen"`
Hidden int `json:"hidden"`
Deactivated string `json:"deactivated"`
Relation int `json:"relation"`
}
type UserCity struct {
ID int `json:"id"`
Title string `json:"title"`
}
type UserCountry struct {
ID int `json:"id"`
Title string `json:"title"`
}
type LastSeen struct {
Time int64 `json:"time"`
Platform int `json:"platform"`
}
type OnlineInfo struct {
Visible bool `json:"visible"`
LastSeen int64 `json:"last_seen"`
}
func (client *VKClient) UsersGet(users []int) ([]*User, error) {
idsString := ArrayToStr(users)
v := url.Values{}
v.Add("user_ids", idsString)
v.Add("fields", userFields)
resp, err := client.MakeRequest("users.get", v)
if err != nil {
return nil, err
}
var userList []*User
json.Unmarshal(resp.Response, &userList)
return userList, nil
}