Class: Twitch::PollsResource

Inherits:
Resource show all
Defined in:
lib/twitch/resources/polls.rb

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Twitch::Resource

Instance Method Details

#create(broadcaster_id:, title:, choices:, duration:, **params) ⇒ Object

Broadcaster ID must match the user in the OAuth token



10
11
12
13
14
15
# File 'lib/twitch/resources/polls.rb', line 10

def create(broadcaster_id:, title:, choices:, duration:, **params)
  attrs = { broadcaster_id: broadcaster_id, title: title, choices: choices, duration: duration }
  response = post_request("polls", body: attrs.merge(params))

  Poll.new(response.body.dig("data")[0]) if response.success?
end

#end(broadcaster_id:, id:, status:) ⇒ Object

Broadcaster ID must match the user in the OAuth token



18
19
20
21
22
23
# File 'lib/twitch/resources/polls.rb', line 18

def end(broadcaster_id:, id:, status:)
  attrs = { broadcaster_id: broadcaster_id, id: id, status: status.upcase }
  response = patch_request("polls", body: attrs)

  Poll.new(response.body.dig("data")[0]) if response.success?
end

#list(broadcaster_id:, **params) ⇒ Object

Broadcaster ID must match the user in the OAuth token



4
5
6
7
# File 'lib/twitch/resources/polls.rb', line 4

def list(broadcaster_id:, **params)
  response = get_request("polls", params: params.merge(broadcaster_id: broadcaster_id))
  Collection.from_response(response, type: Poll)
end