Calls.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. class Services_Twilio_Rest_Calls
  3. extends Services_Twilio_ListResource
  4. {
  5. function init($client, $uri)
  6. {
  7. $this->setupSubresources(
  8. 'feedback_summary'
  9. );
  10. }
  11. public static function isApplicationSid($value)
  12. {
  13. return strlen($value) == 34
  14. && !(strpos($value, "AP") === false);
  15. }
  16. public function create($from, $to, $url, array $params = array())
  17. {
  18. $params["To"] = $to;
  19. $params["From"] = $from;
  20. if (self::isApplicationSid($url)) {
  21. $params["ApplicationSid"] = $url;
  22. } else {
  23. $params["Url"] = $url;
  24. }
  25. return parent::_create($params);
  26. }
  27. /**
  28. * Create a feedback for a call.
  29. *
  30. * @param $callSid
  31. * @param $qualityScore
  32. * @param array $issue
  33. * @return Services_Twilio_Rest_Feedback
  34. */
  35. public function createFeedback($callSid, $qualityScore, array $issue = array())
  36. {
  37. $params["QualityScore"] = $qualityScore;
  38. $params["Issue"] = $issue;
  39. $feedbackUri = $this->uri . '/' . $callSid . '/Feedback';
  40. $response = $this->client->createData($feedbackUri, $params);
  41. return new Services_Twilio_Rest_Feedback($this->client, $feedbackUri, $response);
  42. }
  43. /**
  44. * Delete a feedback for a call.
  45. *
  46. * @param $callSid
  47. */
  48. public function deleteFeedback($callSid)
  49. {
  50. $feedbackUri = $this->uri . '/' . $callSid . '/Feedback';
  51. $this->client->deleteData($feedbackUri);
  52. }
  53. /**
  54. * Get a feedback for a call.
  55. *
  56. * @param $callSid
  57. * @return Services_Twilio_Rest_Feedback
  58. */
  59. public function getFeedback($callSid)
  60. {
  61. $feedbackUri = $this->uri . '/' . $callSid . '/Feedback';
  62. $response = $this->client->retrieveData($feedbackUri);
  63. return new Services_Twilio_Rest_Feedback($this->client, $feedbackUri, $response);
  64. }
  65. }