Module: KalturaFu::Entry::Metadata
- Defined in:
- lib/kaltura_fu.rb,
lib/kaltura_fu/entry/metadata.rb,
lib/kaltura_fu/entry/metadata/class_methods.rb,
lib/kaltura_fu/entry/metadata/class_and_instance_methods.rb
Defined Under Namespace
Modules: ClassAndInstanceMethods, ClassMethods
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
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kaltura_fu/entry/metadata.rb', line 22 def method_missing(name, *args) method_name = name.to_s unless self.class.generated_methods? self.class.define_attribute_methods if self.class.generated_methods.include?(method_name) return self.send(name,*args) else super end else super end end |
Class Method Details
.included(base) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/kaltura_fu/entry/metadata.rb', line 10 def self.included(base) base.extend ClassAndInstanceMethods base.extend ClassMethods 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.
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/kaltura_fu/entry/metadata.rb', line 135 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
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/kaltura_fu/entry/metadata.rb', line 92 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
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/kaltura_fu/entry/metadata.rb', line 107 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.
58 59 60 61 62 |
# File 'lib/kaltura_fu/entry/metadata.rb', line 58 def get_entry(entry_id) KalturaFu.check_for_client_session KalturaFu.client.media_service.get(entry_id) end |
#respond_to?(method) ⇒ Boolean
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/kaltura_fu/entry/metadata.rb', line 39 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.
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/kaltura_fu/entry/metadata.rb', line 78 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 |