Class: Telesocial::Client
- Inherits:
-
Object
- Object
- Telesocial::Client
- Includes:
- HTTParty
- Defined in:
- lib/telesocial/client.rb
Defined Under Namespace
Classes: ResponseParser
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Instance Method Summary collapse
- #add_to_conference(conference_id, network_id, greeting_id = nil, muted = nil) ⇒ Object
- #blast(network_id, media_id, greeting_id = nil) ⇒ Object
- #change_registered_phone_number(network_id, phone) ⇒ Object
- #close_conference(conference_id) ⇒ Object
- #create_conference(network_id, recording_id = nil, greeting_id = nil) ⇒ Object
- #create_media ⇒ Object
- #get_conference_details(conference_id) ⇒ Object
- #get_conferences(active = nil) ⇒ Object
- #get_media_ids ⇒ Object
- #get_registration_status(network_id, query = "exists") ⇒ Object
- #get_version ⇒ Object
- #hangup_call(conference_id, network_id) ⇒ Object
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
- #media_status(media_id) ⇒ Object
- #move_call(from_conference_id, to_conference_id, network_id) ⇒ Object
- #mute(conference_id, network_id) ⇒ Object
- #record(network_id, media_id, greeting_id = nil) ⇒ Object
- #register(network_id, phone, greeting_id = nil) ⇒ Object
- #remove_media(media_id) ⇒ Object
- #request_upload_grant(media_id) ⇒ Object
- #unmute(conference_id, network_id) ⇒ Object
- #upload_file(upload_grant_id, file_path) ⇒ Object
Constructor Details
#initialize(api_key) ⇒ Client
Returns a new instance of Client.
25 26 27 |
# File 'lib/telesocial/client.rb', line 25 def initialize(api_key) @api_key = api_key end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
23 24 25 |
# File 'lib/telesocial/client.rb', line 23 def api_key @api_key end |
Instance Method Details
#add_to_conference(conference_id, network_id, greeting_id = nil, muted = nil) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/telesocial/client.rb', line 204 def add_to_conference(conference_id, network_id, greeting_id = nil, muted = nil) response = post("/api/rest/conference/#{conference_id}", :body => {:networkid => network_id, :appkey => @api_key, :action => 'add', :greetingid => greeting_id, :muted => muted}) case response.status when 200 when 400 raise Telesocial::BadRequest.new("Missing or invalid parameter(s).", response) when 502 raise Telesocial::BadGateway.new("Unable to initiate phone(s) call at this time.", response) end response end |
#blast(network_id, media_id, greeting_id = nil) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/telesocial/client.rb', line 112 def blast(network_id, media_id, greeting_id = nil) response = post("/api/rest/media/#{media_id}", :body => {:networkid => network_id, :appkey => @api_key, :action => "blast", :greetingid => greeting_id}) case response.status when 200,201,202 when 400 raise Telesocial::BadRequest.new("Missing parameter(s).", response) when 404 raise Telesocial::NotFound.new("The application key is invalid or the application is not associated with the networkid.", response) when 502 raise Telesocial::BadGateway.new("Unable to initiate phone call at this time.", response) end response end |
#change_registered_phone_number(network_id, phone) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/telesocial/client.rb', line 63 def change_registered_phone_number(network_id, phone) response = post("/api/rest/registrant/#{network_id}/#{phone}", :body => {:appkey => @api_key}) case response.status when 202 when 400 raise Telesocial::BadRequest.new("One or more parameters were invalid or this (phone, networkid) pair is already registered.", response) when 401 raise Telesocial::Unauthorized.new("The network ID exists but it is not associated with the specified application", response) when 502 raise Telesocial::BadGateway.new("Unable to start the phone authorization process.", response) else raise Telesocial::Error.new(response., response) end response end |
#close_conference(conference_id) ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/telesocial/client.rb', line 219 def close_conference(conference_id) response = post("/api/rest/conference/#{conference_id}", :body => {:appkey => @api_key, :action => 'close'}) case response.status when 200 when 400 raise Telesocial::BadRequest.new("Missing or invalid parameter(s).", response) when 404 raise Telesocial::NotFound.new("The conference ID is invalid.", response) when 502 raise Telesocial::BadGateway.new("Unable to terminate conference calls.", response) end response end |
#create_conference(network_id, recording_id = nil, greeting_id = nil) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/telesocial/client.rb', line 184 def create_conference(network_id, recording_id = nil, greeting_id = nil) = {} [:recordingid] = recording_id if recording_id [:greetingid] = greeting_id if greeting_id response = post("/api/rest/conference/", :body => {:networkid => network_id, :appkey => @api_key}.merge()) case response.status when 201 when 502 raise Telesocial::BadGateway.new("The request cannot be fulfilled at this time.", response) else raise Telesocial::Error.new("The request cannot be fulfilled at this time.", response) end response end |
#create_media ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/telesocial/client.rb', line 81 def create_media() response = post("/api/rest/media/", :body => {:appkey => @api_key}) case response.status when 201 when 400 raise Telesocial::BadRequest.new("Missing parameter(s)", response) when 404 raise Telesocial::NotFound.new("The application key is invalid.", response) end response end |
#get_conference_details(conference_id) ⇒ Object
313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/telesocial/client.rb', line 313 def get_conference_details(conference_id) response = get("/api/rest/conference/#{conference_id}", :query => {:appkey => @api_key}) case response.status when 200 when 400 raise Telesocial::BadRequest.new("Missing or invalid parameter(s).", response) end response end |
#get_conferences(active = nil) ⇒ Object
301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/telesocial/client.rb', line 301 def get_conferences(active = nil) response = get("/api/rest/conference", :query => {:appkey => @api_key, :active => active}) case response.status when 200 when 400 raise Telesocial::BadRequest.new("Missing or invalid parameter(s).", response) end response end |
#get_media_ids ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/telesocial/client.rb', line 172 def get_media_ids() response = get("/api/rest/media", :query => {:appkey => @api_key}) case response.status when 200 when 400 raise Telesocial::BadRequest.new("Missing or invalid parameter(s).", response) end response end |
#get_registration_status(network_id, query = "exists") ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/telesocial/client.rb', line 29 def get_registration_status(network_id, query = "exists") response = post("/api/rest/registrant/#{network_id}", :body => {:query => query, :appkey => @api_key}) case response.status when 200 response.registered = true when 401 raise Telesocial::Unauthorized.new("The network ID exists but it is not associated with the specified application", response) when 404 raise Telesocial::NotFound.new("The device is not registered.", response) else raise Telesocial::Error.new(response., response) end return response end |
#get_version ⇒ Object
325 326 327 |
# File 'lib/telesocial/client.rb', line 325 def get_version response = self.class.get("/api/rest/version").parsed_response end |
#hangup_call(conference_id, network_id) ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/telesocial/client.rb', line 235 def hangup_call(conference_id, network_id) response = post("/api/rest/conference/#{conference_id}/#{network_id}", :body => {:appkey => @api_key, :action => 'hangup'}) case response.status when 200 when 400 raise Telesocial::BadRequest.new("Missing or invalid parameter(s).", response) when 401 raise Telesocial::Unauthorized.new("The specified network ID is not associated with the application identified by the application key.", response) when 404 raise Telesocial::NotFound.new("The conference ID is invalid.", response) when 502 raise Telesocial::BadGateway.new("Unable to terminate call at this time.", response) end response end |
#media_status(media_id) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/telesocial/client.rb', line 142 def media_status(media_id) response = post("/api/rest/media/status/#{media_id}", :query => {:appkey => @api_key}) case response.status when 200,201,202 when 204 raise Telesocial::NoContent.new("No media content exists for this Media ID.", response) when 404 raise Telesocial::NotFound.new("The application key or networkid are invalid.", response) end response end |
#move_call(from_conference_id, to_conference_id, network_id) ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/telesocial/client.rb', line 253 def move_call(from_conference_id, to_conference_id, network_id) response = post("/api/rest/conference/#{from_conference_id}/#{network_id}", :body => {:appkey => @api_key, :toconferenceid => to_conference_id, :action => 'move'}) case response.status when 200 when 400 raise Telesocial::BadRequest.new("Missing or invalid parameter(s).", response) when 401 raise Telesocial::Unauthorized.new("The specified network ID is not associated with the application identified by the application key.", response) when 502 raise Telesocial::BadGateway.new("Unable to move call.", response) end response end |
#mute(conference_id, network_id) ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/telesocial/client.rb', line 269 def mute(conference_id, network_id) response = post("/api/rest/conference/#{conference_id}/#{network_id}", :body => {:appkey => @api_key, :action => "mute"}) case response.status when 200 when 400 raise Telesocial::BadRequest.new("Missing or invalid parameter(s).", response) when 401 raise Telesocial::Unauthorized.new("One or more of the specified network IDs is not associated with the application identified by the application key.", response) when 502 raise Telesocial::BadGateway.new("Unable to mute call(s).", response) end response end |
#record(network_id, media_id, greeting_id = nil) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/telesocial/client.rb', line 95 def record(network_id, media_id, greeting_id = nil) response = post("/api/rest/media/#{media_id}", :body => {:networkid => network_id, :appkey => @api_key, :action => "record", :greetingid => greeting_id}) case response.status when 201 when 400 raise Telesocial::BadRequest.new("Missing parameter(s).", response) when 404 raise Telesocial::NotFound.new("The application key is invalid or the application is not associated with the networkid.", response) when 502 raise Telesocial::BadGateway.new("Unable to initiate phone call at this time.", response) end response end |
#register(network_id, phone, greeting_id = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/telesocial/client.rb', line 47 def register(network_id, phone, greeting_id = nil) response = post("/api/rest/registrant/", :body => {:networkid => network_id, :phone => phone, :appkey => @api_key, :greetingid => greeting_id}) case response.status when 201 when 400 raise Telesocial::BadRequest.new("One or more parameters were invalid or this (phone, networkid) pair is already registered.", response) when 502 raise Telesocial::BadGateway.new("Unable to start the phone authorization process.", response) else raise Telesocial::Error.new(response., response) end response end |
#remove_media(media_id) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/telesocial/client.rb', line 156 def remove_media(media_id) response = post("/api/rest/media/#{media_id}", :body => {:appkey => @api_key, :action => "remove"}) case response.status when 200 when 400 raise Telesocial::BadRequest.new("Missing or invalid parameter(s).", response) when 401 raise Telesocial::Unauthorized.new("The content associated with the media ID cannot be removed.", response) when 404 raise Telesocial::NotFound.new("The media ID is invalid.", response) end response end |
#request_upload_grant(media_id) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/telesocial/client.rb', line 128 def request_upload_grant(media_id) response = post("/api/rest/media/#{media_id}",:body => {:appkey => @api_key, :action => "upload_grant"}) case response.status when 201,202 when 400 raise Telesocial::BadRequest.new("Missing or invalid parameter(s).", response) when 401 raise Telesocial::Unauthorized.new("The media ID is invalid or is not associated with the application identified by the appkey parameter.", response) end response end |
#unmute(conference_id, network_id) ⇒ Object
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/telesocial/client.rb', line 285 def unmute(conference_id, network_id) response = post("/api/rest/conference/#{conference_id}/#{network_id}", :body => {:appkey => @api_key, :action => "unmute"}) case response.status when 200 when 400 raise Telesocial::BadRequest.new("Missing or invalid parameter(s).", response) when 401 raise Telesocial::Unauthorized.new("One or more of the specified network IDs is not associated with the application identified by the application key.", response) when 502 raise Telesocial::BadGateway.new("Unable to unmute call(s).", response) end response end |
#upload_file(upload_grant_id, file_path) ⇒ Object
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/telesocial/client.rb', line 329 def upload_file(upload_grant_id, file_path) uri = URI.parse(self.class.base_uri) req = Net::HTTP::Post::Multipart.new "/forklift/", {"grant" => upload_grant_id, "mediafile" => UploadIO.new(file_path, mime_for(file_path))} http = Net::HTTP.new(uri.host, uri.port) if (uri.scheme == "https") http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end res = http.request(req) case res when Net::HTTPSuccess when Net::HTTPBadRequest raise Telesocial::BadRequest.new("Missing or invalid parameter(s).", res) when Net::HTTPNotFound raise Telesocial::NotFound.new("The grant code is invalid.", res) when Net::HTTPRequestEntityTooLarge raise Telesocial::RequestEntityTooLarge.new("The file is larger than the allowed limit.", res) when Net::HTTPUnsupportedMediaType raise Telesocial::UnsupportedMediaTpe.new("The file is not an MP3 file. Only MP3 files may be uploaded at this time.", res) end res.body end |