-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_profile.go
158 lines (140 loc) · 5.62 KB
/
user_profile.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package deviantart
import (
"fmt"
"github.com/google/uuid"
)
type ModuleCoverDeviation struct {
CoverDeviation Deviation `json:"cover_deviation,omitempty"`
CoverDeviationIDOffsetY uint32 `json:"cover_deviationid_offset_y"`
ImageWidth uint32 `json:"image_width,omitempty"`
ImageHeight uint32 `json:"image_height,omitempty"`
CropX uint32 `json:"crop_x,omitempty"`
CropY uint32 `json:"crop_y,omitempty"`
CropWidth uint32 `json:"crop_width,omitempty"`
CropHeight uint32 `json:"crop_height,omitempty"`
}
type Profile struct {
User User `json:"user"`
IsWatching bool `json:"is_watching"`
ProfileURL string `json:"profile_url"`
UserIsArtist bool `json:"user_is_artist"`
ArtistLevel string `json:"artist_level,omitempty"`
ArtistSpeciality string `json:"artist_specialty,omitempty"`
RealName string `json:"real_name"`
Tagline string `json:"tagline"`
CountryID uint8 `json:"countryid"`
Country string `json:"country"`
Website string `json:"website"`
Bio string `json:"bio"`
CoverPhoto string `json:"cover_photo,omitempty"`
CoverDeviation *ModuleCoverDeviation `json:"cover_deviation,omitempty"`
LastStatus *Status `json:"last_status,omitempty"`
Stats struct {
UserDeviations uint32 `json:"user_deviations"`
UserFavourites uint32 `json:"user_favourites"`
UserComments uint32 `json:"user_comments"`
ProfilePageViews uint32 `json:"profile_pageviews"`
ProfileComments uint32 `json:"profile_comments"`
} `json:"stats"`
Collections []Folder `json:"collections,omitempty"`
Galleries []struct {
FolderID uuid.UUID `json:"folderid"`
Parent uuid.UUID `json:"parent,omitempty"`
Name string `json:"name"`
} `json:"galleries,omitempty"`
}
type GetProfileParams struct {
// Include collection folder info.
IncludeCollections bool `url:"ext_collections,omitempty"`
// Include gallery folder info.
IncludeGalleries bool `url:"ext_galleries,omitempty"`
}
// Profile gets user profile information.
//
// To connect to this endpoint OAuth2 Access Token from the Client Credentials
// Grant, or Authorization Code Grant is required.
//
// The following scopes are required to access this resource:
//
// - browse
func (s *UserService) Profile(username string, params *GetProfileParams) (Profile, error) {
var (
success Profile
failure Error
)
_, err := s.sling.New().Post("profile/").Path(username).QueryStruct(params).Receive(&success, &failure)
if err := relevantError(err, failure); err != nil {
return Profile{}, fmt.Errorf("unable to fetch profile: %w", err)
}
return success, nil
}
// Posts returns all journals & status updates for a given user in a single feed.
//
// To connect to this endpoint OAuth2 Access Token from the Client Credentials
// Grant, or Authorization Code Grant is required.
//
// The following scopes are required to access this resource:
//
// - browse
func (s *UserService) Posts(username string, page *CursorParams) (CursorResponse[Deviation], error) {
var (
success CursorResponse[Deviation]
failure Error
)
params := &usernameParams{Username: username}
_, err := s.sling.New().Get("profile/posts").QueryStruct(params).QueryStruct(page).Receive(&success, &failure)
if err := relevantError(err, failure); err != nil {
return CursorResponse[Deviation]{}, fmt.Errorf("unable to fetch profile: %w", err)
}
return success, nil
}
const (
ArtistLevelNone = "None"
ArtistLevelStudent = "Student"
ArtistLevelHobbyist = "Hobbyist"
ArtistLevelProfessional = "Professional"
)
const (
ArtistSpecialityNone = "None"
ArtistSpecialityArtisanCrafts = "Artisan Crafts"
ArtistLevelDesignInterfaces = "Design & Interfaces"
ArtistLevelDigitalArt = "Digital Art"
ArtistLevelFilmAnimation = "Film & Animation"
ArtistLevelLiterature = "Literature"
ArtistLevelPhotography = "Photography"
ArtistLevelTraditionalArt = "Traditional Art"
ArtistLevelOther = "Other"
ArtistLevelVaried = "Varied"
)
type UserInfoParams struct {
// Is the user an artist?
UserIsArtist bool `url:"user_is_artist,omitempty"`
// If the user is an artist, what level are they.
ArtistLevel string `url:"artist_level,omitempty"`
// If the user is an artist, what is their specialty.
ArtistSpeciality string `url:"artist_specialty,omitempty"`
// The users location.
CountryID int `url:"countryid,omitempty"`
// The users personal website.
Website string `url:"website,omitempty"`
WebsiteLabel string `url:"website_label,omitempty"`
// The users tagline.
Tagline string `url:"tagline,omitempty"`
ShowBadges bool `url:"show_badges,omitempty"`
Interests []string `url:"interests,omitempty"` // TODO: Check positional params.
SocialLinks []string `url:"social_links,omitempty"` // TODO: Check positional params.
}
// UpdateProfile updates the users profile information.
//
// Check [Countries] to get a list of countries and their IDs.
func (s *UserService) UpdateProfile(params *UserInfoParams) (bool, error) {
var (
success map[string]any
failure Error
)
_, err := s.sling.New().Post("profile/update").BodyForm(params).Receive(&success, &failure)
if err := relevantError(err, failure); err != nil {
return false, fmt.Errorf("unable to update user profile: %w", err)
}
return success["success"].(bool), nil
}