twitchrb 0.2.2 → 0.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 +4 -4
- data/.github/workflows/ci.yml +23 -0
- data/Gemfile.lock +7 -26
- data/README.md +132 -6
- data/lib/twitch/client.rb +0 -1
- data/lib/twitch/objects/follow_count.rb +4 -0
- data/lib/twitch/objects/video.rb +27 -0
- data/lib/twitch/resources/channels.rb +16 -1
- data/lib/twitch/resources/users.rb +2 -2
- data/lib/twitch/version.rb +1 -1
- data/lib/twitch.rb +1 -1
- data/lib/twitchrb.rb +1 -0
- data/twitchrb.gemspec +2 -3
- metadata +10 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aed73c860ea357f7be4fed291738092fc960c84db6196828ed038ffc86485778
|
4
|
+
data.tar.gz: 530134f555c196d49b5262a7fea0519cc8d24ef11998dc413578cb0864816c00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 580f55a88bbd26a32a61d1ff6bd112c11c1c4f81b260c11f0cd482fd105dcb67275c456a1798f5b19ef40627cfd85c554f2bd0adf1dd3fbc0b5a5ad4f73db3cb
|
7
|
+
data.tar.gz: 818cdcbceaa214f65976316ea002113706adfef09163e6fd45e3b8b517e8c5fded02dff5801978a46a13028122c563344b6b63bd20862e348e65d85758902f1f
|
@@ -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.
|
5
|
-
faraday (~>
|
6
|
-
faraday_middleware (~> 1.1)
|
4
|
+
twitchrb (0.2.5)
|
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 (
|
13
|
-
faraday-
|
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.2.0)
|
12
|
+
faraday-net_http (~> 2.0)
|
22
13
|
ruby2_keywords (>= 0.0.4)
|
23
|
-
faraday-
|
24
|
-
|
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.2)
|
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.
|
29
|
+
2.3.5
|
data/README.md
CHANGED
@@ -2,16 +2,14 @@
|
|
2
2
|
|
3
3
|
**This library is a work in progress**
|
4
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.
|
5
|
+
TwitchRB is a Ruby library for intereacting with the Twitch Helix API.
|
8
6
|
|
9
7
|
## Installation
|
10
8
|
|
11
9
|
Add this line to your application's Gemfile:
|
12
10
|
|
13
11
|
```ruby
|
14
|
-
gem "twitchrb"
|
12
|
+
gem "twitchrb"
|
15
13
|
```
|
16
14
|
|
17
15
|
## Usage
|
@@ -23,43 +21,171 @@ Firstly you'll need to set a Client ID, Secret Key and an Access Token.
|
|
23
21
|
An access token is required because the Helix API requires authentication.
|
24
22
|
|
25
23
|
```ruby
|
26
|
-
@client = Twitch::Client.new(client_id: "",
|
24
|
+
@client = Twitch::Client.new(client_id: "", client_secret: "", access_token: "")
|
27
25
|
```
|
28
26
|
|
29
27
|
### Users
|
30
28
|
|
31
29
|
```ruby
|
30
|
+
# Retrieves a user by their ID
|
32
31
|
@client.users.get_by_id(user_id: 141981764)
|
32
|
+
|
33
|
+
# Retrieves a user by their username
|
33
34
|
@client.users.get_by_username(username: "twitchdev")
|
35
|
+
|
36
|
+
# Update the currently authenticated user's description
|
37
|
+
# Required scope: user:edit
|
38
|
+
@client.users.update(description: "New Description")
|
39
|
+
|
40
|
+
# Shows users who follow or are following a user ID
|
41
|
+
@client.users.follows(from_id: 141981764)
|
42
|
+
@client.users.follows(to_id: 141981764)
|
43
|
+
|
44
|
+
# A quick method for seeing if a user is following a channel
|
45
|
+
@client.users.following?(from_id: 141981764, to_id: 141981764)
|
46
|
+
|
47
|
+
# Returns Blocked users for a broadcaster
|
48
|
+
# Required scope: user:read:blocked_users
|
49
|
+
@client.users.blocks(broadcaster_id: 141981764)
|
50
|
+
|
51
|
+
# Blocks a user
|
52
|
+
# Required scope: user:manage:blocked_users
|
53
|
+
@client.users.block_user(target_user_id: 141981764)
|
54
|
+
|
55
|
+
# Unblocks a user
|
56
|
+
# Required scope: user:manage:blocked_users
|
57
|
+
@client.users.unblock_user(target_user_id: 141981764)
|
58
|
+
|
34
59
|
```
|
35
60
|
|
36
61
|
### Channels
|
37
62
|
|
38
63
|
```ruby
|
64
|
+
# Retrieve a channel by their ID
|
39
65
|
@client.channels.get(broadcaster_id: 141981764)
|
66
|
+
|
67
|
+
# Retrieve the number of Followers a broadcaster has
|
68
|
+
@client.channels.follows_count(broadcaster_id: 141981764)
|
69
|
+
|
70
|
+
# Retrieve the number of Subscribers and Subscriber Points a broadcaster has
|
71
|
+
# Required scope: channel:read:subscriptions
|
72
|
+
@client.channels.subscribers_count(broadcaster_id: 141981764)
|
73
|
+
|
74
|
+
# Update the currently authenticated channel details
|
75
|
+
# Required scope: channel:manage:broadcast
|
76
|
+
# Parameters which are allowed: game_id, title, broadcaster_language, delay
|
77
|
+
attributes = {title: "My new title"}
|
78
|
+
@client.channels.update(broadcaster_id: 141981764, attributes)
|
79
|
+
|
80
|
+
# Retrieves editors for a channel
|
81
|
+
@client.channels.editors(broadcaster_id: 141981764)
|
40
82
|
```
|
41
83
|
|
42
84
|
### Videos
|
43
85
|
|
44
86
|
```ruby
|
45
|
-
|
87
|
+
# Retrieves a list of videos
|
88
|
+
# Available parameters: id, user_id or game_id
|
89
|
+
@client.videos.list(id: 12345)
|
90
|
+
@client.videos.list(user_id: 12345)
|
91
|
+
@client.videos.list(game_id: 12345)
|
92
|
+
```
|
93
|
+
|
94
|
+
### Clips
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
# Retrieves a list of clips
|
98
|
+
# Available parameters: id, broadcaster_id or game_id
|
99
|
+
@client.clips.list(id: 12345)
|
100
|
+
@client.clips.list(user_id: 12345)
|
101
|
+
@client.clips.list(game_id: 12345)
|
102
|
+
|
103
|
+
# Retrieves a clip by its ID.
|
104
|
+
# Clip IDs are alphanumeric. e.g. AwkwardHelplessSalamanderSwiftRage
|
105
|
+
@client.clips.retrieve(id: "AwkwardHelplessSalamanderSwiftRage")
|
106
|
+
|
107
|
+
# Create a clip of a given Channel
|
108
|
+
# Required scope: clips:edit
|
109
|
+
@client.clips.create(broadcaster_id: 1234)
|
46
110
|
```
|
47
111
|
|
48
112
|
### Emotes
|
49
113
|
|
50
114
|
```ruby
|
115
|
+
# Retrieve all global emotes
|
51
116
|
@client.emotes.global
|
117
|
+
|
118
|
+
# Retrieve emotes for a channel
|
52
119
|
@client.emotes.channel(broadcaster_id: 141981764)
|
120
|
+
|
121
|
+
# Retrieve emotes for an emote set
|
53
122
|
@client.emotes.sets(emote_set_id: 301590448)
|
54
123
|
```
|
55
124
|
|
56
125
|
### Badges
|
57
126
|
|
58
127
|
```ruby
|
128
|
+
# Retrieve all global badges
|
59
129
|
@client.badges.global
|
130
|
+
|
131
|
+
# Retrieve badges for a channel
|
60
132
|
@client.badges.channel(broadcaster_id: 141981764)
|
61
133
|
```
|
62
134
|
|
135
|
+
### Games
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
# Retrieves a game by its ID
|
139
|
+
@client.games.get_by_id(game_id: 123)
|
140
|
+
|
141
|
+
# Retrieves a game by its Name
|
142
|
+
@client.games.get_by_id(name: "Battlefield 4")
|
143
|
+
|
144
|
+
# Retrieves a list of top games
|
145
|
+
@client.games.top
|
146
|
+
```
|
147
|
+
|
148
|
+
## EventSub Subscriptions
|
149
|
+
|
150
|
+
These require an application OAuth access token.
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
# Retrieves a list of EventSub Subscriptions
|
154
|
+
# Available parameters: status, type, after
|
155
|
+
@client.eventsub_subscriptions.list
|
156
|
+
@client.eventsub_subscriptions.list(status: "enabled")
|
157
|
+
@client.eventsub_subscriptions.list(type: "channel.follow")
|
158
|
+
|
159
|
+
# Create an EventSub Subscription
|
160
|
+
@client.eventsub_subscriptions.create(
|
161
|
+
type: "channel.follow",
|
162
|
+
version: 1,
|
163
|
+
condition: {broadcaster_user_id: 123},
|
164
|
+
transport: {method: "webhook", callback: "webhook_url", secret: "secret"}
|
165
|
+
)
|
166
|
+
|
167
|
+
# Delete an EventSub Subscription
|
168
|
+
# IDs are UUIDs
|
169
|
+
@client.eventsub_subscriptions.delete(id: "abc12-abc12-abc12")
|
170
|
+
```
|
171
|
+
|
172
|
+
## Banned Events
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
# Retrieves all ban and un-ban events for a channel
|
176
|
+
# Available parameters: user_id
|
177
|
+
@client.banned_events.list(broadcaster_id: 123)
|
178
|
+
```
|
179
|
+
|
180
|
+
## Banned Users
|
181
|
+
|
182
|
+
```ruby
|
183
|
+
# Retrieves all banned and timed-out users for a channel
|
184
|
+
# Available parameters: user_id
|
185
|
+
@client.banned_users.list(broadcaster_id: 123)
|
186
|
+
```
|
187
|
+
|
188
|
+
|
63
189
|
## Contributing
|
64
190
|
|
65
191
|
Bug reports and pull requests are welcome on GitHub at https://github.com/twitchrb/twitchrb.
|
data/lib/twitch/client.rb
CHANGED
data/lib/twitch/objects/video.rb
CHANGED
@@ -1,4 +1,31 @@
|
|
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
|
+
|
3
30
|
end
|
4
31
|
end
|
@@ -2,7 +2,22 @@ module Twitch
|
|
2
2
|
class ChannelsResource < Resource
|
3
3
|
|
4
4
|
def get(broadcaster_id:)
|
5
|
-
|
5
|
+
Channel.new get_request("channels?broadcaster_id=#{broadcaster_id}").body.dig("data")[0]
|
6
|
+
end
|
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"])
|
6
21
|
end
|
7
22
|
|
8
23
|
# Requires scope: channel:manage:broadcast
|
@@ -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
|
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
|
9
|
+
User.new get_request("users?login=#{username}").body.dig("data")[0]
|
10
10
|
end
|
11
11
|
|
12
12
|
# Updates the current users description
|
data/lib/twitch/version.rb
CHANGED
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
|
|
@@ -67,5 +66,6 @@ module Twitch
|
|
67
66
|
autoload :CustomRewardRedemption, "twitch/objects/custom_reward_redemption"
|
68
67
|
autoload :Goal, "twitch/objects/goal"
|
69
68
|
autoload :HypeTrainEvent, "twitch/objects/hype_train_event"
|
69
|
+
autoload :FollowCount, "twitch/objects/follow_count"
|
70
70
|
|
71
71
|
end
|
data/lib/twitchrb.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "twitch"
|
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://
|
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", "~>
|
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
|
+
version: 0.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:
|
11
|
+
date: 2022-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -16,28 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
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: '
|
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'
|
26
|
+
version: '2.0'
|
41
27
|
description:
|
42
28
|
email:
|
43
29
|
- dean@deanpcmad.com
|
@@ -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
|
@@ -71,6 +58,7 @@ files:
|
|
71
58
|
- lib/twitch/objects/custom_reward_redemption.rb
|
72
59
|
- lib/twitch/objects/emote.rb
|
73
60
|
- lib/twitch/objects/event_sub_subscription.rb
|
61
|
+
- lib/twitch/objects/follow_count.rb
|
74
62
|
- lib/twitch/objects/followed_user.rb
|
75
63
|
- lib/twitch/objects/game.rb
|
76
64
|
- lib/twitch/objects/goal.rb
|
@@ -114,12 +102,13 @@ files:
|
|
114
102
|
- lib/twitch/resources/users.rb
|
115
103
|
- lib/twitch/resources/videos.rb
|
116
104
|
- lib/twitch/version.rb
|
105
|
+
- lib/twitchrb.rb
|
117
106
|
- twitchrb.gemspec
|
118
|
-
homepage: https://
|
107
|
+
homepage: https://deanpcmad.com
|
119
108
|
licenses:
|
120
109
|
- MIT
|
121
110
|
metadata:
|
122
|
-
homepage_uri: https://
|
111
|
+
homepage_uri: https://deanpcmad.com
|
123
112
|
source_code_uri: https://github.com/deanpcmad/twitchrb
|
124
113
|
post_install_message:
|
125
114
|
rdoc_options: []
|
@@ -136,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
125
|
- !ruby/object:Gem::Version
|
137
126
|
version: '0'
|
138
127
|
requirements: []
|
139
|
-
rubygems_version: 3.
|
128
|
+
rubygems_version: 3.2.22
|
140
129
|
signing_key:
|
141
130
|
specification_version: 4
|
142
131
|
summary: A Ruby library for interacting with the Twitch Helix API
|