kaltura-ruby-client 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/README +20 -0
  3. data/Rakefile +19 -0
  4. data/agpl.txt +674 -0
  5. data/kaltura.yml +7 -0
  6. data/lib/kaltura.rb +31 -0
  7. data/lib/kaltura_client.rb +14450 -0
  8. data/lib/kaltura_client_base.rb +432 -0
  9. data/lib/kaltura_plugins/kaltura_abc_screeners_watermark_access_control_client_plugin.rb +37 -0
  10. data/lib/kaltura_plugins/kaltura_ad_cue_point_client_plugin.rb +108 -0
  11. data/lib/kaltura_plugins/kaltura_annotation_client_plugin.rb +237 -0
  12. data/lib/kaltura_plugins/kaltura_aspera_client_plugin.rb +61 -0
  13. data/lib/kaltura_plugins/kaltura_attachment_client_plugin.rb +227 -0
  14. data/lib/kaltura_plugins/kaltura_audit_client_plugin.rb +349 -0
  15. data/lib/kaltura_plugins/kaltura_bulk_upload_client_plugin.rb +109 -0
  16. data/lib/kaltura_plugins/kaltura_bulk_upload_csv_client_plugin.rb +55 -0
  17. data/lib/kaltura_plugins/kaltura_bulk_upload_filter_client_plugin.rb +46 -0
  18. data/lib/kaltura_plugins/kaltura_bulk_upload_xml_client_plugin.rb +40 -0
  19. data/lib/kaltura_plugins/kaltura_caption_client_plugin.rb +406 -0
  20. data/lib/kaltura_plugins/kaltura_caption_search_client_plugin.rb +138 -0
  21. data/lib/kaltura_plugins/kaltura_code_cue_point_client_plugin.rb +97 -0
  22. data/lib/kaltura_plugins/kaltura_content_distribution_client_plugin.rb +1717 -0
  23. data/lib/kaltura_plugins/kaltura_cue_point_client_plugin.rb +290 -0
  24. data/lib/kaltura_plugins/kaltura_document_client_plugin.rb +522 -0
  25. data/lib/kaltura_plugins/kaltura_drm_client_plugin.rb +204 -0
  26. data/lib/kaltura_plugins/kaltura_drop_folder_client_plugin.rb +810 -0
  27. data/lib/kaltura_plugins/kaltura_drop_folder_xml_bulk_upload_client_plugin.rb +39 -0
  28. data/lib/kaltura_plugins/kaltura_email_notification_client_plugin.rb +276 -0
  29. data/lib/kaltura_plugins/kaltura_event_notification_client_plugin.rb +405 -0
  30. data/lib/kaltura_plugins/kaltura_external_media_client_plugin.rb +203 -0
  31. data/lib/kaltura_plugins/kaltura_file_sync_client_plugin.rb +151 -0
  32. data/lib/kaltura_plugins/kaltura_http_notification_client_plugin.rb +309 -0
  33. data/lib/kaltura_plugins/kaltura_kontiki_client_plugin.rb +72 -0
  34. data/lib/kaltura_plugins/kaltura_like_client_plugin.rb +82 -0
  35. data/lib/kaltura_plugins/kaltura_metadata_client_plugin.rb +788 -0
  36. data/lib/kaltura_plugins/kaltura_multi_centers_client_plugin.rb +45 -0
  37. data/lib/kaltura_plugins/kaltura_short_link_client_plugin.rb +231 -0
  38. data/lib/kaltura_plugins/kaltura_tag_search_client_plugin.rb +145 -0
  39. data/lib/kaltura_plugins/kaltura_var_console_client_plugin.rb +238 -0
  40. data/lib/kaltura_plugins/kaltura_velocix_client_plugin.rb +40 -0
  41. data/lib/kaltura_plugins/kaltura_virus_scan_client_plugin.rb +263 -0
  42. data/lib/kaltura_plugins/kaltura_webex_drop_folder_client_plugin.rb +121 -0
  43. data/lib/kaltura_plugins/kaltura_widevine_client_plugin.rb +195 -0
  44. data/license.txt +674 -0
  45. data/test/access_control_service_test.rb +75 -0
  46. data/test/base_entry_service_test.rb +267 -0
  47. data/test/configuration_test.rb +178 -0
  48. data/test/cue_point_service_test.rb +67 -0
  49. data/test/data_service_test.rb +76 -0
  50. data/test/document_service_test.rb +41 -0
  51. data/test/media/test.mov +0 -0
  52. data/test/media/test.pdf +0 -0
  53. data/test/media/test.png +0 -0
  54. data/test/media/test.swf +0 -0
  55. data/test/media/test.wmv +0 -0
  56. data/test/media_service_test.rb +294 -0
  57. data/test/metadata_profile_service_test.rb +63 -0
  58. data/test/test_helper.rb +59 -0
  59. metadata +127 -0
@@ -0,0 +1,432 @@
1
+ # ===================================================================================================
2
+ # _ __ _ _
3
+ # | |/ /__ _| | |_ _ _ _ _ __ _
4
+ # | ' </ _` | | _| || | '_/ _` |
5
+ # |_|\_\__,_|_|\__|\_,_|_| \__,_|
6
+ #
7
+ # This file is part of the Kaltura Collaborative Media Suite which allows users
8
+ # to do with audio, video, and animation what Wiki platfroms allow them to do with
9
+ # text.
10
+ #
11
+ # Copyright (C) 2006-2011 Kaltura Inc.
12
+ #
13
+ # This program is free software: you can redistribute it and/or modify
14
+ # it under the terms of the GNU Affero General Public License as
15
+ # published by the Free Software Foundation, either version 3 of the
16
+ # License, or (at your option) any later version.
17
+ #
18
+ # This program is distributed in the hope that it will be useful,
19
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ # GNU Affero General Public License for more details.
22
+ #
23
+ # You should have received a copy of the GNU Affero General Public License
24
+ # along with this program. If not, see <http:#www.gnu.org/licenses/>.
25
+ #
26
+ # @ignore
27
+ # ===================================================================================================
28
+ require 'rubygems'
29
+ require 'json'
30
+ require 'net/http'
31
+ require 'digest/md5'
32
+ require 'rexml/document'
33
+ require 'rest_client'
34
+
35
+ require 'openssl'
36
+ require 'digest/sha1'
37
+ require 'base64'
38
+ require 'date'
39
+ require 'yaml'
40
+
41
+ module Kaltura
42
+ class KalturaNotImplemented; end
43
+
44
+ class KalturaClientBase
45
+ attr_accessor :config
46
+ attr_accessor :ks
47
+ attr_reader :is_multirequest
48
+ attr_reader :responseHeaders
49
+
50
+ def initialize(config)
51
+ @ks = KalturaNotImplemented
52
+ @should_log = false
53
+ @config = config
54
+ @calls_queue = []
55
+
56
+ if @config.logger != nil
57
+ @should_log = true
58
+ end
59
+ end
60
+
61
+ def queue_service_action_call(service, action, params = {})
62
+ # in start session partner id is optional (default nil). if partner id was not set, use the one in the config
63
+ if !params.key?('partnerId')
64
+ params['partnerId'] = config.partner_id
65
+ params.delete('partnerId__null') if params.key?('partnerId__null')
66
+ end
67
+
68
+ add_param(params, 'ks', @ks);
69
+
70
+ call = KalturaServiceActionCall.new(service, action, params);
71
+ @calls_queue.push(call);
72
+ end
73
+
74
+ def do_queue()
75
+ begin
76
+ @responseHeaders = {}
77
+ start_time = Time.now
78
+
79
+ if @calls_queue.length == 0
80
+ @is_multirequest = false
81
+ return []
82
+ end
83
+
84
+ log('service url: [' + @config.service_url + ']')
85
+
86
+ # append the basic params
87
+ params = {}
88
+ add_param(params, "format", @config.format)
89
+ add_param(params, "clientTag", @config.client_tag)
90
+
91
+ url = @config.service_url+"/api_v3/index.php?service="
92
+ if (@is_multirequest)
93
+ url += "multirequest"
94
+ i = 1
95
+ @calls_queue.each do |call|
96
+ call_params = call.get_params_for_multirequest(i)
97
+ params.merge!(call_params)
98
+ i = i.next
99
+ end
100
+ else
101
+ call = @calls_queue[0]
102
+ url += call.service + "&action=" + call.action
103
+ params.merge!(call.params)
104
+ end
105
+
106
+ # reset
107
+ @calls_queue = []
108
+ @is_multirequest = false
109
+
110
+ signature = signature(params)
111
+ add_param(params, "kalsig", signature)
112
+
113
+ log("url: " + url)
114
+ log("params: " + params.to_yaml)
115
+
116
+ result = do_http_request(url, params)
117
+
118
+ @responseHeaders = result.headers
119
+ log("server: [" + result.headers[:x_me].to_s + "], session: [" + result.headers[:x_kaltura_session].to_s + "]")
120
+
121
+ log("result (xml): " + result.body)
122
+
123
+ result_object = parse_to_objects(result.body)
124
+
125
+ log("result (object yaml dump): " + result_object.to_yaml)
126
+
127
+ end_time = Time.now
128
+
129
+ log("execution time for [#{url}]: [#{end_time - start_time}]")
130
+
131
+ return result_object
132
+
133
+ rescue KalturaAPIError => e
134
+ raise e
135
+ rescue Exception => e
136
+ raise KalturaAPIError.new("KALTURA_RUBY_CLIENT_ERROR", e.to_s)
137
+ end
138
+ end
139
+
140
+ def get_serve_url()
141
+ url = @config.service_url+"/api_v3/index.php?service="
142
+
143
+ call = @calls_queue[0]
144
+ url += call.service + "&action=" + call.action
145
+ params = call.params
146
+
147
+ # reset
148
+ @calls_queue = []
149
+ @is_multirequest = false
150
+
151
+ query_string = ''
152
+ params.each do |name, value|
153
+ query_string << "&#{name}=#{CGI::escape(value.to_s)}"
154
+ end
155
+
156
+ serve_url = "#{url}#{query_string}"
157
+
158
+ log("serve_url: " + serve_url)
159
+
160
+ return serve_url
161
+ end
162
+
163
+ def do_http_request(url, params)
164
+
165
+ options = {:method => :post, :url => url, :payload => params}
166
+
167
+ options.merge!(:headers => @config.requestHeaders)
168
+ options.merge!(:timeout => @config.timeout) if @config.timeout
169
+ options.merge!(:open_timeout => @config.timeout) if @config.timeout
170
+
171
+ res = RestClient::Request.execute(options)
172
+
173
+ return res
174
+ end
175
+
176
+ def parse_to_objects(data)
177
+ parse_xml_to_objects(data)
178
+ end
179
+
180
+ def parse_xml_to_objects(xml)
181
+ doc = REXML::Document.new(xml)
182
+ raise_exception_if_error(doc)
183
+ doc.elements.each('xml/result') do | element |
184
+ return KalturaClassFactory.object_from_xml(element)
185
+ end
186
+ end
187
+
188
+ def raise_exception_if_error(doc)
189
+ if is_error(doc)
190
+ code = doc.elements["xml/result/error/code"].text
191
+ message = doc.elements["xml/result/error/message"].text
192
+ raise KalturaAPIError.new(code, message)
193
+ end
194
+ end
195
+
196
+ def is_error(doc)
197
+ return doc.elements["xml/result/error/message"] && doc.elements["xml/result/error/code"];
198
+ end
199
+
200
+ def start_multirequest()
201
+ @is_multirequest = true
202
+ end
203
+
204
+ def do_multirequest()
205
+ return do_queue()
206
+ end
207
+
208
+ def signature(params)
209
+ kParams = params.select { |key, value| !value.is_a?(File) }
210
+ str = kParams.keys.map {|key| key.to_s }.sort.map {|key|
211
+ "#{key}#{params[key]}"
212
+ }.join("")
213
+
214
+ Digest::MD5.hexdigest(str)
215
+ end
216
+
217
+ def add_param(params, name, value)
218
+ if value == KalturaNotImplemented
219
+ return
220
+ elsif value == nil
221
+ params[name + '__null'] = ''
222
+ elsif value.is_a? Hash
223
+ if value.empty?
224
+ add_param(params, "#{name}:-", "");
225
+ else
226
+ value.each do |sub_name, sub_value|
227
+ add_param(params, "#{name}:#{sub_name}", sub_value);
228
+ end
229
+ end
230
+ elsif value.is_a? Array
231
+ if value.empty?
232
+ add_param(params, "#{name}:-", "");
233
+ else
234
+ value.each_with_index do |ele, i|
235
+ if ele.is_a? KalturaObjectBase
236
+ add_param(params, "#{name}:#{i}", ele.to_params)
237
+ end
238
+ end
239
+ end
240
+ elsif value.is_a? KalturaObjectBase
241
+ add_param(params, name, value.to_params)
242
+ else
243
+ params[name] = value
244
+ end
245
+ end
246
+
247
+ # Escapes a query parameter. Taken from RFuzz
248
+ def escape(s)
249
+ s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) {
250
+ '%' + $1.unpack('H2'*$1.size).join('%').upcase
251
+ }.tr(' ', '+')
252
+ end
253
+
254
+ def log(msg)
255
+ if @should_log
256
+ config.logger.log(Logger::INFO, msg)
257
+ end
258
+ end
259
+
260
+ def generate_session(admin_secret, user_id, kaltura_session_type, partner_id, expiry=86400, privileges=nil)
261
+
262
+ ks = "#{partner_id};#{partner_id};#{Time.now.to_i + expiry};#{kaltura_session_type};#{rand.to_s.gsub("0.", "")};#{user_id};#{privileges};"
263
+
264
+ digest_generator = OpenSSL::Digest::Digest.new('sha1')
265
+
266
+ digest_generator.update(admin_secret)
267
+ digest_generator.update(ks)
268
+
269
+ digest = digest_generator.hexdigest
270
+
271
+ signature = digest + "|" + ks
272
+ b64 = Base64.encode64(signature)
273
+ cleaned = b64.gsub("\n","")
274
+
275
+ @ks = cleaned
276
+ end
277
+ end
278
+
279
+ class KalturaServiceActionCall
280
+ attr_accessor :service
281
+ attr_accessor :action
282
+ attr_accessor :params
283
+
284
+ def initialize(service, action, params = array())
285
+ @service = service
286
+ @action = action
287
+ @params = parse_params(params)
288
+ end
289
+
290
+ def parse_params(params)
291
+ new_params = {}
292
+ params.each do |key, val|
293
+ if val.kind_of? Hash
294
+ new_params[key] = parse_params(val)
295
+ else
296
+ new_params[key] = val
297
+ end
298
+ end
299
+ return new_params
300
+ end
301
+
302
+ def get_params_for_multirequest(multirequest_index)
303
+ multirequest_params = {}
304
+ multirequest_params[multirequest_index.to_s+":service"] = @service
305
+ multirequest_params[multirequest_index.to_s+":action"] = @action
306
+ @params.each_key do |key|
307
+ multirequest_params[multirequest_index.to_s+":"+key] = @params[key]
308
+ end
309
+ return multirequest_params
310
+ end
311
+ end
312
+
313
+ class KalturaObjectBase
314
+ attr_accessor :object_type
315
+
316
+ def to_params
317
+ params = {};
318
+ params["objectType"] = self.class.name.split('::').last
319
+ instance_variables.each do |var|
320
+ value = instance_variable_get(var)
321
+ var = var.to_s.sub('@', '')
322
+ kvar = camelcase(var)
323
+ if (value != nil)
324
+ if (value.is_a? KalturaObjectBase)
325
+ params[kvar] = value.to_params;
326
+ else
327
+ params[kvar] = value;
328
+ end
329
+ else
330
+ params[kvar] = value;
331
+ end
332
+ end
333
+ return params;
334
+ end
335
+
336
+ def to_b(val)
337
+ return [true, 'true', 1, '1'].include?(val.is_a?(String) ? val.downcase : val)
338
+ end
339
+
340
+ def camelcase(val)
341
+ val = val.split('_').map { |e| e.capitalize }.join()
342
+ val[0,1].downcase + val[1,val.length]
343
+ end
344
+ end
345
+
346
+ class KalturaServiceBase
347
+ attr_accessor :client
348
+
349
+ def initialize(client)
350
+ @client = client
351
+ end
352
+ end
353
+
354
+ class KalturaConfiguration
355
+ attr_accessor :logger
356
+ attr_accessor :service_url
357
+ attr_accessor :format
358
+ attr_accessor :client_tag
359
+ attr_accessor :timeout
360
+ attr_accessor :partner_id
361
+ attr_accessor :requestHeaders
362
+
363
+ #
364
+ # Adding service_url to the initialize signature to pass url to your own kaltura ce instance
365
+ # Default is still set to http://www.kaltura.com.
366
+ #
367
+
368
+ def initialize(partner_id = -1,service_url="http://www.kaltura.com")
369
+ @service_url = service_url
370
+ @format = 2 # xml
371
+ @client_tag = "ruby:14-01-16"
372
+ @timeout = 120
373
+ @partner_id = partner_id
374
+ @requestHeaders = {}
375
+ end
376
+
377
+ def service_url=(url)
378
+ @service_url = url.chomp('/')
379
+ end
380
+ end
381
+
382
+ class KalturaClassFactory
383
+ def self.object_from_xml(xml_element)
384
+ instance = nil
385
+ if xml_element.elements.size > 0
386
+ if xml_element.elements[1].name == 'item' # array
387
+ instance = []
388
+ xml_element.elements.each('item') do | element |
389
+ instance.push(KalturaClassFactory.object_from_xml(element))
390
+ end
391
+ else # object
392
+ object_type_element = xml_element.get_text('objectType')
393
+ if (object_type_element != nil)
394
+ object_class = xml_element.get_text('objectType').value.to_s
395
+ instance = Module.const_get("Kaltura")
396
+ instance = instance.const_get(object_class).new
397
+
398
+ xml_element.elements.each do | element |
399
+ value = KalturaClassFactory.object_from_xml(element)
400
+ instance.send(self.underscore(element.name) + "=", value) if instance.class.method_defined?(self.underscore(element.name));
401
+ end
402
+ else # error
403
+ error_element = xml_element.elements['error']
404
+ if (error_element != nil)
405
+ code = xml_element.elements["error/code"].text
406
+ message = xml_element.elements["error/message"].text
407
+
408
+ instance = KalturaAPIError.new(code, message)
409
+ end
410
+ end
411
+ end
412
+ else # simple type
413
+ return xml_element.text
414
+ end
415
+
416
+ return instance;
417
+ end
418
+
419
+ def self.underscore(val)
420
+ val.gsub(/(.)([A-Z])/,'\1_\2').downcase
421
+ end
422
+ end
423
+
424
+ class KalturaAPIError < RuntimeError
425
+ attr_reader :code
426
+ attr_reader :message
427
+ def initialize(code, message)
428
+ @code = code
429
+ @message = message
430
+ end
431
+ end
432
+ end
@@ -0,0 +1,37 @@
1
+ # ===================================================================================================
2
+ # _ __ _ _
3
+ # | |/ /__ _| | |_ _ _ _ _ __ _
4
+ # | ' </ _` | | _| || | '_/ _` |
5
+ # |_|\_\__,_|_|\__|\_,_|_| \__,_|
6
+ #
7
+ # This file is part of the Kaltura Collaborative Media Suite which allows users
8
+ # to do with audio, video, and animation what Wiki platfroms allow them to do with
9
+ # text.
10
+ #
11
+ # Copyright (C) 2006-2011 Kaltura Inc.
12
+ #
13
+ # This program is free software: you can redistribute it and/or modify
14
+ # it under the terms of the GNU Affero General Public License as
15
+ # published by the Free Software Foundation, either version 3 of the
16
+ # License, or (at your option) any later version.
17
+ #
18
+ # This program is distributed in the hope that it will be useful,
19
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ # GNU Affero General Public License for more details.
22
+ #
23
+ # You should have received a copy of the GNU Affero General Public License
24
+ # along with this program. If not, see <http:#www.gnu.org/licenses/>.
25
+ #
26
+ # @ignore
27
+ # ===================================================================================================
28
+ require 'kaltura_client.rb'
29
+
30
+ module Kaltura
31
+
32
+ class KalturaABCScreenersWatermarkCondition < KalturaCondition
33
+
34
+ end
35
+
36
+
37
+ end