-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeviation_journal.go
99 lines (80 loc) · 2.89 KB
/
deviation_journal.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
package deviantart
import (
"fmt"
"github.com/google/uuid"
)
type CreateJournalParams struct {
// Journal title.
Title string `url:"title"`
// The `body` of the journal.
Body string `url:"body,omitempty"`
// Journal tags.
Tags []string `url:"tags,brackets,omitempty"`
// Cover deviation ID.
CoverImageDeviationID uuid.UUID `url:"cover_image_deviation_id,omitempty"`
// ID of the embeded deviation.
EmbeddedImageDeviationID uuid.UUID `url:"embedded_image_deviation_id,omitempty"`
// Submission is mature or not.
IsMature bool `url:"is_mature,omitempty"`
// Allow comments on the submission.
AllowComments bool `url:"allow_comments,omitempty"`
// License options.
LicenseOptions LicenseOptions `url:"license_options,omitempty"`
}
// CreateJournal creates journal.
//
// To connect to this endpoint OAuth2 Access Token from the Authorization Code
// Grant is required.
//
// The following scopes are required to access this resource:
//
// - user.manage
func (s *DeviationService) CreateJournal(params *CreateJournalParams) (uuid.UUID, error) {
var (
success map[string]uuid.UUID
failure Error
)
_, err := s.sling.New().Post("journal/create/").BodyForm(params).Receive(&success, &failure)
if err := relevantError(err, failure); err != nil {
return uuid.UUID{}, fmt.Errorf("unable to create journal: %w", err)
}
return success["deviationid"], nil
}
type UpdateJournalParams struct {
// Journal title.
Title string `url:"title"`
// Journal tags.
Tags []string `url:"tags,brackets,omitempty"`
// Cover deviation ID.
CoverImageDeviationID uuid.UUID `url:"cover_image_deviation_id,omitempty"`
// Reset cover deviation ID.
ResetCoverImageDeviationID bool `url:"reset_cover_image_deviation_id,omitempty"`
// Submission is mature or not.
IsMature bool `url:"is_mature,omitempty"`
// Allow comments on the submission.
AllowComments bool `url:"allow_comments,omitempty"`
// License options.
LicenseOptions LicenseOptions `url:"license_options,omitempty"`
}
// UpdateJournal updates journal. All values left empty, except cover image
// deviation id, will have the corresponding fields cleared. To keep a field
// value send the old one. To clear cover image deviation id value - pass
// `reset_cover_image_deviation_id` param with value `true`.
//
// To connect to this endpoint OAuth2 Access Token from the Authorization Code
// Grant is required.
//
// The following scopes are required to access this resource:
//
// - user.manage
func (s *DeviationService) UpdateJournal(deviationID uuid.UUID, params *UpdateJournalParams) (DeviationUpdateResponse, error) {
var (
success DeviationUpdateResponse
failure Error
)
_, err := s.sling.New().Post("journal/update/").Path(deviationID.String()).BodyForm(params).Receive(&success, &failure)
if err := relevantError(err, failure); err != nil {
return DeviationUpdateResponse{}, fmt.Errorf("unable to update journal: %w", err)
}
return success, nil
}