Class: Twitch::CustomRewardsResource

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



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

def create(broadcaster_id:, title:, cost:, **params)
  attributes = { broadcaster_id: broadcaster_id, title: title, cost: cost }
  response = post_request("channel_points/custom_rewards", body: attributes.merge(params))

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

#delete(broadcaster_id:, reward_id:) ⇒ Object



24
25
26
# File 'lib/twitch/resources/custom_rewards.rb', line 24

def delete(broadcaster_id:, reward_id:)
  delete_request("channel_points/custom_rewards", params: { broadcaster_id: broadcaster_id, id: reward_id })
end

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

Required scope: channel:read:redemptions Broadcaster ID must match the user in the OAuth token



5
6
7
8
# File 'lib/twitch/resources/custom_rewards.rb', line 5

def list(broadcaster_id:, **params)
  response = get_request("channel_points/custom_rewards", params: params.merge(broadcaster_id: broadcaster_id))
  Collection.from_response(response, type: CustomReward)
end

#update(broadcaster_id:, reward_id:, **params) ⇒ Object



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

def update(broadcaster_id:, reward_id:, **params)
  attributes = { broadcaster_id: broadcaster_id, id: reward_id }
  response = patch_request("channel_points/custom_rewards", body: attributes.merge(params))

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