papyromancer-kaltura-ruby 0.0.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.
- data/LICENSE +20 -0
- data/README.rdoc +15 -0
- data/Rakefile +56 -0
- data/lib/kaltura-ruby.rb +3 -0
- data/lib/kaltura_client.rb +1836 -0
- data/lib/kaltura_client_base.rb +217 -0
- data/test/kaltura-ruby_test.rb +7 -0
- data/test/test.rb +23 -0
- data/test/test_helper.rb +10 -0
- metadata +64 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
#
|
|
2
|
+
# This file is part of the Kaltura Collaborative Media Suite which allows users
|
|
3
|
+
# to do with audio, video, and animation what Wiki platfroms allow them to do with
|
|
4
|
+
# text.
|
|
5
|
+
#
|
|
6
|
+
# Copyright (C) 2006-2008 Kaltura Inc.
|
|
7
|
+
#
|
|
8
|
+
# This program is free software: you can redistribute it and/or modify
|
|
9
|
+
# it under the terms of the GNU Affero General Public License as
|
|
10
|
+
# published by the Free Software Foundation, either version 3 of the
|
|
11
|
+
# License, or (at your option) any later version.
|
|
12
|
+
#
|
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
# GNU Affero General Public License for more details.
|
|
17
|
+
#
|
|
18
|
+
# You should have received a copy of the GNU Affero General Public License
|
|
19
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
#
|
|
21
|
+
|
|
22
|
+
require 'rubygems'
|
|
23
|
+
require 'json'
|
|
24
|
+
require 'net/http'
|
|
25
|
+
require 'active_support'
|
|
26
|
+
require 'active_resource'
|
|
27
|
+
require 'digest/md5'
|
|
28
|
+
|
|
29
|
+
module Kaltura
|
|
30
|
+
class KalturaClientBase
|
|
31
|
+
|
|
32
|
+
FORMATS = {
|
|
33
|
+
:KALTURA_SERVICE_FORMAT_JSON => 1,
|
|
34
|
+
:KALTURA_SERVICE_FORMAT_XML => 2,
|
|
35
|
+
:KALTURA_SERVICE_FORMAT_PHP => 3}
|
|
36
|
+
|
|
37
|
+
KALTURA_API_VERSION = "0.7"
|
|
38
|
+
|
|
39
|
+
attr_accessor :config
|
|
40
|
+
attr_accessor :ks
|
|
41
|
+
attr_accessor :shouldLog
|
|
42
|
+
|
|
43
|
+
def serialize_params(params)
|
|
44
|
+
params.keys.map {|key| key.to_s }.sort.map {|key|
|
|
45
|
+
"#{escape(key)}=#{escape(params[key])}"
|
|
46
|
+
}.join("&")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def connection
|
|
50
|
+
@connection ||= ActiveResource::Connection.new(@config.serviceUrl)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def post(path, options)
|
|
54
|
+
connection.post(path, serialize_params(options), headers)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def headers
|
|
58
|
+
@headers ||= { 'Content-Type' => 'application/x-www-form-urlencoded' }
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Escapes a query parameter. Stolen from RFuzz
|
|
62
|
+
def escape(s)
|
|
63
|
+
s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) {
|
|
64
|
+
'%' + $1.unpack('H2'*$1.size).join('%').upcase
|
|
65
|
+
}.tr(' ', '+')
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
#
|
|
69
|
+
# Kaltura client constuctor, expecting configuration object
|
|
70
|
+
#
|
|
71
|
+
# @param KalturaConfiguration $config
|
|
72
|
+
#
|
|
73
|
+
def initialize(config)
|
|
74
|
+
@shouldLog = false
|
|
75
|
+
@config = config;
|
|
76
|
+
|
|
77
|
+
logger = config.getLogger()
|
|
78
|
+
|
|
79
|
+
if logger != nil
|
|
80
|
+
@shouldLog = true
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def hit(method, session_user, params)
|
|
85
|
+
start_time = Time.now
|
|
86
|
+
|
|
87
|
+
log("service url: [#{@config.serviceUrl}]");
|
|
88
|
+
log("trying to call method: [#{method}] for user id: [#{session_user.userId}] using session: [#{@ks}]");
|
|
89
|
+
|
|
90
|
+
# append the basic params
|
|
91
|
+
params["kaltura_api_version"] = KalturaClientBase::KALTURA_API_VERSION
|
|
92
|
+
params["partner_id"] = @config.partnerId
|
|
93
|
+
params["subp_id"] = @config.subPartnerId
|
|
94
|
+
params["format"] = @config.format
|
|
95
|
+
params["uid"] = session_user.userId
|
|
96
|
+
addOptionalParam(params, "user_name", session_user.screenName)
|
|
97
|
+
addOptionalParam(params, "ks", @ks)
|
|
98
|
+
|
|
99
|
+
params["kalsig"] = signature(params);
|
|
100
|
+
|
|
101
|
+
url = "/index.php/partnerservices2/" + method
|
|
102
|
+
log("full reqeust url: [#{url}] params: [#{serialize_params(params)}]")
|
|
103
|
+
|
|
104
|
+
response = post(url, params)
|
|
105
|
+
|
|
106
|
+
log("result (serialized): #{response.body}");
|
|
107
|
+
|
|
108
|
+
json = JSON.parse(response.body)
|
|
109
|
+
#log("result (object dump): #{dump}");
|
|
110
|
+
|
|
111
|
+
end_time = Time.now
|
|
112
|
+
|
|
113
|
+
log("execution time for method [#{method}]: [#{end_time - start_time}]")
|
|
114
|
+
|
|
115
|
+
return json
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def start(session_user, secret)
|
|
119
|
+
result = startSession(session_user, secret)
|
|
120
|
+
|
|
121
|
+
@ks = result["result"]["ks"]
|
|
122
|
+
return result
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def signature(params)
|
|
126
|
+
str = params.keys.map {|key| key.to_s }.sort.map {|key|
|
|
127
|
+
"#{escape(key)}#{escape(params[key])}"
|
|
128
|
+
}.join("")
|
|
129
|
+
|
|
130
|
+
Digest::MD5.hexdigest(str)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def getKs()
|
|
134
|
+
@ks
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def setKs(ks)
|
|
138
|
+
@ks = ks
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def addOptionalParam(params, paramName, paramValue)
|
|
142
|
+
params[paramName] = paramValue if paramValue
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def log(msg)
|
|
146
|
+
#print "#{msg}\n"
|
|
147
|
+
if @shouldLog
|
|
148
|
+
config.getLogger().log(msg)
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
class KalturaSessionUser
|
|
156
|
+
attr_accessor :userId
|
|
157
|
+
attr_accessor :screenName
|
|
158
|
+
|
|
159
|
+
def initialize(userId, screenName = nil)
|
|
160
|
+
@userId = userId;
|
|
161
|
+
@screenName = screenName;
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
class KalturaConfiguration
|
|
166
|
+
attr_accessor :logger
|
|
167
|
+
|
|
168
|
+
def serviceUrl
|
|
169
|
+
URI.parse("http://www.kaltura.com/")
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def format
|
|
173
|
+
KalturaClientBase::FORMATS[:KALTURA_SERVICE_FORMAT_JSON]
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
attr_accessor :partnerId
|
|
177
|
+
attr_accessor :subPartnerId
|
|
178
|
+
|
|
179
|
+
#
|
|
180
|
+
# Constructs new kaltura configuration object, expecting partner id & sub partner id
|
|
181
|
+
#
|
|
182
|
+
# @param int $partnerId
|
|
183
|
+
# @param int $subPartnerId
|
|
184
|
+
#
|
|
185
|
+
def initialize(partnerId, subPartnerId)
|
|
186
|
+
@partnerId = partnerId;
|
|
187
|
+
@subPartnerId = subPartnerId;
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
#
|
|
191
|
+
# Set logger to get kaltura client debug logs
|
|
192
|
+
#
|
|
193
|
+
# @param IKalturaLogger $log
|
|
194
|
+
#
|
|
195
|
+
def setLogger(log)
|
|
196
|
+
@logger = log
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
#
|
|
200
|
+
# Gets the logger (Internal client use)
|
|
201
|
+
#
|
|
202
|
+
# @return unknown
|
|
203
|
+
#
|
|
204
|
+
def getLogger()
|
|
205
|
+
@logger;
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
#
|
|
210
|
+
# Implement to get kaltura client logs
|
|
211
|
+
#
|
|
212
|
+
#
|
|
213
|
+
class IKalturaLogger
|
|
214
|
+
def log(msg)
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
data/test/test.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require "kaltura_client.rb"
|
|
2
|
+
|
|
3
|
+
include Kaltura
|
|
4
|
+
conf = KalturaConfiguration.new(250, 25000)
|
|
5
|
+
user = KalturaSessionUser.new(2)
|
|
6
|
+
cl = KalturaClient.new(conf)
|
|
7
|
+
secert = 'dae1be648b8a86d25adafdac2d32e8c3'
|
|
8
|
+
cl.start(user, secert)
|
|
9
|
+
|
|
10
|
+
kshow = KalturaKShow.new()
|
|
11
|
+
kshow.name = "test ruby"
|
|
12
|
+
kshow.description = "desc ruby"
|
|
13
|
+
|
|
14
|
+
result = cl.addKShow(user, kshow, 1)
|
|
15
|
+
|
|
16
|
+
print (result['result']['kshow']['name'])
|
|
17
|
+
|
|
18
|
+
print("\n")
|
|
19
|
+
print("\n")
|
|
20
|
+
|
|
21
|
+
result = cl.search(user, KalturaEntryMediaType::VIDEO, KalturaEntryMediaSource::MYSPACE, "funny");
|
|
22
|
+
|
|
23
|
+
print (result['result'])
|
data/test/test_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: papyromancer-kaltura-ruby
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- papyromancer
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-05-11 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description:
|
|
17
|
+
email: papyromancer@papyromancer.net
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- LICENSE
|
|
24
|
+
- README.rdoc
|
|
25
|
+
files:
|
|
26
|
+
- LICENSE
|
|
27
|
+
- README.rdoc
|
|
28
|
+
- Rakefile
|
|
29
|
+
- lib/kaltura-ruby.rb
|
|
30
|
+
- lib/kaltura_client.rb
|
|
31
|
+
- lib/kaltura_client_base.rb
|
|
32
|
+
- test/kaltura-ruby_test.rb
|
|
33
|
+
- test/test.rb
|
|
34
|
+
- test/test_helper.rb
|
|
35
|
+
has_rdoc: false
|
|
36
|
+
homepage: http://github.com/papyromancer/kaltura-ruby
|
|
37
|
+
post_install_message:
|
|
38
|
+
rdoc_options:
|
|
39
|
+
- --charset=UTF-8
|
|
40
|
+
require_paths:
|
|
41
|
+
- lib
|
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: "0"
|
|
47
|
+
version:
|
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: "0"
|
|
53
|
+
version:
|
|
54
|
+
requirements: []
|
|
55
|
+
|
|
56
|
+
rubyforge_project:
|
|
57
|
+
rubygems_version: 1.2.0
|
|
58
|
+
signing_key:
|
|
59
|
+
specification_version: 3
|
|
60
|
+
summary: Ruby gem for accessing the Kaltura API
|
|
61
|
+
test_files:
|
|
62
|
+
- test/test_helper.rb
|
|
63
|
+
- test/test.rb
|
|
64
|
+
- test/kaltura-ruby_test.rb
|