diff options
author | r <r@freesoftwareextremist.com> | 2020-02-09 13:42:16 +0000 |
---|---|---|
committer | r <r@freesoftwareextremist.com> | 2020-02-09 13:42:16 +0000 |
commit | cfec7879e3b3fc38956f2dce0acbbeb8a578f4c1 (patch) | |
tree | 5da9a9371fd10667cd6ee68bbd07f7f0f9d8d3d3 /mastodon | |
parent | a68a09a83ef2eb411e2a7a66e919f27c040c0b6a (diff) | |
download | bloat-cfec7879e3b3fc38956f2dce0acbbeb8a578f4c1.tar.gz bloat-cfec7879e3b3fc38956f2dce0acbbeb8a578f4c1.zip |
Add poll support
Currenlty only voting is possible.
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/poll.go | 38 | ||||
-rw-r--r-- | mastodon/status.go | 11 |
2 files changed, 44 insertions, 5 deletions
diff --git a/mastodon/poll.go b/mastodon/poll.go new file mode 100644 index 0000000..274b95e --- /dev/null +++ b/mastodon/poll.go @@ -0,0 +1,38 @@ +package mastodon + +import ( + "context" + "fmt" + "net/http" + "net/url" + "time" +) + +type Poll struct { + ID string `json:"id"` + ExpiresAt time.Time `json:"expires_at"` + Expired bool `json:"expired"` + Multiple bool `json:"multiple"` + VotesCount int64 `json:"votes_count"` + Voted bool `json:"voted"` + Emojis []Emoji `json:"emojis"` + Options []PollOption `json:"options"` +} + +// Poll hold information for a mastodon poll option. +type PollOption struct { + Title string `json:"title"` + VotesCount int64 `json:"votes_count"` +} + +// Vote submits a vote with given choices to the poll specified by id. +func (c *Client) Vote(ctx context.Context, id string, choices []string) (*Poll, error) { + var poll Poll + params := make(url.Values) + params["choices[]"] = choices + err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/polls/%s/votes", id), params, &poll, nil) + if err != nil { + return nil, err + } + return &poll, nil +} diff --git a/mastodon/status.go b/mastodon/status.go index 63de3cf..b4f57ae 100644 --- a/mastodon/status.go +++ b/mastodon/status.go @@ -47,13 +47,14 @@ type Status struct { Application Application `json:"application"` Language string `json:"language"` Pinned interface{} `json:"pinned"` + Poll *Poll `json:"poll"` // Custom fields - Pleroma StatusPleroma `json:"pleroma"` - ShowReplies bool `json:"show_replies"` - ReplyMap map[string][]ReplyInfo `json:"reply_map"` - ReplyNumber int `json:"reply_number"` - RetweetedByID string `json:"retweeted_by_id"` + Pleroma StatusPleroma `json:"pleroma"` + ShowReplies bool `json:"show_replies"` + ReplyMap map[string][]ReplyInfo `json:"reply_map"` + ReplyNumber int `json:"reply_number"` + RetweetedByID string `json:"retweeted_by_id"` } // Context hold information for mastodon context. |