cathodic 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in cathodic.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/cathodic.gemspec ADDED
@@ -0,0 +1,22 @@
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 = ""
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
data/lib/cathodic.rb ADDED
@@ -0,0 +1,54 @@
1
+ #require "cathodic/version"
2
+ require 'json'
3
+ require 'open-uri'
4
+ require 'openssl'
5
+
6
+ module Cathodic
7
+ class TwitchData
8
+ #attr_accessible :account_name, :online, :thumbnail_address, :embed, :viewers, :entry_point, :url
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_code = "<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
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module Cathodic
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cathodic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Paul Forti
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ 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
+ description: ! "Cathodic helps users retreiving the data from a twitch tv stream,
31
+ such as the number of viewers, \n a preview thumbnail, the embed
32
+ code, the status etc from the twitch channel's url"
33
+ email:
34
+ - paul@itsbi.fr
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - .gitignore
40
+ - Gemfile
41
+ - Rakefile
42
+ - cathodic.gemspec
43
+ - lib/cathodic.rb
44
+ - lib/cathodic/version.rb
45
+ homepage: ''
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project: cathodic
65
+ rubygems_version: 1.8.23
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Gets a twitch.tv stream's info from the api
69
+ test_files: []