aboutsummaryrefslogtreecommitdiff
path: root/mastodon
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2021-05-30 09:13:47 +0000
committerr <r@freesoftwareextremist.com>2021-05-30 09:13:47 +0000
commit4ab53547a81aa954b694fbde292c14bd2d04b76c (patch)
tree4ed7280db468abc4b9a05bf05d5d32776772342a /mastodon
parent9f34b607498c09b4a21bdcc82b3295f6c94bd058 (diff)
parent44d4b0d379ddfe004bff710c5c3cb44692500ad4 (diff)
downloadbloat-4ab53547a81aa954b694fbde292c14bd2d04b76c.tar.gz
bloat-4ab53547a81aa954b694fbde292c14bd2d04b76c.zip
Merge branch 'master' into absolute_fluoride
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/filter.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/mastodon/filter.go b/mastodon/filter.go
new file mode 100644
index 0000000..55beac1
--- /dev/null
+++ b/mastodon/filter.go
@@ -0,0 +1,50 @@
+package mastodon
+
+import (
+ "context"
+ "fmt"
+ "net/http"
+ "net/url"
+ "strconv"
+ "time"
+)
+
+type Filter struct {
+ ID string `json:"id"`
+ Phrase string `json:"phrase"`
+ Context []string `json:"context"`
+ WholeWord bool `json:"whole_word"`
+ ExpiresAt *time.Time `json:"expires_at"`
+ Irreversible bool `json:"irreversible"`
+}
+
+func (c *Client) GetFilters(ctx context.Context) ([]*Filter, error) {
+ var filters []*Filter
+ err := c.doAPI(ctx, http.MethodGet, "/api/v1/filters", nil, &filters, nil)
+ if err != nil {
+ return nil, err
+ }
+ return filters, nil
+}
+
+func (c *Client) AddFilter(ctx context.Context, phrase string, context []string, irreversible bool, wholeWord bool, expiresIn *time.Time) error {
+ params := url.Values{}
+ params.Set("phrase", phrase)
+ for i := range context {
+ params.Add("context[]", context[i])
+ }
+ params.Set("irreversible", strconv.FormatBool(irreversible))
+ params.Set("whole_word", strconv.FormatBool(wholeWord))
+ if expiresIn != nil {
+ params.Set("expires_in", expiresIn.Format(time.RFC3339))
+ }
+ err := c.doAPI(ctx, http.MethodPost, "/api/v1/filters", params, nil, nil)
+ if err != nil {
+ return err
+ }
+ return nil
+}
+
+func (c *Client) RemoveFilter(ctx context.Context, id string) error {
+ return c.doAPI(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/filters/%s", id), nil, nil, nil)
+}