Class: Marte::Token
- Inherits:
-
ActiveResource::Base
- Object
- ActiveResource::Base
- Marte::Token
- Defined in:
- lib/marte/token.rb
Constant Summary collapse
- KEY =
"secret"- SERVICE_NAME =
"marteRed5"- MAUTH_VERSION =
"3.1"- MARTE_URL =
"marte.dit.upm.es"- ROOM_SWF_FILE =
"http://marte.dit.upm.es/system/MartEClient.swf"- CHAT_SWF_FILE =
"http://marte.dit.upm.es/system/MartEClient.swf"
Class Method Summary collapse
-
.collection_path(prefix_options = {}, query_options = nil) ⇒ Object
redefined to remove format.extension.
- .element_path(id, prefix_options = {}, query_options = nil) ⇒ Object
- .embed_for(*args) ⇒ Object
-
.headers(user, attributes = {}) ⇒ Object
define the headers to add Authentication.
Instance Method Summary collapse
Class Method Details
.collection_path(prefix_options = {}, query_options = nil) ⇒ Object
redefined to remove format.extension
44 45 46 47 |
# File 'lib/marte/token.rb', line 44 def self.collection_path( = {}, = nil) , = () if .nil? "#{prefix()}#{collection_name}#{query_string()}" end |
.element_path(id, prefix_options = {}, query_options = nil) ⇒ Object
49 50 51 52 |
# File 'lib/marte/token.rb', line 49 def self.element_path(id, = {}, = nil) , = () if .nil? "#{prefix()}#{collection_name}/#{id}#{query_string()}" end |
.embed_for(*args) ⇒ Object
54 55 56 57 58 |
# File 'lib/marte/token.rb', line 54 def self.(*args) new.(*args) rescue StandardError => e "The following error ocurred with the conference server: #{ e }" end |
.headers(user, attributes = {}) ⇒ Object
define the headers to add Authentication
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/marte/token.rb', line 18 def self.headers(user, attributes = {}) #get the params to fill in the headers role = 'admin' #timestamp without decimals =Time.now.to_i #cnonce, we use a randon number between 1 and 999.999.999 cnonce=rand(1000000000) #now we prepare the signature. It is a HMAC:SHA1 of "timestamp,cnonce,username,ro to_sign="#{},#{cnonce},#{user.slug},#{role},#{ user.id }" extra_header=",mauth_username=\"#{user.slug}\",mauth_role=\"#{role}\",mauth_external_uid\=#{ user.id }" #puts "cosas pa firmar " + to_sign signature=Base64.encode64(HMAC::SHA1.hexdigest(KEY, to_sign)).chomp.gsub(/\n/,'') #everything ready, create the message headers headers = { "Accept" => "application/html", "Content-Type" => "application/html", "Authorization"=> "MAuth realm=\"#{MARTE_URL}\", mauth_signature_method=\"HMAC_SHA1\", mauth_serviceid=\"#{SERVICE_NAME}\",mauth_signature=\"#{signature}\",mauth_timestamp=\"#{}\",mauth_cnonce=\"#{cnonce}\",mauth_version=\"#{MAUTH_VERSION}\"#{extra_header}" } end |
Instance Method Details
#createToken(user, room) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/marte/token.rb', line 60 def createToken(user, room) connection.post(collection_path, room, self.class.headers(user, attributes)) do |response| self.id = id_from_response(response) load_attributes_from_response(response) end end |
#embed_for(user, room, options = {}) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/marte/token.rb', line 67 def (user, room, = {}) [:width] ||= 750 [:height] ||= 600 swf_file = ( [:partner].present? ? ROOM_SWF_FILE : CHAT_SWF_FILE ) token = createToken(user, room).body <<-EMBED <object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" id=\"MartEClient\" width=\"#{ [:width] }\" height=\"#{ [:height] }\" codebase=\"http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab\"> <param name=\"movie\" value=\" #{ swf_file }\" /> <param name=\"quality\" value=\"high\" /> <param name=\"allowScriptAccess\" value=\"sameDomain\" /> <param name=\"allowFullscreen\" value=\"true\" /> <param name=\"flashVars\" value=\"token=#{token}&room=#{room}&bgcolor=#FFFFFF\" /> <embed src=\"#{ swf_file }\" quality=\"high\" \" width=\"#{[:width]}\" height=\"#{[:height]}\" name=\"MartEClient\" align=\"top\" padding=\"0px 0px 0px 0px\" flashVars=\"token=#{token}&room=#{room}&bgcolor=#FFFFFF#{ "&partner=#{ [:partner].slug }" if [:partner] }\" play=\"true\" loop=\"false\" quality=\"high\" allowScriptAccess=\"sameDomain\" allowFullscreen=\"true\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.adobe.com/go/getflashplayer\"> </embed> </object> EMBED end |