Class: X::Poll

Inherits:
Resource show all
Defined in:
x-objects/lib/x/objects/poll.rb

Overview

A poll attached to a post

The API offers no lookup of polls, so a poll is read from the response of the post that expanded it, and the class answers no finder. from_id builds one from its identifier, which a poll the response did not expand is built as too, and which compares equal to the poll it identifies, but hydrate and refresh raise UnsupportedOperation for one that is not hydrated, since there is nothing to look it up with.

Constant Summary collapse

FIELDS =

Every public poll field

A minor release may add to it the fields the API adds, so that a lookup asks for them too; see Resource#hydrated? for what that means for a resource looked up with a list of fields of its own.

%w[duration_minutes end_datetime id options voting_status].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Constructor Details

This class inherits a constructor from X::Resource

Instance Attribute Details

#duration_minutes ⇒ Integer? (readonly)

The duration of the poll in minutes

Examples:

Get the duration

poll.duration_minutes

Returns:

  • (Integer, nil) —

    the duration in minutes



57
# File 'x-objects/lib/x/objects/poll.rb', line 57

attribute :duration_minutes, :integer

#end_datetime ⇒ Time? (readonly)

The time when the poll ends

Examples:

Get the end time

poll.end_datetime

Returns:

  • (Time, nil) —

    the end time



65
# File 'x-objects/lib/x/objects/poll.rb', line 65

attribute :end_datetime, :time

#options ⇒ Array<Hash> (readonly)

The poll options with their positions, labels, and vote counts

Examples:

Get the options

poll.options

Returns:

  • (Array<Hash>) —

    the options, empty if there are none



49
# File 'x-objects/lib/x/objects/poll.rb', line 49

attribute :options, :objects

#voting_status ⇒ String? (readonly)

The voting status: open or closed

Examples:

Get the voting status

poll.voting_status

Returns:

  • (String, nil) —

    the voting status



73
# File 'x-objects/lib/x/objects/poll.rb', line 73

attribute :voting_status

Class Method Details

.default_params ⇒ Hash{String => Array<String>}

The default query parameters, which request every field

The API offers no lookup of polls, so they are requested by the posts that expand them, which ask for these fields, and a poll a response included with all of them is hydrated.

Examples:

Get the default parameters

X::Poll.default_params # => {"poll.fields" => [...]}

Returns:

  • (Hash{String => Array<String>}) —

    the default query parameters



30
# File 'x-objects/lib/x/objects/poll.rb', line 30

def self.default_params = {"poll.fields" => FIELDS}