cathodic 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -4
- data/.travis.yml +7 -7
- data/Gemfile +4 -4
- data/Rakefile +1 -1
- data/Readme.md +61 -61
- data/cathodic.gemspec +23 -23
- data/lib/cathodic.rb +80 -61
- data/lib/cathodic/chat.rb +33 -33
- data/lib/cathodic/thumbnail.rb +40 -40
- data/lib/cathodic/version.rb +3 -3
- metadata +17 -36
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 259ed36b98ff8bed8c58801f57fccfbb12f55dd0
|
4
|
+
data.tar.gz: 2f41a2a459df5735f6e260390457c6cb0dd786dc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 59772106084433b58c35043e470f828f1bcbd9d334a0b040ea5a1c97ae5e86ffeda14ddb9757513c83a5678af86b309874173ff804234db1842bad62193e8a32
|
7
|
+
data.tar.gz: 45066154ab5ee7f4a034d3aeca21550dd7a59107f02f16914fd4ea40f12ac16e5398fec213a54748856eb948bf5cac82a27856b053602f545d5d772dbd58245d
|
data/.gitignore
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
*.gem
|
2
|
-
.bundle
|
3
|
-
Gemfile.lock
|
4
|
-
pkg/*
|
1
|
+
*.gem
|
2
|
+
.bundle
|
3
|
+
Gemfile.lock
|
4
|
+
pkg/*
|
data/.travis.yml
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- "1.8.7"
|
4
|
-
- "1.9.2"
|
5
|
-
- "1.9.3"
|
6
|
-
- "2.0.0"
|
7
|
-
# uncomment this line if your project needs to run something other than `rake`:
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- "1.8.7"
|
4
|
+
- "1.9.2"
|
5
|
+
- "1.9.3"
|
6
|
+
- "2.0.0"
|
7
|
+
# uncomment this line if your project needs to run something other than `rake`:
|
8
8
|
script: gem build cathodic.gemspec
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in cathodic.gemspec
|
4
|
-
gemspec
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in cathodic.gemspec
|
4
|
+
gemspec
|
data/Rakefile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'bundler/gem_tasks'
|
1
|
+
require 'bundler/gem_tasks'
|
data/Readme.md
CHANGED
@@ -1,61 +1,61 @@
|
|
1
|
-
Cathodic
|
2
|
-
================================
|
3
|
-
[![Dependency Status](https://gemnasium.com/kustom666/cathodic.png)](https://gemnasium.com/kustom666/cathodic) [![Build Status](https://travis-ci.org/kustom666/cathodic.png?branch=master)](https://travis-ci.org/kustom666/cathodic)
|
4
|
-
|
5
|
-
Cathodic was at first a module created for one of the websites I worked on.
|
6
|
-
I needed a way to easily access the data tied to a twitch.tv stream, such as the state of the stream (online or offine, thus the boolean), the number of viewers, the stream's status, etc.
|
7
|
-
|
8
|
-
Cathodic is now a standalone gem, and it's pretty easy to use, as you can see below.
|
9
|
-
|
10
|
-
Installing Cathodic
|
11
|
-
-----------------------------
|
12
|
-
|
13
|
-
If you're working on a ruby project, you just have to run the following command :
|
14
|
-
```ruby
|
15
|
-
gem install cathodic
|
16
|
-
```
|
17
|
-
|
18
|
-
However, if you're using rails, you might want to use bundler (if you don't, you should, it's awesome), therefore add the following line to your Gemfile
|
19
|
-
```ruby
|
20
|
-
gem cathodic
|
21
|
-
```
|
22
|
-
|
23
|
-
And run the following command :
|
24
|
-
```console
|
25
|
-
bundle install
|
26
|
-
```
|
27
|
-
|
28
|
-
To install the gem, and correctly add it to your rails project.
|
29
|
-
|
30
|
-
Using Cathodic
|
31
|
-
------------------------------
|
32
|
-
|
33
|
-
Cathodic is a very easy to use gem. Once you've installed it, you only need to instanciate a TwitchData object (contained in the Cathodic module) by calling the following constructor :
|
34
|
-
```ruby
|
35
|
-
Cathodic::TwitchData.new(url)
|
36
|
-
```
|
37
|
-
Where url is the url of the twitch.tv channel (http://twitch.tv/kustomgames/ for example). This url can be provided by one of your users, or fetched from the twitch.tv api.
|
38
|
-
|
39
|
-
The data tied to the stream can now be accessed by using the accessors : if you want to retreive the number of viewers on the stream and put it on the console output you just have to call the viewers accessor :
|
40
|
-
```ruby
|
41
|
-
data = Cathodic::TwitchData.new(url)
|
42
|
-
puts data.viewers
|
43
|
-
```
|
44
|
-
Here are all the data you can access at the moment :
|
45
|
-
|
46
|
-
* online : boolean - True if the stream is online, false otherwise
|
47
|
-
* account_name : string - Contains the account name from the provided url
|
48
|
-
* thumbnail_address : string - Contains the url of the stream's preview thumbnail (will soon change to a new thumbnail object)
|
49
|
-
* embed : string - Contains the html embed code for the twitch tv player which will play the stream's livestream
|
50
|
-
* viewers : integer - Contains the number of people currently watching the stream (when the TwitchData object was created!)
|
51
|
-
* entry_point : string - Contains the entry point to the api (for future upgrades of the gem, to support multiple providers)
|
52
|
-
* url : string - Contains the url to the twitch.tv stream page
|
53
|
-
* game : string - Contains the game currently played on the stream (updated by the streamer, might not be accurate)
|
54
|
-
* status : string - Contains the status of the stream, a title displayed on top of the embed which describes the current activity on screen (updated by the streamer, might not be accurate)
|
55
|
-
* logo : string - Contains the url of the stream's logo
|
56
|
-
* banner : string - Contains the url of the stream's banner
|
57
|
-
* stream_name : string - The casse sensitive stream name (example : account_name is kustomgames and stream_name is KustomGames)
|
58
|
-
* chat_embed : string - Conatains the html code used to pop out the stream's chat (incoming)
|
59
|
-
|
60
|
-
|
61
|
-
|
1
|
+
Cathodic
|
2
|
+
================================
|
3
|
+
[![Dependency Status](https://gemnasium.com/kustom666/cathodic.png)](https://gemnasium.com/kustom666/cathodic) [![Build Status](https://travis-ci.org/kustom666/cathodic.png?branch=master)](https://travis-ci.org/kustom666/cathodic)
|
4
|
+
|
5
|
+
Cathodic was at first a module created for one of the websites I worked on.
|
6
|
+
I needed a way to easily access the data tied to a twitch.tv stream, such as the state of the stream (online or offine, thus the boolean), the number of viewers, the stream's status, etc.
|
7
|
+
|
8
|
+
Cathodic is now a standalone gem, and it's pretty easy to use, as you can see below.
|
9
|
+
|
10
|
+
Installing Cathodic
|
11
|
+
-----------------------------
|
12
|
+
|
13
|
+
If you're working on a ruby project, you just have to run the following command :
|
14
|
+
```ruby
|
15
|
+
gem install cathodic
|
16
|
+
```
|
17
|
+
|
18
|
+
However, if you're using rails, you might want to use bundler (if you don't, you should, it's awesome), therefore add the following line to your Gemfile
|
19
|
+
```ruby
|
20
|
+
gem cathodic
|
21
|
+
```
|
22
|
+
|
23
|
+
And run the following command :
|
24
|
+
```console
|
25
|
+
bundle install
|
26
|
+
```
|
27
|
+
|
28
|
+
To install the gem, and correctly add it to your rails project.
|
29
|
+
|
30
|
+
Using Cathodic
|
31
|
+
------------------------------
|
32
|
+
|
33
|
+
Cathodic is a very easy to use gem. Once you've installed it, you only need to instanciate a TwitchData object (contained in the Cathodic module) by calling the following constructor :
|
34
|
+
```ruby
|
35
|
+
Cathodic::TwitchData.new(url)
|
36
|
+
```
|
37
|
+
Where url is the url of the twitch.tv channel (http://twitch.tv/kustomgames/ for example). This url can be provided by one of your users, or fetched from the twitch.tv api.
|
38
|
+
|
39
|
+
The data tied to the stream can now be accessed by using the accessors : if you want to retreive the number of viewers on the stream and put it on the console output you just have to call the viewers accessor :
|
40
|
+
```ruby
|
41
|
+
data = Cathodic::TwitchData.new(url)
|
42
|
+
puts data.viewers
|
43
|
+
```
|
44
|
+
Here are all the data you can access at the moment :
|
45
|
+
|
46
|
+
* online : boolean - True if the stream is online, false otherwise
|
47
|
+
* account_name : string - Contains the account name from the provided url
|
48
|
+
* thumbnail_address : string - Contains the url of the stream's preview thumbnail (will soon change to a new thumbnail object)
|
49
|
+
* embed : string - Contains the html embed code for the twitch tv player which will play the stream's livestream
|
50
|
+
* viewers : integer - Contains the number of people currently watching the stream (when the TwitchData object was created!)
|
51
|
+
* entry_point : string - Contains the entry point to the api (for future upgrades of the gem, to support multiple providers)
|
52
|
+
* url : string - Contains the url to the twitch.tv stream page
|
53
|
+
* game : string - Contains the game currently played on the stream (updated by the streamer, might not be accurate)
|
54
|
+
* status : string - Contains the status of the stream, a title displayed on top of the embed which describes the current activity on screen (updated by the streamer, might not be accurate)
|
55
|
+
* logo : string - Contains the url of the stream's logo
|
56
|
+
* banner : string - Contains the url of the stream's banner
|
57
|
+
* stream_name : string - The casse sensitive stream name (example : account_name is kustomgames and stream_name is KustomGames)
|
58
|
+
* chat_embed : string - Conatains the html code used to pop out the stream's chat (incoming)
|
59
|
+
|
60
|
+
|
61
|
+
|
data/cathodic.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "cathodic/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "cathodic"
|
7
|
-
s.version = Cathodic::VERSION
|
8
|
-
s.authors = ["Paul Forti"]
|
9
|
-
s.email = ["paul@
|
10
|
-
s.homepage = "https://github.com/kustom666/cathodic"
|
11
|
-
s.summary = "Gets a twitch.tv stream's info from the api"
|
12
|
-
s.description = "Cathodic helps users retreiving the data from a twitch tv stream, such as the number of viewers,
|
13
|
-
a preview thumbnail, the embed code, the status etc from the twitch channel's url"
|
14
|
-
|
15
|
-
s.rubyforge_project = "cathodic"
|
16
|
-
s.
|
17
|
-
|
18
|
-
|
19
|
-
s.
|
20
|
-
s.
|
21
|
-
s.
|
22
|
-
s.
|
23
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "cathodic/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "cathodic"
|
7
|
+
s.version = Cathodic::VERSION
|
8
|
+
s.authors = ["Paul Forti"]
|
9
|
+
s.email = ["paul@ensea.fr"]
|
10
|
+
s.homepage = "https://github.com/kustom666/cathodic"
|
11
|
+
s.summary = "Gets a twitch.tv stream's info from the api"
|
12
|
+
s.description = "Cathodic helps users retreiving the data from a twitch tv stream, such as the number of viewers,
|
13
|
+
a preview thumbnail, the embed code, the status etc from the twitch channel's url"
|
14
|
+
|
15
|
+
s.rubyforge_project = "cathodic"
|
16
|
+
s.add_runtime_dependency "json", '~> 0', '~> 0'
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
s.license = 'MIT'
|
23
|
+
end
|
data/lib/cathodic.rb
CHANGED
@@ -1,61 +1,80 @@
|
|
1
|
-
#Cathodic takes the url of a twitch.tv stream and fetch every data tied to it, such as the status, logo, numbed of viewers, thumnails and game
|
2
|
-
#Author::Paul Forti
|
3
|
-
#License::MIT
|
4
|
-
|
5
|
-
require "cathodic/version"
|
6
|
-
require '
|
7
|
-
require '
|
8
|
-
require '
|
9
|
-
require
|
10
|
-
require "cathodic/
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
1
|
+
#Cathodic takes the url of a twitch.tv stream and fetch every data tied to it, such as the status, logo, numbed of viewers, thumnails and game
|
2
|
+
#Author::Paul Forti
|
3
|
+
#License::MIT
|
4
|
+
|
5
|
+
require "cathodic/version"
|
6
|
+
require 'iconv'
|
7
|
+
require 'json'
|
8
|
+
require 'open-uri'
|
9
|
+
require 'openssl'
|
10
|
+
require "cathodic/thumbnail"
|
11
|
+
require "cathodic/chat"
|
12
|
+
|
13
|
+
module Cathodic
|
14
|
+
class TwitchData
|
15
|
+
attr_accessor :account_name, :online, :thumbnail, :embed, :viewers, :entry_point, :url, :game, :status, :logo, :banner, :stream_name, :chat, :embed_width, :embed_height
|
16
|
+
|
17
|
+
def initialize(url, embed_width = 640, embed_height = 360)
|
18
|
+
@entry_point = "https://api.twitch.tv/kraken"
|
19
|
+
@url = url
|
20
|
+
extract_account
|
21
|
+
@query_point = @entry_point + "/streams/" + @account_name
|
22
|
+
@embed_width = embed_width
|
23
|
+
@embed_height = embed_height
|
24
|
+
extract_data
|
25
|
+
end
|
26
|
+
|
27
|
+
def refresh_data
|
28
|
+
answer_string = open(@query_point).read
|
29
|
+
parsed_answer = JSON.parse(answer_string)
|
30
|
+
|
31
|
+
if parsed_answer["stream"] == nil
|
32
|
+
@online = false
|
33
|
+
else
|
34
|
+
@online = true
|
35
|
+
stream = parsed_answer.fetch("stream")
|
36
|
+
channel = stream.fetch("channel")
|
37
|
+
@game = stream["game"]
|
38
|
+
@viewers = stream["viewers"]
|
39
|
+
@status = channel["status"]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def extract_account
|
45
|
+
raise "Bad url" if !@url.include? "twitch.tv"
|
46
|
+
|
47
|
+
regexp = /twitch.tv\/\w*/
|
48
|
+
m = regexp.match @url
|
49
|
+
buff = m.to_s
|
50
|
+
buff.sub! "twitch.tv/", ""
|
51
|
+
@account_name = buff
|
52
|
+
end
|
53
|
+
|
54
|
+
def extract_data
|
55
|
+
answer_string = open(@query_point).read
|
56
|
+
parsed_answer = JSON.parse(answer_string)
|
57
|
+
|
58
|
+
if parsed_answer["stream"] == nil
|
59
|
+
@online = false
|
60
|
+
else
|
61
|
+
@online = true
|
62
|
+
stream = parsed_answer.fetch("stream")
|
63
|
+
channel = stream.fetch("channel")
|
64
|
+
|
65
|
+
@thumbnail = Cathodic::Thumbnail.new(stream)
|
66
|
+
@game = stream["game"]
|
67
|
+
@viewers = stream["viewers"]
|
68
|
+
|
69
|
+
@url = channel["url"]
|
70
|
+
@status = channel["status"]
|
71
|
+
@logo = channel["logo"]
|
72
|
+
@banner = channel["banner"]
|
73
|
+
@stream_name = channel["display_name"]
|
74
|
+
|
75
|
+
@embed = "<object bgcolor='#000000' data='//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf' height='#{@embed_height}' id='clip_embed_player_flash' type='application/x-shockwave-flash' width='#{@embed_width}'><param name='movie' value='//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf' /><param name='allowScriptAccess' value='always' /><param name='allowNetworking' value='all' /><param name='allowFullScreen' value='true' /><param name='flashvars' value='channel=#{@channel}&start_volume=25&auto_play=true' /></object>"
|
76
|
+
@chat_embed = Cathodic::Chat.new(@account_name)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/cathodic/chat.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
module Cathodic
|
2
|
-
#The chat class represents the twitch.tv chat, you can fetch the embed code or the pop out chat code and links
|
3
|
-
#Author::Paul Forti
|
4
|
-
#License::MIT
|
5
|
-
#-embed : the url to the embed version of the chat
|
6
|
-
#-popout : the url used to pop out the chat
|
7
|
-
#-emoticons : the hash containing all the serialized emoticons (image url, regexp, etc)
|
8
|
-
#-popout_link : the html link used to pop out the chat
|
9
|
-
class Chat
|
10
|
-
attr_accessor :embed, :popout, :emoticons, :popout_link
|
11
|
-
|
12
|
-
#The constructor needs to be given an account name, most likely the one retrieved from the stream's url
|
13
|
-
#-account_name : the account name of the stream's chat you want to get
|
14
|
-
def initialize(account_name)
|
15
|
-
@account_name = account_name
|
16
|
-
generate_links
|
17
|
-
end
|
18
|
-
|
19
|
-
#This method fetchs the emoticons info about a stream's chat. It takes a lot of CPU, memory and the query is pretty big
|
20
|
-
#Don't use it unless you REALLY need the emoticons
|
21
|
-
def fetch_emoticons
|
22
|
-
query_point = "https://api.twitch.tv/kraken/chat/"+@account_name+"emoticons"
|
23
|
-
@emoticons = open(query_point).read
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
def generate_links
|
28
|
-
@embed = "http://twitch.tv/chat/embed?channel="+@account_name
|
29
|
-
@popout = @embed + "&popout_chat=true"
|
30
|
-
@popout_link = "<a href=\""+@popout+"\" target=\"_new\">Pop-Out</a>"
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
1
|
+
module Cathodic
|
2
|
+
#The chat class represents the twitch.tv chat, you can fetch the embed code or the pop out chat code and links
|
3
|
+
#Author::Paul Forti
|
4
|
+
#License::MIT
|
5
|
+
#-embed : the url to the embed version of the chat
|
6
|
+
#-popout : the url used to pop out the chat
|
7
|
+
#-emoticons : the hash containing all the serialized emoticons (image url, regexp, etc)
|
8
|
+
#-popout_link : the html link used to pop out the chat
|
9
|
+
class Chat
|
10
|
+
attr_accessor :embed, :popout, :emoticons, :popout_link
|
11
|
+
|
12
|
+
#The constructor needs to be given an account name, most likely the one retrieved from the stream's url
|
13
|
+
#-account_name : the account name of the stream's chat you want to get
|
14
|
+
def initialize(account_name)
|
15
|
+
@account_name = account_name
|
16
|
+
generate_links
|
17
|
+
end
|
18
|
+
|
19
|
+
#This method fetchs the emoticons info about a stream's chat. It takes a lot of CPU, memory and the query is pretty big
|
20
|
+
#Don't use it unless you REALLY need the emoticons
|
21
|
+
def fetch_emoticons
|
22
|
+
query_point = "https://api.twitch.tv/kraken/chat/"+@account_name+"emoticons"
|
23
|
+
@emoticons = open(query_point).read
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def generate_links
|
28
|
+
@embed = "http://twitch.tv/chat/embed?channel="+@account_name
|
29
|
+
@popout = @embed + "&popout_chat=true"
|
30
|
+
@popout_link = "<a href=\""+@popout+"\" target=\"_new\">Pop-Out</a>"
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
34
|
end
|
data/lib/cathodic/thumbnail.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
module Cathodic
|
2
|
-
#The Thumbnail class represents a twitch thumbnail, you can access any type of thumbnail representing a small preview of the stream any time
|
3
|
-
#Author::Paul Forti
|
4
|
-
#License::MIT
|
5
|
-
#-small : the url to a small thumbnail 80x50
|
6
|
-
#-medium : the url to a medium thumbnail 320x200
|
7
|
-
#-large : the url to a large thumbnail 640x400
|
8
|
-
#-template : the url to a generic thumbnail, you have to replace {width} by the width you want, same goes for {height}
|
9
|
-
#-sized_thumb : nil if sized has not been called, otherwise it's the url to a custom sized thumbnail (the size is defined when calling sized)
|
10
|
-
class Thumbnail
|
11
|
-
attr_accessor :small, :medium, :large, :template, :sized_thumb
|
12
|
-
|
13
|
-
#The constructor needs a hash representing the stream object
|
14
|
-
#Must be fetched from the Twitch.tv API (or have the same structure)
|
15
|
-
#-stream_hash : the hash representing the twitch.tv stream.
|
16
|
-
def initialize(stream_hash)
|
17
|
-
raise "Uncorrect stream hash" if !stream_hash.has_key?("preview")
|
18
|
-
@preview = stream_hash.fetch("preview")
|
19
|
-
extract_thumbnails
|
20
|
-
end
|
21
|
-
|
22
|
-
#Sized generates the url of a stream thumbnail that is width large and height tall
|
23
|
-
#width : The thumbnail's desired width
|
24
|
-
#height : The thumbnail's desired height
|
25
|
-
def sized(width, height)
|
26
|
-
@sized_thumb = @template
|
27
|
-
@sized_thumb.sub! "{width}", width.to_s
|
28
|
-
@sized_thumb.sub! "{height}", height.to_s
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
#Extracts the url of the three different sizes of thumbnail, plus the url of a the template (to generate custom sized thumbnails)
|
34
|
-
def extract_thumbnails
|
35
|
-
@small = @preview["small"]
|
36
|
-
@medium = @preview["medium"]
|
37
|
-
@large = @preview["large"]
|
38
|
-
@template = @preview["template"]
|
39
|
-
end
|
40
|
-
end
|
1
|
+
module Cathodic
|
2
|
+
#The Thumbnail class represents a twitch thumbnail, you can access any type of thumbnail representing a small preview of the stream any time
|
3
|
+
#Author::Paul Forti
|
4
|
+
#License::MIT
|
5
|
+
#-small : the url to a small thumbnail 80x50
|
6
|
+
#-medium : the url to a medium thumbnail 320x200
|
7
|
+
#-large : the url to a large thumbnail 640x400
|
8
|
+
#-template : the url to a generic thumbnail, you have to replace {width} by the width you want, same goes for {height}
|
9
|
+
#-sized_thumb : nil if sized has not been called, otherwise it's the url to a custom sized thumbnail (the size is defined when calling sized)
|
10
|
+
class Thumbnail
|
11
|
+
attr_accessor :small, :medium, :large, :template, :sized_thumb
|
12
|
+
|
13
|
+
#The constructor needs a hash representing the stream object
|
14
|
+
#Must be fetched from the Twitch.tv API (or have the same structure)
|
15
|
+
#-stream_hash : the hash representing the twitch.tv stream.
|
16
|
+
def initialize(stream_hash)
|
17
|
+
raise "Uncorrect stream hash" if !stream_hash.has_key?("preview")
|
18
|
+
@preview = stream_hash.fetch("preview")
|
19
|
+
extract_thumbnails
|
20
|
+
end
|
21
|
+
|
22
|
+
#Sized generates the url of a stream thumbnail that is width large and height tall
|
23
|
+
#width : The thumbnail's desired width
|
24
|
+
#height : The thumbnail's desired height
|
25
|
+
def sized(width, height)
|
26
|
+
@sized_thumb = @template
|
27
|
+
@sized_thumb.sub! "{width}", width.to_s
|
28
|
+
@sized_thumb.sub! "{height}", height.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
#Extracts the url of the three different sizes of thumbnail, plus the url of a the template (to generate custom sized thumbnails)
|
34
|
+
def extract_thumbnails
|
35
|
+
@small = @preview["small"]
|
36
|
+
@medium = @preview["medium"]
|
37
|
+
@large = @preview["large"]
|
38
|
+
@template = @preview["template"]
|
39
|
+
end
|
40
|
+
end
|
41
41
|
end
|
data/lib/cathodic/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Cathodic
|
2
|
-
VERSION = "0.
|
3
|
-
end
|
1
|
+
module Cathodic
|
2
|
+
VERSION = "0.2.0"
|
3
|
+
end
|
metadata
CHANGED
@@ -1,59 +1,40 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cathodic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Paul Forti
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-02-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: json
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: json
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
17
|
+
- - "~>"
|
36
18
|
- !ruby/object:Gem::Version
|
37
19
|
version: '0'
|
38
20
|
type: :runtime
|
39
21
|
prerelease: false
|
40
22
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
23
|
requirements:
|
43
|
-
- -
|
24
|
+
- - "~>"
|
44
25
|
- !ruby/object:Gem::Version
|
45
26
|
version: '0'
|
46
|
-
description:
|
47
|
-
|
48
|
-
|
27
|
+
description: "Cathodic helps users retreiving the data from a twitch tv stream, such
|
28
|
+
as the number of viewers, \n a preview thumbnail, the embed code,
|
29
|
+
the status etc from the twitch channel's url"
|
49
30
|
email:
|
50
|
-
- paul@
|
31
|
+
- paul@ensea.fr
|
51
32
|
executables: []
|
52
33
|
extensions: []
|
53
34
|
extra_rdoc_files: []
|
54
35
|
files:
|
55
|
-
- .gitignore
|
56
|
-
- .travis.yml
|
36
|
+
- ".gitignore"
|
37
|
+
- ".travis.yml"
|
57
38
|
- Gemfile
|
58
39
|
- Rakefile
|
59
40
|
- Readme.md
|
@@ -63,27 +44,27 @@ files:
|
|
63
44
|
- lib/cathodic/thumbnail.rb
|
64
45
|
- lib/cathodic/version.rb
|
65
46
|
homepage: https://github.com/kustom666/cathodic
|
66
|
-
licenses:
|
47
|
+
licenses:
|
48
|
+
- MIT
|
49
|
+
metadata: {}
|
67
50
|
post_install_message:
|
68
51
|
rdoc_options: []
|
69
52
|
require_paths:
|
70
53
|
- lib
|
71
54
|
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
55
|
requirements:
|
74
|
-
- -
|
56
|
+
- - ">="
|
75
57
|
- !ruby/object:Gem::Version
|
76
58
|
version: '0'
|
77
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
-
none: false
|
79
60
|
requirements:
|
80
|
-
- -
|
61
|
+
- - ">="
|
81
62
|
- !ruby/object:Gem::Version
|
82
63
|
version: '0'
|
83
64
|
requirements: []
|
84
65
|
rubyforge_project: cathodic
|
85
|
-
rubygems_version:
|
66
|
+
rubygems_version: 2.4.5
|
86
67
|
signing_key:
|
87
|
-
specification_version:
|
68
|
+
specification_version: 4
|
88
69
|
summary: Gets a twitch.tv stream's info from the api
|
89
70
|
test_files: []
|