Class: Kaltura::ClassFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/kaltura/kaltura_client_base.rb

Class Method Summary collapse

Class Method Details

.object_from_xml(xml_element) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/kaltura/kaltura_client_base.rb', line 238

def self.object_from_xml(xml_element)
	instance = nil
       if xml_element.elements.size > 0
		if xml_element.elements[1].name == 'item' # array	
			instance = []
			xml_element.elements.each('item') do | element |
				instance.push(ClassFactory.object_from_xml(element))
			end
		else # object
			object_type_element = xml_element.get_text('objectType')
			if (object_type_element != nil)
				object_class = xml_element.get_text('objectType').value
				instance = ClassFactory.set_instance(object_class)
				xml_element.elements.each do | element |
					value = ClassFactory.object_from_xml(element)
					instance.send(self.underscore(element.name) + "=", value);
				end
			end
		end
	else # simple type
       	return xml_element.text
      	end
	
      	return instance;
end

.request_is_response?(request) ⇒ Boolean

Returns:

  • (Boolean)


284
285
286
287
288
# File 'lib/kaltura/kaltura_client_base.rb', line 284

def self.request_is_response?(request)
 request_array = []
 request_array << request
 request_array == request.split("Response",0)
end

.set_instance(object_request_class) ⇒ Object



268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/kaltura/kaltura_client_base.rb', line 268

def self.set_instance(object_request_class)
 string_object_class = object_request_class.to_s
 instance = nil
 stripped_request = ClassFactory.strip_kaltura_from_request(string_object_class)
 instance = Module.const_get("Kaltura")
 unless ClassFactory.request_is_response?(string_object_class)
   instance = instance.const_get("Response").const_get(stripped_request).new
  else
    instance = instance.const_get(stripped_request).new
   end		  
   instance
end

.strip_kaltura_from_request(request) ⇒ Object



281
282
283
# File 'lib/kaltura/kaltura_client_base.rb', line 281

def self.strip_kaltura_from_request(request)
 request.gsub("Kaltura","")
end

.underscore(val) ⇒ Object



264
265
266
# File 'lib/kaltura/kaltura_client_base.rb', line 264

def self.underscore(val)
	val.gsub(/(.)([A-Z]+)/,'\1_\2').downcase
end