Class: BasicYoutube::Channel
Constant Summary
collapse
- VALID_METHODS =
[:thumbnail, :id, :published, :updated, :category, :title, :content,
:link, {:author=>[:name, :uri]}, :age, :company, :description, :feed_link,
:first_name, :gender, :location, :occupation, {:statistics=> [:last_web_access,
:subscriber_count, :video_watch_count, :view_count, :total_upload_views]}, :username]
Instance Method Summary
collapse
#recursive_hash_access
Constructor Details
#initialize(username) ⇒ Channel
Returns a new instance of Channel.
12
13
14
15
16
17
|
# File 'lib/basic_youtube/channel.rb', line 12
def initialize username
@dynamic_methods = {}
@username = username
@entry = nil
@all_videos=nil
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
72
73
74
75
|
# File 'lib/basic_youtube/channel.rb', line 72
def method_missing method
entry if @dynamic_methods.blank?
@dynamic_methods[method] || super
end
|
Instance Method Details
#entry ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/basic_youtube/channel.rb', line 19
def entry
@entry ||= self.class.call_youtube(@username)["entry"]
if @dynamic_methods.blank?
VALID_METHODS.each {|key| recursive_hash_access @dynamic_methods, @entry, key}
define_feeds
end
return @entry
rescue MultiXml::ParseError
raise InvalidAccount
end
|
#hours_uploaded ⇒ Object
59
60
61
62
|
# File 'lib/basic_youtube/channel.rb', line 59
def hours_uploaded
v=pull_all_videos
v.map(&:hours).sum
end
|
#pull_all_videos ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/basic_youtube/channel.rb', line 35
def pull_all_videos
calls = (upload_count+1)/50
i = 0
videos = []
while i<=calls
pull_videos(i*50+1, 50).each {|v| videos << v}
i+=1
end
@all_videos = videos
return videos
end
|
#pull_raw_videos(start = 1, max_results = 25) ⇒ Object
47
48
49
50
51
|
# File 'lib/basic_youtube/channel.rb', line 47
def pull_raw_videos start=1, max_results=25
max_results=50 if max_results-start>50
videos = self.class.call_youtube(@username,"/uploads?start-index=#{start}&max-results=#{max_results}")["feed"]["entry"]
return max_results==1 ? [videos] : videos
end
|
#pull_videos(start = 1, max_results = 25) ⇒ Object
30
31
32
33
|
# File 'lib/basic_youtube/channel.rb', line 30
def pull_videos start=1, max_results=25
return @all_videos[start-1..start+max_results-1] if @all_videos.present?
pull_raw_videos(start,max_results).map{|v| BasicYoutube::Video.new(v)}
end
|
#respond_to?(method) ⇒ Boolean
53
54
55
56
57
|
# File 'lib/basic_youtube/channel.rb', line 53
def respond_to?(method)
entry if @dynamic_methods.blank?
return true if @dynamic_methods.keys.include? method
super
end
|