cathodic 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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/*
@@ -0,0 +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`:
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,60 +1,61 @@
1
- Cathodic
2
- ================================
3
-
4
- Cathodic was at first a module created for one of the websites I worked on.
5
- 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.
6
-
7
- Cathodic is now a standalone gem, and it's pretty easy to use, as you can see below.
8
-
9
- Installing Cathodic
10
- -----------------------------
11
-
12
- If you're working on a ruby project, you just have to run the following command :
13
- ```ruby
14
- gem install cathodic
15
- ```
16
-
17
- 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
18
- ```ruby
19
- gem cathodic
20
- ```
21
-
22
- And run the following command :
23
- ```console
24
- bundle install
25
- ```
26
-
27
- To install the gem, and correctly add it to your rails project.
28
-
29
- Using Cathodic
30
- ------------------------------
31
-
32
- 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 :
33
- ```ruby
34
- Cathodic::TwitchData.new(url)
35
- ```
36
- 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.
37
-
38
- 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 :
39
- ```ruby
40
- data = Cathodic::TwitchData.new(url)
41
- puts data.viewers
42
- ```
43
- Here are all the data you can access at the moment :
44
-
45
- * online : boolean - True if the stream is online, false otherwise
46
- * account_name : string - Contains the account name from the provided url
47
- * thumbnail_address : string - Contains the url of the stream's preview thumbnail (will soon change to a new thumbnail object)
48
- * embed : string - Contains the html embed code for the twitch tv player which will play the stream's livestream
49
- * viewers : integer - Contains the number of people currently watching the stream (when the TwitchData object was created!)
50
- * entry_point : string - Contains the entry point to the api (for future upgrades of the gem, to support multiple providers)
51
- * url : string - Contains the url to the twitch.tv stream page
52
- * game : string - Contains the game currently played on the stream (updated by the streamer, might not be accurate)
53
- * 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)
54
- * logo : string - Contains the url of the stream's logo
55
- * banner : string - Contains the url of the stream's banner
56
- * stream_name : string - The casse sensitive stream name (example : account_name is kustomgames and stream_name is KustomGames)
57
- * chat_embed : string - Conatains the html code used to pop out the stream's chat (incoming)
58
-
59
-
60
-
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,22 +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@itsbi.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_development_dependency "json"
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
- 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@itsbi.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_development_dependency "json"
17
+ s.add_runtime_dependency "json"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
@@ -1,55 +1,61 @@
1
- #require "cathodic/version"
2
- require 'json'
3
- require 'open-uri'
4
- require 'openssl'
5
-
6
- module Cathodic
7
- class TwitchData
8
- attr_accessor :account_name, :online, :thumbnail_address, :embed, :viewers, :entry_point, :url, :game, :status, :logo, :banner, :stream_name, :chat_embed
9
-
10
- def initialize(url)
11
- @entry_point = "https://api.twitch.tv/kraken"
12
- @url = url
13
- extract_account
14
- @query_point = @entry_point + "/streams/" + @account_name
15
- extract_data
16
- end
17
-
18
- private
19
- def extract_account
20
- raise "Bad url" if !@url.include? "twitch.tv"
21
-
22
- regexp = /twitch.tv\/\w*/
23
- m = regexp.match @url
24
- buff = m.to_s
25
- buff.sub! "twitch.tv/", ""
26
- @account_name = buff
27
- end
28
-
29
- def extract_data
30
- answer_string = open(@query_point).read
31
- parsed_answer = JSON.parse(answer_string)
32
-
33
- if parsed_answer["stream"] == nil
34
- @online = false
35
- else
36
- @online = true
37
- stream = parsed_answer.fetch("stream")
38
- channel = stream.fetch("channel")
39
-
40
- @thumbnail_address = stream.fetch("preview")["medium"]
41
- @game = stream["game"]
42
- @viewers = stream["viewers"]
43
-
44
- @url = channel["url"]
45
- @status = channel["status"]
46
- @logo = channel["logo"]
47
- @banner = channel["banner"]
48
- @stream_name = channel["display_name"]
49
-
50
- @embed = "<object type=\"application/x-shockwave-flash\" height=\"360\" width=\"640\" id=\"live_embed_player_flash\" data=\"http://en.twitch.tv/widgets/live_embed_player.swf?channel="+@account_name+"\" bgcolor=\"#000000\"><param name=\"allowFullScreen\" value=\"true\" /><param name=\"allowScriptAccess\" value=\"always\" /><param name=\"allowNetworking\" value=\"all\" /><param name=\"movie\" value=\"http://en.twitch.tv/widgets/live_embed_player.swf\" /><param name=\"flashvars\" value=\"hostname=en.twitch.tv&channel="+@account_name+"&auto_play=true&start_volume=25\" /></object>"
51
- @chat_embed = "http://twitch.tv/chat/embed?channel="+@account_name+"&popout_chat=true"
52
- end
53
- end
54
- end
55
- end
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 'json'
7
+ require 'open-uri'
8
+ require 'openssl'
9
+ require "cathodic/thumbnail"
10
+ require "cathodic/chat"
11
+
12
+ module Cathodic
13
+ class TwitchData
14
+ attr_accessor :account_name, :online, :thumbnail, :embed, :viewers, :entry_point, :url, :game, :status, :logo, :banner, :stream_name, :chat
15
+
16
+ def initialize(url)
17
+ @entry_point = "https://api.twitch.tv/kraken"
18
+ @url = url
19
+ extract_account
20
+ @query_point = @entry_point + "/streams/" + @account_name
21
+ extract_data
22
+ end
23
+
24
+ private
25
+ def extract_account
26
+ raise "Bad url" if !@url.include? "twitch.tv"
27
+
28
+ regexp = /twitch.tv\/\w*/
29
+ m = regexp.match @url
30
+ buff = m.to_s
31
+ buff.sub! "twitch.tv/", ""
32
+ @account_name = buff
33
+ end
34
+
35
+ def extract_data
36
+ answer_string = open(@query_point).read
37
+ parsed_answer = JSON.parse(answer_string)
38
+
39
+ if parsed_answer["stream"] == nil
40
+ @online = false
41
+ else
42
+ @online = true
43
+ stream = parsed_answer.fetch("stream")
44
+ channel = stream.fetch("channel")
45
+
46
+ @thumbnail = Cathodic::Thumbnail.new(stream)
47
+ @game = stream["game"]
48
+ @viewers = stream["viewers"]
49
+
50
+ @url = channel["url"]
51
+ @status = channel["status"]
52
+ @logo = channel["logo"]
53
+ @banner = channel["banner"]
54
+ @stream_name = channel["display_name"]
55
+
56
+ @embed = "<object type=\"application/x-shockwave-flash\" height=\"360\" width=\"640\" id=\"live_embed_player_flash\" data=\"http://en.twitch.tv/widgets/live_embed_player.swf?channel="+@account_name+"\" bgcolor=\"#000000\"><param name=\"allowFullScreen\" value=\"true\" /><param name=\"allowScriptAccess\" value=\"always\" /><param name=\"allowNetworking\" value=\"all\" /><param name=\"movie\" value=\"http://en.twitch.tv/widgets/live_embed_player.swf\" /><param name=\"flashvars\" value=\"hostname=en.twitch.tv&channel="+@account_name+"&auto_play=true&start_volume=25\" /></object>"
57
+ @chat_embed = Cathodic::Chat.new(@account_name)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +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
34
+ end
@@ -0,0 +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
41
+ end
@@ -1,3 +1,3 @@
1
- module Cathodic
2
- VERSION = "0.0.3"
3
- end
1
+ module Cathodic
2
+ VERSION = "0.1.0"
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cathodic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-29 00:00:00.000000000 Z
12
+ date: 2013-03-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  description: ! "Cathodic helps users retreiving the data from a twitch tv stream,
31
47
  such as the number of viewers, \n a preview thumbnail, the embed
32
48
  code, the status etc from the twitch channel's url"
@@ -37,11 +53,14 @@ extensions: []
37
53
  extra_rdoc_files: []
38
54
  files:
39
55
  - .gitignore
56
+ - .travis.yml
40
57
  - Gemfile
41
58
  - Rakefile
42
59
  - Readme.md
43
60
  - cathodic.gemspec
44
61
  - lib/cathodic.rb
62
+ - lib/cathodic/chat.rb
63
+ - lib/cathodic/thumbnail.rb
45
64
  - lib/cathodic/version.rb
46
65
  homepage: https://github.com/kustom666/cathodic
47
66
  licenses: []
@@ -63,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
82
  version: '0'
64
83
  requirements: []
65
84
  rubyforge_project: cathodic
66
- rubygems_version: 1.8.23
85
+ rubygems_version: 1.8.24
67
86
  signing_key:
68
87
  specification_version: 3
69
88
  summary: Gets a twitch.tv stream's info from the api