Class: YoutubeEmbed::VideoDetails
- Inherits:
-
VideoObject
show all
- Includes:
- HTTParty
- Defined in:
- lib/youtube_embed/video_details.rb
Constant Summary
collapse
- VALID_METHODS =
[:comments, :id, :published, :updated, :category, :title, :content, :link,
:where, {:group => [:category, :content, :description, :keywords,
:player, :thumbnail, :title]}]
Instance Method Summary
collapse
Methods inherited from VideoObject
#recursive_hash_access
Constructor Details
#initialize(video_details) ⇒ VideoDetails
Returns a new instance of VideoDetails.
11
12
13
14
15
|
# File 'lib/youtube_embed/video_details.rb', line 11
def initialize video_details
@dynamic_methods = {}
@id = video_details.respond_to?(:keys) ? video_details["id"].split("/").last : video_details
@entry = (video_details if video_details.respond_to?(:keys))
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/youtube_embed/video_details.rb', line 44
def method_missing method
(entry;@dynamic_methods[method]) if @dynamic_methods.blank?
return self.class.get_youtube(@dynamic_methods[method].split("videos/").last)["feed"]["entry"] if [:raw_video_details_responses,:raw_related_videos].include? method
return send("raw_#{method}").map{|v| YoutubeEmbed::VideoDetails.new(v)} if [:video_details_responses,:related_videos].include? method
@dynamic_methods[method] || super
end
|
Instance Method Details
#dynamic_methods ⇒ Object
21
22
23
24
|
# File 'lib/youtube_embed/video_details.rb', line 21
def dynamic_methods
h={};@dynamic_methods.each {|k,v| h[v.class].nil? ? h[v.class]=[k] : h[v.class] << k}
return h
end
|
#entry ⇒ Object
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/youtube_embed/video_details.rb', line 26
def entry
@entry ||= self.class.get_youtube(@id)["entry"]
if @dynamic_methods.blank?
VALID_METHODS.each {|key| recursive_hash_access @dynamic_methods, @entry, key}
define_links
end
return @entry
rescue MultiXml::ParseError
raise InvalidVideoDetails
end
|
#id ⇒ Object
17
18
19
|
# File 'lib/youtube_embed/video_details.rb', line 17
def id
@id
end
|