twitchrb 1.2.6 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +15 -2
- data/.rubocop.yml +8 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +70 -2
- data/README.md +53 -2
- data/Rakefile +1 -1
- data/lib/twitch/client.rb +5 -5
- data/lib/twitch/collection.rb +12 -0
- data/lib/twitch/oauth.rb +3 -5
- data/lib/twitch/object.rb +1 -1
- data/lib/twitch/objects/warning.rb +4 -0
- data/lib/twitch/resources/announcements.rb +1 -3
- data/lib/twitch/resources/automod.rb +4 -6
- data/lib/twitch/resources/badges.rb +0 -2
- data/lib/twitch/resources/banned_events.rb +0 -2
- data/lib/twitch/resources/banned_users.rb +1 -3
- data/lib/twitch/resources/blocked_terms.rb +2 -4
- data/lib/twitch/resources/channels.rb +2 -4
- data/lib/twitch/resources/charity_campaigns.rb +1 -3
- data/lib/twitch/resources/chat_messages.rb +1 -3
- data/lib/twitch/resources/chatters.rb +1 -3
- data/lib/twitch/resources/clips.rb +1 -3
- data/lib/twitch/resources/custom_reward_redemptions.rb +2 -4
- data/lib/twitch/resources/custom_rewards.rb +3 -5
- data/lib/twitch/resources/emotes.rb +0 -2
- data/lib/twitch/resources/event_sub_conduit.rb +2 -4
- data/lib/twitch/resources/eventsub_conduits.rb +5 -7
- data/lib/twitch/resources/eventsub_subscriptions.rb +2 -4
- data/lib/twitch/resources/games.rb +5 -7
- data/lib/twitch/resources/goals.rb +1 -3
- data/lib/twitch/resources/hype_train_events.rb +1 -3
- data/lib/twitch/resources/moderator_events.rb +0 -2
- data/lib/twitch/resources/moderators.rb +2 -4
- data/lib/twitch/resources/polls.rb +2 -4
- data/lib/twitch/resources/predictions.rb +2 -4
- data/lib/twitch/resources/raids.rb +1 -3
- data/lib/twitch/resources/search.rb +0 -2
- data/lib/twitch/resources/shoutouts.rb +0 -2
- data/lib/twitch/resources/stream_markers.rb +0 -2
- data/lib/twitch/resources/stream_schedule.rb +5 -7
- data/lib/twitch/resources/streams.rb +0 -2
- data/lib/twitch/resources/subscriptions.rb +2 -4
- data/lib/twitch/resources/tags.rb +0 -2
- data/lib/twitch/resources/unban_requests.rb +2 -5
- data/lib/twitch/resources/users.rb +9 -11
- data/lib/twitch/resources/videos.rb +1 -3
- data/lib/twitch/resources/vips.rb +1 -3
- data/lib/twitch/resources/warnings.rb +12 -0
- data/lib/twitch/resources/whispers.rb +1 -3
- data/lib/twitch/version.rb +1 -1
- data/lib/twitch.rb +2 -2
- data/lib/twitchrb.rb +1 -1
- data/twitchrb.gemspec +3 -3
- metadata +5 -2
@@ -1,21 +1,19 @@
|
|
1
1
|
module Twitch
|
2
2
|
class EventSubSubscriptionsResource < Resource
|
3
|
-
|
4
3
|
def list(**params)
|
5
4
|
response = get_request("eventsub/subscriptions", params: params)
|
6
5
|
Collection.from_response(response, type: EventSubSubscription)
|
7
6
|
end
|
8
7
|
|
9
8
|
def create(type:, version:, condition:, transport:, **params)
|
10
|
-
attributes = {type: type, version: version, condition: condition, transport: transport}.merge(params)
|
9
|
+
attributes = { type: type, version: version, condition: condition, transport: transport }.merge(params)
|
11
10
|
response = post_request("eventsub/subscriptions", body: attributes)
|
12
11
|
|
13
12
|
EventSubSubscription.new(response.body.dig("data")[0]) if response.success?
|
14
13
|
end
|
15
14
|
|
16
15
|
def delete(id:)
|
17
|
-
delete_request("eventsub/subscriptions", params: {id: id})
|
16
|
+
delete_request("eventsub/subscriptions", params: { id: id })
|
18
17
|
end
|
19
|
-
|
20
18
|
end
|
21
19
|
end
|
@@ -1,36 +1,34 @@
|
|
1
1
|
module Twitch
|
2
2
|
class EventsubConduitsResource < Resource
|
3
|
-
|
4
3
|
def list(**params)
|
5
4
|
response = get_request("eventsub/conduits", params: params)
|
6
5
|
Collection.from_response(response, type: EventsubConduit)
|
7
6
|
end
|
8
7
|
|
9
8
|
def create(shard_count:)
|
10
|
-
response = post_request("eventsub/conduits", body: {shard_count: shard_count})
|
9
|
+
response = post_request("eventsub/conduits", body: { shard_count: shard_count })
|
11
10
|
|
12
11
|
EventsubConduit.new(response.body.dig("data")[0]) if response.success?
|
13
12
|
end
|
14
13
|
|
15
14
|
def update(id:, shard_count:)
|
16
|
-
response = patch_request("eventsub/conduits", body: {id: id, shard_count: shard_count})
|
15
|
+
response = patch_request("eventsub/conduits", body: { id: id, shard_count: shard_count })
|
17
16
|
|
18
17
|
EventsubConduit.new(response.body.dig("data")[0]) if response.success?
|
19
18
|
end
|
20
19
|
|
21
20
|
def delete(id:)
|
22
|
-
delete_request("eventsub/conduits", params: {id: id})
|
21
|
+
delete_request("eventsub/conduits", params: { id: id })
|
23
22
|
end
|
24
23
|
|
25
24
|
def shards(id:, **params)
|
26
|
-
response = get_request("eventsub/conduits/shards", params: {conduit_id: id}.merge(params))
|
25
|
+
response = get_request("eventsub/conduits/shards", params: { conduit_id: id }.merge(params))
|
27
26
|
Collection.from_response(response, type: EventsubConduitShard)
|
28
27
|
end
|
29
28
|
|
30
29
|
def update_shards(id:, shards:)
|
31
|
-
response = patch_request("eventsub/conduits/shards", body: {conduit_id: id, shards: shards})
|
30
|
+
response = patch_request("eventsub/conduits/shards", body: { conduit_id: id, shards: shards })
|
32
31
|
Collection.from_response(response, type: EventsubConduitShard)
|
33
32
|
end
|
34
|
-
|
35
33
|
end
|
36
34
|
end
|
@@ -1,21 +1,19 @@
|
|
1
1
|
module Twitch
|
2
2
|
class EventsubSubscriptionsResource < Resource
|
3
|
-
|
4
3
|
def list(**params)
|
5
4
|
response = get_request("eventsub/subscriptions", params: params)
|
6
5
|
Collection.from_response(response, type: EventsubSubscription)
|
7
6
|
end
|
8
7
|
|
9
8
|
def create(type:, version:, condition:, transport:, **params)
|
10
|
-
attributes = {type: type, version: version, condition: condition, transport: transport}.merge(params)
|
9
|
+
attributes = { type: type, version: version, condition: condition, transport: transport }.merge(params)
|
11
10
|
response = post_request("eventsub/subscriptions", body: attributes)
|
12
11
|
|
13
12
|
EventsubSubscription.new(response.body.dig("data")[0]) if response.success?
|
14
13
|
end
|
15
14
|
|
16
15
|
def delete(id:)
|
17
|
-
delete_request("eventsub/subscriptions", params: {id: id})
|
16
|
+
delete_request("eventsub/subscriptions", params: { id: id })
|
18
17
|
end
|
19
|
-
|
20
18
|
end
|
21
19
|
end
|
@@ -1,17 +1,16 @@
|
|
1
1
|
module Twitch
|
2
2
|
class GamesResource < Resource
|
3
|
-
|
4
3
|
def retrieve(id: nil, ids: nil, name: nil, names: nil)
|
5
4
|
raise "Either id, ids, name or names is required" unless !id.nil? || !ids.nil? || !name.nil? || !names.nil?
|
6
5
|
|
7
6
|
if id
|
8
|
-
response = get_request("games", params: {id: id})
|
7
|
+
response = get_request("games", params: { id: id })
|
9
8
|
elsif ids
|
10
|
-
response = get_request("games", params: {id: ids})
|
9
|
+
response = get_request("games", params: { id: ids })
|
11
10
|
elsif names
|
12
|
-
response = get_request("games", params: {name: names})
|
11
|
+
response = get_request("games", params: { name: names })
|
13
12
|
else
|
14
|
-
response = get_request("games", params: {name: name})
|
13
|
+
response = get_request("games", params: { name: name })
|
15
14
|
end
|
16
15
|
|
17
16
|
body = response.body.dig("data")
|
@@ -20,7 +19,7 @@ module Twitch
|
|
20
19
|
elsif ids || names && body.count > 1
|
21
20
|
Collection.from_response(response, type: Game)
|
22
21
|
else
|
23
|
-
|
22
|
+
nil
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
@@ -28,6 +27,5 @@ module Twitch
|
|
28
27
|
response = get_request("games/top", params: params)
|
29
28
|
Collection.from_response(response, type: Game)
|
30
29
|
end
|
31
|
-
|
32
30
|
end
|
33
31
|
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
module Twitch
|
2
2
|
class GoalsResource < Resource
|
3
|
-
|
4
3
|
# Required scope: channel:read:goals
|
5
4
|
# Broadcaster ID must match the user in the OAuth token
|
6
5
|
def list(broadcaster_id:)
|
7
|
-
response = get_request("goals", params: {broadcaster_id: broadcaster_id})
|
6
|
+
response = get_request("goals", params: { broadcaster_id: broadcaster_id })
|
8
7
|
Collection.from_response(response, type: Goal)
|
9
8
|
end
|
10
|
-
|
11
9
|
end
|
12
10
|
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
module Twitch
|
2
2
|
class HypeTrainEventsResource < Resource
|
3
|
-
|
4
3
|
# Required scope: channel:read:hype_train
|
5
4
|
# Broadcaster ID must match the user in the OAuth token
|
6
5
|
def list(broadcaster_id:)
|
7
|
-
response = get_request("hypetrain/events", params: {broadcaster_id: broadcaster_id})
|
6
|
+
response = get_request("hypetrain/events", params: { broadcaster_id: broadcaster_id })
|
8
7
|
Collection.from_response(response, type: HypeTrainEvent)
|
9
8
|
end
|
10
|
-
|
11
9
|
end
|
12
10
|
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
module Twitch
|
2
2
|
class ModeratorEventsResource < 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/moderators/events", params: params.merge(broadcaster_id: broadcaster_id))
|
7
6
|
Collection.from_response(response, type: ModeratorEvent)
|
8
7
|
end
|
9
|
-
|
10
8
|
end
|
11
9
|
end
|
@@ -1,9 +1,8 @@
|
|
1
1
|
module Twitch
|
2
2
|
class ModeratorsResource < Resource
|
3
|
-
|
4
3
|
# User ID must match the user in the OAuth token
|
5
4
|
def channels(user_id:)
|
6
|
-
response = get_request("moderation/channels", params: {user_id: user_id})
|
5
|
+
response = get_request("moderation/channels", params: { user_id: user_id })
|
7
6
|
Collection.from_response(response, type: Channel)
|
8
7
|
end
|
9
8
|
|
@@ -14,12 +13,11 @@ module Twitch
|
|
14
13
|
end
|
15
14
|
|
16
15
|
def create(broadcaster_id:, user_id:)
|
17
|
-
post_request("moderation/moderators", body: {broadcaster_id: broadcaster_id, user_id: user_id})
|
16
|
+
post_request("moderation/moderators", body: { broadcaster_id: broadcaster_id, user_id: user_id })
|
18
17
|
end
|
19
18
|
|
20
19
|
def delete(broadcaster_id:, user_id:)
|
21
20
|
delete_request("moderation/moderators?broadcaster_id=#{broadcaster_id}&user_id=#{user_id}")
|
22
21
|
end
|
23
|
-
|
24
22
|
end
|
25
23
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Twitch
|
2
2
|
class PollsResource < 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("polls", params: params.merge(broadcaster_id: broadcaster_id))
|
@@ -9,7 +8,7 @@ module Twitch
|
|
9
8
|
|
10
9
|
# Broadcaster ID must match the user in the OAuth token
|
11
10
|
def create(broadcaster_id:, title:, choices:, duration:, **params)
|
12
|
-
attrs = {broadcaster_id: broadcaster_id, title: title, choices: choices, duration: duration}
|
11
|
+
attrs = { broadcaster_id: broadcaster_id, title: title, choices: choices, duration: duration }
|
13
12
|
response = post_request("polls", body: attrs.merge(params))
|
14
13
|
|
15
14
|
Poll.new(response.body.dig("data")[0]) if response.success?
|
@@ -17,11 +16,10 @@ module Twitch
|
|
17
16
|
|
18
17
|
# Broadcaster ID must match the user in the OAuth token
|
19
18
|
def end(broadcaster_id:, id:, status:)
|
20
|
-
attrs = {broadcaster_id: broadcaster_id, id: id, status: status.upcase}
|
19
|
+
attrs = { broadcaster_id: broadcaster_id, id: id, status: status.upcase }
|
21
20
|
response = patch_request("polls", body: attrs)
|
22
21
|
|
23
22
|
Poll.new(response.body.dig("data")[0]) if response.success?
|
24
23
|
end
|
25
|
-
|
26
24
|
end
|
27
25
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Twitch
|
2
2
|
class PredictionsResource < 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("predictions", params: params.merge(broadcaster_id: broadcaster_id))
|
@@ -14,7 +13,7 @@ module Twitch
|
|
14
13
|
|
15
14
|
# Broadcaster ID must match the user in the OAuth token
|
16
15
|
def create(broadcaster_id:, title:, outcomes:, duration:, **params)
|
17
|
-
attrs = {broadcaster_id: broadcaster_id, title: title, outcomes: outcomes, prediction_window: duration}
|
16
|
+
attrs = { broadcaster_id: broadcaster_id, title: title, outcomes: outcomes, prediction_window: duration }
|
18
17
|
response = post_request("predictions", body: attrs.merge(params))
|
19
18
|
|
20
19
|
Prediction.new(response.body.dig("data")[0]) if response.success?
|
@@ -22,11 +21,10 @@ module Twitch
|
|
22
21
|
|
23
22
|
# Broadcaster ID must match the user in the OAuth token
|
24
23
|
def end(broadcaster_id:, id:, status:, **params)
|
25
|
-
attrs = {broadcaster_id: broadcaster_id, id: id, status: status.upcase}
|
24
|
+
attrs = { broadcaster_id: broadcaster_id, id: id, status: status.upcase }
|
26
25
|
response = patch_request("predictions", body: attrs.merge(params))
|
27
26
|
|
28
27
|
Prediction.new(response.body.dig("data")[0]) if response.success?
|
29
28
|
end
|
30
|
-
|
31
29
|
end
|
32
30
|
end
|
@@ -1,9 +1,8 @@
|
|
1
1
|
module Twitch
|
2
2
|
class RaidsResource < Resource
|
3
|
-
|
4
3
|
# from_broadcaster_id must match the user in the OAuth token
|
5
4
|
def create(from_broadcaster_id:, to_broadcaster_id:)
|
6
|
-
attrs = {from_broadcaster_id: from_broadcaster_id, to_broadcaster_id: to_broadcaster_id}
|
5
|
+
attrs = { from_broadcaster_id: from_broadcaster_id, to_broadcaster_id: to_broadcaster_id }
|
7
6
|
|
8
7
|
response = post_request("raids", body: attrs)
|
9
8
|
|
@@ -14,6 +13,5 @@ module Twitch
|
|
14
13
|
def delete(broadcaster_id:)
|
15
14
|
delete_request("raids?broadcaster_id=#{broadcaster_id}")
|
16
15
|
end
|
17
|
-
|
18
16
|
end
|
19
17
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Twitch
|
2
2
|
class SearchResource < Resource
|
3
|
-
|
4
3
|
def categories(query:, **params)
|
5
4
|
response = get_request("search/categories", params: params.merge(query: query))
|
6
5
|
|
@@ -12,6 +11,5 @@ module Twitch
|
|
12
11
|
|
13
12
|
Collection.from_response(response, type: SearchResult)
|
14
13
|
end
|
15
|
-
|
16
14
|
end
|
17
15
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Twitch
|
2
2
|
class ShoutoutsResource < Resource
|
3
|
-
|
4
3
|
# Moderator ID must match the user in the OAuth token
|
5
4
|
# From: the ID of the Broadcaster creating the Shoutout
|
6
5
|
# To: the ID of the Broadcaster the Shoutout will be for
|
@@ -8,6 +7,5 @@ module Twitch
|
|
8
7
|
def create(from:, to:, moderator_id:)
|
9
8
|
post_request("chat/shoutouts?from_broadcaster_id=#{from}&to_broadcaster_id=#{to}&moderator_id=#{moderator_id}", body: nil)
|
10
9
|
end
|
11
|
-
|
12
10
|
end
|
13
11
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Twitch
|
2
2
|
class StreamMarkersResource < Resource
|
3
|
-
|
4
3
|
# Required scope: user:read:broadcast
|
5
4
|
def list(**params)
|
6
5
|
response = get_request("streams/markers", params: params)
|
@@ -14,6 +13,5 @@ module Twitch
|
|
14
13
|
|
15
14
|
StreamMarker.new(response.body.dig("data")[0]) if response.success?
|
16
15
|
end
|
17
|
-
|
18
16
|
end
|
19
17
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Twitch
|
2
2
|
class StreamScheduleResource < 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("schedule", params: params.merge(broadcaster_id: broadcaster_id))
|
@@ -10,7 +9,7 @@ module Twitch
|
|
10
9
|
|
11
10
|
# Broadcaster ID must match the user in the OAuth token
|
12
11
|
def icalendar(broadcaster_id:)
|
13
|
-
response = get_request("schedule/icalendar", params: {broadcaster_id: broadcaster_id})
|
12
|
+
response = get_request("schedule/icalendar", params: { broadcaster_id: broadcaster_id })
|
14
13
|
|
15
14
|
response.body
|
16
15
|
end
|
@@ -23,7 +22,7 @@ module Twitch
|
|
23
22
|
|
24
23
|
# Broadcaster ID must match the user in the OAuth token
|
25
24
|
def create_segment(broadcaster_id:, start_time:, timezone:, duration:, is_recurring:, **params)
|
26
|
-
attrs = {broadcaster_id: broadcaster_id, start_time: start_time, duration: duration, timezone: timezone, is_recurring: is_recurring}
|
25
|
+
attrs = { broadcaster_id: broadcaster_id, start_time: start_time, duration: duration, timezone: timezone, is_recurring: is_recurring }
|
27
26
|
response = post_request("schedule/segment", body: attrs.merge(params))
|
28
27
|
|
29
28
|
StreamSchedule.new(response.body) if response.success?
|
@@ -31,7 +30,7 @@ module Twitch
|
|
31
30
|
|
32
31
|
# Broadcaster ID must match the user in the OAuth token
|
33
32
|
def update_segment(broadcaster_id:, id:, **params)
|
34
|
-
attrs = {broadcaster_id: broadcaster_id, id: id}
|
33
|
+
attrs = { broadcaster_id: broadcaster_id, id: id }
|
35
34
|
response = patch_request("schedule/segment", body: attrs.merge(params))
|
36
35
|
|
37
36
|
StreamSchedule.new(response.body) if response.success?
|
@@ -39,9 +38,8 @@ module Twitch
|
|
39
38
|
|
40
39
|
# Broadcaster ID must match the user in the OAuth token
|
41
40
|
def delete_segment(broadcaster_id:, id:)
|
42
|
-
attrs = {broadcaster_id: broadcaster_id, id: id}
|
41
|
+
attrs = { broadcaster_id: broadcaster_id, id: id }
|
43
42
|
delete_request("schedule/segment", params: attrs)
|
44
|
-
end
|
45
|
-
|
43
|
+
end
|
46
44
|
end
|
47
45
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Twitch
|
2
2
|
class SubscriptionsResource < Resource
|
3
|
-
|
4
3
|
# Get all subscriptions for a broadcaster
|
5
4
|
# Broadcaster ID must match the user in the OAuth token
|
6
5
|
# Required scope: channel:read:subscriptions
|
@@ -14,7 +13,7 @@ module Twitch
|
|
14
13
|
# User ID must match the user in the OAuth token
|
15
14
|
# Required scope: user:read:subscriptions
|
16
15
|
def is_subscribed(broadcaster_id:, user_id:, **params)
|
17
|
-
attrs = {broadcaster_id: broadcaster_id, user_id: user_id}
|
16
|
+
attrs = { broadcaster_id: broadcaster_id, user_id: user_id }
|
18
17
|
response = get_request("subscriptions/user", params: attrs.merge(params))
|
19
18
|
Collection.from_response(response, type: Subscription)
|
20
19
|
end
|
@@ -23,10 +22,9 @@ module Twitch
|
|
23
22
|
# Broadcaster ID must match the user in the OAuth token
|
24
23
|
# Required scope: channel:read:subscriptions
|
25
24
|
def counts(broadcaster_id:)
|
26
|
-
response = get_request("subscriptions", params: {broadcaster_id: broadcaster_id})
|
25
|
+
response = get_request("subscriptions", params: { broadcaster_id: broadcaster_id })
|
27
26
|
|
28
27
|
SubscriptionCount.new(count: response.body["total"], points: response.body["points"])
|
29
28
|
end
|
30
|
-
|
31
29
|
end
|
32
30
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Twitch
|
2
2
|
class TagsResource < Resource
|
3
|
-
|
4
3
|
def list(**params)
|
5
4
|
response = get_request("tags/streams", params: params)
|
6
5
|
Collection.from_response(response, type: Tag)
|
@@ -15,6 +14,5 @@ module Twitch
|
|
15
14
|
def replace(broadcaster_id:, **params)
|
16
15
|
put_request("streams/tags", body: params.merge(broadcaster_id: broadcaster_id))
|
17
16
|
end
|
18
|
-
|
19
17
|
end
|
20
18
|
end
|
@@ -1,18 +1,15 @@
|
|
1
1
|
module Twitch
|
2
2
|
class UnbanRequestsResource < Resource
|
3
|
-
|
4
3
|
def list(broadcaster_id:, moderator_id:, status:, **params)
|
5
|
-
attrs = {broadcaster_id: broadcaster_id, moderator_id: moderator_id, status: status}
|
4
|
+
attrs = { broadcaster_id: broadcaster_id, moderator_id: moderator_id, status: status }
|
6
5
|
response = get_request("moderation/unban_requests", params: attrs.merge(params))
|
7
6
|
Collection.from_response(response, type: UnbanRequest)
|
8
7
|
end
|
9
8
|
|
10
9
|
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}
|
10
|
+
attrs = { broadcaster_id: broadcaster_id, moderator_id: moderator_id, unban_request_id: id, status: status }
|
12
11
|
response = patch_request("moderation/unban_requests", body: attrs.merge(params))
|
13
12
|
UnbanRequest.new(response.body.dig("data")[0])
|
14
|
-
|
15
13
|
end
|
16
|
-
|
17
14
|
end
|
18
15
|
end
|
@@ -1,17 +1,16 @@
|
|
1
1
|
module Twitch
|
2
2
|
class UsersResource < Resource
|
3
|
-
|
4
3
|
def retrieve(id: nil, ids: nil, username: nil, usernames: nil)
|
5
4
|
raise "Either id, ids, username or usernames is required" unless !id.nil? || !ids.nil? || !username.nil? || !usernames.nil?
|
6
5
|
|
7
6
|
if id
|
8
|
-
response = get_request("users", params: {id: id})
|
7
|
+
response = get_request("users", params: { id: id })
|
9
8
|
elsif ids
|
10
|
-
response = get_request("users", params: {id: ids})
|
9
|
+
response = get_request("users", params: { id: ids })
|
11
10
|
elsif usernames
|
12
|
-
response = get_request("users", params: {login: usernames})
|
11
|
+
response = get_request("users", params: { login: usernames })
|
13
12
|
else
|
14
|
-
response = get_request("users", params: {login: username})
|
13
|
+
response = get_request("users", params: { login: username })
|
15
14
|
end
|
16
15
|
|
17
16
|
body = response.body.dig("data")
|
@@ -20,20 +19,20 @@ module Twitch
|
|
20
19
|
elsif ids || usernames && body.count > 1
|
21
20
|
Collection.from_response(response, type: User)
|
22
21
|
else
|
23
|
-
|
22
|
+
nil
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
27
26
|
# Updates the current users description
|
28
27
|
# Required scope: user:edit
|
29
28
|
def update(description:)
|
30
|
-
response = put_request("users", body: {description: description})
|
29
|
+
response = put_request("users", body: { description: description })
|
31
30
|
User.new response.body.dig("data")[0]
|
32
31
|
end
|
33
32
|
|
34
33
|
def get_color(user_id: nil, user_ids: nil)
|
35
34
|
if user_ids != nil
|
36
|
-
users = user_ids.split(",").map{|i| "user_id=#{i.strip}"}.join("&")
|
35
|
+
users = user_ids.split(",").map { |i| "user_id=#{i.strip}" }.join("&")
|
37
36
|
puts "chat/color?#{users}"
|
38
37
|
response = get_request("chat/color?#{users}")
|
39
38
|
Collection.from_response(response, type: UserColor)
|
@@ -80,7 +79,7 @@ module Twitch
|
|
80
79
|
def following?(from_id:, to_id:)
|
81
80
|
warn "`users.following?` is deprecated. Use `channels.followers` or `channels.following` instead."
|
82
81
|
|
83
|
-
response = get_request("users/follows", params: {from_id: from_id, to_id: to_id})
|
82
|
+
response = get_request("users/follows", params: { from_id: from_id, to_id: to_id })
|
84
83
|
|
85
84
|
if response.body["data"].empty?
|
86
85
|
false
|
@@ -90,10 +89,9 @@ module Twitch
|
|
90
89
|
end
|
91
90
|
|
92
91
|
def emotes(user_id:, **params)
|
93
|
-
attrs = {user_id: user_id}
|
92
|
+
attrs = { user_id: user_id }
|
94
93
|
response = get_request("chat/emotes/user", params: attrs.merge(params))
|
95
94
|
Collection.from_response(response, type: Emote)
|
96
95
|
end
|
97
|
-
|
98
96
|
end
|
99
97
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Twitch
|
2
2
|
class VideosResource < Resource
|
3
|
-
|
4
3
|
def list(**params)
|
5
4
|
raise "user_id or game_id is required" unless !params[:user_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
|
-
response = get_request("videos", params: {id: id})
|
11
|
+
response = get_request("videos", params: { id: id })
|
13
12
|
if response.body
|
14
13
|
Video.new response.body["data"].first
|
15
14
|
end
|
@@ -19,6 +18,5 @@ module Twitch
|
|
19
18
|
def delete(video_id:)
|
20
19
|
delete_request("videos?id=#{video_id}")
|
21
20
|
end
|
22
|
-
|
23
21
|
end
|
24
22
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Twitch
|
2
2
|
class VipsResource < 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("channels/vips", params: params.merge(broadcaster_id: broadcaster_id))
|
@@ -8,12 +7,11 @@ module Twitch
|
|
8
7
|
end
|
9
8
|
|
10
9
|
def create(broadcaster_id:, user_id:)
|
11
|
-
post_request("channels/vips", body: {broadcaster_id: broadcaster_id, user_id: user_id})
|
10
|
+
post_request("channels/vips", body: { broadcaster_id: broadcaster_id, user_id: user_id })
|
12
11
|
end
|
13
12
|
|
14
13
|
def delete(broadcaster_id:, user_id:)
|
15
14
|
delete_request("channels/vips?broadcaster_id=#{broadcaster_id}&user_id=#{user_id}")
|
16
15
|
end
|
17
|
-
|
18
16
|
end
|
19
17
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Twitch
|
2
|
+
class WarningsResource < Resource
|
3
|
+
# Moderator ID must match the user in the OAuth token
|
4
|
+
# Required scope: moderator:manage:warnings
|
5
|
+
def create(broadcaster_id:, moderator_id:, user_id:, reason:)
|
6
|
+
attrs = { user_id: user_id, reason: reason }
|
7
|
+
|
8
|
+
response = post_request("moderation/warnings?broadcaster_id=#{broadcaster_id}&moderator_id=#{moderator_id}", body: { data: attrs })
|
9
|
+
Collection.from_response(response, type: Warning)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
module Twitch
|
2
2
|
class WhispersResource < Resource
|
3
|
-
|
4
3
|
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})
|
4
|
+
post_request("whispers", body: { from_user_id: from_user_id, to_user_id: to_user_id, message: message })
|
6
5
|
end
|
7
|
-
|
8
6
|
end
|
9
7
|
end
|
data/lib/twitch/version.rb
CHANGED
data/lib/twitch.rb
CHANGED
@@ -3,7 +3,6 @@ require "json"
|
|
3
3
|
require "twitch/version"
|
4
4
|
|
5
5
|
module Twitch
|
6
|
-
|
7
6
|
autoload :Client, "twitch/client"
|
8
7
|
autoload :Collection, "twitch/collection"
|
9
8
|
autoload :Error, "twitch/error"
|
@@ -49,6 +48,7 @@ module Twitch
|
|
49
48
|
autoload :ChattersResource, "twitch/resources/chatters"
|
50
49
|
autoload :ShoutoutsResource, "twitch/resources/shoutouts"
|
51
50
|
autoload :UnbanRequestsResource, "twitch/resources/unban_requests"
|
51
|
+
autoload :WarningsResource, "twitch/resources/warnings"
|
52
52
|
|
53
53
|
|
54
54
|
autoload :User, "twitch/objects/user"
|
@@ -93,5 +93,5 @@ module Twitch
|
|
93
93
|
autoload :Chatter, "twitch/objects/chatter"
|
94
94
|
autoload :ChatMessage, "twitch/objects/chat_message"
|
95
95
|
autoload :UnbanRequest, "twitch/objects/unban_request"
|
96
|
-
|
96
|
+
autoload :Warning, "twitch/objects/warning"
|
97
97
|
end
|
data/lib/twitchrb.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require "twitch"
|
1
|
+
require "twitch"
|
data/twitchrb.gemspec
CHANGED
@@ -3,8 +3,8 @@ require_relative 'lib/twitch/version'
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "twitchrb"
|
5
5
|
spec.version = Twitch::VERSION
|
6
|
-
spec.authors = ["Dean Perry"]
|
7
|
-
spec.email = ["dean@deanpcmad.com"]
|
6
|
+
spec.authors = [ "Dean Perry" ]
|
7
|
+
spec.email = [ "dean@deanpcmad.com" ]
|
8
8
|
|
9
9
|
spec.summary = "A Ruby library for interacting with the Twitch Helix API"
|
10
10
|
spec.homepage = "https://deanpcmad.com"
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
end
|
23
23
|
spec.bindir = "exe"
|
24
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
-
spec.require_paths = ["lib"]
|
25
|
+
spec.require_paths = [ "lib" ]
|
26
26
|
|
27
27
|
spec.add_dependency "faraday", "~> 2.0"
|
28
28
|
end
|