Module: KalturaFu::Entry::Metadata

Defined in:
lib/kaltura_fu/entry/metadata.rb,
lib/kaltura_fu.rb,
lib/kaltura_fu/entry/metadata/class_methods.rb,
lib/kaltura_fu/entry/metadata/class_and_instance_methods.rb

Overview

The Metadata module provides methods that get/set and add metadata to the Kaltura installation.

Author:

  • Patrick Robertson

Defined Under Namespace

Modules: ClassAndInstanceMethods, ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/kaltura_fu/entry/metadata.rb', line 29

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



17
18
19
20
21
22
23
24
# File 'lib/kaltura_fu/entry/metadata.rb', line 17

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.

Parameters:

  • attr_name (String)

    The attribute to set.

  • entry_id (String)

    The Kaltura entry ID.

  • value (String)

    The value you wish to append the attribute with.

Returns:

  • (String)

    Returns the value as stored in the Kaltura database. Tag strings come back slightly funny.

Raises:

  • (Kaltura::APIError)

    Passes Kaltura API errors directly through.



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/kaltura_fu/entry/metadata.rb', line 142

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



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/kaltura_fu/entry/metadata.rb', line 99

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

Returns:

  • (Boolean)


114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/kaltura_fu/entry/metadata.rb', line 114

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.

Parameters:

  • video_id (String)

    Kaltura entry_id of the video.

Returns:

  • (Kaltura::MediaEntry)

    The MediaEntry object for the Kaltura entry.



65
66
67
68
69
# File 'lib/kaltura_fu/entry/metadata.rb', line 65

def get_entry(entry_id)  
  KalturaFu.check_for_client_session

  KalturaFu.client.media_service.get(entry_id)      
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
55
# File 'lib/kaltura_fu/entry/metadata.rb', line 46

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.

Parameters:

  • attr_name (String)

    The attribute to set.

  • entry_id (String)

    The Kaltura entry ID.

  • value (String)

    The value you wish to set the attribute to.

Returns:

  • (String)

    Returns the value as stored in the Kaltura database. Tag strings come back slightly funny.

Raises:

  • (Kaltura::APIError)

    Passes Kaltura API errors directly through.



85
86
87
88
89
90
91
92
93
94
# File 'lib/kaltura_fu/entry/metadata.rb', line 85

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