twitchrb 1.1.0 → 1.2.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: 828f7c0543e796014befead46a15222e41a9c775ea7baa4d4cd346e674777dd8
4
- data.tar.gz: 2a9a88da2bf52a0362c24d38201806545d0483a36217f14ed30f120c89664f88
3
+ metadata.gz: 15c7d6175a906c3469b5d3ac691f66ef8f86d0682959a648b69cb0d35f39523f
4
+ data.tar.gz: 8a505c88b94833d36805006b7a8ab1e6cb54e76ecb05cb99ffb81cca5c7bd491
5
5
  SHA512:
6
- metadata.gz: 3a0695cf7d5600a1c171f43ff1fae6ba39c2242ddd5092d7e04c1c234c03a9ca00f9f2c51036a685a6d08356bc5fb5f9cdabb2e150ecd9854962074f69df75a1
7
- data.tar.gz: be4161b6cdc5f83c6169fc49733146c1c3fc210b43be9b8823fbd0f8e4b97dc42c1d722b5d8b01bf98623498b367318779f94f790b9cfc2c99cb125697310889
6
+ metadata.gz: 197a13bac91e7f1ff361bf021cff8f2c15a7d9b6f1812a393908fffd9cf0df34cf71863521c8ca85253dfeeab4ac9c81388ced713a047babfcc449fc1d906672
7
+ data.tar.gz: 992d0eb6c70cde046b94b42d2c969c3530ebbc9dfc3b14cf288b0d804280fc4af03347361fc311889aa268049bdf1e7fdec2c8121f924492850dd6eb365a994d
data/.github/FUNDING.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  # These are supported funding model platforms
2
2
 
3
+ github: deanpcmad
3
4
  ko_fi: deanpcmad
@@ -7,12 +7,12 @@ jobs:
7
7
  fail-fast: false
8
8
  matrix:
9
9
  ruby_version:
10
- - 2.6
11
- - 2.7
12
- - 3.0
13
- - 3.1
10
+ - '3.0'
11
+ - '3.1'
12
+ - '3.2'
13
+ - '3.3'
14
14
  steps:
15
- - uses: actions/checkout@v2
15
+ - uses: actions/checkout@v3
16
16
  - uses: ruby/setup-ruby@v1
17
17
  with:
18
18
  ruby-version: ${{ matrix.ruby_version }}
data/Gemfile.lock CHANGED
@@ -1,14 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- twitchrb (1.1.0)
4
+ twitchrb (1.2.1)
5
5
  faraday (~> 2.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ base64 (0.2.0)
10
11
  dotenv (2.7.6)
11
- faraday (2.7.4)
12
+ faraday (2.8.1)
13
+ base64
12
14
  faraday-net_http (>= 2.0, < 3.1)
13
15
  ruby2_keywords (>= 0.0.4)
14
16
  faraday-net_http (3.0.2)
data/README.md CHANGED
@@ -26,23 +26,23 @@ An access token is required because the Helix API requires authentication.
26
26
 
27
27
  ```ruby
28
28
  # Retrieves a user by their ID
29
- @client.users.get_by_id(user_id: 141981764)
29
+ @client.users.retrieve(id: 141981764)
30
+
31
+ # Retrieves multiple users by their IDs
32
+ # Requires an array of IDs
33
+ @client.users.retrieve(ids: [141981764, 72938118])
30
34
 
31
35
  # Retrieves a user by their username
32
- @client.users.get_by_username(username: "twitchdev")
36
+ @client.users.retrieve(username: "twitchdev")
37
+
38
+ # Retrieves multiple users by their usernames
39
+ # Requires an array of IDs
40
+ @client.users.retrieve(usernames: ["twitchdev", "deanpcmad"])
33
41
 
34
42
  # Update the currently authenticated user's description
35
43
  # Required scope: user:edit
36
44
  @client.users.update(description: "New Description")
37
45
 
38
- # Deprecated. Please look at using channels.followed or channels.followers
39
- # Shows users who follow or are following a user ID
40
- @client.users.follows(from_id: 141981764)
41
- @client.users.follows(to_id: 141981764)
42
-
43
- # A quick method for seeing if a user is following a channel
44
- @client.users.following?(from_id: 141981764, to_id: 141981764)
45
-
46
46
  # Returns Blocked users for a broadcaster
47
47
  # Required scope: user:read:blocked_users
48
48
  @client.users.blocks(broadcaster_id: 141981764)
@@ -74,7 +74,7 @@ An access token is required because the Helix API requires authentication.
74
74
 
75
75
  ```ruby
76
76
  # Retrieve a channel by their ID
77
- @client.channels.get(broadcaster_id: 141981764)
77
+ @client.channels.retrieve(id: 141981764)
78
78
 
79
79
  # Retrieve a list of broadcasters a specified user follows
80
80
  # user_id must match the currently authenticated user
@@ -82,7 +82,8 @@ An access token is required because the Helix API requires authentication.
82
82
  @client.channels.followed user_id: 123123
83
83
 
84
84
  # Retrieve a list of users that follow a specified broadcaster
85
- # broadcaster_id must match the currently authenticated user
85
+ # broadcaster_id must match the currently authenticated user or
86
+ # a moderator of the specified broadcaster
86
87
  # Required scope: moderator:read:followers
87
88
  @client.channels.followers broadcaster_id: 123123
88
89
 
@@ -107,18 +108,19 @@ attributes = {title: "My new title"}
107
108
 
108
109
  ```ruby
109
110
  # Retrieves a list of videos
110
- # Available parameters: id, user_id or game_id
111
- @client.videos.list(id: 12345)
111
+ # Available parameters: user_id or game_id
112
112
  @client.videos.list(user_id: 12345)
113
113
  @client.videos.list(game_id: 12345)
114
+
115
+ # Retrieves a video by its ID
116
+ @client.videos.retrieve(id: 12345)
114
117
  ```
115
118
 
116
119
  ### Clips
117
120
 
118
121
  ```ruby
119
122
  # Retrieves a list of clips
120
- # Available parameters: id, broadcaster_id or game_id
121
- @client.clips.list(id: 12345)
123
+ # Available parameters: broadcaster_id or game_id
122
124
  @client.clips.list(user_id: 12345)
123
125
  @client.clips.list(game_id: 12345)
124
126
 
@@ -157,19 +159,24 @@ attributes = {title: "My new title"}
157
159
  ### Games
158
160
 
159
161
  ```ruby
160
- # Retrieves a game by its ID
161
- @client.games.get_by_id(game_id: 123)
162
+ # Retrieves a game by ID
163
+ @client.games.retrieve(id: 514974)
164
+
165
+ # Retrieves multiple games by IDs
166
+ # Requires an array of IDs
167
+ @client.games.retrieve(ids: [66402, 514974])
162
168
 
163
- # Retrieves a game by its Name
164
- @client.games.get_by_id(name: "Battlefield 4")
169
+ # Retrieves a game by name
170
+ @client.games.retrieve(name: "Battlefield 4")
165
171
 
166
- # Retrieves a list of top games
167
- @client.games.top
172
+ # Retrieves multiple games by names
173
+ # Requires an array of IDs
174
+ @client.games.retrieve(names: ["Battlefield 4", "Battlefield 2042"])
168
175
  ```
169
176
 
170
- ## EventSub Subscriptions
177
+ ### EventSub Subscriptions
171
178
 
172
- These require an application OAuth access token.
179
+ These require an application OAuth access token.
173
180
 
174
181
  ```ruby
175
182
  # Retrieves a list of EventSub Subscriptions
@@ -191,7 +198,7 @@ These require an application OAuth access token.
191
198
  @client.eventsub_subscriptions.delete(id: "abc12-abc12-abc12")
192
199
  ```
193
200
 
194
- ## Banned Events
201
+ ### Banned Events
195
202
 
196
203
  ```ruby
197
204
  # Retrieves all ban and un-ban events for a channel
@@ -199,7 +206,7 @@ These require an application OAuth access token.
199
206
  @client.banned_events.list(broadcaster_id: 123)
200
207
  ```
201
208
 
202
- ## Banned Users
209
+ ### Banned Users
203
210
 
204
211
  ```ruby
205
212
  # Retrieves all banned and timed-out users for a channel
@@ -221,7 +228,7 @@ These require an application OAuth access token.
221
228
  @client.banned_users.delete broadcaster_id: 123, moderator_id: 321, user_id: 112233
222
229
  ```
223
230
 
224
- ## Send Chat Announcement
231
+ ### Send Chat Announcement
225
232
 
226
233
  ```ruby
227
234
  # Sends an announcement to the broadcaster's chat room
@@ -231,7 +238,7 @@ These require an application OAuth access token.
231
238
  @client.announcements.create broadcaster_id: 123, moderator_id: 123, message: "test message", color: "purple"
232
239
  ```
233
240
 
234
- ## Create a Shoutout
241
+ ### Create a Shoutout
235
242
 
236
243
  ```ruby
237
244
  # Creates a Shoutout for a broadcaster
@@ -242,7 +249,7 @@ These require an application OAuth access token.
242
249
  @client.shoutouts.create from: 123, to: 321, moderator_id: 123
243
250
  ```
244
251
 
245
- ## Moderators
252
+ ### Moderators
246
253
 
247
254
  ```ruby
248
255
  # List all moderators for a broadcaster
@@ -265,7 +272,7 @@ These require an application OAuth access token.
265
272
  @client.moderators.delete broadcaster_id: 123, user_id: 321
266
273
  ```
267
274
 
268
- ## VIPs
275
+ ### VIPs
269
276
 
270
277
  ```ruby
271
278
  # List all VIPs for a broadcaster
@@ -288,10 +295,10 @@ These require an application OAuth access token.
288
295
  @client.vips.delete broadcaster_id: 123, user_id: 321
289
296
  ```
290
297
 
291
- ## Raids
298
+ ### Raids
292
299
 
293
300
  ```ruby
294
- # Starts a raid
301
+ # Starts a raid
295
302
  # Requires channel:manage:raids
296
303
  # from_broadcaster_id must be the authenticated user
297
304
  @client.raids.create from_broadcaster_id: 123, to_broadcaster_id: 321
@@ -310,7 +317,7 @@ These require an application OAuth access token.
310
317
  @client.chat_messages.delete broadcaster_id: 123, moderator_id: 123, message_id: "abc123-abc123"
311
318
  ```
312
319
 
313
- ## Whispers
320
+ ### Whispers
314
321
 
315
322
  ```ruby
316
323
  # Send a Whisper
@@ -319,7 +326,7 @@ These require an application OAuth access token.
319
326
  @client.whispers.create from_user_id: 123, to_user_id: 321, message: "this is a test"
320
327
  ```
321
328
 
322
- ## AutoMod
329
+ ### AutoMod
323
330
 
324
331
  ```ruby
325
332
  # Check if a message meets the channel's AutoMod requirements
@@ -353,7 +360,7 @@ messages = [{msg_id: "abc1", msg_text: "is this allowed?"}, {msg_id: "abc2", msg
353
360
  @client.automod.update_settings broadcaster_id: 123, moderator_id: 321, swearing: 1
354
361
  ```
355
362
 
356
- ## Creator Goals
363
+ ### Creator Goals
357
364
 
358
365
  ```ruby
359
366
  # List all active creator goals
@@ -362,7 +369,7 @@ messages = [{msg_id: "abc1", msg_text: "is this allowed?"}, {msg_id: "abc2", msg
362
369
  @client.goals.list broadcaster_id: 123
363
370
  ```
364
371
 
365
- ## Blocked Terms
372
+ ### Blocked Terms
366
373
 
367
374
  ```ruby
368
375
  # List all blocked terms
@@ -385,7 +392,7 @@ messages = [{msg_id: "abc1", msg_text: "is this allowed?"}, {msg_id: "abc2", msg
385
392
  @client.blocked_terms.delete broadcaster_id: 123, moderator_id: 321, id: "abc12-12abc"
386
393
  ```
387
394
 
388
- ## Charity Campaigns
395
+ ### Charity Campaigns
389
396
 
390
397
  ```ruby
391
398
  # Gets information about the charity campaign that a broadcaster is running
@@ -394,7 +401,7 @@ messages = [{msg_id: "abc1", msg_text: "is this allowed?"}, {msg_id: "abc2", msg
394
401
  @client.charity_campaigns.list broadcaster_id: 123
395
402
  ```
396
403
 
397
- ## Chatters
404
+ ### Chatters
398
405
 
399
406
  ```ruby
400
407
  # Gets the list of users that are connected to the specified broadcaster’s chat session
@@ -403,9 +410,49 @@ messages = [{msg_id: "abc1", msg_text: "is this allowed?"}, {msg_id: "abc2", msg
403
410
  @client.chatters.list broadcaster_id: 123, moderator_id: 123
404
411
  ```
405
412
 
413
+ ### Channel Points Custom Rewards
414
+
415
+ ```ruby
416
+ # Gets a list of custom rewards for a specific channel
417
+ # Required scope: channel:read:redemptions
418
+ # broadcaster_id must match the currently authenticated user
419
+ @client.custom_rewards.list broadcaster_id: 123
420
+
421
+ # Create a custom reward
422
+ # Required scope: channel:manage:redemptions
423
+ # broadcaster_id must match the currently authenticated user
424
+ @client.custom_rewards.create broadcaster_id: 123, title: "New Reward", cost: 1000
425
+
426
+ # Update a custom reward
427
+ # Required scope: channel:manage:redemptions
428
+ # broadcaster_id must match the currently authenticated user
429
+ @client.custom_rewards.update broadcaster_id: 123, reward_id: 321, title: "Updated Reward"
430
+
431
+ # Delete a custom reward
432
+ # Required scope: channel:manage:redemptions
433
+ # broadcaster_id must match the currently authenticated user
434
+ @client.custom_rewards.delete broadcaster_id: 123, reward_id: 321
435
+ ```
436
+
437
+ ### Channel Points Custom Reward Redemptions
438
+
439
+ ```ruby
440
+ # Gets a list of custom reward redemptions for a specific channel
441
+ # Required scope: channel:read:redemptions
442
+ # broadcaster_id must match the currently authenticated user
443
+ @client.custom_reward_redemptions.list broadcaster_id: 123, reward_id: 321, status: "UNFULFILLED"
444
+
445
+ # Update a custom reward redemption status
446
+ # Required scope: channel:manage:redemptions
447
+ # broadcaster_id must match the currently authenticated user
448
+ # Status can be FULFILLED or CANCELED
449
+ @client.custom_reward_redemptions.update broadcaster_id: 123, reward_id: 321, redemption_id: 123, status: "FULFILLED"
450
+ ```
451
+
452
+
406
453
  ## Contributing
407
454
 
408
- Bug reports and pull requests are welcome on GitHub at https://github.com/twitchrb/twitchrb.
455
+ Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/twitchrb.
409
456
 
410
457
  ## License
411
458
 
data/lib/twitch/client.rb CHANGED
@@ -36,7 +36,7 @@ module Twitch
36
36
  def videos
37
37
  VideosResource.new(self)
38
38
  end
39
-
39
+
40
40
  def clips
41
41
  ClipsResource.new(self)
42
42
  end
@@ -152,12 +152,14 @@ module Twitch
152
152
  def connection
153
153
  @connection ||= Faraday.new(BASE_URL) do |conn|
154
154
  conn.request :authorization, :Bearer, access_token
155
-
155
+
156
+ conn.options.params_encoder = Faraday::FlatParamsEncoder
157
+
156
158
  conn.headers = {
157
159
  "User-Agent" => "twitchrb/v#{VERSION} (github.com/deanpcmad/twitchrb)",
158
160
  "Client-ID": client_id
159
161
  }
160
-
162
+
161
163
  conn.request :json
162
164
 
163
165
  conn.response :json, content_type: "application/json"
@@ -1,8 +1,8 @@
1
1
  module Twitch
2
2
  class ChannelsResource < Resource
3
-
4
- def get(broadcaster_id:)
5
- Channel.new get_request("channels?broadcaster_id=#{broadcaster_id}").body.dig("data")[0]
3
+
4
+ def retrieve(id:)
5
+ Channel.new get_request("channels?broadcaster_id=#{id}").body.dig("data")[0]
6
6
  end
7
7
 
8
8
  # Retrieve a list of broadcasters a specified user follows
@@ -1,21 +1,21 @@
1
1
  module Twitch
2
2
  class ClipsResource < Resource
3
-
3
+
4
4
  def list(**params)
5
- raise "id, broadcaster_id or game_id is required" unless !params[:id].nil? || !params[:broadcaster_id].nil? || !params[:game_id].nil?
5
+ raise "broadcaster_id or game_id is required" unless !params[:broadcaster_id].nil? || !params[:game_id].nil?
6
6
 
7
7
  response = get_request("clips", params: params)
8
8
  Collection.from_response(response, type: Clip)
9
9
  end
10
10
 
11
11
  def retrieve(id:)
12
- Clip.new get_request("clips?id=#{id}").body.dig("data")[0]
12
+ Clip.new get_request("clips", params: {id: id}).body.dig("data")[0]
13
13
  end
14
14
 
15
15
  # Required scope: clips:edit
16
16
  def create(broadcaster_id:, **attributes)
17
17
  response = post_request("clips", body: attributes.merge(broadcaster_id: broadcaster_id))
18
-
18
+
19
19
  Clip.new(response.body.dig("data")[0]) if response.success?
20
20
  end
21
21
 
@@ -1,6 +1,6 @@
1
1
  module Twitch
2
2
  class CustomRewardRedemptionsResource < Resource
3
-
3
+
4
4
  # Required scope: channel:read:redemptions
5
5
  # Broadcaster ID must match the user in the OAuth token
6
6
  def list(broadcaster_id:, reward_id:, status:, **params)
@@ -9,14 +9,15 @@ module Twitch
9
9
  Collection.from_response(response, type: CustomRewardRedemption)
10
10
  end
11
11
 
12
- # Currently disabled as getting this error and can't work out why
13
- # Twitch::Error (Error 400: Your request was malformed. 'The parameter "id" was malformed: the value must be greater than or equal to 1')
14
- # def update(broadcaster_id:, reward_id:, redemption_id:, status:)
15
- # attributes = {broadcaster_id: broadcaster_id, reward_id: reward_id, id: redemption_id, status: status.upcase}
16
- # response = patch_request("channel_points/custom_rewards/redemptions", body: attributes)
12
+ # Required scope: channel:manage:redemptions
13
+ # Broadcaster ID must match the user in the OAuth token
14
+ def update(broadcaster_id:, reward_id:, redemption_id:, status:)
15
+ attributes = {status: status.upcase}
16
+ url = "channel_points/custom_rewards/redemptions?broadcaster_id=#{broadcaster_id}&reward_id=#{reward_id}&id=#{redemption_id}&status=#{status.upcase}"
17
+ response = patch_request(url, body: attributes)
17
18
 
18
- # CustomRewardRedemption.new(response.body.dig("data")[0]) if response.success?
19
- # end
19
+ CustomRewardRedemption.new(response.body.dig("data")[0]) if response.success?
20
+ end
20
21
 
21
22
  end
22
23
  end
@@ -1,14 +1,27 @@
1
1
  module Twitch
2
2
  class GamesResource < Resource
3
3
 
4
- def get_by_id(game_id:)
5
- response = get_request("games?id=#{game_id}")
6
- Collection.from_response(response, type: Game)
7
- end
4
+ def retrieve(id: nil, ids: nil, name: nil, names: nil)
5
+ raise "Either id, ids, name or names is required" unless !id.nil? || !ids.nil? || !name.nil? || !names.nil?
8
6
 
9
- def get_by_name(name:)
10
- response = get_request("games?name=#{name}")
11
- Collection.from_response(response, type: Game)
7
+ if id
8
+ response = get_request("games", params: {id: id})
9
+ elsif ids
10
+ response = get_request("games", params: {id: ids})
11
+ elsif names
12
+ response = get_request("games", params: {name: names})
13
+ else
14
+ response = get_request("games", params: {name: name})
15
+ end
16
+
17
+ body = response.body.dig("data")
18
+ if body.count == 1
19
+ Game.new body[0]
20
+ elsif body.count > 1
21
+ Collection.from_response(response, type: Game)
22
+ else
23
+ return nil
24
+ end
12
25
  end
13
26
 
14
27
  def top(**params)
@@ -1,12 +1,27 @@
1
1
  module Twitch
2
2
  class UsersResource < Resource
3
-
4
- def get_by_id(user_id:)
5
- User.new get_request("users?id=#{user_id}").body.dig("data")[0]
6
- end
7
3
 
8
- def get_by_username(username:)
9
- User.new get_request("users?login=#{username}").body.dig("data")[0]
4
+ def retrieve(id: nil, ids: nil, username: nil, usernames: nil)
5
+ raise "Either id, ids, username or usernames is required" unless !id.nil? || !ids.nil? || !username.nil? || !usernames.nil?
6
+
7
+ if id
8
+ response = get_request("users", params: {id: id})
9
+ elsif ids
10
+ response = get_request("users", params: {id: ids})
11
+ elsif usernames
12
+ response = get_request("users", params: {login: usernames})
13
+ else
14
+ response = get_request("users", params: {login: username})
15
+ end
16
+
17
+ body = response.body.dig("data")
18
+ if body.count == 1
19
+ User.new body[0]
20
+ elsif body.count > 1
21
+ Collection.from_response(response, type: User)
22
+ else
23
+ return nil
24
+ end
10
25
  end
11
26
 
12
27
  # Updates the current users description
@@ -38,7 +53,7 @@ module Twitch
38
53
  # Deprecated.
39
54
  def follows(**params)
40
55
  warn "`users.follows` is deprecated. Use `channels.followers` or `channels.following` instead."
41
-
56
+
42
57
  raise "from_id or to_id is required" unless !params[:from_id].nil? || !params[:to_id].nil?
43
58
 
44
59
  response = get_request("users/follows", params: params)
@@ -1,17 +1,24 @@
1
1
  module Twitch
2
2
  class VideosResource < Resource
3
-
3
+
4
4
  def list(**params)
5
- raise "id, user_id or game_id is required" unless !params[:id].nil? || !params[:user_id].nil? || !params[:game_id].nil?
5
+ raise "user_id or game_id is required" unless !params[:user_id].nil? || !params[:game_id].nil?
6
6
 
7
7
  response = get_request("videos", params: params)
8
8
  Collection.from_response(response, type: Video)
9
9
  end
10
10
 
11
+ def retrieve(id:)
12
+ response = get_request("videos", params: {id: id})
13
+ if response.body
14
+ Video.new response.body["data"].first
15
+ end
16
+ end
17
+
11
18
  # Required scope: channel:manage:videos
12
- # def delete(video_id:)
13
- # delete_request("videos?id=#{video_id}")
14
- # end
19
+ def delete(video_id:)
20
+ delete_request("videos?id=#{video_id}")
21
+ end
15
22
 
16
23
  end
17
24
  end
@@ -1,3 +1,3 @@
1
1
  module Twitch
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.1"
3
3
  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: 1.1.0
4
+ version: 1.2.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: 2023-02-21 00:00:00.000000000 Z
11
+ date: 2024-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubygems_version: 3.4.6
146
+ rubygems_version: 3.4.22
147
147
  signing_key:
148
148
  specification_version: 4
149
149
  summary: A Ruby library for interacting with the Twitch Helix API