twitchrb 0.2.5 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aed73c860ea357f7be4fed291738092fc960c84db6196828ed038ffc86485778
4
- data.tar.gz: 530134f555c196d49b5262a7fea0519cc8d24ef11998dc413578cb0864816c00
3
+ metadata.gz: f8ee21feb703fb97c6fe0d5a3dd7da8072f70d1a959fc84f5e502aaa2ec45d68
4
+ data.tar.gz: 75723ca8b4285ac950ebe0e722238b72c42b3be9d0e7214d57afbaf613586b3c
5
5
  SHA512:
6
- metadata.gz: 580f55a88bbd26a32a61d1ff6bd112c11c1c4f81b260c11f0cd482fd105dcb67275c456a1798f5b19ef40627cfd85c554f2bd0adf1dd3fbc0b5a5ad4f73db3cb
7
- data.tar.gz: 818cdcbceaa214f65976316ea002113706adfef09163e6fd45e3b8b517e8c5fded02dff5801978a46a13028122c563344b6b63bd20862e348e65d85758902f1f
6
+ metadata.gz: 28c24c46f1b678e8db7e56ff24a5e80f25b3c0a491a61373b57d98ccf9081ca2157adf91f8767c01aa23bcfbfd04559188ef589d5055aee38f6aef945e8ef21e
7
+ data.tar.gz: e6253a4bc7c31232fff212dbfddca8b86d2205c4be7bffc9da9beb5e233016a9c8bb97bfcd4147a6833521e09b01cfa2be3d3c661ceb4a33e886cbb48440c9d5
data/.github/FUNDING.yml CHANGED
@@ -1,4 +1,3 @@
1
1
  # These are supported funding model platforms
2
2
 
3
- github: deanpcmad
4
- custom: https://www.buymeacoffee.com/deanpcmad
3
+ ko_fi: deanpcmad
data/Gemfile.lock CHANGED
@@ -1,17 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- twitchrb (0.2.5)
4
+ twitchrb (1.0.1)
5
5
  faraday (~> 2.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  dotenv (2.7.6)
11
- faraday (2.2.0)
12
- faraday-net_http (~> 2.0)
11
+ faraday (2.5.2)
12
+ faraday-net_http (>= 2.0, < 3.1)
13
13
  ruby2_keywords (>= 0.0.4)
14
- faraday-net_http (2.0.2)
14
+ faraday-net_http (3.0.0)
15
15
  minitest (5.15.0)
16
16
  rake (12.3.3)
17
17
  ruby2_keywords (0.0.5)
@@ -26,4 +26,4 @@ DEPENDENCIES
26
26
  twitchrb!
27
27
 
28
28
  BUNDLED WITH
29
- 2.3.5
29
+ 2.3.21
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # TwitchRB
2
2
 
3
- **This library is a work in progress**
4
-
5
- TwitchRB is a Ruby library for intereacting with the Twitch Helix API.
3
+ TwitchRB is a Ruby library for interacting with the Twitch Helix API.
6
4
 
7
5
  ## Installation
8
6
 
@@ -16,12 +14,12 @@ gem "twitchrb"
16
14
 
17
15
  ### Set Client Details
18
16
 
19
- Firstly you'll need to set a Client ID, Secret Key and an Access Token.
17
+ Firstly you'll need to set a Client ID and an Access Token.
20
18
 
21
19
  An access token is required because the Helix API requires authentication.
22
20
 
23
21
  ```ruby
24
- @client = Twitch::Client.new(client_id: "", client_secret: "", access_token: "")
22
+ @client = Twitch::Client.new(client_id: "", access_token: "")
25
23
  ```
26
24
 
27
25
  ### Users
@@ -56,6 +54,19 @@ An access token is required because the Helix API requires authentication.
56
54
  # Required scope: user:manage:blocked_users
57
55
  @client.users.unblock_user(target_user_id: 141981764)
58
56
 
57
+ # Get a User's Chat Color
58
+ @client.users.get_color(user_id: 123)
59
+
60
+ # Or get multiple users' chat colors
61
+ # Returns a collection
62
+ @client.users.get_color(user_ids: "123,321")
63
+
64
+ # Update a User's Chat Color
65
+ # Requires user:manage:chat_color
66
+ # user_id must be the currently authenticated user
67
+ # Current allowed colours: blue, blue_violet, cadet_blue, chocolate, coral, dodger_blue, firebrick, golden_rod, green, hot_pink, orange_red, red, sea_green, spring_green, yellow_green
68
+ # For Turbo and Prime users, a hex colour code is allowed.
69
+ @client.users.update_color(user_id: 123, color: "blue")
59
70
  ```
60
71
 
61
72
  ### Channels
@@ -185,6 +196,181 @@ These require an application OAuth access token.
185
196
  @client.banned_users.list(broadcaster_id: 123)
186
197
  ```
187
198
 
199
+ ```ruby
200
+ # Ban/Timeout a user from a broadcaster's channel
201
+ # Required scope: moderator:manage:banned_users
202
+ # A reason is required
203
+ # To time a user out, a duration is required. If no duration is set, the user will be banned.
204
+ @client.banned_users.create broadcaster_id: 123, moderator_id: 321, user_id: 112233, reason: "testing", duration: 60
205
+ ```
206
+
207
+ ```ruby
208
+ # Unban/untimeout a user from a broadcaster's channel
209
+ # Required scope: moderator:manage:banned_users
210
+ @client.banned_users.delete broadcaster_id: 123, moderator_id: 321, user_id: 112233
211
+ ```
212
+
213
+ ## Send Chat Announcement
214
+
215
+ ```ruby
216
+ # Sends an announcement to the broadcaster's chat room
217
+ # Requires moderator:manage:announcements
218
+ # moderator_id can be either the currently authenticated moderator or the broadcaster
219
+ # color can be either blue, green, orange, purple, primary. If left blank, primary is default
220
+ @client.announcements.create broadcaster_id: 123, moderator_id: 123, message: "test message", color: "purple"
221
+ ```
222
+
223
+ ## Moderators
224
+
225
+ ```ruby
226
+ # List all moderators for a broadcaster
227
+ # Required scope: moderation:read
228
+ # broadcaster_id must be the currently authenticated user
229
+ @client.moderators.list broadcaster_id: 123
230
+ ```
231
+
232
+ ```ruby
233
+ # Add a Moderator
234
+ # Required scope: channel:manage:moderators
235
+ # broadcaster_id must be the currently authenticated user
236
+ @client.moderators.create broadcaster_id: 123, user_id: 321
237
+ ```
238
+
239
+ ```ruby
240
+ # Remove a Moderator
241
+ # Required scope: channel:manage:moderators
242
+ # broadcaster_id must be the currently authenticated user
243
+ @client.moderators.delete broadcaster_id: 123, user_id: 321
244
+ ```
245
+
246
+ ## VIPs
247
+
248
+ ```ruby
249
+ # List all VIPs for a broadcaster
250
+ # Required scope: channel:read:vips or channel:manage:vips
251
+ # broadcaster_id must be the currently authenticated user
252
+ @client.vips.list broadcaster_id: 123
253
+ ```
254
+
255
+ ```ruby
256
+ # Add a VIP
257
+ # Required scope: channel:manage:vips
258
+ # broadcaster_id must be the currently authenticated user
259
+ @client.vips.create broadcaster_id: 123, user_id: 321
260
+ ```
261
+
262
+ ```ruby
263
+ # Remove a VIP
264
+ # Required scope: channel:manage:vips
265
+ # broadcaster_id must be the currently authenticated user
266
+ @client.vips.delete broadcaster_id: 123, user_id: 321
267
+ ```
268
+
269
+ ## Raids
270
+
271
+ ```ruby
272
+ # Starts a raid
273
+ # Requires channel:manage:raids
274
+ # from_broadcaster_id must be the authenticated user
275
+ @client.raids.create from_broadcaster_id: 123, to_broadcaster_id: 321
276
+ ```
277
+
278
+ ```ruby
279
+ # Requires channel:manage:raids
280
+ # broadcaster_id must be the authenticated user
281
+ @client.raids.delete broadcaster_id: 123
282
+ ```
283
+
284
+ ```ruby
285
+ # Removes a single chat message from the broadcaster's chat room
286
+ # Requires moderator:manage:chat_messages
287
+ # moderator_id can be either the currently authenticated moderator or the broadcaster
288
+ @client.chat_messages.delete broadcaster_id: 123, moderator_id: 123, message_id: "abc123-abc123"
289
+ ```
290
+
291
+ ## Whispers
292
+
293
+ ```ruby
294
+ # Send a Whisper
295
+ # Required scope: user:manage:whispers
296
+ # from_user_id must be the currently authenticated user's ID and have a verified phone number
297
+ @client.whispers.create from_user_id: 123, to_user_id: 321, message: "this is a test"
298
+ ```
299
+
300
+ ## AutoMod
301
+
302
+ ```ruby
303
+ # Check if a message meets the channel's AutoMod requirements
304
+ # Required scope: moderation:read
305
+ # id is a developer-generated identifier for mapping messages to results.
306
+ @client.automod.check_status_multiple broadcaster_id: 123, id: "abc123", text: "Is this message allowed?"
307
+
308
+ #> #<Twitch::AutomodStatus msg_id="abc123", is_permitted=true>
309
+ ```
310
+
311
+ ```ruby
312
+ # Check if multiple messages meet the channel's AutoMod requirements
313
+ # messages must be an array of hashes and must include msg_id and msg_text
314
+ # Returns a collection
315
+ messages = [{msg_id: "abc1", msg_text: "is this allowed?"}, {msg_id: "abc2", msg_text: "What about this?"}]
316
+ @client.automod.check_status_multiple broadcaster_id: 123, messages: messages
317
+ ```
318
+
319
+ ```ruby
320
+ # Get AutoMod settings
321
+ # Required scope: moderator:read:automod_settings
322
+ # moderator_id can be either the currently authenticated moderator or the broadcaster
323
+ @client.automod.settings broadcaster_id: 123, moderator_id: 321
324
+ ```
325
+
326
+ ```ruby
327
+ # Update AutoMod settings
328
+ # Required scope: moderator:manage:automod_settings
329
+ # moderator_id can be either the currently authenticated moderator or the broadcaster
330
+ # As this is a PUT method, it overwrites all options so all fields you want set should be supplied
331
+ @client.automod.update_settings broadcaster_id: 123, moderator_id: 321, swearing: 1
332
+ ```
333
+
334
+ ## Creator Goals
335
+
336
+ ```ruby
337
+ # List all active creator goals
338
+ # Required scope: channel:read:goals
339
+ # broadcaster_id must match the currently authenticated user
340
+ @client.goals.list broadcaster_id: 123
341
+ ```
342
+
343
+ ## Blocked Terms
344
+
345
+ ```ruby
346
+ # List all blocked terms
347
+ # Required scope: moderator:read:blocked_terms
348
+ # moderator_id can be either the currently authenticated moderator or the broadcaster
349
+ @client.blocked_terms.list broadcaster_id: 123, moderator_id: 321
350
+ ```
351
+
352
+ ```ruby
353
+ # Create a blocked term
354
+ # Required scope: moderator:manage:blocked_terms
355
+ # moderator_id can be either the currently authenticated moderator or the broadcaster
356
+ @client.blocked_terms.create broadcaster_id: 123, moderator_id: 321, text: "term to block"
357
+ ```
358
+
359
+ ```ruby
360
+ # Delete a blocked term
361
+ # Required scope: moderator:manage:blocked_terms
362
+ # moderator_id can be either the currently authenticated moderator or the broadcaster
363
+ @client.blocked_terms.delete broadcaster_id: 123, moderator_id: 321, id: "abc12-12abc"
364
+ ```
365
+
366
+ ## Charity Campaigns
367
+
368
+ ```ruby
369
+ # Gets information about the charity campaign that a broadcaster is running
370
+ # Required scope: channel:read:charity
371
+ # broadcaster_id must match the currently authenticated user
372
+ @client.charity_campaigns.list broadcaster_id: 123
373
+ ```
188
374
 
189
375
  ## Contributing
190
376
 
data/bin/console CHANGED
@@ -13,7 +13,7 @@ require 'dotenv/load'
13
13
  # require "pry"
14
14
  # Pry.start
15
15
 
16
- @client = Twitch::Client.new(client_id: ENV["TWITCH_CLIENT_ID"], client_secret: ENV["TWITCH_CLIENT_SECRET"], access_token: ENV["TWITCH_ACCESS_TOKEN"])
16
+ @client = Twitch::Client.new(client_id: ENV["TWITCH_CLIENT_ID"], access_token: ENV["TWITCH_ACCESS_TOKEN"])
17
17
 
18
18
  require "irb"
19
19
  IRB.start(__FILE__)
data/lib/twitch/client.rb CHANGED
@@ -2,11 +2,10 @@ module Twitch
2
2
  class Client
3
3
  BASE_URL = "https://api.twitch.tv/helix"
4
4
 
5
- attr_reader :client_id, :client_secret, :access_token, :adapter
5
+ attr_reader :client_id, :access_token, :adapter
6
6
 
7
- def initialize(client_id:, client_secret:, access_token:, adapter: Faraday.default_adapter, stubs: nil)
7
+ def initialize(client_id:, access_token:, adapter: Faraday.default_adapter, stubs: nil)
8
8
  @client_id = client_id
9
- @client_secret = client_secret
10
9
  @access_token = access_token
11
10
  @adapter = adapter
12
11
 
@@ -110,6 +109,38 @@ module Twitch
110
109
  HypeTrainEventsResource.new(self)
111
110
  end
112
111
 
112
+ def announcements
113
+ AnnouncementsResource.new(self)
114
+ end
115
+
116
+ def raids
117
+ RaidsResource.new(self)
118
+ end
119
+
120
+ def chat_messages
121
+ ChatMessagesResource.new(self)
122
+ end
123
+
124
+ def vips
125
+ VipsResource.new(self)
126
+ end
127
+
128
+ def whispers
129
+ WhispersResource.new(self)
130
+ end
131
+
132
+ def automod
133
+ AutomodResource.new(self)
134
+ end
135
+
136
+ def blocked_terms
137
+ BlockedTermsResource.new(self)
138
+ end
139
+
140
+ def charity_campaigns
141
+ CharityCampaignsResource.new(self)
142
+ end
143
+
113
144
  def connection
114
145
  @connection ||= Faraday.new(BASE_URL) do |conn|
115
146
  conn.request :authorization, :Bearer, access_token
@@ -0,0 +1,4 @@
1
+ module Twitch
2
+ class AutomodSetting < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Twitch
2
+ class AutomodStatus < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Twitch
2
+ class BlockedTerm < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Twitch
2
+ class CharityCampaign < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Twitch
2
+ class Raid < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Twitch
2
+ class UserColor < Object
3
+ end
4
+ end
@@ -1,31 +1,4 @@
1
1
  module Twitch
2
2
  class Video < Object
3
-
4
- def initialize(options = {})
5
- super options
6
-
7
- self.thumbnail_url_large = generate_thumbnail_url_large
8
- self.animated_url = generate_animated_url
9
- end
10
-
11
-
12
- # Generates the Large Thumbnail image URL
13
- def generate_thumbnail_url_large
14
- return "" if thumbnail_url.empty?
15
-
16
- thumbnail_url.gsub("%{width}", "640").gsub("%{height}", "360")
17
- end
18
-
19
- # Generates a Storyboard/Animated image URL
20
- def generate_animated_url
21
- return "" if thumbnail_url.empty?
22
-
23
- thumb = thumbnail_url.dup
24
- thumb.gsub!("https://static-cdn.jtvnw.net/cf_vods/", "").gsub!("/thumb/thumb0-%{width}x%{height}.jpg", "storyboards/#{id}-strip-0.jpg")
25
- split = thumb.split("/")
26
-
27
- "https://#{split[0]}.cloudfront.net/#{split[1..].join("/")}"
28
- end
29
-
30
3
  end
31
4
  end
@@ -0,0 +1,4 @@
1
+ module Twitch
2
+ class Vip < Object
3
+ end
4
+ end
@@ -40,6 +40,8 @@ module Twitch
40
40
  raise Error, "Error 404: No results were found for your request. '#{response.body["error"]}'"
41
41
  when 409
42
42
  raise Error, "Error 409: Your request was a conflict. '#{response.body["message"]}'"
43
+ when 422
44
+ raise Error, "Error 422: Unprocessable Entity. '#{response.body["message"]}"
43
45
  when 429
44
46
  raise Error, "Error 429: Your request exceeded the API rate limit. '#{response.body["error"]}'"
45
47
  when 500
@@ -0,0 +1,12 @@
1
+ module Twitch
2
+ class AnnouncementsResource < Resource
3
+
4
+ # Moderator ID must match the user in the OAuth token
5
+ def create(broadcaster_id:, moderator_id:, message:, color: nil)
6
+ attrs = {message: message, color: color}
7
+
8
+ post_request("chat/announcements?broadcaster_id=#{broadcaster_id}&moderator_id=#{moderator_id}", body: attrs)
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,37 @@
1
+ module Twitch
2
+ class AutomodResource < Resource
3
+
4
+ # Checks if a supplied message meets the channel's AutoMod requirements
5
+ # Required scope: moderation:read
6
+ def check_status(broadcaster_id:, id:, text:)
7
+ attrs = {broadcaster_id: broadcaster_id, data: [{msg_id: id, msg_text: text}]}
8
+ response = post_request("moderation/enforcements/status", body: attrs)
9
+ AutomodStatus.new response.body.dig("data")[0]
10
+ end
11
+
12
+ # Checks if multiple supplied messages meet the channel's AutoMod requirements
13
+ # Required scope: moderation:read
14
+ def check_status_multiple(broadcaster_id:, messages:)
15
+ attrs = {broadcaster_id: broadcaster_id, data: messages}
16
+ response = post_request("moderation/enforcements/status", body: attrs)
17
+ Collection.from_response(response, type: AutomodStatus)
18
+ end
19
+
20
+ def manage_message(user_id:, msg_id:, action:)
21
+ attrs = {user_id: user_id, msg_id: msg_id, action: action}
22
+ post_request("moderation/automod/message", body: attrs)
23
+ end
24
+
25
+ def settings(broadcaster_id:, moderator_id:)
26
+ response = get_request("moderation/automod/settings?broadcaster_id=#{broadcaster_id}&moderator_id=#{moderator_id}")
27
+ AutomodSetting.new response.body.dig("data")[0]
28
+ end
29
+
30
+ def update_settings(broadcaster_id:, moderator_id:, **params)
31
+ attrs = {broadcaster_id: broadcaster_id, moderator_id: moderator_id}
32
+ response = put_request("moderation/automod/settings", body: attrs.merge(params))
33
+ AutomodSetting.new response.body.dig("data")[0]
34
+ end
35
+
36
+ end
37
+ end
@@ -7,5 +7,19 @@ module Twitch
7
7
  Collection.from_response(response, type: BannedUser)
8
8
  end
9
9
 
10
+ # Required scope: moderator:manage:banned_users
11
+ # moderator_id must match the currently authenticated user. Can be either the broadcaster ID or moderator ID
12
+ def create(broadcaster_id:, moderator_id:, user_id:, reason:, duration: nil)
13
+ attrs = {broadcaster_id: broadcaster_id, moderator_id: moderator_id, data: {user_id: user_id, reason: reason, duration: duration}}
14
+ response = post_request("moderation/bans", body: attrs)
15
+ BannedUser.new response.body.dig("data")[0]
16
+ end
17
+
18
+ # Required scope: moderator:manage:banned_users
19
+ # moderator_id must match the currently authenticated user. Can be either the broadcaster ID or moderator ID
20
+ def delete(broadcaster_id:, moderator_id:, user_id:)
21
+ delete_request("moderation/bans?broadcaster_id=#{broadcaster_id}&moderator_id=#{moderator_id}&user_id=#{user_id}")
22
+ end
23
+
10
24
  end
11
25
  end
@@ -0,0 +1,27 @@
1
+ module Twitch
2
+ class BlockedTermsResource < Resource
3
+
4
+ # Required scope: moderator:read:blocked_terms
5
+ # moderator_id must match the currently authenticated user. Can be either the broadcaster ID or moderator ID
6
+ def list(broadcaster_id:, moderator_id:, **params)
7
+ attrs = {broadcaster_id: broadcaster_id, moderator_id: moderator_id}
8
+ response = get_request("moderation/blocked_terms", params: attrs.merge(params))
9
+ Collection.from_response(response, type: BlockedTerm)
10
+ end
11
+
12
+ # Required scope: moderator:manage:blocked_terms
13
+ # moderator_id must match the currently authenticated user. Can be either the broadcaster ID or moderator ID
14
+ def create(broadcaster_id:, moderator_id:, text:)
15
+ attrs = {broadcaster_id: broadcaster_id, moderator_id: moderator_id, text: text}
16
+ response = post_request("moderation/blocked_terms", body: attrs)
17
+ BannedUser.new response.body.dig("data")[0]
18
+ end
19
+
20
+ # Required scope: moderator:manage:blocked_terms
21
+ # moderator_id must match the currently authenticated user. Can be either the broadcaster ID or moderator ID
22
+ def delete(broadcaster_id:, moderator_id:, id:)
23
+ delete_request("moderation/blocked_terms?broadcaster_id=#{broadcaster_id}&moderator_id=#{moderator_id}&id=#{id}")
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ module Twitch
2
+ class CharityCampaignsResource < Resource
3
+
4
+ # Required scope: channel:read:charity
5
+ # Broadcaster ID must match the user in the OAuth token
6
+ def list(broadcaster_id:)
7
+ response = get_request("charity/campaigns?broadcaster_id=#{broadcaster_id}")
8
+ Collection.from_response(response, type: CharityCampaign)
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module Twitch
2
+ class ChatMessagesResource < Resource
3
+
4
+ # moderator_id must match the user in the OAuth token
5
+ def delete(broadcaster_id:, moderator_id:, message_id:)
6
+ delete_request("moderation/chat?broadcaster_id=#{broadcaster_id}&moderator_id=#{moderator_id}&message_id=#{message_id}")
7
+ end
8
+
9
+ end
10
+ end
@@ -7,5 +7,13 @@ module Twitch
7
7
  Collection.from_response(response, type: Moderator)
8
8
  end
9
9
 
10
+ def create(broadcaster_id:, user_id:)
11
+ post_request("moderation/moderators", body: {broadcaster_id: broadcaster_id, user_id: user_id})
12
+ end
13
+
14
+ def delete(broadcaster_id:, user_id:)
15
+ delete_request("moderation/moderators?broadcaster_id=#{broadcaster_id}&user_id=#{user_id}")
16
+ end
17
+
10
18
  end
11
19
  end
@@ -0,0 +1,19 @@
1
+ module Twitch
2
+ class RaidsResource < Resource
3
+
4
+ # from_broadcaster_id must match the user in the OAuth token
5
+ def create(from_broadcaster_id:, to_broadcaster_id:)
6
+ attrs = {from_broadcaster_id: from_broadcaster_id, to_broadcaster_id: to_broadcaster_id}
7
+
8
+ response = post_request("raids", body: attrs)
9
+
10
+ Raid.new(response.body.dig("data")[0]) if response.success?
11
+ end
12
+
13
+ # broadcaster_id must match the user in the OAuth token
14
+ def delete(broadcaster_id:)
15
+ delete_request("raids?broadcaster_id=#{broadcaster_id}")
16
+ end
17
+
18
+ end
19
+ end
@@ -16,6 +16,25 @@ module Twitch
16
16
  User.new response.body.dig("data")[0]
17
17
  end
18
18
 
19
+ def get_color(user_id: nil, user_ids: nil)
20
+ if user_ids != nil
21
+ users = user_ids.split(",").map{|i| "user_id=#{i.strip}"}.join("&")
22
+ puts "chat/color?#{users}"
23
+ response = get_request("chat/color?#{users}")
24
+ Collection.from_response(response, type: UserColor)
25
+ else
26
+ response = get_request("chat/color?user_id=#{user_id}")
27
+ UserColor.new response.body.dig("data")[0]
28
+ end
29
+ end
30
+
31
+ # Update a user's color
32
+ # Required scope: user:manage:chat_color
33
+ # user_id must be the currently authenticated user
34
+ def update_color(user_id:, color:)
35
+ put_request("chat/color?user_id=#{user_id}&color=#{color}", body: {})
36
+ end
37
+
19
38
  def follows(**params)
20
39
  raise "from_id or to_id is required" unless !params[:from_id].nil? || !params[:to_id].nil?
21
40
 
@@ -0,0 +1,19 @@
1
+ module Twitch
2
+ class VipsResource < Resource
3
+
4
+ # Broadcaster ID must match the user in the OAuth token
5
+ def list(broadcaster_id:, **params)
6
+ response = get_request("channels/vips", params: params.merge(broadcaster_id: broadcaster_id))
7
+ Collection.from_response(response, type: Vip)
8
+ end
9
+
10
+ def create(broadcaster_id:, user_id:)
11
+ post_request("channels/vips", body: {broadcaster_id: broadcaster_id, user_id: user_id})
12
+ end
13
+
14
+ def delete(broadcaster_id:, user_id:)
15
+ delete_request("channels/vips?broadcaster_id=#{broadcaster_id}&user_id=#{user_id}")
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module Twitch
2
+ class WhispersResource < Resource
3
+
4
+ def create(from_user_id:, to_user_id:, message:)
5
+ post_request("whispers", body: {from_user_id: from_user_id, to_user_id: to_user_id, message: message})
6
+ end
7
+
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Twitch
2
- VERSION = "0.2.5"
2
+ VERSION = "1.0.1"
3
3
  end
data/lib/twitch.rb CHANGED
@@ -35,6 +35,14 @@ module Twitch
35
35
  autoload :CustomRewardRedemptionsResource, "twitch/resources/custom_reward_redemptions"
36
36
  autoload :GoalsResource, "twitch/resources/goals"
37
37
  autoload :HypeTrainEventsResource, "twitch/resources/hype_train_events"
38
+ autoload :AnnouncementsResource, "twitch/resources/announcements"
39
+ autoload :RaidsResource, "twitch/resources/raids"
40
+ autoload :ChatMessagesResource, "twitch/resources/chat_messages"
41
+ autoload :VipsResource, "twitch/resources/vips"
42
+ autoload :WhispersResource, "twitch/resources/whispers"
43
+ autoload :AutomodResource, "twitch/resources/automod"
44
+ autoload :BlockedTermsResource, "twitch/resources/blocked_terms"
45
+ autoload :CharityCampaignsResource, "twitch/resources/charity_campaigns"
38
46
 
39
47
 
40
48
  autoload :User, "twitch/objects/user"
@@ -67,5 +75,12 @@ module Twitch
67
75
  autoload :Goal, "twitch/objects/goal"
68
76
  autoload :HypeTrainEvent, "twitch/objects/hype_train_event"
69
77
  autoload :FollowCount, "twitch/objects/follow_count"
78
+ autoload :Raid, "twitch/objects/raid"
79
+ autoload :UserColor, "twitch/objects/user_color"
80
+ autoload :Vip, "twitch/objects/vip"
81
+ autoload :AutomodStatus, "twitch/objects/automod_status"
82
+ autoload :AutomodSetting, "twitch/objects/automod_setting"
83
+ autoload :BlockedTerm, "twitch/objects/blocked_term"
84
+ autoload :CHarityCampaign, "twitch/objects/charity_campaign"
70
85
 
71
86
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitchrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Perry
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-10 00:00:00.000000000 Z
11
+ date: 2022-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -47,12 +47,16 @@ files:
47
47
  - lib/twitch/collection.rb
48
48
  - lib/twitch/error.rb
49
49
  - lib/twitch/object.rb
50
+ - lib/twitch/objects/automod_setting.rb
51
+ - lib/twitch/objects/automod_status.rb
50
52
  - lib/twitch/objects/badge.rb
51
53
  - lib/twitch/objects/banned_event.rb
52
54
  - lib/twitch/objects/banned_user.rb
55
+ - lib/twitch/objects/blocked_term.rb
53
56
  - lib/twitch/objects/blocked_user.rb
54
57
  - lib/twitch/objects/channel.rb
55
58
  - lib/twitch/objects/channel_editor.rb
59
+ - lib/twitch/objects/charity_campaign.rb
56
60
  - lib/twitch/objects/clip.rb
57
61
  - lib/twitch/objects/custom_reward.rb
58
62
  - lib/twitch/objects/custom_reward_redemption.rb
@@ -67,6 +71,7 @@ files:
67
71
  - lib/twitch/objects/moderator_event.rb
68
72
  - lib/twitch/objects/poll.rb
69
73
  - lib/twitch/objects/prediction.rb
74
+ - lib/twitch/objects/raid.rb
70
75
  - lib/twitch/objects/search_result.rb
71
76
  - lib/twitch/objects/stream.rb
72
77
  - lib/twitch/objects/stream_marker.rb
@@ -75,12 +80,19 @@ files:
75
80
  - lib/twitch/objects/subscription_count.rb
76
81
  - lib/twitch/objects/tag.rb
77
82
  - lib/twitch/objects/user.rb
83
+ - lib/twitch/objects/user_color.rb
78
84
  - lib/twitch/objects/video.rb
85
+ - lib/twitch/objects/vip.rb
79
86
  - lib/twitch/resource.rb
87
+ - lib/twitch/resources/announcements.rb
88
+ - lib/twitch/resources/automod.rb
80
89
  - lib/twitch/resources/badges.rb
81
90
  - lib/twitch/resources/banned_events.rb
82
91
  - lib/twitch/resources/banned_users.rb
92
+ - lib/twitch/resources/blocked_terms.rb
83
93
  - lib/twitch/resources/channels.rb
94
+ - lib/twitch/resources/charity_campaigns.rb
95
+ - lib/twitch/resources/chat_messages.rb
84
96
  - lib/twitch/resources/clips.rb
85
97
  - lib/twitch/resources/custom_reward_redemptions.rb
86
98
  - lib/twitch/resources/custom_rewards.rb
@@ -93,6 +105,7 @@ files:
93
105
  - lib/twitch/resources/moderators.rb
94
106
  - lib/twitch/resources/polls.rb
95
107
  - lib/twitch/resources/predictions.rb
108
+ - lib/twitch/resources/raids.rb
96
109
  - lib/twitch/resources/search.rb
97
110
  - lib/twitch/resources/stream_markers.rb
98
111
  - lib/twitch/resources/stream_schedule.rb
@@ -101,6 +114,8 @@ files:
101
114
  - lib/twitch/resources/tags.rb
102
115
  - lib/twitch/resources/users.rb
103
116
  - lib/twitch/resources/videos.rb
117
+ - lib/twitch/resources/vips.rb
118
+ - lib/twitch/resources/whispers.rb
104
119
  - lib/twitch/version.rb
105
120
  - lib/twitchrb.rb
106
121
  - twitchrb.gemspec
@@ -125,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
140
  - !ruby/object:Gem::Version
126
141
  version: '0'
127
142
  requirements: []
128
- rubygems_version: 3.2.22
143
+ rubygems_version: 3.3.7
129
144
  signing_key:
130
145
  specification_version: 4
131
146
  summary: A Ruby library for interacting with the Twitch Helix API