krz/devianter
A DeviantArt guest API library for Go.
clone: git clone https://gitbay.org/krz/devianter.git
v0.2.5: user-group.go · raw
1package devianter
2
3import (
4 "errors"
5 "strconv"
6 "strings"
7)
8
9// структура группы или пользователя
10type GRuser struct {
11 ErrorDescription string
12 Owner struct {
13 Group bool `json:"isGroup"`
14 Username string
15 }
16 Gruser struct {
17 ID int `json:"gruserId"`
18 Page struct {
19 Modules []struct {
20 Name string
21 ModuleData struct {
22 GroupAbout GroupAbout
23 GroupAdmins GroupAdmins
24 users
25 }
26 }
27 }
28 }
29 Extra struct {
30 Tag string `json:"gruserTagline"`
31 Stats struct {
32 Deviations, Watchers, Watching, Pageviews, CommentsMade, Favourites, Friends int
33 FeedComments int `json:"commentsReceivedProfile"`
34 }
35 } `json:"pageExtraData"`
36}
37
38type Gallery struct {
39 Gruser struct {
40 ID int `json:"gruserId"`
41 Page struct {
42 Modules []struct {
43 Name string
44 ModuleData struct {
45 // группы
46 Folders struct {
47 HasMore bool
48 Results []struct {
49 FolderId int
50 Size int
51 Name string
52 Thumb Deviation
53 }
54 }
55
56 // галерея
57 Folder struct {
58 HasMore bool
59 Username string
60 Pages int `json:"totalPageCount"`
61 Deviations []Deviation
62 } `json:"folderDeviations"`
63 }
64 }
65 }
66 }
67 HasMore bool
68 Results []Deviation
69}
70
71type Group struct {
72 Name string // обязательно заполнить
73 Content Gallery
74}
75
76// подходит как группа, так и пользователь
77func (s Group) GetGroup() (g GRuser, err error) {
78 if s.Name == "" {
79 return g, errors.New("missing Name field")
80 }
81 ujson("dauserprofile/init/about?username="+s.Name, &g)
82
83 return
84}
85
86// гарелея пользователя или группы
87func (s Group) GetGallery(page int, folderid ...int) (g Group, err error) {
88 if s.Name == "" {
89 return g, errors.New("missing Name field")
90 }
91
92 var url strings.Builder
93 if folderid[0] > 0 {
94 page--
95 url.WriteString("dashared/gallection/contents?username=")
96 url.WriteString(s.Name)
97 url.WriteString("&folderid=")
98 url.WriteString(strconv.Itoa(folderid[0]))
99 url.WriteString("&offset=")
100 url.WriteString(strconv.Itoa(page * 50))
101 url.WriteString("&type=gallery&")
102 } else {
103 url.WriteString("dauserprofile/init/gallery?username=")
104 url.WriteString(s.Name)
105 url.WriteString("&page=")
106 url.WriteString(strconv.Itoa(page))
107 url.WriteString("&deviations_")
108 }
109 url.WriteString("limit=50")
110 url.WriteString("&with_subfolders=false")
111
112 ujson(url.String(), &g.Content)
113 return
114}
115
116type GroupAbout struct {
117 FoundatedAt timeStamp `json:"foundationTs"`
118 Description Text
119}
120type GroupAdmins struct {
121 Results []struct {
122 TypeId int
123 User struct {
124 Username string
125 }
126 }
127}
128
129type About struct {
130 Country, Website, WebsiteLabel, Gender string
131 RegDate int64 `json:"deviantFor"`
132 Description Text `json:"textContent"`
133
134 SocialLinks []struct {
135 Value string
136 }
137 Interests []struct {
138 Label, Value string
139 }
140}
141
142type users struct {
143 About About
144 CoverDeviation struct {
145 Deviation Deviation `json:"coverDeviation"`
146 }
147}