go-mastodon/report.go

41 lines
973 B
Go
Raw Normal View History

2017-04-16 21:51:16 +02:00
package mastodon
2017-04-17 05:36:27 +02:00
import (
"context"
2017-04-19 11:09:43 +02:00
"fmt"
2017-04-17 05:36:27 +02:00
"net/http"
2017-04-19 11:09:43 +02:00
"net/url"
2017-04-17 05:36:27 +02:00
)
2017-04-16 21:51:16 +02:00
// Report hold information for mastodon report.
type Report struct {
ID int64 `json:"id"`
ActionTaken bool `json:"action_taken"`
}
2017-04-17 05:39:41 +02:00
// GetReports return report of the current user.
func (c *Client) GetReports(ctx context.Context) ([]*Report, error) {
var reports []*Report
2017-04-18 10:08:48 +02:00
err := c.doAPI(ctx, http.MethodGet, "/api/v1/reports", nil, &reports, nil)
2017-04-16 21:51:16 +02:00
if err != nil {
return nil, err
}
2017-04-17 05:39:41 +02:00
return reports, nil
2017-04-16 21:51:16 +02:00
}
// Report reports the report
2017-04-19 11:09:43 +02:00
func (c *Client) Report(ctx context.Context, accountId int64, ids []int64, comment string) (*Report, error) {
params := url.Values{}
params.Set("account_id", fmt.Sprint(accountId))
for _, id := range ids {
params.Add("status_ids[]", fmt.Sprint(id))
}
params.Set("comment", comment)
2017-04-16 21:51:16 +02:00
var report Report
2017-04-19 11:09:43 +02:00
err := c.doAPI(ctx, http.MethodPost, "/api/v1/reports", params, &report, nil)
2017-04-16 21:51:16 +02:00
if err != nil {
return nil, err
}
2017-04-17 05:36:27 +02:00
return &report, nil
2017-04-16 21:51:16 +02:00
}