Class: Twitch::ChannelsResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/twitch/resources/channels.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

#commercial(broadcaster_id:, length:) ⇒ Object



54
55
56
# File 'lib/twitch/resources/channels.rb', line 54

def commercial(broadcaster_id:, length:)
  post_request("channels/commercial", body: { broadcaster_id: broadcaster_id, length: length })
end

#editors(broadcaster_id:) ⇒ Object

Requires scope: channel:read:editors



44
45
46
47
# File 'lib/twitch/resources/channels.rb', line 44

def editors(broadcaster_id:)
  response = get_request("channels/editors?broadcaster_id=#{broadcaster_id}")
  Collection.from_response(response, type: ChannelEditor)
end

#followed(user_id:, **params) ⇒ Object

Retrieve a list of broadcasters a specified user follows Required scope: user:read:follows user_id must match the authenticated user



10
11
12
13
# File 'lib/twitch/resources/channels.rb', line 10

def followed(user_id:, **params)
  response = get_request("channels/followed", params: params.merge(user_id: user_id))
  Collection.from_response(response, type: User)
end

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

Retrieve a list of users that follow a specified broadcaster Required scope: moderator:read:followers broadcaster_id must match the authenticated user



18
19
20
21
# File 'lib/twitch/resources/channels.rb', line 18

def followers(broadcaster_id:, **params)
  response = get_request("channels/followers", params: params.merge(broadcaster_id: broadcaster_id))
  Collection.from_response(response, type: User)
end

#follows_count(broadcaster_id:) ⇒ Object

Grabs the number of Followers a broadcaster has



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

def follows_count(broadcaster_id:)
  response = get_request("channels/followers", params: { broadcaster_id: broadcaster_id })

  FollowCount.new(count: response.body["total"])
end

#retrieve(id:) ⇒ Object



3
4
5
# File 'lib/twitch/resources/channels.rb', line 3

def retrieve(id:)
  Channel.new get_request("channels?broadcaster_id=#{id}").body.dig("data")[0]
end

#stream_key(broadcaster_id:) ⇒ Object



49
50
51
52
# File 'lib/twitch/resources/channels.rb', line 49

def stream_key(broadcaster_id:)
  response = get_request("streams/key?broadcaster_id=#{broadcaster_id}")
  StreamKey.new(response.body.dig("data")[0])
end

#subscribers_count(broadcaster_id:) ⇒ Object

Grabs the number of Subscribers and Subscriber Points a broadcaster has Required scope: channel:read:subscriptions



32
33
34
35
36
# File 'lib/twitch/resources/channels.rb', line 32

def subscribers_count(broadcaster_id:)
  response = get_request("subscriptions", params: { broadcaster_id: broadcaster_id })

  SubscriptionCount.new(count: response.body["total"], points: response.body["points"])
end

#update(broadcaster_id:, **attributes) ⇒ Object

Requires scope: channel:manage:broadcast



39
40
41
# File 'lib/twitch/resources/channels.rb', line 39

def update(broadcaster_id:, **attributes)
  patch_request("channels", body: attributes.merge(broadcaster_id: broadcaster_id))
end