Class: EventMachine::UCEngine::Client::Session
- Inherits:
-
UCEngine::Client::Session
- Object
- Struct
- UCEngine::Client::Session
- EventMachine::UCEngine::Client::Session
- Includes:
- EventMachineRequest, EventMachineResponse
- Defined in:
- lib/em-ucengine/client_em.rb
Instance Attribute Summary
Attributes inherited from UCEngine::Client::Session
Instance Method Summary collapse
-
#download(meeting, filename, &block) ⇒ Object
Download a file The result will a File object uce.download(“demo”, “myfile”) do |err, file| puts file.open.read end.
-
#subscribe(meeting, params = {}, &block) ⇒ Object
Subscribe to events.
-
#upload(meeting, file, metadata = {}, &block) ⇒ Object
Upload a file in a meeting room.
Methods included from EventMachineRequest
#delete, #get, #http_request, #json_post, #post, #put
Methods included from EventMachineResponse
#answer, #answer_bool, #answer_connect, #answer_download
Methods inherited from UCEngine::Client::Session
#create_meeting, #create_role, #create_user, #delete_file, #delete_role, #delete_user, #disconnect, #event, #events, #files, #join_roster, #meeting, #meetings, #presence, #publish, #quit_roster, #roster, #search, #time, #update_meeting, #update_user, #url, #user, #user_can, #user_role, #users
Methods included from UCEngine::NetHttpRequest
#delete, #get, #json_post, #post
Methods included from UCEngine::NetHttpResponse
#answer, #answer_bool, #answer_connect
Instance Method Details
#download(meeting, filename, &block) ⇒ Object
Download a file The result will a File object uce.download(“demo”, “myfile”) do |err, file|
puts file.open.read
end
232 233 234 |
# File 'lib/em-ucengine/client_em.rb', line 232 def download(meeting, filename, &block) answer_download get(url("/file/#{meeting}/#{filename}")), &block end |
#subscribe(meeting, params = {}, &block) ⇒ Object
Subscribe to events
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/em-ucengine/client_em.rb', line 178 def subscribe(meeting, params={}, &block) params[:mode] = "eventsource" params.merge!(:uid => uid, :sid => sid) s = Subscription.new(url("/live/#{meeting}"), params) time do |err, now| s. do || block.call(nil, [JSON.parse()]) end s.error do |error| if s.ready_state != EM::EventSource::CONNECTING puts error block.call error, nil end end s.start(now) end s end |
#upload(meeting, file, metadata = {}, &block) ⇒ Object
Upload a file in a meeting room
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/em-ucengine/client_em.rb', line 202 def upload(meeting, file, ={}, &block) partfile = Part.new( :name => 'content', :filename => File.basename(file.path), :body => file.read) partuid = Part.new( :name => 'uid', :body => uid) partsid = Part.new( :name => 'sid', :body => sid) parts = [partfile, partsid, partuid] parts << .inject([]) { |array, (key, value)| array << Part.new( :name => "metadata[#{key}]", :body => value ) } body = MultipartBody.new(parts) conn = EM::HttpRequest.new(uce.url "/file/#{meeting}") req = conn.post( :head => {'content-type' => "multipart/form-data; boundary=#{body.boundary}"}, :body => "#{body.to_s}\r\n") answer(req, &block) end |