twitchrb 1.2.6 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +15 -2
  3. data/.rubocop.yml +8 -0
  4. data/Gemfile +3 -1
  5. data/Gemfile.lock +70 -2
  6. data/README.md +53 -2
  7. data/Rakefile +1 -1
  8. data/lib/twitch/client.rb +5 -5
  9. data/lib/twitch/collection.rb +12 -0
  10. data/lib/twitch/oauth.rb +3 -5
  11. data/lib/twitch/object.rb +1 -1
  12. data/lib/twitch/objects/warning.rb +4 -0
  13. data/lib/twitch/resources/announcements.rb +1 -3
  14. data/lib/twitch/resources/automod.rb +4 -6
  15. data/lib/twitch/resources/badges.rb +0 -2
  16. data/lib/twitch/resources/banned_events.rb +0 -2
  17. data/lib/twitch/resources/banned_users.rb +1 -3
  18. data/lib/twitch/resources/blocked_terms.rb +2 -4
  19. data/lib/twitch/resources/channels.rb +2 -4
  20. data/lib/twitch/resources/charity_campaigns.rb +1 -3
  21. data/lib/twitch/resources/chat_messages.rb +1 -3
  22. data/lib/twitch/resources/chatters.rb +1 -3
  23. data/lib/twitch/resources/clips.rb +1 -3
  24. data/lib/twitch/resources/custom_reward_redemptions.rb +2 -4
  25. data/lib/twitch/resources/custom_rewards.rb +3 -5
  26. data/lib/twitch/resources/emotes.rb +0 -2
  27. data/lib/twitch/resources/event_sub_conduit.rb +2 -4
  28. data/lib/twitch/resources/eventsub_conduits.rb +5 -7
  29. data/lib/twitch/resources/eventsub_subscriptions.rb +2 -4
  30. data/lib/twitch/resources/games.rb +5 -7
  31. data/lib/twitch/resources/goals.rb +1 -3
  32. data/lib/twitch/resources/hype_train_events.rb +1 -3
  33. data/lib/twitch/resources/moderator_events.rb +0 -2
  34. data/lib/twitch/resources/moderators.rb +2 -4
  35. data/lib/twitch/resources/polls.rb +2 -4
  36. data/lib/twitch/resources/predictions.rb +2 -4
  37. data/lib/twitch/resources/raids.rb +1 -3
  38. data/lib/twitch/resources/search.rb +0 -2
  39. data/lib/twitch/resources/shoutouts.rb +0 -2
  40. data/lib/twitch/resources/stream_markers.rb +0 -2
  41. data/lib/twitch/resources/stream_schedule.rb +5 -7
  42. data/lib/twitch/resources/streams.rb +0 -2
  43. data/lib/twitch/resources/subscriptions.rb +2 -4
  44. data/lib/twitch/resources/tags.rb +0 -2
  45. data/lib/twitch/resources/unban_requests.rb +2 -5
  46. data/lib/twitch/resources/users.rb +9 -11
  47. data/lib/twitch/resources/videos.rb +1 -3
  48. data/lib/twitch/resources/vips.rb +1 -3
  49. data/lib/twitch/resources/warnings.rb +12 -0
  50. data/lib/twitch/resources/whispers.rb +1 -3
  51. data/lib/twitch/version.rb +1 -1
  52. data/lib/twitch.rb +2 -2
  53. data/lib/twitchrb.rb +1 -1
  54. data/twitchrb.gemspec +3 -3
  55. metadata +5 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60980d8bf5b14573901d2e1f804a1b84f7b0cea44a9c973af72ce2de2f0e6297
4
- data.tar.gz: 0bd059ad24e3a80481d85e674a5566010bbd6a4921e1d2d79ecd7704dc8f93aa
3
+ metadata.gz: 6774429fbfacd30d1308f5240f54d31bddfc9e5511ca11a5318317d8ecd426fe
4
+ data.tar.gz: 8483a2e2a75269d40a6fcc56e1206dfc59a4033ef6d4d8bb679aaca6ab1e72dc
5
5
  SHA512:
6
- metadata.gz: 930c750a7dcaee2e7c2d59af797ec97c4b11fafcf91b299a2992f57e48982520437e86260b4713aaf3b3eb4e07366807c38401242973bde28024911db761fdc3
7
- data.tar.gz: 4a143222b85001d94bc213c492c189b80e3f3b69cbc8a3d74984231469a4b5174bb57e67c1730f739d213f6959b82bf39ffb1db126a5e7826303bed4df108f6c
6
+ metadata.gz: 36c6bea9d2c2e8e1ff5eab8d3daf2edc0b2edc1047bb65f5d38c77b78b9fcba7333dc628593c5d5e9aa6cc2a0543115738f7a437200867a4d7186c0edd5e01c6
7
+ data.tar.gz: f775ef2e85b39651f8c4fcea07791badce94086b3129f52dab6d44bf08456a1083d2b805bb3b6ef2c3eb965ae1178190623af7f243109042dc7ae0b10b0dd1a9
@@ -1,18 +1,31 @@
1
1
  name: CI
2
2
  on: push
3
3
  jobs:
4
+ lint:
5
+ runs-on: ubuntu-latest
6
+ steps:
7
+ - name: Checkout code
8
+ uses: actions/checkout@v4
9
+ - name: Set up Ruby
10
+ uses: ruby/setup-ruby@v1
11
+ with:
12
+ ruby-version: '3.3'
13
+ bundler-cache: true
14
+ - name: Lint code for consistent style
15
+ run: bundle exec rubocop -f github
16
+
4
17
  test:
5
18
  runs-on: ubuntu-latest
19
+ needs: lint
6
20
  strategy:
7
21
  fail-fast: false
8
22
  matrix:
9
23
  ruby_version:
10
- - '3.0'
11
24
  - '3.1'
12
25
  - '3.2'
13
26
  - '3.3'
14
27
  steps:
15
- - uses: actions/checkout@v3
28
+ - uses: actions/checkout@v4
16
29
  - uses: ruby/setup-ruby@v1
17
30
  with:
18
31
  ruby-version: ${{ matrix.ruby_version }}
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ # Omakase Ruby styling for Rails
2
+ inherit_gem: { rubocop-rails-omakase: rubocop.yml }
3
+
4
+ # Overwrite or add rules to create your own house style
5
+ #
6
+ # # Use `[a, [b, c]]` not `[ a, [ b, c ] ]`
7
+ # Layout/SpaceInsideArrayLiteralBrackets:
8
+ # Enabled: false
data/Gemfile CHANGED
@@ -5,4 +5,6 @@ gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "minitest", "~> 5.0"
8
- gem "dotenv"
8
+ gem "dotenv"
9
+ gem "vcr"
10
+ gem "rubocop-rails-omakase", require: false
data/Gemfile.lock CHANGED
@@ -1,22 +1,88 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- twitchrb (1.2.5)
4
+ twitchrb (1.3.0)
5
5
  faraday (~> 2.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ activesupport (7.1.3.4)
11
+ base64
12
+ bigdecimal
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ connection_pool (>= 2.2.5)
15
+ drb
16
+ i18n (>= 1.6, < 2)
17
+ minitest (>= 5.1)
18
+ mutex_m
19
+ tzinfo (~> 2.0)
20
+ ast (2.4.2)
21
+ base64 (0.2.0)
22
+ bigdecimal (3.1.8)
23
+ concurrent-ruby (1.3.3)
24
+ connection_pool (2.4.1)
10
25
  dotenv (2.7.6)
11
- faraday (2.9.0)
26
+ drb (2.2.1)
27
+ faraday (2.9.2)
12
28
  faraday-net_http (>= 2.0, < 3.2)
13
29
  faraday-net_http (3.1.0)
14
30
  net-http
31
+ i18n (1.14.5)
32
+ concurrent-ruby (~> 1.0)
33
+ json (2.7.2)
34
+ language_server-protocol (3.17.0.3)
15
35
  minitest (5.15.0)
36
+ mutex_m (0.2.0)
16
37
  net-http (0.4.1)
17
38
  uri
39
+ parallel (1.25.1)
40
+ parser (3.3.3.0)
41
+ ast (~> 2.4.1)
42
+ racc
43
+ racc (1.8.0)
44
+ rack (3.1.3)
45
+ rainbow (3.1.1)
18
46
  rake (12.3.3)
47
+ regexp_parser (2.9.2)
48
+ rexml (3.3.0)
49
+ strscan
50
+ rubocop (1.64.1)
51
+ json (~> 2.3)
52
+ language_server-protocol (>= 3.17.0)
53
+ parallel (~> 1.10)
54
+ parser (>= 3.3.0.2)
55
+ rainbow (>= 2.2.2, < 4.0)
56
+ regexp_parser (>= 1.8, < 3.0)
57
+ rexml (>= 3.2.5, < 4.0)
58
+ rubocop-ast (>= 1.31.1, < 2.0)
59
+ ruby-progressbar (~> 1.7)
60
+ unicode-display_width (>= 2.4.0, < 3.0)
61
+ rubocop-ast (1.31.3)
62
+ parser (>= 3.3.1.0)
63
+ rubocop-minitest (0.35.0)
64
+ rubocop (>= 1.61, < 2.0)
65
+ rubocop-ast (>= 1.31.1, < 2.0)
66
+ rubocop-performance (1.21.0)
67
+ rubocop (>= 1.48.1, < 2.0)
68
+ rubocop-ast (>= 1.31.1, < 2.0)
69
+ rubocop-rails (2.25.0)
70
+ activesupport (>= 4.2.0)
71
+ rack (>= 1.1)
72
+ rubocop (>= 1.33.0, < 2.0)
73
+ rubocop-ast (>= 1.31.1, < 2.0)
74
+ rubocop-rails-omakase (1.0.0)
75
+ rubocop
76
+ rubocop-minitest
77
+ rubocop-performance
78
+ rubocop-rails
79
+ ruby-progressbar (1.13.0)
80
+ strscan (3.1.0)
81
+ tzinfo (2.0.6)
82
+ concurrent-ruby (~> 1.0)
83
+ unicode-display_width (2.5.0)
19
84
  uri (0.13.0)
85
+ vcr (6.2.0)
20
86
 
21
87
  PLATFORMS
22
88
  ruby
@@ -25,7 +91,9 @@ DEPENDENCIES
25
91
  dotenv
26
92
  minitest (~> 5.0)
27
93
  rake (~> 12.0)
94
+ rubocop-rails-omakase
28
95
  twitchrb!
96
+ vcr
29
97
 
30
98
  BUNDLED WITH
31
99
  2.3.21
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TwitchRB
2
2
 
3
- TwitchRB is a Ruby library for interacting with the Twitch Helix API.
3
+ TwitchRB is the easiest and most complete Ruby library for the [Twitch Helix API](https://dev.twitch.tv/docs/api).
4
4
 
5
5
  ## Installation
6
6
 
@@ -19,7 +19,49 @@ Firstly you'll need to set a Client ID and an Access Token.
19
19
  An access token is required because the Helix API requires authentication.
20
20
 
21
21
  ```ruby
22
- @client = Twitch::Client.new(client_id: "", access_token: "")
22
+ @client = Twitch::Client.new(client_id: "abc123", access_token: "xyz123")
23
+ ```
24
+
25
+ ### Resources
26
+
27
+ The gem maps as closely as we can to the Twitch API so you can easily convert API examples to gem code.
28
+
29
+ Responses are created as objects like `Twitch::Channel`. Having types like `Twitch::User` is handy for understanding what
30
+ type of object you're working with. They're built using OpenStruct so you can easily access data in a Ruby-ish way.
31
+
32
+ ### Pagination
33
+
34
+ Some of the endpoints return pages of results. The result object will have a `data` key to access the results, as well as metadata like `cursor`
35
+ for retrieving the next and previous pages. This can be used by using `before` and `after` parameters, on API endpoints that support it.
36
+
37
+ An example of using collections, including pagination:
38
+
39
+ ```ruby
40
+ results = @client.clips.list(broadcaster_id: 123)
41
+ #=> Twitch::Collection
42
+
43
+ results.total
44
+ #=> 30
45
+
46
+ results.data
47
+ #=> [#<Twitch::Clip>, #<Twitch::Clip>]
48
+
49
+ results.each do |result|
50
+ puts result.id
51
+ end
52
+
53
+ results.first
54
+ #=> #<Twitch::Clip>
55
+
56
+ results.last
57
+ #=> #<Twitch::Clip>
58
+
59
+ results.cursor
60
+ #=> "abc123"
61
+
62
+ # Retrieve the next page
63
+ @client.clips.list(broadcaster_id: 123, after: results.cursor)
64
+ #=> Twitch::Collection
23
65
  ```
24
66
 
25
67
  ### OAuth
@@ -513,6 +555,15 @@ messages = [{msg_id: "abc1", msg_text: "is this allowed?"}, {msg_id: "abc2", msg
513
555
  @client.unban_requests.resolve broadcaster_id: 123, moderator_id: 123, id: "abc123", status: "approved"
514
556
  ```
515
557
 
558
+ ### Warnings
559
+
560
+ ```ruby
561
+ # Sends a warning to a user
562
+ # Required scope: moderator:manage:warnings
563
+ # moderator_id must match the currently authenticated user
564
+ @client.warnings.create broadcaster_id: 123, moderator_id: 123, user_id: 321, reason: "dont do that"
565
+ ```
566
+
516
567
 
517
568
  ## Contributing
518
569
 
data/Rakefile CHANGED
@@ -7,4 +7,4 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.test_files = FileList["test/**/*_test.rb"]
8
8
  end
9
9
 
10
- task :default => :test
10
+ task default: :test
data/lib/twitch/client.rb CHANGED
@@ -4,13 +4,10 @@ module Twitch
4
4
 
5
5
  attr_reader :client_id, :access_token, :adapter
6
6
 
7
- def initialize(client_id:, access_token:, adapter: Faraday.default_adapter, stubs: nil)
7
+ def initialize(client_id:, access_token:, adapter: Faraday.default_adapter)
8
8
  @client_id = client_id
9
9
  @access_token = access_token
10
10
  @adapter = adapter
11
-
12
- # Test stubs for requests
13
- @stubs = stubs
14
11
  end
15
12
 
16
13
  def users
@@ -157,6 +154,10 @@ module Twitch
157
154
  UnbanRequestsResource.new(self)
158
155
  end
159
156
 
157
+ def warnings
158
+ WarningsResource.new(self)
159
+ end
160
+
160
161
  def connection
161
162
  @connection ||= Faraday.new(BASE_URL) do |conn|
162
163
  conn.request :authorization, :Bearer, access_token
@@ -173,6 +174,5 @@ module Twitch
173
174
  conn.adapter adapter, @stubs
174
175
  end
175
176
  end
176
-
177
177
  end
178
178
  end
@@ -17,5 +17,17 @@ module Twitch
17
17
  @total = total
18
18
  @cursor = cursor.nil? ? nil : cursor
19
19
  end
20
+
21
+ def each(&block)
22
+ data.each(&block)
23
+ end
24
+
25
+ def first
26
+ data.first
27
+ end
28
+
29
+ def last
30
+ data.last
31
+ end
20
32
  end
21
33
  end
data/lib/twitch/oauth.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module Twitch
2
2
  class OAuth
3
-
4
3
  attr_reader :client_id, :client_secret
5
4
 
6
5
  def initialize(client_id:, client_secret:)
@@ -27,11 +26,11 @@ module Twitch
27
26
  end
28
27
 
29
28
  def device(scopes:)
30
- send_request(url: "https://id.twitch.tv/oauth2/device", body: {client_id: client_id, scope: scopes})
29
+ send_request(url: "https://id.twitch.tv/oauth2/device", body: { client_id: client_id, scope: scopes })
31
30
  end
32
31
 
33
32
  def validate(token:)
34
- response = Faraday.get("https://id.twitch.tv/oauth2/validate", nil, {"Authorization" => "OAuth #{token}"})
33
+ response = Faraday.get("https://id.twitch.tv/oauth2/validate", nil, { "Authorization" => "OAuth #{token}" })
35
34
 
36
35
  return false if response.status != 200
37
36
 
@@ -46,7 +45,7 @@ module Twitch
46
45
 
47
46
  JSON.parse(response.body, object_class: OpenStruct) if response.status != 200
48
47
 
49
- return true
48
+ true
50
49
  end
51
50
 
52
51
  private
@@ -58,6 +57,5 @@ module Twitch
58
57
 
59
58
  JSON.parse(response.body, object_class: OpenStruct)
60
59
  end
61
-
62
60
  end
63
61
  end
data/lib/twitch/object.rb CHANGED
@@ -8,7 +8,7 @@ module Twitch
8
8
 
9
9
  def to_ostruct(obj)
10
10
  if obj.is_a?(Hash)
11
- OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h)
11
+ OpenStruct.new(obj.map { |key, val| [ key, to_ostruct(val) ] }.to_h)
12
12
  elsif obj.is_a?(Array)
13
13
  obj.map { |o| to_ostruct(o) }
14
14
  else # Assumed to be a primitive value
@@ -0,0 +1,4 @@
1
+ module Twitch
2
+ class Warning < Object
3
+ end
4
+ end
@@ -1,13 +1,11 @@
1
1
  module Twitch
2
2
  class AnnouncementsResource < Resource
3
-
4
3
  # Moderator ID must match the user in the OAuth token
5
4
  # Required scope: moderator:manage:announcements
6
5
  def create(broadcaster_id:, moderator_id:, message:, color: nil)
7
- attrs = {message: message, color: color}
6
+ attrs = { message: message, color: color }
8
7
 
9
8
  post_request("chat/announcements?broadcaster_id=#{broadcaster_id}&moderator_id=#{moderator_id}", body: attrs)
10
9
  end
11
-
12
10
  end
13
11
  end
@@ -1,10 +1,9 @@
1
1
  module Twitch
2
2
  class AutomodResource < Resource
3
-
4
3
  # Checks if a supplied message meets the channel's AutoMod requirements
5
4
  # Required scope: moderation:read
6
5
  def check_status(broadcaster_id:, id:, text:)
7
- attrs = {broadcaster_id: broadcaster_id, data: [{msg_id: id, msg_text: text}]}
6
+ attrs = { broadcaster_id: broadcaster_id, data: [ { msg_id: id, msg_text: text } ] }
8
7
  response = post_request("moderation/enforcements/status", body: attrs)
9
8
  AutomodStatus.new response.body.dig("data")[0]
10
9
  end
@@ -12,13 +11,13 @@ module Twitch
12
11
  # Checks if multiple supplied messages meet the channel's AutoMod requirements
13
12
  # Required scope: moderation:read
14
13
  def check_status_multiple(broadcaster_id:, messages:)
15
- attrs = {broadcaster_id: broadcaster_id, data: messages}
14
+ attrs = { broadcaster_id: broadcaster_id, data: messages }
16
15
  response = post_request("moderation/enforcements/status", body: attrs)
17
16
  Collection.from_response(response, type: AutomodStatus)
18
17
  end
19
18
 
20
19
  def manage_message(user_id:, msg_id:, action:)
21
- attrs = {user_id: user_id, msg_id: msg_id, action: action}
20
+ attrs = { user_id: user_id, msg_id: msg_id, action: action }
22
21
  post_request("moderation/automod/message", body: attrs)
23
22
  end
24
23
 
@@ -28,10 +27,9 @@ module Twitch
28
27
  end
29
28
 
30
29
  def update_settings(broadcaster_id:, moderator_id:, **params)
31
- attrs = {broadcaster_id: broadcaster_id, moderator_id: moderator_id}
30
+ attrs = { broadcaster_id: broadcaster_id, moderator_id: moderator_id }
32
31
  response = put_request("moderation/automod/settings", body: attrs.merge(params))
33
32
  AutomodSetting.new response.body.dig("data")[0]
34
33
  end
35
-
36
34
  end
37
35
  end
@@ -1,6 +1,5 @@
1
1
  module Twitch
2
2
  class BadgesResource < Resource
3
-
4
3
  def channel(broadcaster_id:)
5
4
  response = get_request("chat/badges?broadcaster_id=#{broadcaster_id}")
6
5
  Collection.from_response(response, type: Badge)
@@ -10,6 +9,5 @@ module Twitch
10
9
  response = get_request("chat/badges/global")
11
10
  Collection.from_response(response, type: Badge)
12
11
  end
13
-
14
12
  end
15
13
  end
@@ -1,10 +1,8 @@
1
1
  module Twitch
2
2
  class BannedEventsResource < Resource
3
-
4
3
  def list(broadcaster_id:, **params)
5
4
  response = get_request("moderation/banned/events", params: params.merge(broadcaster_id: broadcaster_id))
6
5
  Collection.from_response(response, type: BannedEvent)
7
6
  end
8
-
9
7
  end
10
8
  end
@@ -1,6 +1,5 @@
1
1
  module Twitch
2
2
  class BannedUsersResource < Resource
3
-
4
3
  # Broadcaster ID must match the user in the OAuth token
5
4
  def list(broadcaster_id:, **params)
6
5
  response = get_request("moderation/banned", params: params.merge(broadcaster_id: broadcaster_id))
@@ -10,7 +9,7 @@ module Twitch
10
9
  # Required scope: moderator:manage:banned_users
11
10
  # moderator_id must match the currently authenticated user. Can be either the broadcaster ID or moderator ID
12
11
  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}}
12
+ attrs = { broadcaster_id: broadcaster_id, moderator_id: moderator_id, data: { user_id: user_id, reason: reason, duration: duration } }
14
13
  response = post_request("moderation/bans", body: attrs)
15
14
  BannedUser.new response.body.dig("data")[0]
16
15
  end
@@ -20,6 +19,5 @@ module Twitch
20
19
  def delete(broadcaster_id:, moderator_id:, user_id:)
21
20
  delete_request("moderation/bans?broadcaster_id=#{broadcaster_id}&moderator_id=#{moderator_id}&user_id=#{user_id}")
22
21
  end
23
-
24
22
  end
25
23
  end
@@ -1,10 +1,9 @@
1
1
  module Twitch
2
2
  class BlockedTermsResource < Resource
3
-
4
3
  # Required scope: moderator:read:blocked_terms
5
4
  # moderator_id must match the currently authenticated user. Can be either the broadcaster ID or moderator ID
6
5
  def list(broadcaster_id:, moderator_id:, **params)
7
- attrs = {broadcaster_id: broadcaster_id, moderator_id: moderator_id}
6
+ attrs = { broadcaster_id: broadcaster_id, moderator_id: moderator_id }
8
7
  response = get_request("moderation/blocked_terms", params: attrs.merge(params))
9
8
  Collection.from_response(response, type: BlockedTerm)
10
9
  end
@@ -12,7 +11,7 @@ module Twitch
12
11
  # Required scope: moderator:manage:blocked_terms
13
12
  # moderator_id must match the currently authenticated user. Can be either the broadcaster ID or moderator ID
14
13
  def create(broadcaster_id:, moderator_id:, text:)
15
- attrs = {broadcaster_id: broadcaster_id, moderator_id: moderator_id, text: text}
14
+ attrs = { broadcaster_id: broadcaster_id, moderator_id: moderator_id, text: text }
16
15
  response = post_request("moderation/blocked_terms", body: attrs)
17
16
  BannedUser.new response.body.dig("data")[0]
18
17
  end
@@ -22,6 +21,5 @@ module Twitch
22
21
  def delete(broadcaster_id:, moderator_id:, id:)
23
22
  delete_request("moderation/blocked_terms?broadcaster_id=#{broadcaster_id}&moderator_id=#{moderator_id}&id=#{id}")
24
23
  end
25
-
26
24
  end
27
25
  end
@@ -1,6 +1,5 @@
1
1
  module Twitch
2
2
  class ChannelsResource < Resource
3
-
4
3
  def retrieve(id:)
5
4
  Channel.new get_request("channels?broadcaster_id=#{id}").body.dig("data")[0]
6
5
  end
@@ -23,7 +22,7 @@ module Twitch
23
22
 
24
23
  # Grabs the number of Followers a broadcaster has
25
24
  def follows_count(broadcaster_id:)
26
- response = get_request("channels/followers", params: {broadcaster_id: broadcaster_id})
25
+ response = get_request("channels/followers", params: { broadcaster_id: broadcaster_id })
27
26
 
28
27
  FollowCount.new(count: response.body["total"])
29
28
  end
@@ -31,7 +30,7 @@ module Twitch
31
30
  # Grabs the number of Subscribers and Subscriber Points a broadcaster has
32
31
  # Required scope: channel:read:subscriptions
33
32
  def subscribers_count(broadcaster_id:)
34
- response = get_request("subscriptions", params: {broadcaster_id: broadcaster_id})
33
+ response = get_request("subscriptions", params: { broadcaster_id: broadcaster_id })
35
34
 
36
35
  SubscriptionCount.new(count: response.body["total"], points: response.body["points"])
37
36
  end
@@ -46,6 +45,5 @@ module Twitch
46
45
  response = get_request("channels/editors?broadcaster_id=#{broadcaster_id}")
47
46
  Collection.from_response(response, type: ChannelEditor)
48
47
  end
49
-
50
48
  end
51
49
  end
@@ -1,16 +1,14 @@
1
1
  module Twitch
2
2
  class CharityCampaignsResource < Resource
3
-
4
3
  # Required scope: channel:read:charity
5
4
  # Broadcaster ID must match the user in the OAuth token
6
5
  def list(broadcaster_id:)
7
- response = get_request("charity/campaigns?broadcaster_id=#{broadcaster_id}")
6
+ response = get_request("charity/campaigns?broadcaster_id=#{broadcaster_id}")
8
7
  if response.body.dig("data")[0]
9
8
  CharityCampaign.new(response.body.dig("data")[0])
10
9
  else
11
10
  nil
12
11
  end
13
12
  end
14
-
15
13
  end
16
14
  end
@@ -1,8 +1,7 @@
1
1
  module Twitch
2
2
  class ChatMessagesResource < Resource
3
-
4
3
  def create(broadcaster_id:, sender_id:, message:, reply_to: nil)
5
- attrs = {broadcaster_id: broadcaster_id, sender_id: sender_id, message: message, reply_parent_message_id: reply_to}
4
+ attrs = { broadcaster_id: broadcaster_id, sender_id: sender_id, message: message, reply_parent_message_id: reply_to }
6
5
 
7
6
  response = post_request("chat/messages", body: attrs)
8
7
  ChatMessage.new(response.body.dig("data")[0])
@@ -12,6 +11,5 @@ module Twitch
12
11
  def delete(broadcaster_id:, moderator_id:, message_id:)
13
12
  delete_request("moderation/chat?broadcaster_id=#{broadcaster_id}&moderator_id=#{moderator_id}&message_id=#{message_id}")
14
13
  end
15
-
16
14
  end
17
15
  end
@@ -1,15 +1,13 @@
1
1
  module Twitch
2
2
  class ChattersResource < Resource
3
-
4
3
  # Gets a list of users that are connected to the specified broadcaster's chat session
5
4
  # Moderator ID must match the user in the OAuth token
6
5
  # Required scope: moderator:read:chatters
7
6
  def list(broadcaster_id:, moderator_id:, **params)
8
- attrs = {broadcaster_id: broadcaster_id, moderator_id: moderator_id}
7
+ attrs = { broadcaster_id: broadcaster_id, moderator_id: moderator_id }
9
8
  response = get_request("chat/chatters", params: attrs.merge(params))
10
9
 
11
10
  Collection.from_response(response, type: Chatter)
12
11
  end
13
-
14
12
  end
15
13
  end
@@ -1,6 +1,5 @@
1
1
  module Twitch
2
2
  class ClipsResource < Resource
3
-
4
3
  def list(**params)
5
4
  raise "broadcaster_id or game_id is required" unless !params[:broadcaster_id].nil? || !params[:game_id].nil?
6
5
 
@@ -9,7 +8,7 @@ module Twitch
9
8
  end
10
9
 
11
10
  def retrieve(id:)
12
- Clip.new get_request("clips", params: {id: id}).body.dig("data")[0]
11
+ Clip.new get_request("clips", params: { id: id }).body.dig("data")[0]
13
12
  end
14
13
 
15
14
  # Required scope: clips:edit
@@ -18,6 +17,5 @@ module Twitch
18
17
 
19
18
  Clip.new(response.body.dig("data")[0]) if response.success?
20
19
  end
21
-
22
20
  end
23
21
  end
@@ -1,10 +1,9 @@
1
1
  module Twitch
2
2
  class CustomRewardRedemptionsResource < Resource
3
-
4
3
  # Required scope: channel:read:redemptions
5
4
  # Broadcaster ID must match the user in the OAuth token
6
5
  def list(broadcaster_id:, reward_id:, status:, **params)
7
- attributes = {broadcaster_id: broadcaster_id, reward_id: reward_id, status: status.upcase}
6
+ attributes = { broadcaster_id: broadcaster_id, reward_id: reward_id, status: status.upcase }
8
7
  response = get_request("channel_points/custom_rewards/redemptions", params: attributes.merge(params))
9
8
  Collection.from_response(response, type: CustomRewardRedemption)
10
9
  end
@@ -12,12 +11,11 @@ module Twitch
12
11
  # Required scope: channel:manage:redemptions
13
12
  # Broadcaster ID must match the user in the OAuth token
14
13
  def update(broadcaster_id:, reward_id:, redemption_id:, status:)
15
- attributes = {status: status.upcase}
14
+ attributes = { status: status.upcase }
16
15
  url = "channel_points/custom_rewards/redemptions?broadcaster_id=#{broadcaster_id}&reward_id=#{reward_id}&id=#{redemption_id}&status=#{status.upcase}"
17
16
  response = patch_request(url, body: attributes)
18
17
 
19
18
  CustomRewardRedemption.new(response.body.dig("data")[0]) if response.success?
20
19
  end
21
-
22
20
  end
23
21
  end
@@ -1,6 +1,5 @@
1
1
  module Twitch
2
2
  class CustomRewardsResource < Resource
3
-
4
3
  # Required scope: channel:read:redemptions
5
4
  # Broadcaster ID must match the user in the OAuth token
6
5
  def list(broadcaster_id:, **params)
@@ -9,22 +8,21 @@ module Twitch
9
8
  end
10
9
 
11
10
  def create(broadcaster_id:, title:, cost:, **params)
12
- attributes = {broadcaster_id: broadcaster_id, title: title, cost: cost}
11
+ attributes = { broadcaster_id: broadcaster_id, title: title, cost: cost }
13
12
  response = post_request("channel_points/custom_rewards", body: attributes.merge(params))
14
13
 
15
14
  CustomReward.new(response.body.dig("data")[0]) if response.success?
16
15
  end
17
16
 
18
17
  def update(broadcaster_id:, reward_id:, **params)
19
- attributes = {broadcaster_id: broadcaster_id, id: reward_id}
18
+ attributes = { broadcaster_id: broadcaster_id, id: reward_id }
20
19
  response = patch_request("channel_points/custom_rewards", body: attributes.merge(params))
21
20
 
22
21
  CustomReward.new(response.body.dig("data")[0]) if response.success?
23
22
  end
24
23
 
25
24
  def delete(broadcaster_id:, reward_id:)
26
- delete_request("channel_points/custom_rewards", params: {broadcaster_id: broadcaster_id, id: reward_id})
25
+ delete_request("channel_points/custom_rewards", params: { broadcaster_id: broadcaster_id, id: reward_id })
27
26
  end
28
-
29
27
  end
30
28
  end
@@ -1,6 +1,5 @@
1
1
  module Twitch
2
2
  class EmotesResource < Resource
3
-
4
3
  def channel(broadcaster_id:)
5
4
  response = get_request("chat/emotes?broadcaster_id=#{broadcaster_id}")
6
5
  Collection.from_response(response, type: Emote)
@@ -15,6 +14,5 @@ module Twitch
15
14
  response = get_request("chat/emotes/set?emote_set_id=#{emote_set_id}")
16
15
  Collection.from_response(response, type: Emote)
17
16
  end
18
-
19
17
  end
20
18
  end