Class: Twitch::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/twitch/client.rb

Constant Summary collapse

BASE_URL =
"https://api.twitch.tv/helix"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id:, access_token:, adapter: Faraday.default_adapter, rate_limit_threshold: 10, auto_retry_rate_limit: true, logger: nil) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/twitch/client.rb', line 8

def initialize(
  client_id:,
  access_token:,
  adapter: Faraday.default_adapter,
  rate_limit_threshold: 10,
  auto_retry_rate_limit: true,
  logger: nil
)
  @client_id = client_id
  @access_token = access_token
  @adapter = adapter
  @rate_limit_threshold = rate_limit_threshold
  @auto_retry_rate_limit = auto_retry_rate_limit
  @logger = logger
  @rate_limiter = RateLimiter.new(logger: logger)
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



5
6
7
# File 'lib/twitch/client.rb', line 5

def access_token
  @access_token
end

#adapterObject (readonly)

Returns the value of attribute adapter.



5
6
7
# File 'lib/twitch/client.rb', line 5

def adapter
  @adapter
end

#auto_retry_rate_limitObject (readonly)

Returns the value of attribute auto_retry_rate_limit.



6
7
8
# File 'lib/twitch/client.rb', line 6

def auto_retry_rate_limit
  @auto_retry_rate_limit
end

#client_idObject (readonly)

Returns the value of attribute client_id.



5
6
7
# File 'lib/twitch/client.rb', line 5

def client_id
  @client_id
end

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/twitch/client.rb', line 6

def logger
  @logger
end

#rate_limit_thresholdObject (readonly)

Returns the value of attribute rate_limit_threshold.



6
7
8
# File 'lib/twitch/client.rb', line 6

def rate_limit_threshold
  @rate_limit_threshold
end

#rate_limiterObject (readonly)

Returns the value of attribute rate_limiter.



5
6
7
# File 'lib/twitch/client.rb', line 5

def rate_limiter
  @rate_limiter
end

Instance Method Details

#announcementsObject



125
126
127
# File 'lib/twitch/client.rb', line 125

def announcements
  AnnouncementsResource.new(self)
end

#automodObject



145
146
147
# File 'lib/twitch/client.rb', line 145

def automod
  AutomodResource.new(self)
end

#badgesObject



37
38
39
# File 'lib/twitch/client.rb', line 37

def badges
  BadgesResource.new(self)
end

#banned_eventsObject



61
62
63
# File 'lib/twitch/client.rb', line 61

def banned_events
  BannedEventsResource.new(self)
end

#banned_usersObject



65
66
67
# File 'lib/twitch/client.rb', line 65

def banned_users
  BannedUsersResource.new(self)
end

#blocked_termsObject



149
150
151
# File 'lib/twitch/client.rb', line 149

def blocked_terms
  BlockedTermsResource.new(self)
end

#channelsObject



29
30
31
# File 'lib/twitch/client.rb', line 29

def channels
  ChannelsResource.new(self)
end

#charity_campaignsObject



153
154
155
# File 'lib/twitch/client.rb', line 153

def charity_campaigns
  CharityCampaignsResource.new(self)
end

#chat_messagesObject



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

def chat_messages
  ChatMessagesResource.new(self)
end

#chattersObject



157
158
159
# File 'lib/twitch/client.rb', line 157

def chatters
  ChattersResource.new(self)
end

#clipsObject



49
50
51
# File 'lib/twitch/client.rb', line 49

def clips
  ClipsResource.new(self)
end

#connectionObject



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/twitch/client.rb', line 173

def connection
  @connection ||= Faraday.new(BASE_URL) do |conn|
    conn.request :authorization, :Bearer, access_token

    conn.headers = {
      "User-Agent" => "twitchrb/v#{VERSION} (github.com/deanpcmad/twitchrb)",
      "Client-ID": client_id
    }

    conn.request :json

    conn.response :json, content_type: "application/json"

    conn.adapter adapter, @stubs
  end
end

#custom_reward_redemptionsObject



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

def custom_reward_redemptions
  CustomRewardRedemptionsResource.new(self)
end

#custom_rewardsObject



109
110
111
# File 'lib/twitch/client.rb', line 109

def custom_rewards
  CustomRewardsResource.new(self)
end

#emotesObject



33
34
35
# File 'lib/twitch/client.rb', line 33

def emotes
  EmotesResource.new(self)
end

#eventsub_conduitsObject



57
58
59
# File 'lib/twitch/client.rb', line 57

def eventsub_conduits
  EventsubConduitsResource.new(self)
end

#eventsub_subscriptionsObject



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

def eventsub_subscriptions
  EventsubSubscriptionsResource.new(self)
end

#gamesObject



41
42
43
# File 'lib/twitch/client.rb', line 41

def games
  GamesResource.new(self)
end

#goalsObject



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

def goals
  GoalsResource.new(self)
end

#hype_train_eventsObject



121
122
123
# File 'lib/twitch/client.rb', line 121

def hype_train_events
  HypeTrainEventsResource.new(self)
end

#moderator_eventsObject



73
74
75
# File 'lib/twitch/client.rb', line 73

def moderator_events
  ModeratorEventsResource.new(self)
end

#moderatorsObject



69
70
71
# File 'lib/twitch/client.rb', line 69

def moderators
  ModeratorsResource.new(self)
end

#pollsObject



77
78
79
# File 'lib/twitch/client.rb', line 77

def polls
  PollsResource.new(self)
end

#predictionsObject



81
82
83
# File 'lib/twitch/client.rb', line 81

def predictions
  PredictionsResource.new(self)
end

#raidsObject



129
130
131
# File 'lib/twitch/client.rb', line 129

def raids
  RaidsResource.new(self)
end

#searchObject



89
90
91
# File 'lib/twitch/client.rb', line 89

def search
  SearchResource.new(self)
end

#shoutoutsObject



161
162
163
# File 'lib/twitch/client.rb', line 161

def shoutouts
  ShoutoutsResource.new(self)
end

#stream_markersObject



97
98
99
# File 'lib/twitch/client.rb', line 97

def stream_markers
  StreamMarkersResource.new(self)
end

#stream_scheduleObject



85
86
87
# File 'lib/twitch/client.rb', line 85

def stream_schedule
  StreamScheduleResource.new(self)
end

#streamsObject



93
94
95
# File 'lib/twitch/client.rb', line 93

def streams
  StreamsResource.new(self)
end

#subscriptionsObject



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

def subscriptions
  SubscriptionsResource.new(self)
end

#tagsObject



105
106
107
# File 'lib/twitch/client.rb', line 105

def tags
  TagsResource.new(self)
end

#unban_requestsObject



165
166
167
# File 'lib/twitch/client.rb', line 165

def unban_requests
  UnbanRequestsResource.new(self)
end

#usersObject



25
26
27
# File 'lib/twitch/client.rb', line 25

def users
  UsersResource.new(self)
end

#videosObject



45
46
47
# File 'lib/twitch/client.rb', line 45

def videos
  VideosResource.new(self)
end

#vipsObject



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

def vips
  VipsResource.new(self)
end

#warningsObject



169
170
171
# File 'lib/twitch/client.rb', line 169

def warnings
  WarningsResource.new(self)
end

#whispersObject



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

def whispers
  WhispersResource.new(self)
end