twitchrb 0.2.4 → 1.0.0

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: 5da5d24c0516dd123d3c603f728f1afb89dd388d8850bc39f6a46a62c7497b2f
4
- data.tar.gz: 4c664108c26f55cceeb5d8c5524fc79fe15a14c16d9114abb3ad481e20afc028
3
+ metadata.gz: 4921296177c80efd1a41535907c5e2e1ce41a6c6695e319f968a2d9bc5012e34
4
+ data.tar.gz: 4ad72356f24394069cbf9a2845038db485d75fc9a273446665a18ad59b15274a
5
5
  SHA512:
6
- metadata.gz: 2fc664b3ae6a78bb1fbf61d65a04cbd8c6a97dd79cd47d418c007e000e6a568fcded0fa0246fb5907197684942c5549f26b6a8f287289cf0200a47f11dd2ea1e
7
- data.tar.gz: e04d75f5c8f88392316fc652391998f842c6cd23f9e1484246f876c786ae828b2195dab346506445f945941aaf728c82034eccf596319c47f1f21c2b2484255a
6
+ metadata.gz: b39f99a455e2d7b02d4c537b55e52576f2a5f232e488a90d3e48480621bec11ab92c9994c9119bacd402f3852654944103a7a1eb0b67e1d1d299e22471c3a9c0
7
+ data.tar.gz: 2cd4c7b9c6582e9d337343b2dd81f9c8c14b81954dbe6795496115602e6cdd78e2809c8d5f0a004cdcb27602b271a96d68778a85720a31292db999c00f663839
@@ -0,0 +1,23 @@
1
+ name: CI
2
+ on: push
3
+ jobs:
4
+ test:
5
+ runs-on: ubuntu-latest
6
+ strategy:
7
+ fail-fast: false
8
+ matrix:
9
+ ruby_version:
10
+ - 2.6
11
+ - 2.7
12
+ - 3.0
13
+ - 3.1
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby_version }}
19
+ bundler: default
20
+ bundler-cache: true
21
+
22
+ - name: Run tests
23
+ run: bundle exec rake test
data/Gemfile.lock CHANGED
@@ -1,37 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- twitchrb (0.2.4)
5
- faraday (~> 1.7)
6
- faraday_middleware (~> 1.1)
4
+ twitchrb (1.0.0)
5
+ faraday (~> 2.0)
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
10
9
  specs:
11
10
  dotenv (2.7.6)
12
- faraday (1.8.0)
13
- faraday-em_http (~> 1.0)
14
- faraday-em_synchrony (~> 1.0)
15
- faraday-excon (~> 1.1)
16
- faraday-httpclient (~> 1.0.1)
17
- faraday-net_http (~> 1.0)
18
- faraday-net_http_persistent (~> 1.1)
19
- faraday-patron (~> 1.0)
20
- faraday-rack (~> 1.0)
21
- multipart-post (>= 1.2, < 3)
11
+ faraday (2.3.0)
12
+ faraday-net_http (~> 2.0)
22
13
  ruby2_keywords (>= 0.0.4)
23
- faraday-em_http (1.0.0)
24
- faraday-em_synchrony (1.0.0)
25
- faraday-excon (1.1.0)
26
- faraday-httpclient (1.0.1)
27
- faraday-net_http (1.0.1)
28
- faraday-net_http_persistent (1.2.0)
29
- faraday-patron (1.0.0)
30
- faraday-rack (1.0.0)
31
- faraday_middleware (1.2.0)
32
- faraday (~> 1.0)
33
- minitest (5.14.1)
34
- multipart-post (2.1.1)
14
+ faraday-net_http (2.0.3)
15
+ minitest (5.15.0)
35
16
  rake (12.3.3)
36
17
  ruby2_keywords (0.0.5)
37
18
 
@@ -45,4 +26,4 @@ DEPENDENCIES
45
26
  twitchrb!
46
27
 
47
28
  BUNDLED WITH
48
- 2.1.4
29
+ 2.3.5
data/README.md CHANGED
@@ -1,10 +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 API.
6
-
7
- It only supports the Helix API as v5 is deprecated.
3
+ TwitchRB is a Ruby library for interacting with the Twitch Helix API.
8
4
 
9
5
  ## Installation
10
6
 
@@ -18,48 +14,355 @@ gem "twitchrb"
18
14
 
19
15
  ### Set Client Details
20
16
 
21
- 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.
22
18
 
23
19
  An access token is required because the Helix API requires authentication.
24
20
 
25
21
  ```ruby
26
- @client = Twitch::Client.new(client_id: "", client_secret: "", access_token: "")
22
+ @client = Twitch::Client.new(client_id: "", access_token: "")
27
23
  ```
28
24
 
29
25
  ### Users
30
26
 
31
27
  ```ruby
28
+ # Retrieves a user by their ID
32
29
  @client.users.get_by_id(user_id: 141981764)
30
+
31
+ # Retrieves a user by their username
33
32
  @client.users.get_by_username(username: "twitchdev")
33
+
34
+ # Update the currently authenticated user's description
35
+ # Required scope: user:edit
36
+ @client.users.update(description: "New Description")
37
+
38
+ # Shows users who follow or are following a user ID
39
+ @client.users.follows(from_id: 141981764)
40
+ @client.users.follows(to_id: 141981764)
41
+
42
+ # A quick method for seeing if a user is following a channel
43
+ @client.users.following?(from_id: 141981764, to_id: 141981764)
44
+
45
+ # Returns Blocked users for a broadcaster
46
+ # Required scope: user:read:blocked_users
47
+ @client.users.blocks(broadcaster_id: 141981764)
48
+
49
+ # Blocks a user
50
+ # Required scope: user:manage:blocked_users
51
+ @client.users.block_user(target_user_id: 141981764)
52
+
53
+ # Unblocks a user
54
+ # Required scope: user:manage:blocked_users
55
+ @client.users.unblock_user(target_user_id: 141981764)
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")
34
70
  ```
35
71
 
36
72
  ### Channels
37
73
 
38
74
  ```ruby
75
+ # Retrieve a channel by their ID
39
76
  @client.channels.get(broadcaster_id: 141981764)
77
+
78
+ # Retrieve the number of Followers a broadcaster has
79
+ @client.channels.follows_count(broadcaster_id: 141981764)
80
+
81
+ # Retrieve the number of Subscribers and Subscriber Points a broadcaster has
82
+ # Required scope: channel:read:subscriptions
83
+ @client.channels.subscribers_count(broadcaster_id: 141981764)
84
+
85
+ # Update the currently authenticated channel details
86
+ # Required scope: channel:manage:broadcast
87
+ # Parameters which are allowed: game_id, title, broadcaster_language, delay
88
+ attributes = {title: "My new title"}
89
+ @client.channels.update(broadcaster_id: 141981764, attributes)
90
+
91
+ # Retrieves editors for a channel
92
+ @client.channels.editors(broadcaster_id: 141981764)
40
93
  ```
41
94
 
42
95
  ### Videos
43
96
 
44
97
  ```ruby
45
- @client.videos.get(user_id: 141981764)
98
+ # Retrieves a list of videos
99
+ # Available parameters: id, user_id or game_id
100
+ @client.videos.list(id: 12345)
101
+ @client.videos.list(user_id: 12345)
102
+ @client.videos.list(game_id: 12345)
103
+ ```
104
+
105
+ ### Clips
106
+
107
+ ```ruby
108
+ # Retrieves a list of clips
109
+ # Available parameters: id, broadcaster_id or game_id
110
+ @client.clips.list(id: 12345)
111
+ @client.clips.list(user_id: 12345)
112
+ @client.clips.list(game_id: 12345)
113
+
114
+ # Retrieves a clip by its ID.
115
+ # Clip IDs are alphanumeric. e.g. AwkwardHelplessSalamanderSwiftRage
116
+ @client.clips.retrieve(id: "AwkwardHelplessSalamanderSwiftRage")
117
+
118
+ # Create a clip of a given Channel
119
+ # Required scope: clips:edit
120
+ @client.clips.create(broadcaster_id: 1234)
46
121
  ```
47
122
 
48
123
  ### Emotes
49
124
 
50
125
  ```ruby
126
+ # Retrieve all global emotes
51
127
  @client.emotes.global
128
+
129
+ # Retrieve emotes for a channel
52
130
  @client.emotes.channel(broadcaster_id: 141981764)
131
+
132
+ # Retrieve emotes for an emote set
53
133
  @client.emotes.sets(emote_set_id: 301590448)
54
134
  ```
55
135
 
56
136
  ### Badges
57
137
 
58
138
  ```ruby
139
+ # Retrieve all global badges
59
140
  @client.badges.global
141
+
142
+ # Retrieve badges for a channel
60
143
  @client.badges.channel(broadcaster_id: 141981764)
61
144
  ```
62
145
 
146
+ ### Games
147
+
148
+ ```ruby
149
+ # Retrieves a game by its ID
150
+ @client.games.get_by_id(game_id: 123)
151
+
152
+ # Retrieves a game by its Name
153
+ @client.games.get_by_id(name: "Battlefield 4")
154
+
155
+ # Retrieves a list of top games
156
+ @client.games.top
157
+ ```
158
+
159
+ ## EventSub Subscriptions
160
+
161
+ These require an application OAuth access token.
162
+
163
+ ```ruby
164
+ # Retrieves a list of EventSub Subscriptions
165
+ # Available parameters: status, type, after
166
+ @client.eventsub_subscriptions.list
167
+ @client.eventsub_subscriptions.list(status: "enabled")
168
+ @client.eventsub_subscriptions.list(type: "channel.follow")
169
+
170
+ # Create an EventSub Subscription
171
+ @client.eventsub_subscriptions.create(
172
+ type: "channel.follow",
173
+ version: 1,
174
+ condition: {broadcaster_user_id: 123},
175
+ transport: {method: "webhook", callback: "webhook_url", secret: "secret"}
176
+ )
177
+
178
+ # Delete an EventSub Subscription
179
+ # IDs are UUIDs
180
+ @client.eventsub_subscriptions.delete(id: "abc12-abc12-abc12")
181
+ ```
182
+
183
+ ## Banned Events
184
+
185
+ ```ruby
186
+ # Retrieves all ban and un-ban events for a channel
187
+ # Available parameters: user_id
188
+ @client.banned_events.list(broadcaster_id: 123)
189
+ ```
190
+
191
+ ## Banned Users
192
+
193
+ ```ruby
194
+ # Retrieves all banned and timed-out users for a channel
195
+ # Available parameters: user_id
196
+ @client.banned_users.list(broadcaster_id: 123)
197
+ ```
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
+
63
366
  ## Contributing
64
367
 
65
368
  Bug reports and pull requests are welcome on GitHub at https://github.com/twitchrb/twitchrb.
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,13 +109,40 @@ 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
+
113
140
  def connection
114
141
  @connection ||= Faraday.new(BASE_URL) do |conn|
115
142
  conn.request :authorization, :Bearer, access_token
116
143
  conn.headers = { "Client-ID": client_id }
117
144
  conn.request :json
118
145
 
119
- conn.response :dates
120
146
  conn.response :json, content_type: "application/json"
121
147
 
122
148
  conn.adapter adapter, @stubs
@@ -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 FollowCount < 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
@@ -5,6 +5,21 @@ module Twitch
5
5
  Channel.new get_request("channels?broadcaster_id=#{broadcaster_id}").body.dig("data")[0]
6
6
  end
7
7
 
8
+ # Grabs the number of Followers a broadcaster has
9
+ def follows_count(broadcaster_id:)
10
+ response = get_request("users/follows", params: {to_id: broadcaster_id})
11
+
12
+ FollowCount.new(count: response.body["total"])
13
+ end
14
+
15
+ # Grabs the number of Subscribers and Subscriber Points a broadcaster has
16
+ # Required scope: channel:read:subscriptions
17
+ def subscribers_count(broadcaster_id:)
18
+ response = get_request("subscriptions", params: {broadcaster_id: broadcaster_id})
19
+
20
+ SubscriptionCount.new(count: response.body["total"], points: response.body["points"])
21
+ end
22
+
8
23
  # Requires scope: channel:manage:broadcast
9
24
  def update(broadcaster_id:, **attributes)
10
25
  patch_request("channels", body: attributes.merge(broadcaster_id: broadcaster_id))
@@ -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
@@ -2,11 +2,11 @@ module Twitch
2
2
  class UsersResource < Resource
3
3
 
4
4
  def get_by_id(user_id:)
5
- User.new get_request("users/?id=#{user_id}").body.dig("data")[0]
5
+ User.new get_request("users?id=#{user_id}").body.dig("data")[0]
6
6
  end
7
7
 
8
8
  def get_by_username(username:)
9
- User.new get_request("users/?login=#{username}").body.dig("data")[0]
9
+ User.new get_request("users?login=#{username}").body.dig("data")[0]
10
10
  end
11
11
 
12
12
  # Updates the current users description
@@ -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.4"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/twitch.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require "faraday"
2
- require "faraday_middleware"
3
2
  require "json"
4
3
  require "twitch/version"
5
4
 
@@ -36,6 +35,13 @@ module Twitch
36
35
  autoload :CustomRewardRedemptionsResource, "twitch/resources/custom_reward_redemptions"
37
36
  autoload :GoalsResource, "twitch/resources/goals"
38
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"
39
45
 
40
46
 
41
47
  autoload :User, "twitch/objects/user"
@@ -67,5 +73,12 @@ module Twitch
67
73
  autoload :CustomRewardRedemption, "twitch/objects/custom_reward_redemption"
68
74
  autoload :Goal, "twitch/objects/goal"
69
75
  autoload :HypeTrainEvent, "twitch/objects/hype_train_event"
76
+ autoload :FollowCount, "twitch/objects/follow_count"
77
+ autoload :Raid, "twitch/objects/raid"
78
+ autoload :UserColor, "twitch/objects/user_color"
79
+ autoload :Vip, "twitch/objects/vip"
80
+ autoload :AutomodStatus, "twitch/objects/automod_status"
81
+ autoload :AutomodSetting, "twitch/objects/automod_setting"
82
+ autoload :BlockedTerm, "twitch/objects/blocked_term"
70
83
 
71
84
  end
data/twitchrb.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.email = ["dean@deanpcmad.com"]
8
8
 
9
9
  spec.summary = "A Ruby library for interacting with the Twitch Helix API"
10
- spec.homepage = "https://twitchrb.com"
10
+ spec.homepage = "https://deanpcmad.com"
11
11
  spec.license = "MIT"
12
12
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
13
 
@@ -24,6 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
26
26
 
27
- spec.add_dependency "faraday", "~> 1.7"
28
- spec.add_dependency "faraday_middleware", "~> 1.1"
27
+ spec.add_dependency "faraday", "~> 2.0"
29
28
  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.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Perry
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-31 00:00:00.000000000 Z
11
+ date: 2022-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,29 +16,15 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
27
- - !ruby/object:Gem::Dependency
28
- name: faraday_middleware
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.1'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.1'
41
- description:
26
+ version: '2.0'
27
+ description:
42
28
  email:
43
29
  - dean@deanpcmad.com
44
30
  executables: []
@@ -47,6 +33,7 @@ extra_rdoc_files: []
47
33
  files:
48
34
  - ".env.example"
49
35
  - ".github/FUNDING.yml"
36
+ - ".github/workflows/ci.yml"
50
37
  - ".gitignore"
51
38
  - Gemfile
52
39
  - Gemfile.lock
@@ -60,9 +47,12 @@ files:
60
47
  - lib/twitch/collection.rb
61
48
  - lib/twitch/error.rb
62
49
  - lib/twitch/object.rb
50
+ - lib/twitch/objects/automod_setting.rb
51
+ - lib/twitch/objects/automod_status.rb
63
52
  - lib/twitch/objects/badge.rb
64
53
  - lib/twitch/objects/banned_event.rb
65
54
  - lib/twitch/objects/banned_user.rb
55
+ - lib/twitch/objects/blocked_term.rb
66
56
  - lib/twitch/objects/blocked_user.rb
67
57
  - lib/twitch/objects/channel.rb
68
58
  - lib/twitch/objects/channel_editor.rb
@@ -71,6 +61,7 @@ files:
71
61
  - lib/twitch/objects/custom_reward_redemption.rb
72
62
  - lib/twitch/objects/emote.rb
73
63
  - lib/twitch/objects/event_sub_subscription.rb
64
+ - lib/twitch/objects/follow_count.rb
74
65
  - lib/twitch/objects/followed_user.rb
75
66
  - lib/twitch/objects/game.rb
76
67
  - lib/twitch/objects/goal.rb
@@ -79,6 +70,7 @@ files:
79
70
  - lib/twitch/objects/moderator_event.rb
80
71
  - lib/twitch/objects/poll.rb
81
72
  - lib/twitch/objects/prediction.rb
73
+ - lib/twitch/objects/raid.rb
82
74
  - lib/twitch/objects/search_result.rb
83
75
  - lib/twitch/objects/stream.rb
84
76
  - lib/twitch/objects/stream_marker.rb
@@ -87,12 +79,18 @@ files:
87
79
  - lib/twitch/objects/subscription_count.rb
88
80
  - lib/twitch/objects/tag.rb
89
81
  - lib/twitch/objects/user.rb
82
+ - lib/twitch/objects/user_color.rb
90
83
  - lib/twitch/objects/video.rb
84
+ - lib/twitch/objects/vip.rb
91
85
  - lib/twitch/resource.rb
86
+ - lib/twitch/resources/announcements.rb
87
+ - lib/twitch/resources/automod.rb
92
88
  - lib/twitch/resources/badges.rb
93
89
  - lib/twitch/resources/banned_events.rb
94
90
  - lib/twitch/resources/banned_users.rb
91
+ - lib/twitch/resources/blocked_terms.rb
95
92
  - lib/twitch/resources/channels.rb
93
+ - lib/twitch/resources/chat_messages.rb
96
94
  - lib/twitch/resources/clips.rb
97
95
  - lib/twitch/resources/custom_reward_redemptions.rb
98
96
  - lib/twitch/resources/custom_rewards.rb
@@ -105,6 +103,7 @@ files:
105
103
  - lib/twitch/resources/moderators.rb
106
104
  - lib/twitch/resources/polls.rb
107
105
  - lib/twitch/resources/predictions.rb
106
+ - lib/twitch/resources/raids.rb
108
107
  - lib/twitch/resources/search.rb
109
108
  - lib/twitch/resources/stream_markers.rb
110
109
  - lib/twitch/resources/stream_schedule.rb
@@ -113,16 +112,18 @@ files:
113
112
  - lib/twitch/resources/tags.rb
114
113
  - lib/twitch/resources/users.rb
115
114
  - lib/twitch/resources/videos.rb
115
+ - lib/twitch/resources/vips.rb
116
+ - lib/twitch/resources/whispers.rb
116
117
  - lib/twitch/version.rb
117
118
  - lib/twitchrb.rb
118
119
  - twitchrb.gemspec
119
- homepage: https://twitchrb.com
120
+ homepage: https://deanpcmad.com
120
121
  licenses:
121
122
  - MIT
122
123
  metadata:
123
- homepage_uri: https://twitchrb.com
124
+ homepage_uri: https://deanpcmad.com
124
125
  source_code_uri: https://github.com/deanpcmad/twitchrb
125
- post_install_message:
126
+ post_install_message:
126
127
  rdoc_options: []
127
128
  require_paths:
128
129
  - lib
@@ -137,8 +138,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
138
  - !ruby/object:Gem::Version
138
139
  version: '0'
139
140
  requirements: []
140
- rubygems_version: 3.1.6
141
- signing_key:
141
+ rubygems_version: 3.3.7
142
+ signing_key:
142
143
  specification_version: 4
143
144
  summary: A Ruby library for interacting with the Twitch Helix API
144
145
  test_files: []