Compare commits
No commits in common. "905f1209d044a9289f4f2c578ce74d9b08545c6b" and "4038814d6ad88940e9ef47be3ff623d0a3cbc6ee" have entirely different histories.
905f1209d0
...
4038814d6a
4 changed files with 51 additions and 91 deletions
|
@ -25,20 +25,42 @@ func (g *Client) GetStatus(statusID string) (model.Status, error) {
|
||||||
return status, nil
|
return status, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateStatusForm struct {
|
func (g *Client) CreateStatus(
|
||||||
Content string `json:"status"`
|
content,
|
||||||
Language string `json:"language"`
|
contentType,
|
||||||
SpoilerText string `json:"spoiler_text"`
|
language,
|
||||||
Boostable bool `json:"boostable"`
|
spoilerText string,
|
||||||
Federated bool `json:"federated"`
|
boostable,
|
||||||
Likeable bool `json:"likeable"`
|
federated,
|
||||||
Replyable bool `json:"replyable"`
|
likeable,
|
||||||
Sensitive bool `json:"sensitive"`
|
replyable,
|
||||||
ContentType model.StatusContentType `json:"content_type"`
|
sensitive bool,
|
||||||
Visibility model.StatusVisibility `json:"visibility"`
|
visibility model.StatusVisibility,
|
||||||
}
|
) (model.Status, error) {
|
||||||
|
form := struct {
|
||||||
|
ContentType string `json:"content_type"`
|
||||||
|
Language string `json:"language"`
|
||||||
|
SpoilerText string `json:"spoiler_text"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Boostable bool `json:"boostable"`
|
||||||
|
Federated bool `json:"federated"`
|
||||||
|
Likeable bool `json:"likeable"`
|
||||||
|
Replyable bool `json:"replyable"`
|
||||||
|
Sensitive bool `json:"sensitive"`
|
||||||
|
Visibility model.StatusVisibility `json:"visibility"`
|
||||||
|
}{
|
||||||
|
ContentType: contentType,
|
||||||
|
Language: language,
|
||||||
|
SpoilerText: spoilerText,
|
||||||
|
Status: content,
|
||||||
|
Boostable: boostable,
|
||||||
|
Federated: federated,
|
||||||
|
Likeable: likeable,
|
||||||
|
Sensitive: sensitive,
|
||||||
|
Replyable: replyable,
|
||||||
|
Visibility: visibility,
|
||||||
|
}
|
||||||
|
|
||||||
func (g *Client) CreateStatus(form CreateStatusForm) (model.Status, error) {
|
|
||||||
data, err := json.Marshal(form)
|
data, err := json.Marshal(form)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return model.Status{}, fmt.Errorf("unable to create the JSON form; %w", err)
|
return model.Status{}, fmt.Errorf("unable to create the JSON form; %w", err)
|
||||||
|
|
|
@ -40,7 +40,7 @@ func NewCreateExecutor(tlf TopLevelFlags, name, summary string) *CreateExecutor
|
||||||
createExe.BoolVar(&createExe.replyable, flagReplyable, true, "specify if the status can be replied to")
|
createExe.BoolVar(&createExe.replyable, flagReplyable, true, "specify if the status can be replied to")
|
||||||
createExe.BoolVar(&createExe.sensitive, flagSensitive, false, "specify if the status should be marked as sensitive")
|
createExe.BoolVar(&createExe.sensitive, flagSensitive, false, "specify if the status should be marked as sensitive")
|
||||||
createExe.StringVar(&createExe.content, flagContent, "", "the content of the status to create")
|
createExe.StringVar(&createExe.content, flagContent, "", "the content of the status to create")
|
||||||
createExe.StringVar(&createExe.contentType, flagContentType, "plain", "the type that the contents should be parsed from (valid values are plain and markdown)")
|
createExe.StringVar(&createExe.contentType, flagContentType, "text/plain", "the type that the contents should be parsed from (valid values are plain and markdown)")
|
||||||
createExe.StringVar(&createExe.language, flagLanguage, "", "the ISO 639 language code for this status")
|
createExe.StringVar(&createExe.language, flagLanguage, "", "the ISO 639 language code for this status")
|
||||||
createExe.StringVar(&createExe.spoilerText, flagSpoilerText, "", "the text to display as the status' warning or subject")
|
createExe.StringVar(&createExe.spoilerText, flagSpoilerText, "", "the text to display as the status' warning or subject")
|
||||||
createExe.StringVar(&createExe.visibility, flagVisibility, "", "the visibility of the posted status")
|
createExe.StringVar(&createExe.visibility, flagVisibility, "", "the visibility of the posted status")
|
||||||
|
@ -126,28 +126,21 @@ func (c *CreateExecutor) createStatus(gtsClient *client.Client) error {
|
||||||
|
|
||||||
parsedVisibility := model.ParseStatusVisibility(visibility)
|
parsedVisibility := model.ParseStatusVisibility(visibility)
|
||||||
if parsedVisibility == model.StatusVisibilityUnknown {
|
if parsedVisibility == model.StatusVisibilityUnknown {
|
||||||
return InvalidStatusVisibilityError{Visibility: visibility}
|
return fmt.Errorf("invalid status visibility %q", visibility)
|
||||||
}
|
}
|
||||||
|
|
||||||
parsedContentType := model.ParseStatusContentType(c.contentType)
|
status, err := gtsClient.CreateStatus(
|
||||||
if parsedContentType == model.StatusContentTypeUnknown {
|
c.content,
|
||||||
return InvalidStatusContentTypeError{ContentType: c.contentType}
|
c.contentType,
|
||||||
}
|
language,
|
||||||
|
c.spoilerText,
|
||||||
form := client.CreateStatusForm{
|
c.boostable,
|
||||||
Content: c.content,
|
c.federated,
|
||||||
ContentType: parsedContentType,
|
c.likeable,
|
||||||
Language: language,
|
c.replyable,
|
||||||
SpoilerText: c.spoilerText,
|
c.sensitive,
|
||||||
Boostable: c.boostable,
|
parsedVisibility,
|
||||||
Federated: c.federated,
|
)
|
||||||
Likeable: c.likeable,
|
|
||||||
Replyable: c.replyable,
|
|
||||||
Sensitive: c.sensitive,
|
|
||||||
Visibility: parsedVisibility,
|
|
||||||
}
|
|
||||||
|
|
||||||
status, err := gtsClient.CreateStatus(form)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to create the status; %w", err)
|
return fmt.Errorf("unable to create the status; %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,19 +53,3 @@ type EmptyContentError struct{}
|
||||||
func (e EmptyContentError) Error() string {
|
func (e EmptyContentError) Error() string {
|
||||||
return "content should not be empty"
|
return "content should not be empty"
|
||||||
}
|
}
|
||||||
|
|
||||||
type InvalidStatusVisibilityError struct {
|
|
||||||
Visibility string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e InvalidStatusVisibilityError) Error() string {
|
|
||||||
return "'" + e.Visibility + "' is an invalid status visibility (valid values are public, unlisted, private, mutuals_only and direct)"
|
|
||||||
}
|
|
||||||
|
|
||||||
type InvalidStatusContentTypeError struct {
|
|
||||||
ContentType string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e InvalidStatusContentTypeError) Error() string {
|
|
||||||
return "'" + e.ContentType + "' is an invalid status content type (valid values are plain and markdown)"
|
|
||||||
}
|
|
||||||
|
|
|
@ -225,8 +225,8 @@ func (s StatusVisibility) String() string {
|
||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseStatusVisibility(value string) StatusVisibility {
|
func ParseStatusVisibility(visibility string) StatusVisibility {
|
||||||
switch value {
|
switch visibility {
|
||||||
case "public":
|
case "public":
|
||||||
return StatusVisibilityPublic
|
return StatusVisibilityPublic
|
||||||
case "private":
|
case "private":
|
||||||
|
@ -265,42 +265,3 @@ func (s *StatusVisibility) UnmarshalJSON(data []byte) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type StatusContentType int
|
|
||||||
|
|
||||||
const (
|
|
||||||
StatusContentTypePlainText StatusContentType = iota
|
|
||||||
StatusContentTypeMarkdown
|
|
||||||
StatusContentTypeUnknown
|
|
||||||
)
|
|
||||||
|
|
||||||
func (s StatusContentType) String() string {
|
|
||||||
switch s {
|
|
||||||
case StatusContentTypePlainText:
|
|
||||||
return "text/plain"
|
|
||||||
case StatusContentTypeMarkdown:
|
|
||||||
return "text/markdown"
|
|
||||||
}
|
|
||||||
|
|
||||||
return "unknown"
|
|
||||||
}
|
|
||||||
|
|
||||||
func ParseStatusContentType(value string) StatusContentType {
|
|
||||||
switch value {
|
|
||||||
case "plain", "text/plain":
|
|
||||||
return StatusContentTypePlainText
|
|
||||||
case "markdown", "text/markdown":
|
|
||||||
return StatusContentTypeMarkdown
|
|
||||||
}
|
|
||||||
|
|
||||||
return StatusContentTypeUnknown
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s StatusContentType) MarshalJSON() ([]byte, error) {
|
|
||||||
value := s.String()
|
|
||||||
if value == "unknown" {
|
|
||||||
return nil, fmt.Errorf("%q is not a valid status content type", value)
|
|
||||||
}
|
|
||||||
|
|
||||||
return json.Marshal(value)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue