PageRenderTime 26ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Twilio/Rest/Conversations/V1/Conversation/WebhookList.php

http://github.com/twilio/twilio-php
PHP | 159 lines | 56 code | 21 blank | 82 comment | 0 complexity | 5c1584218c3eae448d43d383a298e837 MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /**
  3. * This code was generated by
  4. * \ / _ _ _| _ _
  5. * | (_)\/(_)(_|\/| |(/_ v1.0.0
  6. * / /
  7. */
  8. namespace Twilio\Rest\Conversations\V1\Conversation;
  9. use Twilio\Exceptions\TwilioException;
  10. use Twilio\ListResource;
  11. use Twilio\Options;
  12. use Twilio\Serialize;
  13. use Twilio\Stream;
  14. use Twilio\Values;
  15. use Twilio\Version;
  16. class WebhookList extends ListResource {
  17. /**
  18. * Construct the WebhookList
  19. *
  20. * @param Version $version Version that contains the resource
  21. * @param string $conversationSid The unique ID of the Conversation for this
  22. * webhook.
  23. */
  24. public function __construct(Version $version, string $conversationSid) {
  25. parent::__construct($version);
  26. // Path Solution
  27. $this->solution = ['conversationSid' => $conversationSid, ];
  28. $this->uri = '/Conversations/' . \rawurlencode($conversationSid) . '/Webhooks';
  29. }
  30. /**
  31. * Streams WebhookInstance records from the API as a generator stream.
  32. * This operation lazily loads records as efficiently as possible until the
  33. * limit
  34. * is reached.
  35. * The results are returned as a generator, so this operation is memory
  36. * efficient.
  37. *
  38. * @param int $limit Upper limit for the number of records to return. stream()
  39. * guarantees to never return more than limit. Default is no
  40. * limit
  41. * @param mixed $pageSize Number of records to fetch per request, when not set
  42. * will use the default value of 50 records. If no
  43. * page_size is defined but a limit is defined, stream()
  44. * will attempt to read the limit with the most
  45. * efficient page size, i.e. min(limit, 1000)
  46. * @return Stream stream of results
  47. */
  48. public function stream(int $limit = null, $pageSize = null): Stream {
  49. $limits = $this->version->readLimits($limit, $pageSize);
  50. $page = $this->page($limits['pageSize']);
  51. return $this->version->stream($page, $limits['limit'], $limits['pageLimit']);
  52. }
  53. /**
  54. * Reads WebhookInstance records from the API as a list.
  55. * Unlike stream(), this operation is eager and will load `limit` records into
  56. * memory before returning.
  57. *
  58. * @param int $limit Upper limit for the number of records to return. read()
  59. * guarantees to never return more than limit. Default is no
  60. * limit
  61. * @param mixed $pageSize Number of records to fetch per request, when not set
  62. * will use the default value of 50 records. If no
  63. * page_size is defined but a limit is defined, read()
  64. * will attempt to read the limit with the most
  65. * efficient page size, i.e. min(limit, 1000)
  66. * @return WebhookInstance[] Array of results
  67. */
  68. public function read(int $limit = null, $pageSize = null): array {
  69. return \iterator_to_array($this->stream($limit, $pageSize), false);
  70. }
  71. /**
  72. * Retrieve a single page of WebhookInstance records from the API.
  73. * Request is executed immediately
  74. *
  75. * @param mixed $pageSize Number of records to return, defaults to 50
  76. * @param string $pageToken PageToken provided by the API
  77. * @param mixed $pageNumber Page Number, this value is simply for client state
  78. * @return WebhookPage Page of WebhookInstance
  79. */
  80. public function page($pageSize = Values::NONE, string $pageToken = Values::NONE, $pageNumber = Values::NONE): WebhookPage {
  81. $params = Values::of(['PageToken' => $pageToken, 'Page' => $pageNumber, 'PageSize' => $pageSize, ]);
  82. $response = $this->version->page('GET', $this->uri, $params);
  83. return new WebhookPage($this->version, $response, $this->solution);
  84. }
  85. /**
  86. * Retrieve a specific page of WebhookInstance records from the API.
  87. * Request is executed immediately
  88. *
  89. * @param string $targetUrl API-generated URL for the requested results page
  90. * @return WebhookPage Page of WebhookInstance
  91. */
  92. public function getPage(string $targetUrl): WebhookPage {
  93. $response = $this->version->getDomain()->getClient()->request(
  94. 'GET',
  95. $targetUrl
  96. );
  97. return new WebhookPage($this->version, $response, $this->solution);
  98. }
  99. /**
  100. * Create the WebhookInstance
  101. *
  102. * @param string $target The target of this webhook.
  103. * @param array|Options $options Optional Arguments
  104. * @return WebhookInstance Created WebhookInstance
  105. * @throws TwilioException When an HTTP error occurs.
  106. */
  107. public function create(string $target, array $options = []): WebhookInstance {
  108. $options = new Values($options);
  109. $data = Values::of([
  110. 'Target' => $target,
  111. 'Configuration.Url' => $options['configurationUrl'],
  112. 'Configuration.Method' => $options['configurationMethod'],
  113. 'Configuration.Filters' => Serialize::map($options['configurationFilters'], function($e) { return $e; }),
  114. 'Configuration.Triggers' => Serialize::map($options['configurationTriggers'], function($e) { return $e; }),
  115. 'Configuration.FlowSid' => $options['configurationFlowSid'],
  116. 'Configuration.ReplayAfter' => $options['configurationReplayAfter'],
  117. ]);
  118. $payload = $this->version->create('POST', $this->uri, [], $data);
  119. return new WebhookInstance($this->version, $payload, $this->solution['conversationSid']);
  120. }
  121. /**
  122. * Constructs a WebhookContext
  123. *
  124. * @param string $sid A 34 character string that uniquely identifies this
  125. * resource.
  126. */
  127. public function getContext(string $sid): WebhookContext {
  128. return new WebhookContext($this->version, $this->solution['conversationSid'], $sid);
  129. }
  130. /**
  131. * Provide a friendly representation
  132. *
  133. * @return string Machine friendly representation
  134. */
  135. public function __toString(): string {
  136. return '[Twilio.Conversations.V1.WebhookList]';
  137. }
  138. }