WebhookContext.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * This code was generated by
  4. * \ / _ _ _| _ _
  5. * | (_)\/(_)(_|\/| |(/_ v1.0.0
  6. * / /
  7. */
  8. namespace Twilio\Rest\Chat\V2\Service\Channel;
  9. use Twilio\InstanceContext;
  10. use Twilio\Options;
  11. use Twilio\Serialize;
  12. use Twilio\Values;
  13. use Twilio\Version;
  14. class WebhookContext extends InstanceContext {
  15. /**
  16. * Initialize the WebhookContext
  17. *
  18. * @param \Twilio\Version $version Version that contains the resource
  19. * @param string $serviceSid The service_sid
  20. * @param string $channelSid The channel_sid
  21. * @param string $sid The sid
  22. * @return \Twilio\Rest\Chat\V2\Service\Channel\WebhookContext
  23. */
  24. public function __construct(Version $version, $serviceSid, $channelSid, $sid) {
  25. parent::__construct($version);
  26. // Path Solution
  27. $this->solution = array('serviceSid' => $serviceSid, 'channelSid' => $channelSid, 'sid' => $sid, );
  28. $this->uri = '/Services/' . rawurlencode($serviceSid) . '/Channels/' . rawurlencode($channelSid) . '/Webhooks/' . rawurlencode($sid) . '';
  29. }
  30. /**
  31. * Fetch a WebhookInstance
  32. *
  33. * @return WebhookInstance Fetched WebhookInstance
  34. * @throws TwilioException When an HTTP error occurs.
  35. */
  36. public function fetch() {
  37. $params = Values::of(array());
  38. $payload = $this->version->fetch(
  39. 'GET',
  40. $this->uri,
  41. $params
  42. );
  43. return new WebhookInstance(
  44. $this->version,
  45. $payload,
  46. $this->solution['serviceSid'],
  47. $this->solution['channelSid'],
  48. $this->solution['sid']
  49. );
  50. }
  51. /**
  52. * Update the WebhookInstance
  53. *
  54. * @param array|Options $options Optional Arguments
  55. * @return WebhookInstance Updated WebhookInstance
  56. * @throws TwilioException When an HTTP error occurs.
  57. */
  58. public function update($options = array()) {
  59. $options = new Values($options);
  60. $data = Values::of(array(
  61. 'Configuration.Url' => $options['configurationUrl'],
  62. 'Configuration.Method' => $options['configurationMethod'],
  63. 'Configuration.Filters' => Serialize::map($options['configurationFilters'], function($e) { return $e; }),
  64. 'Configuration.Triggers' => Serialize::map($options['configurationTriggers'], function($e) { return $e; }),
  65. 'Configuration.FlowSid' => $options['configurationFlowSid'],
  66. 'Configuration.RetryCount' => $options['configurationRetryCount'],
  67. ));
  68. $payload = $this->version->update(
  69. 'POST',
  70. $this->uri,
  71. array(),
  72. $data
  73. );
  74. return new WebhookInstance(
  75. $this->version,
  76. $payload,
  77. $this->solution['serviceSid'],
  78. $this->solution['channelSid'],
  79. $this->solution['sid']
  80. );
  81. }
  82. /**
  83. * Deletes the WebhookInstance
  84. *
  85. * @return boolean True if delete succeeds, false otherwise
  86. * @throws TwilioException When an HTTP error occurs.
  87. */
  88. public function delete() {
  89. return $this->version->delete('delete', $this->uri);
  90. }
  91. /**
  92. * Provide a friendly representation
  93. *
  94. * @return string Machine friendly representation
  95. */
  96. public function __toString() {
  97. $context = array();
  98. foreach ($this->solution as $key => $value) {
  99. $context[] = "$key=$value";
  100. }
  101. return '[Twilio.Chat.V2.WebhookContext ' . implode(' ', $context) . ']';
  102. }
  103. }