Class: Twitch::PredictionsResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/twitch/resources/predictions.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:, outcomes:, duration:, **params) ⇒ Object

Broadcaster ID must match the user in the OAuth token



15
16
17
18
19
20
# File 'lib/twitch/resources/predictions.rb', line 15

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

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

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

Broadcaster ID must match the user in the OAuth token



23
24
25
26
27
28
# File 'lib/twitch/resources/predictions.rb', line 23

def end(broadcaster_id:, id:, status:, **params)
  attrs = { broadcaster_id: broadcaster_id, id: id, status: status.upcase }
  response = patch_request("predictions", body: attrs.merge(params))

  Prediction.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
8
9
10
11
12
# File 'lib/twitch/resources/predictions.rb', line 4

def list(broadcaster_id:, **params)
  response = get_request("predictions", params: params.merge(broadcaster_id: broadcaster_id))

  if response.body["data"]
    Collection.from_response(response, type: Prediction)
  else
    nil
  end
end