jtv 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,2 +1,8 @@
1
1
  # v0.0.1
2
2
  * Initial Release with JtvChannel and JtvClip
3
+
4
+ # v0.0.2
5
+ * Added Jtv.channel_viewers
6
+
7
+ # v0.0.3
8
+ * Added JtvSearch
data/README.md CHANGED
@@ -50,6 +50,30 @@ Jtv.channel_viewers( 'channel_handle' )
50
50
  This method will return nil if the stream is offline. Use this
51
51
  method for providing realtime viewer numbers and stream status.
52
52
 
53
+ ### JtvSearch
54
+
55
+ The JtvSearch provides access to the search api. If you pass
56
+ JtvSearch.get a search query, it will return an array of channels.
57
+ This class makes it easy to include a generic livestream list for your
58
+ website.
59
+
60
+ ```ruby
61
+ streams = JtvSearch.get( 'league of legends', 50 )
62
+ # You can pass the get method a search query, as well as
63
+ # an optional stream limit that goes up to 100 and defaults to 20
64
+
65
+ streams.each do |stream|
66
+
67
+ stream.id
68
+ stream.title
69
+ stream.url
70
+ stream.viewers
71
+ stream.image_huge
72
+ stream.screen_cap_huge
73
+
74
+ end
75
+ ```
76
+
53
77
  ### JtvChannel
54
78
 
55
79
  The JtvChannel class provides access to stream information for a
@@ -0,0 +1,34 @@
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
data/lib/jtv/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jtv
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/jtv.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "jtv/version"
2
2
  require 'jtv/jtv_channel'
3
3
  require 'jtv/jtv_clip'
4
+ require 'jtv/jtv_search'
4
5
 
5
6
  require 'json'
6
7
 
@@ -8,6 +9,7 @@ module Jtv
8
9
 
9
10
  require 'oauth'
10
11
 
12
+ # Get current viewers for a specific channel
11
13
  def self.channel_viewers( channel )
12
14
  client = Jtv::JtvClient.new
13
15
  json_data = client.get( "/stream/list.json?channel=#{channel}" )
@@ -13,9 +13,9 @@ describe JtvChannel do
13
13
 
14
14
  describe 'viewers' do
15
15
 
16
- it 'should return an integer' do
16
+ it 'should return nil' do
17
17
  channel = JtvChannel.new( 'mockra' )
18
- channel.viewers.should be_a Integer
18
+ channel.viewers.should be_nil
19
19
  end
20
20
 
21
21
  end
@@ -0,0 +1,25 @@
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
data/spec/jtv_spec.rb CHANGED
@@ -2,6 +2,15 @@ require 'spec_helper'
2
2
 
3
3
  describe Jtv do
4
4
 
5
+ describe 'channel_viewers' do
6
+
7
+ it 'should return nil' do
8
+ views = Jtv.channel_viewers( 'mockra' )
9
+ views.should be_nil
10
+ end
11
+
12
+ end
13
+
5
14
  describe 'JtvClient' do
6
15
 
7
16
  it 'should set the consumer_key' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jtv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70359962754580 !ruby/object:Gem::Requirement
16
+ requirement: &70137589529880 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70359962754580
24
+ version_requirements: *70137589529880
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &70359962753100 !ruby/object:Gem::Requirement
27
+ requirement: &70137589528640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70359962753100
35
+ version_requirements: *70137589528640
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: oauth
38
- requirement: &70359962751300 !ruby/object:Gem::Requirement
38
+ requirement: &70137589526900 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70359962751300
46
+ version_requirements: *70137589526900
47
47
  description: Gem for quickly accessing the Justin.TV API
48
48
  email:
49
49
  - david@mockra.com
@@ -62,9 +62,11 @@ files:
62
62
  - lib/jtv.rb
63
63
  - lib/jtv/jtv_channel.rb
64
64
  - lib/jtv/jtv_clip.rb
65
+ - lib/jtv/jtv_search.rb
65
66
  - lib/jtv/version.rb
66
67
  - spec/jtv/jtv_channel_spec.rb
67
68
  - spec/jtv/jtv_clip_spec.rb
69
+ - spec/jtv/jtv_search_spec.rb
68
70
  - spec/jtv_spec.rb
69
71
  - spec/spec_helper.rb
70
72
  homepage: ''
@@ -81,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
83
  version: '0'
82
84
  segments:
83
85
  - 0
84
- hash: -4210132887760206074
86
+ hash: -1700366459635922060
85
87
  required_rubygems_version: !ruby/object:Gem::Requirement
86
88
  none: false
87
89
  requirements:
@@ -90,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
92
  version: '0'
91
93
  segments:
92
94
  - 0
93
- hash: -4210132887760206074
95
+ hash: -1700366459635922060
94
96
  requirements: []
95
97
  rubyforge_project:
96
98
  rubygems_version: 1.8.11
@@ -100,5 +102,6 @@ summary: This tool provides simple Rails integration for common Justin.TV API ca
100
102
  test_files:
101
103
  - spec/jtv/jtv_channel_spec.rb
102
104
  - spec/jtv/jtv_clip_spec.rb
105
+ - spec/jtv/jtv_search_spec.rb
103
106
  - spec/jtv_spec.rb
104
107
  - spec/spec_helper.rb