twitchrb 0.2.0 → 0.2.4
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/Gemfile.lock +2 -2
- data/README.md +2 -2
- data/lib/twitch/client.rb +1 -22
- data/lib/twitch/objects/video.rb +27 -0
- data/lib/twitch/resources/channels.rb +1 -1
- data/lib/twitch/resources/clips.rb +4 -0
- data/lib/twitch/resources/subscriptions.rb +4 -45
- data/lib/twitch/version.rb +1 -1
- data/lib/twitch.rb +0 -20
- data/lib/twitchrb.rb +1 -0
- metadata +3 -3
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5da5d24c0516dd123d3c603f728f1afb89dd388d8850bc39f6a46a62c7497b2f
|
4
|
+
data.tar.gz: 4c664108c26f55cceeb5d8c5524fc79fe15a14c16d9114abb3ad481e20afc028
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fc664b3ae6a78bb1fbf61d65a04cbd8c6a97dd79cd47d418c007e000e6a568fcded0fa0246fb5907197684942c5549f26b6a8f287289cf0200a47f11dd2ea1e
|
7
|
+
data.tar.gz: e04d75f5c8f88392316fc652391998f842c6cd23f9e1484246f876c786ae828b2195dab346506445f945941aaf728c82034eccf596319c47f1f21c2b2484255a
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
twitchrb (0.2.
|
4
|
+
twitchrb (0.2.4)
|
5
5
|
faraday (~> 1.7)
|
6
6
|
faraday_middleware (~> 1.1)
|
7
7
|
|
@@ -28,7 +28,7 @@ GEM
|
|
28
28
|
faraday-net_http_persistent (1.2.0)
|
29
29
|
faraday-patron (1.0.0)
|
30
30
|
faraday-rack (1.0.0)
|
31
|
-
faraday_middleware (1.
|
31
|
+
faraday_middleware (1.2.0)
|
32
32
|
faraday (~> 1.0)
|
33
33
|
minitest (5.14.1)
|
34
34
|
multipart-post (2.1.1)
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ It only supports the Helix API as v5 is deprecated.
|
|
11
11
|
Add this line to your application's Gemfile:
|
12
12
|
|
13
13
|
```ruby
|
14
|
-
gem "twitchrb"
|
14
|
+
gem "twitchrb"
|
15
15
|
```
|
16
16
|
|
17
17
|
## Usage
|
@@ -23,7 +23,7 @@ Firstly you'll need to set a Client ID, Secret Key and an Access Token.
|
|
23
23
|
An access token is required because the Helix API requires authentication.
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
@client = Twitch::Client.new(client_id: "",
|
26
|
+
@client = Twitch::Client.new(client_id: "", client_secret: "", access_token: "")
|
27
27
|
```
|
28
28
|
|
29
29
|
### Users
|
data/lib/twitch/client.rb
CHANGED
@@ -1,25 +1,3 @@
|
|
1
|
-
# require "httparty"
|
2
|
-
|
3
|
-
|
4
|
-
# def headers(kind)
|
5
|
-
# if kind == :helix
|
6
|
-
# {
|
7
|
-
# "Client-ID" => @client_id,
|
8
|
-
# "Accept" => "application/json",
|
9
|
-
# "Content-Type" => "application/json",
|
10
|
-
# "Authorization" => "Bearer #{@access_token}"
|
11
|
-
# }
|
12
|
-
# else
|
13
|
-
# {
|
14
|
-
# "Client-ID" => @client_id,
|
15
|
-
# "Accept" => "application/vnd.twitchtv.v5+json",
|
16
|
-
# # "Authorization" => "OAuth #{@access_token}"
|
17
|
-
# }
|
18
|
-
# end
|
19
|
-
# end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
1
|
module Twitch
|
24
2
|
class Client
|
25
3
|
BASE_URL = "https://api.twitch.tv/helix"
|
@@ -144,5 +122,6 @@ module Twitch
|
|
144
122
|
conn.adapter adapter, @stubs
|
145
123
|
end
|
146
124
|
end
|
125
|
+
|
147
126
|
end
|
148
127
|
end
|
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,7 @@ 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
6
|
end
|
7
7
|
|
8
8
|
# Requires scope: channel:manage:broadcast
|
@@ -8,6 +8,10 @@ module Twitch
|
|
8
8
|
Collection.from_response(response, type: Clip)
|
9
9
|
end
|
10
10
|
|
11
|
+
def retrieve(id:)
|
12
|
+
Clip.new get_request("clips?id=#{id}").body.dig("data")[0]
|
13
|
+
end
|
14
|
+
|
11
15
|
# Required scope: clips:edit
|
12
16
|
def create(broadcaster_id:, **attributes)
|
13
17
|
response = post_request("clips", body: attributes.merge(broadcaster_id: broadcaster_id))
|
@@ -19,55 +19,14 @@ module Twitch
|
|
19
19
|
Collection.from_response(response, type: Subscription)
|
20
20
|
end
|
21
21
|
|
22
|
-
#
|
22
|
+
# Grabs the number of Subscribers and Subscriber Points a broadcaster has
|
23
23
|
# Broadcaster ID must match the user in the OAuth token
|
24
24
|
# Required scope: channel:read:subscriptions
|
25
|
-
def
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
25
|
+
def counts(broadcaster_id:)
|
26
|
+
response = get_request("subscriptions", params: {broadcaster_id: broadcaster_id})
|
30
27
|
|
31
|
-
|
32
|
-
subs = []
|
33
|
-
cursor = nil
|
34
|
-
count = 1
|
35
|
-
|
36
|
-
while count > 0
|
37
|
-
sub_response = list(broadcaster_id: broadcaster_id, first: 100, after: cursor)
|
38
|
-
|
39
|
-
subs += sub_response.data
|
40
|
-
|
41
|
-
cursor = sub_response.cursor
|
42
|
-
count = sub_response.total
|
43
|
-
end
|
44
|
-
|
45
|
-
return subs
|
28
|
+
SubscriptionCount.new(count: response.body["total"], points: response.body["points"])
|
46
29
|
end
|
47
|
-
|
48
|
-
def calculate_subs(broadcaster_id:, remove_count:, remove_points:)
|
49
|
-
subs = get_subscriptions(broadcaster_id: broadcaster_id)
|
50
|
-
|
51
|
-
count = 0
|
52
|
-
points = 0
|
53
|
-
|
54
|
-
if !subs.empty? && subs.count >= 1
|
55
|
-
subs.each do |sub|
|
56
|
-
# We don't want to add the broadcaster into the count
|
57
|
-
next if sub.user_id.to_s == broadcaster_id.to_s
|
58
|
-
|
59
|
-
count += 1
|
60
|
-
points += 1 if sub.tier == "1000"
|
61
|
-
points += 2 if sub.tier == "2000"
|
62
|
-
points += 6 if sub.tier == "3000"
|
63
|
-
end
|
64
|
-
|
65
|
-
count = (count - remove_count)
|
66
|
-
points = (points - remove_points)
|
67
|
-
end
|
68
|
-
|
69
|
-
SubscriptionCount.new(count: count, points: points)
|
70
|
-
end
|
71
30
|
|
72
31
|
end
|
73
32
|
end
|
data/lib/twitch/version.rb
CHANGED
data/lib/twitch.rb
CHANGED
@@ -3,26 +3,6 @@ require "faraday_middleware"
|
|
3
3
|
require "json"
|
4
4
|
require "twitch/version"
|
5
5
|
|
6
|
-
require "twitch/version"
|
7
|
-
|
8
|
-
# require "twitch/client"
|
9
|
-
# require "twitch/initializable"
|
10
|
-
|
11
|
-
# # Models
|
12
|
-
# require "twitch/models/channel"
|
13
|
-
# require "twitch/models/badge"
|
14
|
-
# require "twitch/models/game"
|
15
|
-
# require "twitch/models/emote"
|
16
|
-
# require "twitch/models/poll"
|
17
|
-
# require "twitch/models/poll_choice"
|
18
|
-
|
19
|
-
# # Helix API
|
20
|
-
# require "twitch/channels"
|
21
|
-
# require "twitch/emotes"
|
22
|
-
# require "twitch/badges"
|
23
|
-
# require "twitch/games"
|
24
|
-
# require "twitch/polls"
|
25
|
-
|
26
6
|
module Twitch
|
27
7
|
|
28
8
|
autoload :Client, "twitch/client"
|
data/lib/twitchrb.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "twitch"
|
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.4
|
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-
|
11
|
+
date: 2021-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -48,7 +48,6 @@ files:
|
|
48
48
|
- ".env.example"
|
49
49
|
- ".github/FUNDING.yml"
|
50
50
|
- ".gitignore"
|
51
|
-
- ".travis.yml"
|
52
51
|
- Gemfile
|
53
52
|
- Gemfile.lock
|
54
53
|
- LICENSE.txt
|
@@ -115,6 +114,7 @@ files:
|
|
115
114
|
- lib/twitch/resources/users.rb
|
116
115
|
- lib/twitch/resources/videos.rb
|
117
116
|
- lib/twitch/version.rb
|
117
|
+
- lib/twitchrb.rb
|
118
118
|
- twitchrb.gemspec
|
119
119
|
homepage: https://twitchrb.com
|
120
120
|
licenses:
|