twitchrb 1.2.4 → 1.2.5

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: 1269fdc61b940ec41b8dc926e407f7f33075998ad7ab488e191bb12e7f2926ee
4
- data.tar.gz: 393eaef53b73443c32b2a26911acdfe45496d77ee0ce6f748daa61e8227a9fcc
3
+ metadata.gz: 5b1b5b00194116bc482bebd6b536a95906bd7f0bda470ab0518fbf6c0818b0ff
4
+ data.tar.gz: 584c1cf4d98be59ea654d2bed1e142d6fc6a9c7de476c3fe0cd260818aa5be6a
5
5
  SHA512:
6
- metadata.gz: 97c97cf66f5fe20ccea0f39fdbc14721359c81f29ec14b8aab501da91f73b603b8d77296d01eb63c6225619828f112629312742a70fae91c55c1c086f0b989f6
7
- data.tar.gz: d8d65949ae74ea874ab22c4d4e4ed39d26a5f80824254245e31a200e9067d8ac6c944d277bba087eefefceb6b93cafa863ba006f2e038fe0789cbf6f1fb8166c
6
+ metadata.gz: 6a4065eac3b0e609537672668ecf33d48ca9d045ccb7cfceaad614a52637e7bad133234a55a1fe5011063751297ca500e74bb97c827c48023ba62bf573fbc568
7
+ data.tar.gz: 43f822492d36433f9cd3854c8cbf63bd7aa6607bd27a75363ff4dc73b7a041e26302d485422cd9aa543dc7cf46af38ca9c4fe9de1995d9998ed68e8b02a861bf
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- twitchrb (1.2.3)
4
+ twitchrb (1.2.5)
5
5
  faraday (~> 2.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -22,6 +22,34 @@ An access token is required because the Helix API requires authentication.
22
22
  @client = Twitch::Client.new(client_id: "", access_token: "")
23
23
  ```
24
24
 
25
+ ### OAuth
26
+
27
+ This library includes the ability to create, refresh and revoke OAuth tokens.
28
+
29
+ ```ruby
30
+ # Firstly, set the client details
31
+ @oauth = Twitch::OAuth.new(client_id: "", client_secret: "")
32
+
33
+ # Create a Token
34
+ # grant_type can be either "authorization_code" or "client_credentials"
35
+ # scope is a space-delimited list of scopes. This is optional depending on the grant_type
36
+ @oauth.create(grant_type: "", scope: "")
37
+
38
+ # Refresh a Token
39
+ @oauth.refresh(refresh_token: "")
40
+
41
+ # Device Code Grant Flow
42
+ # scopes is required and is a space-delimited list of scopes
43
+ # https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#device-code-grant-flow
44
+ @oauth.device(scopes: "bits:read channel:read:subscriptions")
45
+
46
+ # Validate an Access Token
47
+ @oauth.validate(access_token: "")
48
+
49
+ # Revoke a Token
50
+ @oauth.revoke(token: "")
51
+ ```
52
+
25
53
  ### Users
26
54
 
27
55
  ```ruby
@@ -68,6 +96,12 @@ An access token is required because the Helix API requires authentication.
68
96
  # 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
69
97
  # For Turbo and Prime users, a hex colour code is allowed.
70
98
  @client.users.update_color(user_id: 123, color: "blue")
99
+
100
+ # Get Emotes a User has
101
+ # Required scope: user:read:emotes
102
+ @client.users.emotes(user_id: 123)
103
+ @client.users.emotes(user_id: 123, broadcaster_id: 321)
104
+ @client.users.emotes(user_id: 123, after: "abc123")
71
105
  ```
72
106
 
73
107
  ### Channels
@@ -464,6 +498,20 @@ messages = [{msg_id: "abc1", msg_text: "is this allowed?"}, {msg_id: "abc2", msg
464
498
  @client.custom_reward_redemptions.update broadcaster_id: 123, reward_id: 321, redemption_id: 123, status: "FULFILLED"
465
499
  ```
466
500
 
501
+ ### Unban Requests
502
+
503
+ ```ruby
504
+ # Retrieves a list of Unban Requests for a broadcaster
505
+ # Required scope: moderator:read:unban_requests or moderator:manage:unban_requests
506
+ # moderator_id must match the currently authenticated user
507
+ @client.unban_requests.list broadcaster_id: 123, moderator_id: 123, status: "pending"
508
+
509
+ # Resolve an Unban Request
510
+ # Required scope: moderator:manage:unban_requests
511
+ # moderator_id must match the currently authenticated user
512
+ @client.unban_requests.resolve broadcaster_id: 123, moderator_id: 123, id: "abc123", status: "approved"
513
+ ```
514
+
467
515
 
468
516
  ## Contributing
469
517
 
data/bin/console CHANGED
@@ -13,7 +13,11 @@ require 'dotenv/load'
13
13
  # require "pry"
14
14
  # Pry.start
15
15
 
16
+ @oauth = Twitch::OAuth.new(client_id: ENV["TWITCH_CLIENT_ID"], client_secret: ENV["TWITCH_CLIENT_SECRET"])
17
+
16
18
  @client = Twitch::Client.new(client_id: ENV["TWITCH_CLIENT_ID"], access_token: ENV["TWITCH_ACCESS_TOKEN"])
17
19
 
20
+ @clientapp = Twitch::Client.new(client_id: ENV["TWITCH_CLIENT_ID"], access_token: ENV["TWITCH_APP_ACCESS_TOKEN"])
21
+
18
22
  require "irb"
19
23
  IRB.start(__FILE__)
data/lib/twitch/client.rb CHANGED
@@ -42,7 +42,11 @@ module Twitch
42
42
  end
43
43
 
44
44
  def eventsub_subscriptions
45
- EventSubSubscriptionsResource.new(self)
45
+ EventsubSubscriptionsResource.new(self)
46
+ end
47
+
48
+ def eventsub_conduits
49
+ EventsubConduitsResource.new(self)
46
50
  end
47
51
 
48
52
  def banned_events
@@ -149,12 +153,14 @@ module Twitch
149
153
  ShoutoutsResource.new(self)
150
154
  end
151
155
 
156
+ def unban_requests
157
+ UnbanRequestsResource.new(self)
158
+ end
159
+
152
160
  def connection
153
161
  @connection ||= Faraday.new(BASE_URL) do |conn|
154
162
  conn.request :authorization, :Bearer, access_token
155
163
 
156
- conn.options.params_encoder = Faraday::FlatParamsEncoder
157
-
158
164
  conn.headers = {
159
165
  "User-Agent" => "twitchrb/v#{VERSION} (github.com/deanpcmad/twitchrb)",
160
166
  "Client-ID": client_id
@@ -0,0 +1,61 @@
1
+ module Twitch
2
+ class OAuth
3
+
4
+ attr_reader :client_id, :client_secret
5
+
6
+ def initialize(client_id:, client_secret:)
7
+ @client_id = client_id
8
+ @client_secret = client_secret
9
+ end
10
+
11
+ def create(grant_type:, scope: nil)
12
+ send_request(url: "https://id.twitch.tv/oauth2/token", body: {
13
+ client_id: client_id,
14
+ client_secret: client_secret,
15
+ grant_type: grant_type,
16
+ scope: scope
17
+ })
18
+ end
19
+
20
+ def refresh(refresh_token:)
21
+ send_request(url: "https://id.twitch.tv/oauth2/token", body: {
22
+ client_id: client_id,
23
+ client_secret: client_secret,
24
+ grant_type: "refresh_token",
25
+ refresh_token: refresh_token
26
+ })
27
+ end
28
+
29
+ def device(scopes:)
30
+ send_request(url: "https://id.twitch.tv/oauth2/device", body: {client_id: client_id, scope: scopes})
31
+ end
32
+
33
+ def validate(token:)
34
+ response = Faraday.get("https://id.twitch.tv/oauth2/validate", nil, {"Authorization" => "OAuth #{token}"})
35
+
36
+ JSON.parse(response.body, object_class: OpenStruct)
37
+ end
38
+
39
+ def revoke(token:)
40
+ response = Faraday.post("https://id.twitch.tv/oauth2/revoke", {
41
+ client_id: client_id,
42
+ token: token
43
+ })
44
+
45
+ JSON.parse(response.body, object_class: OpenStruct) if response.status != 200
46
+
47
+ return true
48
+ end
49
+
50
+ private
51
+
52
+ def send_request(url:, body:)
53
+ response = Faraday.post(url, body)
54
+
55
+ return false if response.status != 200
56
+
57
+ JSON.parse(response.body, object_class: OpenStruct)
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,4 @@
1
+ module Twitch
2
+ class EventsubConduit < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Twitch
2
+ class EventsubConduitShard < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Twitch
2
+ class EventsubSubscription < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Twitch
2
+ class UnbanRequest < Object
3
+ end
4
+ end
@@ -1,13 +1,13 @@
1
1
  module Twitch
2
2
  class EventSubSubscriptionsResource < Resource
3
-
3
+
4
4
  def list(**params)
5
5
  response = get_request("eventsub/subscriptions", params: params)
6
6
  Collection.from_response(response, type: EventSubSubscription)
7
7
  end
8
8
 
9
- def create(type:, version:, condition:, transport:)
10
- attributes = {type: type, version: version, condition: condition, transport: transport}
9
+ def create(type:, version:, condition:, transport:, **params)
10
+ attributes = {type: type, version: version, condition: condition, transport: transport}.merge(params)
11
11
  response = post_request("eventsub/subscriptions", body: attributes)
12
12
 
13
13
  EventSubSubscription.new(response.body.dig("data")[0]) if response.success?
@@ -0,0 +1,36 @@
1
+ module Twitch
2
+ class EventsubConduitsResource < Resource
3
+
4
+ def list(**params)
5
+ response = get_request("eventsub/conduits", params: params)
6
+ Collection.from_response(response, type: EventsubConduit)
7
+ end
8
+
9
+ def create(shard_count:)
10
+ response = post_request("eventsub/conduits", body: {shard_count: shard_count})
11
+
12
+ EventsubConduit.new(response.body.dig("data")[0]) if response.success?
13
+ end
14
+
15
+ def update(id:, shard_count:)
16
+ response = patch_request("eventsub/conduits", body: {id: id, shard_count: shard_count})
17
+
18
+ EventsubConduit.new(response.body.dig("data")[0]) if response.success?
19
+ end
20
+
21
+ def delete(id:)
22
+ delete_request("eventsub/conduits", params: {id: id})
23
+ end
24
+
25
+ def shards(id:, **params)
26
+ response = get_request("eventsub/conduits/shards", params: {conduit_id: id}.merge(params))
27
+ Collection.from_response(response, type: EventsubConduitShard)
28
+ end
29
+
30
+ def update_shards(id:, shards:)
31
+ response = patch_request("eventsub/conduits/shards", body: {conduit_id: id, shards: shards})
32
+ Collection.from_response(response, type: EventsubConduitShard)
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,21 @@
1
+ module Twitch
2
+ class EventsubSubscriptionsResource < Resource
3
+
4
+ def list(**params)
5
+ response = get_request("eventsub/subscriptions", params: params)
6
+ Collection.from_response(response, type: EventsubSubscription)
7
+ end
8
+
9
+ def create(type:, version:, condition:, transport:, **params)
10
+ attributes = {type: type, version: version, condition: condition, transport: transport}.merge(params)
11
+ response = post_request("eventsub/subscriptions", body: attributes)
12
+
13
+ EventsubSubscription.new(response.body.dig("data")[0]) if response.success?
14
+ end
15
+
16
+ def delete(id:)
17
+ delete_request("eventsub/subscriptions", params: {id: id})
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ module Twitch
2
+ class UnbanRequestsResource < Resource
3
+
4
+ def list(broadcaster_id:, moderator_id:, status:, **params)
5
+ attrs = {broadcaster_id: broadcaster_id, moderator_id: moderator_id, status: status}
6
+ response = get_request("moderation/unban_requests", params: attrs.merge(params))
7
+ Collection.from_response(response, type: UnbanRequest)
8
+ end
9
+
10
+ def resolve(broadcaster_id:, moderator_id:, id:, status:, **params)
11
+ attrs = {broadcaster_id: broadcaster_id, moderator_id: moderator_id, unban_request_id: id, status: status}
12
+ response = patch_request("moderation/unban_requests", body: attrs.merge(params))
13
+ UnbanRequest.new(response.body.dig("data")[0])
14
+
15
+ end
16
+
17
+ end
18
+ end
@@ -89,5 +89,11 @@ module Twitch
89
89
  end
90
90
  end
91
91
 
92
+ def emotes(user_id:, **params)
93
+ attrs = {user_id: user_id}
94
+ response = get_request("chat/emotes/user", params: attrs.merge(params))
95
+ Collection.from_response(response, type: Emote)
96
+ end
97
+
92
98
  end
93
99
  end
@@ -1,3 +1,3 @@
1
1
  module Twitch
2
- VERSION = "1.2.4"
2
+ VERSION = "1.2.5"
3
3
  end
data/lib/twitch.rb CHANGED
@@ -10,6 +10,8 @@ module Twitch
10
10
  autoload :Resource, "twitch/resource"
11
11
  autoload :Object, "twitch/object"
12
12
 
13
+ autoload :OAuth, "twitch/oauth"
14
+
13
15
 
14
16
  autoload :UsersResource, "twitch/resources/users"
15
17
  autoload :ChannelsResource, "twitch/resources/channels"
@@ -18,7 +20,8 @@ module Twitch
18
20
  autoload :GamesResource, "twitch/resources/games"
19
21
  autoload :VideosResource, "twitch/resources/videos"
20
22
  autoload :ClipsResource, "twitch/resources/clips"
21
- autoload :EventSubSubscriptionsResource, "twitch/resources/event_sub_subscriptions"
23
+ autoload :EventsubSubscriptionsResource, "twitch/resources/eventsub_subscriptions"
24
+ autoload :EventsubConduitsResource, "twitch/resources/eventsub_conduits"
22
25
  autoload :BannedEventsResource, "twitch/resources/banned_events"
23
26
  autoload :BannedUsersResource, "twitch/resources/banned_users"
24
27
  autoload :ModeratorsResource, "twitch/resources/moderators"
@@ -45,6 +48,7 @@ module Twitch
45
48
  autoload :CharityCampaignsResource, "twitch/resources/charity_campaigns"
46
49
  autoload :ChattersResource, "twitch/resources/chatters"
47
50
  autoload :ShoutoutsResource, "twitch/resources/shoutouts"
51
+ autoload :UnbanRequestsResource, "twitch/resources/unban_requests"
48
52
 
49
53
 
50
54
  autoload :User, "twitch/objects/user"
@@ -58,7 +62,9 @@ module Twitch
58
62
  autoload :Game, "twitch/objects/game"
59
63
  autoload :Video, "twitch/objects/video"
60
64
  autoload :Clip, "twitch/objects/clip"
61
- autoload :EventSubSubscription, "twitch/objects/event_sub_subscription"
65
+ autoload :EventsubSubscription, "twitch/objects/eventsub_subscription"
66
+ autoload :EventsubConduit, "twitch/objects/eventsub_conduit"
67
+ autoload :EventsubConduitShard, "twitch/objects/eventsub_conduit_shard"
62
68
  autoload :BannedEvent, "twitch/objects/banned_event"
63
69
  autoload :BannedUser, "twitch/objects/banned_user"
64
70
  autoload :Moderator, "twitch/objects/moderator"
@@ -86,5 +92,6 @@ module Twitch
86
92
  autoload :CharityCampaign, "twitch/objects/charity_campaign"
87
93
  autoload :Chatter, "twitch/objects/chatter"
88
94
  autoload :ChatMessage, "twitch/objects/chat_message"
95
+ autoload :UnbanRequest, "twitch/objects/unban_request"
89
96
 
90
97
  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.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Perry
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-31 00:00:00.000000000 Z
11
+ date: 2024-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -46,6 +46,7 @@ files:
46
46
  - lib/twitch/client.rb
47
47
  - lib/twitch/collection.rb
48
48
  - lib/twitch/error.rb
49
+ - lib/twitch/oauth.rb
49
50
  - lib/twitch/object.rb
50
51
  - lib/twitch/objects/automod_setting.rb
51
52
  - lib/twitch/objects/automod_status.rb
@@ -63,7 +64,9 @@ files:
63
64
  - lib/twitch/objects/custom_reward.rb
64
65
  - lib/twitch/objects/custom_reward_redemption.rb
65
66
  - lib/twitch/objects/emote.rb
66
- - lib/twitch/objects/event_sub_subscription.rb
67
+ - lib/twitch/objects/eventsub_conduit.rb
68
+ - lib/twitch/objects/eventsub_conduit_shard.rb
69
+ - lib/twitch/objects/eventsub_subscription.rb
67
70
  - lib/twitch/objects/follow_count.rb
68
71
  - lib/twitch/objects/followed_user.rb
69
72
  - lib/twitch/objects/game.rb
@@ -81,6 +84,7 @@ files:
81
84
  - lib/twitch/objects/subscription.rb
82
85
  - lib/twitch/objects/subscription_count.rb
83
86
  - lib/twitch/objects/tag.rb
87
+ - lib/twitch/objects/unban_request.rb
84
88
  - lib/twitch/objects/user.rb
85
89
  - lib/twitch/objects/user_color.rb
86
90
  - lib/twitch/objects/video.rb
@@ -100,7 +104,9 @@ files:
100
104
  - lib/twitch/resources/custom_reward_redemptions.rb
101
105
  - lib/twitch/resources/custom_rewards.rb
102
106
  - lib/twitch/resources/emotes.rb
103
- - lib/twitch/resources/event_sub_subscriptions.rb
107
+ - lib/twitch/resources/event_sub_conduit.rb
108
+ - lib/twitch/resources/eventsub_conduits.rb
109
+ - lib/twitch/resources/eventsub_subscriptions.rb
104
110
  - lib/twitch/resources/games.rb
105
111
  - lib/twitch/resources/goals.rb
106
112
  - lib/twitch/resources/hype_train_events.rb
@@ -116,6 +122,7 @@ files:
116
122
  - lib/twitch/resources/streams.rb
117
123
  - lib/twitch/resources/subscriptions.rb
118
124
  - lib/twitch/resources/tags.rb
125
+ - lib/twitch/resources/unban_requests.rb
119
126
  - lib/twitch/resources/users.rb
120
127
  - lib/twitch/resources/videos.rb
121
128
  - lib/twitch/resources/vips.rb
@@ -1,4 +0,0 @@
1
- module Twitch
2
- class EventSubSubscription < Object
3
- end
4
- end