Compare commits

...

2 commits

Author SHA1 Message Date
2bb801b6d0
feat: add ability to reply to statuses 2024-07-09 03:13:54 +01:00
ec282e207f
refactor: use baseListPath where necessary
Replace the static string of the base list API path with the
baseListPath constant.
2024-07-09 00:25:43 +01:00
5 changed files with 29 additions and 15 deletions

View file

@ -401,6 +401,10 @@ enbas show --type status --status-id 01J1Z9PT0243JT9QNQ5W96Z8CA
```
enbas create --type status --content-type markdown --visibility private --from-file status.md
```
- Reply to another status.
```
enbas create --type status --in-reply-to 01J2A86E3M7WWH37H1QENT7CSH --content "@bernie thanks for this! Looking forward to trying this out."
```
- Create a status with a poll
```
enbas create \
@ -428,6 +432,7 @@ enbas show --type status --status-id 01J1Z9PT0243JT9QNQ5W96Z8CA
| `enable-likes` | boolean | false | The status can be liked (favourtied). | true |
| `enable-replies` | boolean | false | The status can be replied to. | true |
| `from-file` | string | false | The path to the file where to read the contents of the status from. | |
| `in-reply-to` | string | false | The ID of the status that you want to reply to. | |
| `language` | string | false | The ISO 639 language code that the status is written in.<br>If this is not specified then the default language from your posting preferences will be used. | |
| `sensitive` | string | false | The status should be marked as sensitive.<br>If this is not specified then the default sensitivity from your posting preferences will be used. | |
| `spoiler-text` | string | false | The text to display as the status' warning or subject. | |

View file

@ -14,11 +14,11 @@ import (
)
const (
listPath string = "/api/v1/lists"
baseListPath string = "/api/v1/lists"
)
func (g *Client) GetAllLists() ([]model.List, error) {
url := g.Authentication.Instance + listPath
url := g.Authentication.Instance + baseListPath
var lists []model.List
@ -33,7 +33,7 @@ func (g *Client) GetAllLists() ([]model.List, error) {
}
func (g *Client) GetList(listID string) (model.List, error) {
url := g.Authentication.Instance + listPath + "/" + listID
url := g.Authentication.Instance + baseListPath + "/" + listID
var list model.List
@ -59,7 +59,7 @@ func (g *Client) CreateList(form CreateListForm) (model.List, error) {
}
requestBody := bytes.NewBuffer(data)
url := g.Authentication.Instance + "/api/v1/lists"
url := g.Authentication.Instance + baseListPath
var list model.List
@ -88,7 +88,7 @@ func (g *Client) UpdateList(listToUpdate model.List) (model.List, error) {
}
requestBody := bytes.NewBuffer(data)
url := g.Authentication.Instance + listPath + "/" + listToUpdate.ID
url := g.Authentication.Instance + baseListPath + "/" + listToUpdate.ID
var updatedList model.List
@ -103,7 +103,7 @@ func (g *Client) UpdateList(listToUpdate model.List) (model.List, error) {
}
func (g *Client) DeleteList(listID string) error {
url := g.Authentication.Instance + "/api/v1/lists/" + listID
url := g.Authentication.Instance + baseListPath + "/" + listID
return g.sendRequest(http.MethodDelete, url, nil, nil)
}
@ -121,7 +121,7 @@ func (g *Client) AddAccountsToList(listID string, accountIDs []string) error {
}
requestBody := bytes.NewBuffer(data)
url := g.Authentication.Instance + listPath + "/" + listID + "/accounts"
url := g.Authentication.Instance + baseListPath + "/" + listID + "/accounts"
if err := g.sendRequest(http.MethodPost, url, requestBody, nil); err != nil {
return fmt.Errorf(
@ -146,7 +146,7 @@ func (g *Client) RemoveAccountsFromList(listID string, accountIDs []string) erro
}
requestBody := bytes.NewBuffer(data)
url := g.Authentication.Instance + listPath + "/" + listID + "/accounts"
url := g.Authentication.Instance + baseListPath + "/" + listID + "/accounts"
if err := g.sendRequest(http.MethodDelete, url, requestBody, nil); err != nil {
return fmt.Errorf(
@ -159,7 +159,7 @@ func (g *Client) RemoveAccountsFromList(listID string, accountIDs []string) erro
}
func (g *Client) GetAccountsFromList(listID string, limit int) ([]model.Account, error) {
path := fmt.Sprintf("%s/%s/accounts?limit=%d", listPath, listID, limit)
path := fmt.Sprintf("%s/%s/accounts?limit=%d", baseListPath, listID, limit)
url := g.Authentication.Instance + path
var accounts []model.Account

View file

@ -13,8 +13,12 @@ import (
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
)
const (
baseStatusesPath string = "/api/v1/statuses"
)
func (g *Client) GetStatus(statusID string) (model.Status, error) {
path := "/api/v1/statuses/" + statusID
path := baseStatusesPath + "/" + statusID
url := g.Authentication.Instance + path
var status model.Status
@ -31,6 +35,7 @@ func (g *Client) GetStatus(statusID string) (model.Status, error) {
type CreateStatusForm struct {
Content string `json:"status"`
InReplyTo string `json:"in_reply_to_id"`
Language string `json:"language"`
SpoilerText string `json:"spoiler_text"`
Boostable bool `json:"boostable"`
@ -57,7 +62,7 @@ func (g *Client) CreateStatus(form CreateStatusForm) (model.Status, error) {
}
requestBody := bytes.NewBuffer(data)
url := g.Authentication.Instance + "/api/v1/statuses"
url := g.Authentication.Instance + baseStatusesPath
var status model.Status
@ -119,7 +124,7 @@ func (g *Client) RemoveStatusFromBookmarks(statusID string) error {
}
func (g *Client) LikeStatus(statusID string) error {
url := g.Authentication.Instance + "/api/v1/statuses/" + statusID + "/favourite"
url := g.Authentication.Instance + baseStatusesPath + "/" + statusID + "/favourite"
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
return fmt.Errorf(
@ -132,7 +137,7 @@ func (g *Client) LikeStatus(statusID string) error {
}
func (g *Client) UnlikeStatus(statusID string) error {
url := g.Authentication.Instance + "/api/v1/statuses/" + statusID + "/unfavourite"
url := g.Authentication.Instance + baseStatusesPath + "/" + statusID + "/unfavourite"
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
return fmt.Errorf(
@ -163,7 +168,7 @@ func (g *Client) GetLikedStatuses(limit int, resourceName string) (model.StatusL
}
func (g *Client) ReblogStatus(statusID string) error {
url := g.Authentication.Instance + "/api/v1/statuses/" + statusID + "/reblog"
url := g.Authentication.Instance + baseStatusesPath + "/" + statusID + "/reblog"
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
return fmt.Errorf(
@ -176,7 +181,7 @@ func (g *Client) ReblogStatus(statusID string) error {
}
func (g *Client) UnreblogStatus(statusID string) error {
url := g.Authentication.Instance + "/api/v1/statuses/" + statusID + "/unreblog"
url := g.Authentication.Instance + baseStatusesPath + "/" + statusID + "/unreblog"
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
return fmt.Errorf(

View file

@ -32,6 +32,7 @@ type CreateExecutor struct {
content string
contentType string
fromFile string
inReplyTo string
language string
resourceType string
listTitle string
@ -58,6 +59,7 @@ func NewCreateExecutor(printer *printer.Printer, config *config.Config, name, su
createExe.StringVar(&createExe.contentType, flagContentType, "plain", "The type that the contents should be parsed from (valid values are plain and markdown)")
createExe.BoolVar(&createExe.federated, flagEnableFederation, true, "Specify if the status can be federated beyond the local timelines")
createExe.StringVar(&createExe.fromFile, flagFromFile, "", "The file path where to read the contents from")
createExe.StringVar(&createExe.inReplyTo, flagInReplyTo, "", "The ID of the status that you want to reply to")
createExe.StringVar(&createExe.language, flagLanguage, "", "The ISO 639 language code for this status")
createExe.BoolVar(&createExe.likeable, flagEnableLikes, true, "Specify if the status can be liked/favourited")
createExe.BoolVar(&createExe.replyable, flagEnableReplies, true, "Specify if the status can be replied to")
@ -204,6 +206,7 @@ func (c *CreateExecutor) createStatus(gtsClient *client.Client) error {
SpoilerText: c.spoilerText,
Boostable: c.boostable,
Federated: c.federated,
InReplyTo: c.inReplyTo,
Likeable: c.likeable,
Replyable: c.replyable,
Sensitive: sensitive,

View file

@ -25,6 +25,7 @@ const (
flagFrom = "from"
flagFromFile = "from-file"
flagFull = "full"
flagInReplyTo = "in-reply-to"
flagInstance = "instance"
flagLanguage = "language"
flagLimit = "limit"