Class: Licode::Client
Instance Method Summary collapse
- #create_room(name, options = {}) ⇒ Object
- #create_service(name, key) ⇒ Object
- #create_token(room, username, role) ⇒ Object
- #delete_room(room) ⇒ Object
- #delete_service(service) ⇒ Object
- #get_room(room) ⇒ Object
- #get_room_users(room) ⇒ Object
- #get_rooms ⇒ Object
- #get_service(service) ⇒ Object
- #get_services ⇒ Object
-
#initialize(service_id, service_key, service_url) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(service_id, service_key, service_url) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/licode/client.rb', line 13 def initialize(service_id,service_key,service_url) self.class.base_uri service_url self.class.headers({ "User-Agent" => "licode-ruby-sdk/#{VERSION}", "Content-Type" => "application/json" }) @service_id = service_id @service_key = service_key @service_url = service_url end |
Instance Method Details
#create_room(name, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/licode/client.rb', line 43 def create_room (name, ={}) response = self.class.post("/rooms", :body => {:name => name, :options => }.to_json, :headers => { "Authorization" => mauth_header }) case response.code when (200..300) response when 403 raise LicodeAuthenticationError, "Authentication failed while creating a room. Service: #{@service_id}" else raise LicodeError, "Failed to create room. Response code: #{response}" end rescue StandardError => e raise LicodeError, "Failed to connect to Licode. Response code: #{e.}" end |
#create_service(name, key) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/licode/client.rb', line 88 def create_service (name, key) response = self.class.post('/services/', :body => {'name' => name, 'key' => key}, :headers => { "Authorization" => mauth_header }) rescue StandardError => e raise LicodeError, "Failed to connect to Licode. Response code: #{e.}" end |
#create_token(room, username, role) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/licode/client.rb', line 79 def create_token(room, username, role) response = self.class.post('/rooms/' + room + '/tokens', { :headers => { "Authorization" => mauth_header(:username => username.to_s, :role => role) } }) response rescue StandardError => e raise LicodeError, "Failed to connect to Licode. Response code: #{e.}" end |
#delete_room(room) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/licode/client.rb', line 69 def delete_room (room) response = self.class.delete('/rooms/' + room, { :headers => { "Authorization" => mauth_header } }) rescue StandardError => e raise LicodeError, "Failed to connect to Licode. Response code: #{e.}" end |
#delete_service(service) ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'lib/licode/client.rb', line 119 def delete_service (service) response = self.class.delete('/services/' + service, :headers => { "Authorization" => mauth_header, "Content-Type" => "application/json" }) rescue StandardError => e raise LicodeError, "Failed to connect to Licode. Response code: #{e.}" end |
#get_room(room) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/licode/client.rb', line 59 def get_room (room) response = self.class.get('/rooms/' + room, { :headers => { "Authorization" => mauth_header } }) rescue StandardError => e raise LicodeError, "Failed to connect to Licode. Response code: #{e.}" end |
#get_room_users(room) ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'lib/licode/client.rb', line 129 def get_room_users (room) response = self.class.get('/rooms/' + room + '/users/', :headers => { "Authorization" => mauth_header, "Content-Type" => "application/json" }) rescue StandardError => e raise LicodeError, "Failed to connect to Licode. Response code: #{e.}" end |
#get_rooms ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/licode/client.rb', line 24 def get_rooms () response = self.class.get('/rooms', { :headers => { "Authorization" => mauth_header } }) case response.code when 200 response when 403 raise LicodeAuthenticationError, "Authentication failed while retrieving rooms. Service: #{@service_id}" else raise LicodeArchiveError, "The rooms could not be retrieved." end rescue StandardError => e raise LicodeError, "Failed to connect to Licode. Response code: #{e.}" end |
#get_service(service) ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/licode/client.rb', line 108 def get_service (service) response = self.class.get('/services/' + service, :headers => { "Authorization" => mauth_header, "Content-Type" => "application/json", "Content-Type" => "application/json" }) rescue StandardError => e raise LicodeError, "Failed to connect to Licode. Response code: #{e.}" end |
#get_services ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/licode/client.rb', line 98 def get_services () response = self.class.get('/services/', :headers => { "Authorization" => mauth_header, "Content-Type" => "application/json" }) rescue StandardError => e raise LicodeError, "Failed to connect to Licode. Response code: #{e.}" end |