jtv 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -33,15 +33,31 @@ ENV['JTV_CONSUMER_SECRET']
33
33
  ## Usage
34
34
 
35
35
  The Jtv gem offers various classes depending on the type of information
36
- you're looking for.
36
+ you're looking for. JtvChannel and JtvClip should be used for creating records.
37
+ Jtv methods should be used for updating records.
38
+
39
+ It's reccomended to cache your requests, and to always keep your
40
+ account's rate limit in mind.
41
+
42
+ Check out the [RDOC](http://rubydoc.info/github/Mockra/Jtv/).
43
+
44
+ ### Jtv
45
+
46
+ ```ruby
47
+ Jtv.channel_viewers( 'channel_handle' )
48
+ ```
49
+
50
+ This method will return nil if the stream is offline. Use this
51
+ method for providing realtime viewer numbers and stream status.
37
52
 
38
53
  ### JtvChannel
54
+
39
55
  The JtvChannel class provides access to stream information for a
40
56
  specific channel. You'll need to pass the channel handle when you
41
57
  initialize your object.
42
58
 
43
59
  ```ruby
44
- channel = JtvChannel.new( 'channel' )
60
+ channel = JtvChannel.new( 'channel_handle' )
45
61
  ```
46
62
 
47
63
  You'll then have access to the following information.
@@ -49,6 +65,11 @@ You'll then have access to the following information.
49
65
  ```ruby
50
66
  channel.viewers
51
67
  # Number of current viewers on the stream, requires a second API call
68
+ # If the stream is offline, this will return nil
69
+
70
+ Jtv.channel_viewers( 'channel_handle' )
71
+ # This will return nil for offline streams.
72
+ # Use this method for updating current viewers
52
73
 
53
74
  channel.image_huge
54
75
  # 320x240 Image URL
@@ -75,6 +96,7 @@ channel.description
75
96
  ```
76
97
 
77
98
  ### JtvClip
99
+
78
100
  The JtvClip class provides access to specific clip information. To
79
101
  create a clip object, simply pass the clip id when you initialize the
80
102
  object.
@@ -106,11 +128,6 @@ Contributions and feedback are more than welcome and highly encouraged.
106
128
  4. Push to the branch (`git push origin my-new-feature`)
107
129
  5. Create new Pull Request
108
130
 
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
131
  ## Contact
115
132
 
116
133
  [david@mockra.com](mailto:david@mockra.com)
data/lib/jtv.rb CHANGED
@@ -8,6 +8,17 @@ module Jtv
8
8
 
9
9
  require 'oauth'
10
10
 
11
+ def self.channel_viewers( channel )
12
+ client = Jtv::JtvClient.new
13
+ json_data = client.get( "/stream/list.json?channel=#{channel}" )
14
+ if json_data.body == "[]"
15
+ return nil
16
+ else
17
+ data = JSON.parse( json_data.body )
18
+ end
19
+ data[0]['stream_count'].to_i
20
+ end
21
+
11
22
  class JtvClient
12
23
 
13
24
  # Set API Keys through environment variables.
@@ -5,6 +5,8 @@ class JtvChannel
5
5
  attr_reader :viewers, :title, :url, :image_huge, :screen_cap_huge,
6
6
  :id, :about, :description, :embed, :blog, :facebook
7
7
 
8
+ # Create a new channel object, this method should be passed the channel handle.
9
+ # Example: channel = JtvChannel.new( 'day9tv' )
8
10
  def initialize(channel)
9
11
  client = Jtv::JtvClient.new
10
12
  json_data = client.get( "/channel/show/#{channel}.json" )
@@ -23,11 +25,12 @@ class JtvChannel
23
25
  @facebook = data['facebook']
24
26
  end
25
27
 
28
+ # Polls the Justin.TV API to find the number of current viewers on the channel.
26
29
  def viewers
27
30
  client = Jtv::JtvClient.new
28
31
  json_data = client.get( "/stream/list.json?channel=#{self.id}" )
29
32
  if json_data.body == "[]"
30
- return 0
33
+ return nil
31
34
  else
32
35
  data = JSON.parse( json_data.body )
33
36
  end
data/lib/jtv/jtv_clip.rb CHANGED
@@ -5,6 +5,8 @@ class JtvClip
5
5
  attr_reader :description, :created_on, :length, :id, :title,
6
6
  :tags, :embed, :image_huge
7
7
 
8
+ # Create a new clip object, this method should be passed the clip id.
9
+ # Example: clip = JtvClip.new( 1894735 )
8
10
  def initialize(clip)
9
11
 
10
12
  client = Jtv::JtvClient.new
data/lib/jtv/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jtv
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-29 00:00:00.000000000 Z
12
+ date: 2012-04-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70143935183360 !ruby/object:Gem::Requirement
16
+ requirement: &70359962754580 !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: *70143935183360
24
+ version_requirements: *70359962754580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &70143935182380 !ruby/object:Gem::Requirement
27
+ requirement: &70359962753100 !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: *70143935182380
35
+ version_requirements: *70359962753100
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: oauth
38
- requirement: &70143935181580 !ruby/object:Gem::Requirement
38
+ requirement: &70359962751300 !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: *70143935181580
46
+ version_requirements: *70359962751300
47
47
  description: Gem for quickly accessing the Justin.TV API
48
48
  email:
49
49
  - david@mockra.com
@@ -79,15 +79,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
79
  - - ! '>='
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
+ segments:
83
+ - 0
84
+ hash: -4210132887760206074
82
85
  required_rubygems_version: !ruby/object:Gem::Requirement
83
86
  none: false
84
87
  requirements:
85
88
  - - ! '>='
86
89
  - !ruby/object:Gem::Version
87
90
  version: '0'
91
+ segments:
92
+ - 0
93
+ hash: -4210132887760206074
88
94
  requirements: []
89
95
  rubyforge_project:
90
- rubygems_version: 1.8.13
96
+ rubygems_version: 1.8.11
91
97
  signing_key:
92
98
  specification_version: 3
93
99
  summary: This tool provides simple Rails integration for common Justin.TV API calls.