Module: KalturaFu::Entry::Metadata
- Defined in:
- lib/kaltura_fu.rb,
lib/kaltura_fu/entry/metadata.rb,
lib/kaltura_fu/entry/metadata/class_and_instance_methods.rb
Defined Under Namespace
Modules: ClassAndInstanceMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#add_attribute(attr_name, entry_id, value) ⇒ String
Appends a specific Kaltura::MediaEntry attribute to the end of the original attribute given a Kaltura entry.
- #add_categories_to_kaltura(categories) ⇒ Object
- #category_exists?(category_name) ⇒ Boolean
-
#get_entry(entry_id) ⇒ Kaltura::MediaEntry
Gets a Kaltura::MediaEntry given a Kaltura entry.
- #method_missing(name, *args) ⇒ Object
- #respond_to?(method) ⇒ Boolean
-
#set_attribute(attr_name, entry_id, value) ⇒ String
Sets a specific Kaltura::MediaEntry attribute given a Kaltura entry.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/kaltura_fu/entry/metadata.rb', line 21 def method_missing(name, *args) case name.to_s when /^set_(.*)/ valid_entry_attribute?($1.to_sym) ? set_attribute($1,*args) : super when /^add_(.*)/ valid_entry_attribute?($1.pluralize.to_sym) ? add_attribute($1.pluralize,*args) : super when /^get_(.*)/ valid_entry_attribute?($1.to_sym) ? get_entry(*args).send($1.to_sym) : super else super end end |
Class Method Details
.included(base) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/kaltura_fu/entry/metadata.rb', line 10 def self.included(base) base.extend ClassAndInstanceMethods base.class_eval do include ClassAndInstanceMethods end super end |
Instance Method Details
#add_attribute(attr_name, entry_id, value) ⇒ String
Appends a specific Kaltura::MediaEntry attribute to the end of the original attribute given a Kaltura entry. This method is called by method_missing, allowing this module add attributes based off of the current API wrapper, rather than having to update along side the API wrapper.
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/kaltura_fu/entry/metadata.rb', line 133 def add_attribute(attr_name,entry_id,value) KalturaFu.check_for_client_session add_categories_to_kaltura(value) if (attr_name =~ /^(.*)_categor(ies|y)/ || attr_name =~ /^categor(ies|y)/) old_attributes = KalturaFu.client.media_service.get(entry_id).send(attr_name.to_sym) media_entry = Kaltura::MediaEntry.new media_entry.send("#{attr_name}=","#{old_attributes},#{value}") KalturaFu.client.media_service.update(entry_id,media_entry).send(attr_name.to_sym) end |
#add_categories_to_kaltura(categories) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/kaltura_fu/entry/metadata.rb', line 90 def add_categories_to_kaltura(categories) KalturaFu.check_for_client_session categories.split(",").each do |category| unless category_exists?(category) cat = Kaltura::Category.new cat.name = category KalturaFu.client.category_service.add(cat) end end end |
#category_exists?(category_name) ⇒ Boolean
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/kaltura_fu/entry/metadata.rb', line 105 def category_exists?(category_name) KalturaFu.check_for_client_session category_filter = Kaltura::Filter::CategoryFilter.new category_filter.full_name_equal = category_name category_check = KalturaFu.client.category_service.list(category_filter).objects if category_check.nil? false else category_check end end |
#get_entry(entry_id) ⇒ Kaltura::MediaEntry
Gets a Kaltura::MediaEntry given a Kaltura entry.
56 57 58 59 60 |
# File 'lib/kaltura_fu/entry/metadata.rb', line 56 def get_entry(entry_id) KalturaFu.check_for_client_session KalturaFu.client.media_service.get(entry_id) end |
#respond_to?(method) ⇒ Boolean
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/kaltura_fu/entry/metadata.rb', line 37 def respond_to?(method) case method.to_s when /^(get|set)_(.*)/ valid_entry_attribute?($2.to_sym) || super when /^(add)_(.*)/ (valid_entry_attribute?($2.pluralize.to_sym) && valid_add_attribute?($2) ) || super else super end end |
#set_attribute(attr_name, entry_id, value) ⇒ String
Sets a specific Kaltura::MediaEntry attribute given a Kaltura entry. This method is called by method_missing, allowing this module set attributes based off of the current API wrapper, rather than having to update along side the API wrapper.
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/kaltura_fu/entry/metadata.rb', line 76 def set_attribute(attr_name,entry_id,value) KalturaFu.check_for_client_session add_categories_to_kaltura(value) if (attr_name =~ /^(.*)_categories/ || attr_name =~ /^categories/) media_entry = Kaltura::MediaEntry.new media_entry.send("#{attr_name}=",value) KalturaFu.client.media_service.update(entry_id,media_entry).send(attr_name.to_sym) end |