twitchrb 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 828f7c0543e796014befead46a15222e41a9c775ea7baa4d4cd346e674777dd8
4
- data.tar.gz: 2a9a88da2bf52a0362c24d38201806545d0483a36217f14ed30f120c89664f88
3
+ metadata.gz: 62be7346346cf921307a581b64b68bd364342b81a93e334b4fbf1ffd8198b6c2
4
+ data.tar.gz: 6d4a106e899173699181fd01e0be36d2461287b6c8520d83293421a2e6a5704c
5
5
  SHA512:
6
- metadata.gz: 3a0695cf7d5600a1c171f43ff1fae6ba39c2242ddd5092d7e04c1c234c03a9ca00f9f2c51036a685a6d08356bc5fb5f9cdabb2e150ecd9854962074f69df75a1
7
- data.tar.gz: be4161b6cdc5f83c6169fc49733146c1c3fc210b43be9b8823fbd0f8e4b97dc42c1d722b5d8b01bf98623498b367318779f94f790b9cfc2c99cb125697310889
6
+ metadata.gz: aa82df2fb8d72bfd37b36abfaa51c01bc0159ff764fa2f2f7da927b04166bb4d3b5fbe1023cd3d8a0a36689d39707743d9b2c1fcffe1615de2606a739cf4685b
7
+ data.tar.gz: 18faf9bc25f3d9d98910434835d73c02e5f0acd3a942639ee72ae0759b07c0b8f2035d56b11486c27b50e2fbb16292ad8d99002f3a1236160ef950a4829422ef
@@ -7,12 +7,12 @@ jobs:
7
7
  fail-fast: false
8
8
  matrix:
9
9
  ruby_version:
10
- - 2.6
11
10
  - 2.7
12
11
  - 3.0
13
12
  - 3.1
13
+ - 3.2
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.0)
5
5
  faraday (~> 2.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ base64 (0.1.1)
10
11
  dotenv (2.7.6)
11
- faraday (2.7.4)
12
+ faraday (2.7.11)
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
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
@@ -291,7 +298,7 @@ These require an application OAuth access token.
291
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
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,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.0"
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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Perry
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-21 00:00:00.000000000 Z
11
+ date: 2023-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
- description:
27
+ description:
28
28
  email:
29
29
  - dean@deanpcmad.com
30
30
  executables: []
@@ -128,7 +128,7 @@ licenses:
128
128
  metadata:
129
129
  homepage_uri: https://deanpcmad.com
130
130
  source_code_uri: https://github.com/deanpcmad/twitchrb
131
- post_install_message:
131
+ post_install_message:
132
132
  rdoc_options: []
133
133
  require_paths:
134
134
  - lib
@@ -143,8 +143,8 @@ 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
147
- signing_key:
146
+ rubygems_version: 3.4.10
147
+ signing_key:
148
148
  specification_version: 4
149
149
  summary: A Ruby library for interacting with the Twitch Helix API
150
150
  test_files: []