twitchrb 0.2.3 → 0.2.6

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: daefb5be94569e5fc14f586f740c4d469f4e76b60fc2b066870f2f55748b678f
4
- data.tar.gz: e3ad55b7bc2fd6b9fa8d0453136b69b9ce25612cdd945114173a0b03a4026285
3
+ metadata.gz: 0d886e0f7218418d1e253a5cbbf8734d8d30e03294ac99c1a3d20bc9f7bac58d
4
+ data.tar.gz: 2492fff4fdaf14a44060a085f02053963ab840745a5e7257bd128e6a637f1107
5
5
  SHA512:
6
- metadata.gz: 6d0c1fc6409e6878d840b75b502310a22891a7bb3e0ebf0de74362f9996cd6703624f0e4a280024b4659a1c6c8b0e45c6d7d70fab09d6d82ccdff6963d1a93ed
7
- data.tar.gz: a1218538954e97ee5c06115dcc3925312f705e5b835074a0f536806eff4822f7b6e08c1739ddf9be18a01420b6511bbbb794f298b2fb734d207c8d58d929695c
6
+ metadata.gz: 52834e38179f6ee69af7abc21156e781373e1198bd810f9eb220b26e0bd861f8cad51a9501e76d2a77a9b64fbb767996c85abb2eecd244b876c0dea2b229fdc7
7
+ data.tar.gz: 5e4faadb40fc2aa20f66635aa71e31e3e8f60aeb0e97f5f6cb756aa21705176a0b8a516ffff4b32e8283944169435548237b4e4716d08e66694b50bd181652f9
@@ -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.3)
5
- faraday (~> 1.7)
6
- faraday_middleware (~> 1.1)
4
+ twitchrb (0.2.6)
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 (1.8.0)
13
- faraday-em_http (~> 1.0)
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-em_http (1.0.0)
24
- faraday-em_synchrony (1.0.0)
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.1.4
29
+ 2.3.5
data/README.md CHANGED
@@ -2,9 +2,7 @@
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
 
@@ -29,37 +27,165 @@ An access token is required because the Helix API requires authentication.
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
- @client.videos.get(user_id: 141981764)
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
@@ -116,7 +116,6 @@ module Twitch
116
116
  conn.headers = { "Client-ID": client_id }
117
117
  conn.request :json
118
118
 
119
- conn.response :dates
120
119
  conn.response :json, content_type: "application/json"
121
120
 
122
121
  conn.adapter adapter, @stubs
@@ -0,0 +1,4 @@
1
+ module Twitch
2
+ class FollowCount < Object
3
+ end
4
+ end
@@ -1,27 +1,4 @@
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
- thumbnail_url.gsub("%{width}", "640").gsub("%{height}", "360")
15
- end
16
-
17
- # Generates a Storyboard/Animated image URL
18
- def generate_animated_url
19
- thumb = thumbnail_url.dup
20
- thumb.gsub!("https://static-cdn.jtvnw.net/cf_vods/", "").gsub!("/thumb/thumb0-%{width}x%{height}.jpg", "storyboards/#{id}-strip-0.jpg")
21
- split = thumb.split("/")
22
-
23
- "https://#{split[0]}.cloudfront.net/#{split[1..].join("/")}"
24
- end
25
-
26
3
  end
27
4
  end
@@ -5,6 +5,21 @@ module Twitch
5
5
  Channel.new get_request("channels?broadcaster_id=#{broadcaster_id}").body.dig("data")[0]
6
6
  end
7
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"])
21
+ end
22
+
8
23
  # Requires scope: channel:manage:broadcast
9
24
  def update(broadcaster_id:, **attributes)
10
25
  patch_request("channels", body: attributes.merge(broadcaster_id: broadcaster_id))
@@ -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/?id=#{user_id}").body.dig("data")[0]
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/?login=#{username}").body.dig("data")[0]
9
+ User.new get_request("users?login=#{username}").body.dig("data")[0]
10
10
  end
11
11
 
12
12
  # Updates the current users description
@@ -1,3 +1,3 @@
1
1
  module Twitch
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.6"
3
3
  end
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/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://twitchrb.com"
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", "~> 1.7"
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.3
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Perry
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-31 00:00:00.000000000 Z
11
+ date: 2022-04-26 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: '1.7'
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: '1.7'
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
@@ -116,11 +104,11 @@ files:
116
104
  - lib/twitch/version.rb
117
105
  - lib/twitchrb.rb
118
106
  - twitchrb.gemspec
119
- homepage: https://twitchrb.com
107
+ homepage: https://deanpcmad.com
120
108
  licenses:
121
109
  - MIT
122
110
  metadata:
123
- homepage_uri: https://twitchrb.com
111
+ homepage_uri: https://deanpcmad.com
124
112
  source_code_uri: https://github.com/deanpcmad/twitchrb
125
113
  post_install_message:
126
114
  rdoc_options: []
@@ -137,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
125
  - !ruby/object:Gem::Version
138
126
  version: '0'
139
127
  requirements: []
140
- rubygems_version: 3.1.6
128
+ rubygems_version: 3.3.7
141
129
  signing_key:
142
130
  specification_version: 4
143
131
  summary: A Ruby library for interacting with the Twitch Helix API