@@ -249,6 +249,114 @@ public function getCall(
249
249
return new ApiResponse ($ response ->code , $ response ->headers , $ deserializedResponse );
250
250
}
251
251
252
+ /**
253
+ * Replaces the bxml for an active call
254
+ *
255
+ * @param string $accountId TODO: type description here
256
+ * @param string $callId TODO: type description here
257
+ * @param string $body Valid BXML string
258
+ * @return ApiResponse response from the API call
259
+ * @throws APIException Thrown if API call fails
260
+ */
261
+ public function modifyCallBxml (
262
+ $ accountId ,
263
+ $ callId ,
264
+ $ body
265
+ ) {
266
+
267
+ //prepare query string for API call
268
+ $ _queryBuilder = '/api/v2/accounts/{accountId}/calls/{callId} ' ;
269
+
270
+ //process optional query parameters
271
+ $ _queryBuilder = APIHelper::appendUrlWithTemplateParameters ($ _queryBuilder , array (
272
+ 'accountId ' => $ accountId ,
273
+ 'callId ' => $ callId ,
274
+ ));
275
+
276
+ //validate and preprocess url
277
+ $ _queryUrl = APIHelper::cleanUrl ($ this ->config ->getBaseUri (Servers::VOICEDEFAULT ) . $ _queryBuilder );
278
+
279
+ //prepare headers
280
+ $ _headers = array (
281
+ 'user-agent ' => BaseController::USER_AGENT ,
282
+ 'content-type ' => 'application/xml; charset=utf-8 '
283
+ );
284
+
285
+ //set HTTP basic auth parameters
286
+ Request::auth ($ this ->config ->getVoiceBasicAuthUserName (), $ this ->config ->getVoiceBasicAuthPassword ());
287
+
288
+ $ _httpRequest = new HttpRequest (HttpMethod::POST , $ _headers , $ _queryUrl );
289
+
290
+ //call on-before Http callback
291
+ if ($ this ->getHttpCallBack () != null ) {
292
+ $ this ->getHttpCallBack ()->callOnBeforeRequest ($ _httpRequest );
293
+ }
294
+ // Set request timeout
295
+ Request::timeout ($ this ->config ->getTimeout ());
296
+
297
+ // and invoke the API call request to fetch the response
298
+ $ response = Request::post ($ _queryUrl , $ _headers , $ body );
299
+
300
+ $ _httpResponse = new HttpResponse ($ response ->code , $ response ->headers , $ response ->raw_body );
301
+ $ _httpContext = new HttpContext ($ _httpRequest , $ _httpResponse );
302
+
303
+ //call on-after Http callback
304
+ if ($ this ->getHttpCallBack () != null ) {
305
+ $ this ->getHttpCallBack ()->callOnAfterRequest ($ _httpContext );
306
+ }
307
+
308
+ //Error handling using HTTP status codes
309
+ if ($ response ->code == 400 ) {
310
+ throw new Exceptions \ApiErrorException (
311
+ 'Something \'s not quite right... Your request is invalid. Please fix it before trying again. ' ,
312
+ $ _httpContext
313
+ );
314
+ }
315
+
316
+ if ($ response ->code == 401 ) {
317
+ throw new APIException (
318
+ 'Your credentials are invalid. Please use your Bandwidth dashboard credentials to authenticate to ' .
319
+ 'the API. ' ,
320
+ $ _httpContext
321
+ );
322
+ }
323
+
324
+ if ($ response ->code == 403 ) {
325
+ throw new Exceptions \ApiErrorException ('User unauthorized to perform this action. ' , $ _httpContext );
326
+ }
327
+
328
+ if ($ response ->code == 404 ) {
329
+ throw new Exceptions \ApiErrorException (
330
+ 'The resource specified cannot be found or does not belong to you. ' ,
331
+ $ _httpContext
332
+ );
333
+ }
334
+
335
+ if ($ response ->code == 415 ) {
336
+ throw new Exceptions \ApiErrorException (
337
+ 'We don \'t support that media type for this endpoint. If a request body is required, please send it to us as ' .
338
+ '`application/xml`. ' ,
339
+ $ _httpContext
340
+ );
341
+ }
342
+
343
+ if ($ response ->code == 429 ) {
344
+ throw new Exceptions \ApiErrorException (
345
+ 'You \'re sending requests to this endpoint too frequently. Please slow your request rate down and ' .
346
+ 'try again. ' ,
347
+ $ _httpContext
348
+ );
349
+ }
350
+
351
+ if ($ response ->code == 500 ) {
352
+ throw new Exceptions \ApiErrorException ('Something unexpected happened. Please try again. ' , $ _httpContext );
353
+ }
354
+
355
+ //handle errors defined at the API level
356
+ $ this ->validateResponse ($ _httpResponse , $ _httpContext );
357
+ return new ApiResponse ($ response ->code , $ response ->headers , null );
358
+ }
359
+
252
360
/**
253
361
* Interrupts and replaces an active call's BXML document.
254
362
*
0 commit comments