jtv 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,2 @@
1
+ # v0.0.1
2
+ * Initial Release with JtvChannel and JtvClip
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jtv.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Mockra
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,120 @@
1
+ # Jtv
2
+
3
+ This gem allows you to quickly add Justin.TV integration to your Ruby applications. Jtv is a useful tool for providing a list of livestreams, as well as embedding Justin.TV streams and clips.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'jtv'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install jtv
18
+
19
+ ## Justin.TV API Keys
20
+
21
+ If you want access to higher rate limits for your application, then you
22
+ need to sign up for a [Justin.TV developer account](http://www.justin.tv/developer/activate).
23
+
24
+ Once you have your API Keys, you'll need to set them up as environment
25
+ variables for them to work with this gem. A great article on environment
26
+ variables can be found at [Heroku](https://devcenter.heroku.com/articles/config-vars).
27
+
28
+ ``` ruby
29
+ ENV['JTV_CONSUMER_KEY']
30
+ ENV['JTV_CONSUMER_SECRET']
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ The Jtv gem offers various classes depending on the type of information
36
+ you're looking for.
37
+
38
+ ### JtvChannel
39
+ The JtvChannel class provides access to stream information for a
40
+ specific channel. You'll need to pass the channel handle when you
41
+ initialize your object.
42
+
43
+ ```ruby
44
+ channel = JtvChannel.new( 'channel' )
45
+ ```
46
+
47
+ You'll then have access to the following information.
48
+
49
+ ```ruby
50
+ channel.viewers
51
+ # Number of current viewers on the stream, requires a second API call
52
+
53
+ channel.image_huge
54
+ # 320x240 Image URL
55
+
56
+ channel.screen_cap_huge
57
+ # 320x240 Screen Capture URL
58
+
59
+ channel.id
60
+ # The channel handle
61
+
62
+ channel.embed
63
+ #Code required to embed the Justin.TV Player, response looks like:
64
+ ```
65
+
66
+ ```
67
+ <object type="application/x-shockwave-flash" height="295" width="353" id="jtv_player_flash" data="http://www.justin.tv/widgets/jtv_player.swf?channel=apidemo&quot; bgcolor="#000000"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://www.justin.tv/widgets/jtv_player.swf&quot; /><param name="flashvars" value="channel=apidemo&auto_play=false&start_volume=25" /></object>
68
+ ```
69
+
70
+ ```ruby
71
+ channel.title
72
+ channel.url
73
+ channel.about
74
+ channel.description
75
+ ```
76
+
77
+ ### JtvClip
78
+ The JtvClip class provides access to specific clip information. To
79
+ create a clip object, simply pass the clip id when you initialize the
80
+ object.
81
+
82
+ ```ruby
83
+ clip = JtvClip.new( 1278312 )
84
+ ```
85
+
86
+ The following method calls are available through the Clip class.
87
+
88
+ ```ruby
89
+ clip.description
90
+ clip.title
91
+ clip.id
92
+ clip.tags
93
+ clip.embed
94
+ clip.image_huge
95
+ clip.length
96
+ clip.created_on
97
+ ```
98
+
99
+ ## Contributing
100
+
101
+ Contributions and feedback are more than welcome and highly encouraged.
102
+
103
+ 1. Fork it
104
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
105
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
106
+ 4. Push to the branch (`git push origin my-new-feature`)
107
+ 5. Create new Pull Request
108
+
109
+ ## TODO
110
+
111
+ * Add JtvCategory, which will return an array of objects from a category.
112
+ * Add support for POST API calls.
113
+
114
+ ## Contact
115
+
116
+ [david@mockra.com](mailto:david@mockra.com)
117
+
118
+ [@Mockra_](http://twitter.com/#!/mockra_)
119
+
120
+ [mockra.com](http://mockra.com)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/jtv/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Mockra"]
6
+ gem.email = ["david@mockra.com"]
7
+ gem.description = %q{Gem for quickly accessing the Justin.TV API}
8
+ gem.summary = %q{This tool provides simple Rails integration for common Justin.TV API calls.}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "jtv"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Jtv::VERSION
17
+
18
+ gem.add_development_dependency 'rspec'
19
+ gem.add_dependency 'json'
20
+ gem.add_dependency 'oauth'
21
+ end
@@ -0,0 +1,48 @@
1
+ require "jtv/version"
2
+ require 'jtv/jtv_channel'
3
+ require 'jtv/jtv_clip'
4
+
5
+ require 'json'
6
+
7
+ module Jtv
8
+
9
+ require 'oauth'
10
+
11
+ class JtvClient
12
+
13
+ # Set API Keys through environment variables.
14
+ CONSUMER_KEY = ENV['JTV_CONSUMER_KEY']
15
+ CONSUMER_SECRET = ENV['JTV_CONSUMER_SECRET']
16
+
17
+ def initialize
18
+ @consumer = OAuth::Consumer.new(
19
+ CONSUMER_KEY,
20
+ CONSUMER_SECRET,
21
+ :site => "http://api.justin.tv",
22
+ :http_method => :get
23
+ )
24
+ end
25
+
26
+ def get(path, access_token=nil)
27
+ (access_token || default_token).get("/api#{path}")
28
+ end
29
+
30
+ def post(path, post_params, access_token=nil)
31
+ (access_token || default_token).post("/api#{path}", post_params)
32
+ end
33
+
34
+ def make_request_token
35
+ @consumer.get_request_token
36
+ end
37
+
38
+ def exchange_request_token_for_access_token(request_token)
39
+ request_token.get_access_token
40
+ end
41
+
42
+ private
43
+ def default_token
44
+ OAuth::AccessToken.new @consumer
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,37 @@
1
+ class JtvChannel
2
+
3
+ require 'jtv'
4
+
5
+ attr_reader :viewers, :title, :url, :image_huge, :screen_cap_huge,
6
+ :id, :about, :description, :embed, :blog, :facebook
7
+
8
+ def initialize(channel)
9
+ client = Jtv::JtvClient.new
10
+ json_data = client.get( "/channel/show/#{channel}.json" )
11
+
12
+ data = JSON.parse json_data.body
13
+
14
+ @id = channel
15
+ @title = data['title']
16
+ @url = data['channel_url']
17
+ @image_huge = data['image_url_huge']
18
+ @screen_cap_huge = data['screen_cap_url_huge']
19
+ @about = data['about']
20
+ @description = data['description']
21
+ @embed = data['embed_code']
22
+ @blog = data['blog']
23
+ @facebook = data['facebook']
24
+ end
25
+
26
+ def viewers
27
+ client = Jtv::JtvClient.new
28
+ json_data = client.get( "/stream/list.json?channel=#{self.id}" )
29
+ if json_data.body == "[]"
30
+ return 0
31
+ else
32
+ data = JSON.parse( json_data.body )
33
+ end
34
+ data[0]['stream_count'].to_i
35
+ end
36
+
37
+ end
@@ -0,0 +1,26 @@
1
+ class JtvClip
2
+
3
+ require 'jtv'
4
+
5
+ attr_reader :description, :created_on, :length, :id, :title,
6
+ :tags, :embed, :image_huge
7
+
8
+ def initialize(clip)
9
+
10
+ client = Jtv::JtvClient.new
11
+ json_data = client.get( "/clip/show/#{clip}.json" )
12
+
13
+ data = JSON.parse json_data.body
14
+ data = data[0]
15
+
16
+ @description = data['description']
17
+ @created_on = data['created_on']
18
+ @length = data['length']
19
+ @id = clip
20
+ @title = data['title']
21
+ @tags = data['tags']
22
+ @embed = data['embed_code']
23
+ @image_huge = data['image_url_huge']
24
+ end
25
+
26
+ end
@@ -0,0 +1,3 @@
1
+ module Jtv
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe JtvChannel do
4
+
5
+ describe 'initialize' do
6
+
7
+ it 'should create a channel' do
8
+ channel = JtvChannel.new( 'mockra' )
9
+ channel.should be_a JtvChannel
10
+ end
11
+
12
+ end
13
+
14
+ describe 'viewers' do
15
+
16
+ it 'should return an integer' do
17
+ channel = JtvChannel.new( 'mockra' )
18
+ channel.viewers.should be_a Integer
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe JtvClip do
4
+
5
+ describe 'initialize' do
6
+
7
+ it 'should create a clip' do
8
+ clip = JtvClip.new( 1278312 )
9
+ clip.should be_a JtvClip
10
+ end
11
+
12
+ it 'should set the correct length' do
13
+ clip = JtvClip.new( 1278312 )
14
+ clip.length.should == 22
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jtv do
4
+
5
+ describe 'JtvClient' do
6
+
7
+ it 'should set the consumer_key' do
8
+ pending('Need to test the environment variables')
9
+ Jtv::JtvClient::CONSUMER_KEY.should == ENV['JTV_CONSUMER_KEY']
10
+ end
11
+
12
+ it 'should create a client' do
13
+ client = Jtv::JtvClient.new
14
+ client.should be_a Jtv::JtvClient
15
+ end
16
+
17
+ describe 'get' do
18
+
19
+ it 'should return Net::HTTPOK' do
20
+ client = Jtv::JtvClient.new
21
+ data = client.get( '/stream/list.json' )
22
+ data.should be_a(Net::HTTPOK)
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1 @@
1
+ require 'jtv'
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jtv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mockra
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70143935183360 !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: *70143935183360
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ requirement: &70143935182380 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70143935182380
36
+ - !ruby/object:Gem::Dependency
37
+ name: oauth
38
+ requirement: &70143935181580 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70143935181580
47
+ description: Gem for quickly accessing the Justin.TV API
48
+ email:
49
+ - david@mockra.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .rspec
56
+ - CHANGELOG.md
57
+ - Gemfile
58
+ - LICENSE
59
+ - README.md
60
+ - Rakefile
61
+ - jtv.gemspec
62
+ - lib/jtv.rb
63
+ - lib/jtv/jtv_channel.rb
64
+ - lib/jtv/jtv_clip.rb
65
+ - lib/jtv/version.rb
66
+ - spec/jtv/jtv_channel_spec.rb
67
+ - spec/jtv/jtv_clip_spec.rb
68
+ - spec/jtv_spec.rb
69
+ - spec/spec_helper.rb
70
+ homepage: ''
71
+ licenses: []
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.13
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: This tool provides simple Rails integration for common Justin.TV API calls.
94
+ test_files:
95
+ - spec/jtv/jtv_channel_spec.rb
96
+ - spec/jtv/jtv_clip_spec.rb
97
+ - spec/jtv_spec.rb
98
+ - spec/spec_helper.rb