jtv 0.0.3 → 1.0.0.alpha1
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.
- data/CHANGELOG.md +5 -0
- data/LICENSE +2 -2
- data/README.md +44 -92
- data/jtv.gemspec +10 -5
- data/lib/jtv.rb +12 -49
- data/lib/jtv/client.rb +44 -0
- data/lib/jtv/configuration.rb +9 -0
- data/lib/jtv/defaults.rb +23 -0
- data/lib/jtv/stream.rb +18 -0
- data/lib/jtv/version.rb +1 -1
- data/spec/features/stream_spec.rb +33 -0
- data/spec/jtv/client_spec.rb +28 -0
- data/spec/jtv/configuration_spec.rb +16 -0
- data/spec/jtv/defaults_spec.rb +25 -0
- data/spec/jtv/stream_spec.rb +29 -0
- data/spec/jtv_spec.rb +20 -23
- data/spec/vcr_cassettes/Jtv_Stream.yml +81 -0
- data/spec/vcr_cassettes/Jtv_Stream/_list.yml +408 -0
- data/spec/vcr_cassettes/Jtv_Stream/_search.yml +156 -0
- data/spec/vcr_cassettes/Jtv_Stream/_summary.yml +81 -0
- data/spec/vcr_config.rb +11 -0
- metadata +107 -33
- data/lib/jtv/jtv_channel.rb +0 -40
- data/lib/jtv/jtv_clip.rb +0 -28
- data/lib/jtv/jtv_search.rb +0 -34
- data/spec/jtv/jtv_channel_spec.rb +0 -23
- data/spec/jtv/jtv_clip_spec.rb +0 -20
- data/spec/jtv/jtv_search_spec.rb +0 -25
data/lib/jtv/jtv_channel.rb
DELETED
@@ -1,40 +0,0 @@
|
|
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
|
-
# Create a new channel object, this method should be passed the channel handle.
|
9
|
-
# Example: channel = JtvChannel.new( 'day9tv' )
|
10
|
-
def initialize(channel)
|
11
|
-
client = Jtv::JtvClient.new
|
12
|
-
json_data = client.get( "/channel/show/#{channel}.json" )
|
13
|
-
|
14
|
-
data = JSON.parse json_data.body
|
15
|
-
|
16
|
-
@id = channel
|
17
|
-
@title = data['title']
|
18
|
-
@url = data['channel_url']
|
19
|
-
@image_huge = data['image_url_huge']
|
20
|
-
@screen_cap_huge = data['screen_cap_url_huge']
|
21
|
-
@about = data['about']
|
22
|
-
@description = data['description']
|
23
|
-
@embed = data['embed_code']
|
24
|
-
@blog = data['blog']
|
25
|
-
@facebook = data['facebook']
|
26
|
-
end
|
27
|
-
|
28
|
-
# Polls the Justin.TV API to find the number of current viewers on the channel.
|
29
|
-
def viewers
|
30
|
-
client = Jtv::JtvClient.new
|
31
|
-
json_data = client.get( "/stream/list.json?channel=#{self.id}" )
|
32
|
-
if json_data.body == "[]"
|
33
|
-
return nil
|
34
|
-
else
|
35
|
-
data = JSON.parse( json_data.body )
|
36
|
-
end
|
37
|
-
data[0]['stream_count'].to_i
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
data/lib/jtv/jtv_clip.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
class JtvClip
|
2
|
-
|
3
|
-
require 'jtv'
|
4
|
-
|
5
|
-
attr_reader :description, :created_on, :length, :id, :title,
|
6
|
-
:tags, :embed, :image_huge
|
7
|
-
|
8
|
-
# Create a new clip object, this method should be passed the clip id.
|
9
|
-
# Example: clip = JtvClip.new( 1894735 )
|
10
|
-
def initialize(clip)
|
11
|
-
|
12
|
-
client = Jtv::JtvClient.new
|
13
|
-
json_data = client.get( "/clip/show/#{clip}.json" )
|
14
|
-
|
15
|
-
data = JSON.parse json_data.body
|
16
|
-
data = data[0]
|
17
|
-
|
18
|
-
@description = data['description']
|
19
|
-
@created_on = data['created_on']
|
20
|
-
@length = data['length']
|
21
|
-
@id = clip
|
22
|
-
@title = data['title']
|
23
|
-
@tags = data['tags']
|
24
|
-
@embed = data['embed_code']
|
25
|
-
@image_huge = data['image_url_huge']
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
data/lib/jtv/jtv_search.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
class JtvSearch
|
2
|
-
|
3
|
-
require 'jtv'
|
4
|
-
|
5
|
-
attr_reader :viewers, :title, :url, :image_huge, :screen_cap_huge, :id
|
6
|
-
|
7
|
-
# Creates a new JtvSearch object
|
8
|
-
def initialize( stream )
|
9
|
-
@viewers = stream['stream_count']
|
10
|
-
@title = stream['title']
|
11
|
-
@url = stream['channel']['channel_url']
|
12
|
-
@image_huge = stream['channel']['image_url_huge']
|
13
|
-
@screen_cap_huge = stream['channel']['screen_cap_url_huge']
|
14
|
-
@id = stream['channel']['login']
|
15
|
-
end
|
16
|
-
|
17
|
-
# Returns an array of objects based on search paramaters,
|
18
|
-
# pass the desired query, as well as an optional limit up to 100
|
19
|
-
def self.get( query, limit=20 )
|
20
|
-
client = Jtv::JtvClient.new
|
21
|
-
query.gsub!( /[ ]/, '%20' )
|
22
|
-
json_data = client.get( "/stream/search/#{query}.json?limit=#{limit}" )
|
23
|
-
|
24
|
-
data = JSON.parse json_data.body
|
25
|
-
search_array = Array.new
|
26
|
-
|
27
|
-
data.each do |stream|
|
28
|
-
search_array << JtvSearch.new( stream )
|
29
|
-
end
|
30
|
-
|
31
|
-
search_array
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
@@ -1,23 +0,0 @@
|
|
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 nil' do
|
17
|
-
channel = JtvChannel.new( 'mockra' )
|
18
|
-
channel.viewers.should be_nil
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
data/spec/jtv/jtv_clip_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
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
|
-
|
data/spec/jtv/jtv_search_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe JtvSearch do
|
4
|
-
|
5
|
-
describe 'get' do
|
6
|
-
|
7
|
-
it 'should return an array' do
|
8
|
-
streams = JtvSearch.get( 'league of legends', 20 )
|
9
|
-
streams.should be_a Array
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'should allow a search limit' do
|
13
|
-
streams = JtvSearch.get( 'league of legends', 4 )
|
14
|
-
streams.count.should <= 4
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should work with no search results' do
|
18
|
-
query = 'x' * 50
|
19
|
-
streams = JtvSearch.get( query )
|
20
|
-
streams.count.should == 0
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|