Class: Twitch::Client

Inherits:
Object
  • Object
show all
Includes:
CustomRewards, Extensions, Games, Moderation, Streams, Subscriptions, Users
Defined in:
lib/twitch/client.rb,
lib/twitch/client/games.rb,
lib/twitch/client/users.rb,
lib/twitch/client/streams.rb,
lib/twitch/client/extensions.rb,
lib/twitch/client/moderation.rb,
lib/twitch/client/subscriptions.rb,
lib/twitch/client/custom_rewards.rb

Overview

Core class for requests

Defined Under Namespace

Modules: CustomRewards, Extensions, Games, Moderation, Streams, Subscriptions, Users

Constant Summary collapse

CONNECTION =

Base connection to Helix API.

Faraday.new(
  'https://api.twitch.tv/helix', {
    headers: { 'User-Agent': "twitch-api ruby client #{Twitch::VERSION}" }
  }
) do |faraday|
  faraday.request :retry,
    exceptions: [*Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS, Faraday::ConnectionFailed]

  faraday.response :parse_dates

  faraday.request :json
  faraday.response :json
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CustomRewards

#create_custom_reward, #delete_custom_reward, #get_custom_reward, #get_custom_reward_redemption, #update_custom_reward, #update_redemption_status

Methods included from Users

#get_users, #get_users_follows, #update_user

Methods included from Subscriptions

#get_broadcaster_subscription

Methods included from Streams

#create_stream_marker, #get_stream_key, #get_stream_markers, #get_streams, #get_streams_metadata

Methods included from Moderation

#check_automod_status, #get_banned_events, #get_banned_users, #get_moderator_events, #get_moderators

Methods included from Games

#get_game_analytics, #get_games, #get_top_games

Methods included from Extensions

#get_user_active_extensions, #get_user_extensions, #update_user_extensions

Constructor Details

#initialize(tokens:) ⇒ Client

Initializes a Twitch client.

  • tokens [TwitchOAuth2::Tokens] Tokens object with their refreshing logic inside.

All client and authentication information (‘client_id`, `:scopes`, etc.) stores there.



59
60
61
62
63
64
65
# File 'lib/twitch/client.rb', line 59

def initialize(tokens:)
  @tokens = tokens

  CONNECTION.headers['Client-ID'] = self.tokens.client.client_id

  renew_authorization_header
end

Instance Attribute Details

#tokensObject (readonly)

Returns the value of attribute tokens.



53
54
55
# File 'lib/twitch/client.rb', line 53

def tokens
  @tokens
end

Instance Method Details

#create_clip(options = {}) ⇒ Object



67
68
69
# File 'lib/twitch/client.rb', line 67

def create_clip(options = {})
  initialize_response Clip, post('clips', options)
end

#create_entitlement_grant_url(options = {}) ⇒ Object



71
72
73
# File 'lib/twitch/client.rb', line 71

def create_entitlement_grant_url(options = {})
  initialize_response EntitlementGrantUrl, post('entitlements/upload', options)
end

#get_bits_leaderboard(options = {}) ⇒ Object



79
80
81
# File 'lib/twitch/client.rb', line 79

def get_bits_leaderboard(options = {})
  initialize_response BitsLeader, get('bits/leaderboard', options)
end

#get_channel_editors(options = {}) ⇒ Object



137
138
139
# File 'lib/twitch/client.rb', line 137

def get_channel_editors(options = {})
  initialize_response Editor, get('channels/editors', options)
end

#get_channels(options = {}) ⇒ Object



113
114
115
# File 'lib/twitch/client.rb', line 113

def get_channels(options = {})
  initialize_response Channel, get('channels', options)
end

#get_cheermotes(options = {}) ⇒ Object



83
84
85
# File 'lib/twitch/client.rb', line 83

def get_cheermotes(options = {})
  initialize_response Cheermote, get('bits/cheermotes', options)
end

#get_clips(options = {}) ⇒ Object



75
76
77
# File 'lib/twitch/client.rb', line 75

def get_clips(options = {})
  initialize_response Clip, get('clips', options)
end

#get_videos(options = {}) ⇒ Object



102
103
104
# File 'lib/twitch/client.rb', line 102

def get_videos(options = {})
  initialize_response Video, get('videos', options)
end

#modify_channel(options = {}) ⇒ Object



123
124
125
126
127
128
129
# File 'lib/twitch/client.rb', line 123

def modify_channel(options = {})
  response = patch('channels', options)

  return true if response.body.empty?

  response.body
end

#search_categories(options = {}) ⇒ Object



142
143
144
# File 'lib/twitch/client.rb', line 142

def search_categories(options = {})
  initialize_response Category, get('search/categories', options)
end

#search_channels(options = {}) ⇒ Object



118
119
120
# File 'lib/twitch/client.rb', line 118

def search_channels(options = {})
  initialize_response Channel, get('search/channels', options)
end

#start_commercial(options = {}) ⇒ Object



132
133
134
# File 'lib/twitch/client.rb', line 132

def start_commercial(options = {})
  initialize_response nil, post('channels/commercial', options)
end