1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
module Plugin::Mastodon
# https://docs.joinmastodon.org/api/entities/#poll-option
class PollOption < Diva::Model
register :mastodon_poll_option, name: Plugin[:mastodon]._('Mastodon投票候補')
field.string :title, required: true
field.int :votes_count
def path
"/#{title}"
end
def inspect
"mastodon-poll-option(#{title}, #{votes_count})"
end
end
# https://docs.joinmastodon.org/api/entities/#poll
class Poll < Diva::Model
register :mastodon_poll, name: Plugin[:mastodon]._('Mastodon投票')
field.string :id, required: true
field.time :expires_at
field.bool :expired, required: true
field.bool :multiple, required: true
field.int :votes_count, required: true
field.has :options, [PollOption], required: true
field.bool :voted
def initialize(hash)
if hash[:expires_at].is_a?(String)
hash[:expires_at] = Time.parse(hash[:expires_at]).localtime
end
super hash
end
def path
"/#{id}"
end
def inspect
"mastodon-poll(#{id})"
end
end
end
|