diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/mastotypes/account.go | 68 | ||||
-rw-r--r-- | pkg/mastotypes/application.go | 4 | ||||
-rw-r--r-- | pkg/mastotypes/field.go | 1 | ||||
-rw-r--r-- | pkg/mastotypes/source.go | 19 | ||||
-rw-r--r-- | pkg/mastotypes/tag.go | 1 | ||||
-rw-r--r-- | pkg/mastotypes/token.go | 31 |
6 files changed, 118 insertions, 6 deletions
diff --git a/pkg/mastotypes/account.go b/pkg/mastotypes/account.go index 031fa7c02..3ddd3c517 100644 --- a/pkg/mastotypes/account.go +++ b/pkg/mastotypes/account.go @@ -18,6 +18,8 @@ package mastotypes +import "mime/multipart" + // Account represents a mastodon-api Account object, as described here: https://docs.joinmastodon.org/entities/account/ type Account struct { // The account id @@ -31,7 +33,7 @@ type Account struct { // Whether the account manually approves follow requests. Locked bool `json:"locked"` // Whether the account has opted into discovery features such as the profile directory. - Discoverable bool `json:"discoverable"` + Discoverable bool `json:"discoverable,omitempty"` // A presentational flag. Indicates that the account may perform automated actions, may not be monitored, or identifies as a robot. Bot bool `json:"bot"` // When the account was created. (ISO 8601 Datetime) @@ -61,9 +63,69 @@ type Account struct { // Additional metadata attached to a profile as name-value pairs. Fields []Field `json:"fields"` // An extra entity returned when an account is suspended. - Suspended bool `json:"suspended"` + Suspended bool `json:"suspended,omitempty"` // When a timed mute will expire, if applicable. (ISO 8601 Datetime) - MuteExpiresAt string `json:"mute_expires_at"` + MuteExpiresAt string `json:"mute_expires_at,omitempty"` // An extra entity to be used with API methods to verify credentials and update credentials. Source *Source `json:"source"` } + +// AccountCreateRequest represents the form submitted during a POST request to /api/v1/accounts. +// See https://docs.joinmastodon.org/methods/accounts/ +type AccountCreateRequest struct { + // Text that will be reviewed by moderators if registrations require manual approval. + Reason string `form:"reason"` + // The desired username for the account + Username string `form:"username" binding:"required"` + // The email address to be used for login + Email string `form:"email" binding:"required"` + // The password to be used for login + Password string `form:"password" binding:"required"` + // Whether the user agrees to the local rules, terms, and policies. + // These should be presented to the user in order to allow them to consent before setting this parameter to TRUE. + Agreement bool `form:"agreement" binding:"required"` + // The language of the confirmation email that will be sent + Locale string `form:"locale" binding:"required"` +} + +// UpdateCredentialsRequest represents the form submitted during a PATCH request to /api/v1/accounts/update_credentials. +// See https://docs.joinmastodon.org/methods/accounts/ +type UpdateCredentialsRequest struct { + // Whether the account should be shown in the profile directory. + Discoverable *bool `form:"discoverable"` + // Whether the account has a bot flag. + Bot *bool `form:"bot"` + // The display name to use for the profile. + DisplayName *string `form:"display_name"` + // The account bio. + Note *string `form:"note"` + // Avatar image encoded using multipart/form-data + Avatar *multipart.FileHeader `form:"avatar"` + // Header image encoded using multipart/form-data + Header *multipart.FileHeader `form:"header"` + // Whether manual approval of follow requests is required. + Locked *bool `form:"locked"` + // New Source values for this account + Source *UpdateSource `form:"source"` + // Profile metadata name and value + FieldsAttributes *[]UpdateField `form:"fields_attributes"` +} + +// UpdateSource is to be used specifically in an UpdateCredentialsRequest. +type UpdateSource struct { + // Default post privacy for authored statuses. + Privacy *string `form:"privacy"` + // Whether to mark authored statuses as sensitive by default. + Sensitive *bool `form:"sensitive"` + // Default language to use for authored statuses. (ISO 6391) + Language *string `form:"language"` +} + +// UpdateField is to be used specifically in an UpdateCredentialsRequest. +// By default, max 4 fields and 255 characters per property/value. +type UpdateField struct { + // Name of the field + Name *string `form:"name"` + // Value of the field + Value *string `form:"value"` +} diff --git a/pkg/mastotypes/application.go b/pkg/mastotypes/application.go index 88128f71d..1984eff46 100644 --- a/pkg/mastotypes/application.go +++ b/pkg/mastotypes/application.go @@ -43,11 +43,11 @@ type Application struct { // And here: https://docs.joinmastodon.org/client/token/ type ApplicationPOSTRequest struct { // A name for your application - ClientName string `form:"client_name"` + ClientName string `form:"client_name" binding:"required"` // Where the user should be redirected after authorization. // To display the authorization code to the user instead of redirecting // to a web page, use urn:ietf:wg:oauth:2.0:oob in this parameter. - RedirectURIs string `form:"redirect_uris"` + RedirectURIs string `form:"redirect_uris" binding:"required"` // Space separated list of scopes. If none is provided, defaults to read. Scopes string `form:"scopes"` // A URL to the homepage of your app diff --git a/pkg/mastotypes/field.go b/pkg/mastotypes/field.go index dbfe08c54..29b5a1803 100644 --- a/pkg/mastotypes/field.go +++ b/pkg/mastotypes/field.go @@ -28,7 +28,6 @@ type Field struct { Value string `json:"value"` // OPTIONAL - // Timestamp of when the server verified a URL value for a rel="me” link. String (ISO 8601 Datetime) if value is a verified URL VerifiedAt string `json:"verified_at,omitempty"` } diff --git a/pkg/mastotypes/source.go b/pkg/mastotypes/source.go index e4a2ca06a..4142540a7 100644 --- a/pkg/mastotypes/source.go +++ b/pkg/mastotypes/source.go @@ -18,5 +18,24 @@ package mastotypes +// Source represents display or publishing preferences of user's own account. +// Returned as an additional entity when verifying and updated credentials, as an attribute of Account. +// See https://docs.joinmastodon.org/entities/source/ type Source struct { + // The default post privacy to be used for new statuses. + // public = Public post + // unlisted = Unlisted post + // private = Followers-only post + // direct = Direct post + Privacy string `json:"privacy,omitempty"` + // Whether new statuses should be marked sensitive by default. + Sensitive bool `json:"sensitive,omitempty"` + // The default posting language for new statuses. + Language string `json:"language,omitempty"` + // Profile bio. + Note string `json:"note"` + // Metadata about the account. + Fields []Field `json:"fields"` + // The number of pending follow requests. + FollowRequestsCount int `json:"follow_requests_count,omitempty"` } diff --git a/pkg/mastotypes/tag.go b/pkg/mastotypes/tag.go index d34314b0b..4431ac3e9 100644 --- a/pkg/mastotypes/tag.go +++ b/pkg/mastotypes/tag.go @@ -18,5 +18,6 @@ package mastotypes +// Tag represents a hashtag used within the content of a status. See https://docs.joinmastodon.org/entities/tag/ type Tag struct { } diff --git a/pkg/mastotypes/token.go b/pkg/mastotypes/token.go new file mode 100644 index 000000000..c9ac1f177 --- /dev/null +++ b/pkg/mastotypes/token.go @@ -0,0 +1,31 @@ +/* + GoToSocial + Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +package mastotypes + +// Token represents an OAuth token used for authenticating with the API and performing actions.. See https://docs.joinmastodon.org/entities/token/ +type Token struct { + // An OAuth token to be used for authorization. + AccessToken string `json:"access_token"` + // The OAuth token type. Mastodon uses Bearer tokens. + TokenType string `json:"token_type"` + // The OAuth scopes granted by this token, space-separated. + Scope string `json:"scope"` + // When the token was generated. (UNIX timestamp seconds) + CreatedAt int64 `json:"created_at"` +} |