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