/vendor/twilio/sdk/src/Twilio/Rest/Conversations/V1/Conversation/MessageList.php

https://gitlab.com/D-apos-software/Alcesac · PHP · 168 lines · 62 code · 22 blank · 84 comment · 0 complexity · 63178c07309ff9238600ac01a9bed53c MD5 · raw file

  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 MessageList extends ListResource {
  17. /**
  18. * Construct the MessageList
  19. *
  20. * @param Version $version Version that contains the resource
  21. * @param string $conversationSid The unique ID of the Conversation for this
  22. * message.
  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) . '/Messages';
  29. }
  30. /**
  31. * Create the MessageInstance
  32. *
  33. * @param array|Options $options Optional Arguments
  34. * @return MessageInstance Created MessageInstance
  35. * @throws TwilioException When an HTTP error occurs.
  36. */
  37. public function create(array $options = []): MessageInstance {
  38. $options = new Values($options);
  39. $data = Values::of([
  40. 'Author' => $options['author'],
  41. 'Body' => $options['body'],
  42. 'DateCreated' => Serialize::iso8601DateTime($options['dateCreated']),
  43. 'DateUpdated' => Serialize::iso8601DateTime($options['dateUpdated']),
  44. 'Attributes' => $options['attributes'],
  45. 'MediaSid' => $options['mediaSid'],
  46. ]);
  47. $headers = Values::of(['X-Twilio-Webhook-Enabled' => $options['xTwilioWebhookEnabled'], ]);
  48. $payload = $this->version->create('POST', $this->uri, [], $data, $headers);
  49. return new MessageInstance($this->version, $payload, $this->solution['conversationSid']);
  50. }
  51. /**
  52. * Streams MessageInstance records from the API as a generator stream.
  53. * This operation lazily loads records as efficiently as possible until the
  54. * limit
  55. * is reached.
  56. * The results are returned as a generator, so this operation is memory
  57. * efficient.
  58. *
  59. * @param array|Options $options Optional Arguments
  60. * @param int $limit Upper limit for the number of records to return. stream()
  61. * guarantees to never return more than limit. Default is no
  62. * limit
  63. * @param mixed $pageSize Number of records to fetch per request, when not set
  64. * will use the default value of 50 records. If no
  65. * page_size is defined but a limit is defined, stream()
  66. * will attempt to read the limit with the most
  67. * efficient page size, i.e. min(limit, 1000)
  68. * @return Stream stream of results
  69. */
  70. public function stream(array $options = [], int $limit = null, $pageSize = null): Stream {
  71. $limits = $this->version->readLimits($limit, $pageSize);
  72. $page = $this->page($options, $limits['pageSize']);
  73. return $this->version->stream($page, $limits['limit'], $limits['pageLimit']);
  74. }
  75. /**
  76. * Reads MessageInstance records from the API as a list.
  77. * Unlike stream(), this operation is eager and will load `limit` records into
  78. * memory before returning.
  79. *
  80. * @param array|Options $options Optional Arguments
  81. * @param int $limit Upper limit for the number of records to return. read()
  82. * guarantees to never return more than limit. Default is no
  83. * limit
  84. * @param mixed $pageSize Number of records to fetch per request, when not set
  85. * will use the default value of 50 records. If no
  86. * page_size is defined but a limit is defined, read()
  87. * will attempt to read the limit with the most
  88. * efficient page size, i.e. min(limit, 1000)
  89. * @return MessageInstance[] Array of results
  90. */
  91. public function read(array $options = [], int $limit = null, $pageSize = null): array {
  92. return \iterator_to_array($this->stream($options, $limit, $pageSize), false);
  93. }
  94. /**
  95. * Retrieve a single page of MessageInstance records from the API.
  96. * Request is executed immediately
  97. *
  98. * @param array|Options $options Optional Arguments
  99. * @param mixed $pageSize Number of records to return, defaults to 50
  100. * @param string $pageToken PageToken provided by the API
  101. * @param mixed $pageNumber Page Number, this value is simply for client state
  102. * @return MessagePage Page of MessageInstance
  103. */
  104. public function page(array $options = [], $pageSize = Values::NONE, string $pageToken = Values::NONE, $pageNumber = Values::NONE): MessagePage {
  105. $options = new Values($options);
  106. $params = Values::of([
  107. 'Order' => $options['order'],
  108. 'PageToken' => $pageToken,
  109. 'Page' => $pageNumber,
  110. 'PageSize' => $pageSize,
  111. ]);
  112. $response = $this->version->page('GET', $this->uri, $params);
  113. return new MessagePage($this->version, $response, $this->solution);
  114. }
  115. /**
  116. * Retrieve a specific page of MessageInstance records from the API.
  117. * Request is executed immediately
  118. *
  119. * @param string $targetUrl API-generated URL for the requested results page
  120. * @return MessagePage Page of MessageInstance
  121. */
  122. public function getPage(string $targetUrl): MessagePage {
  123. $response = $this->version->getDomain()->getClient()->request(
  124. 'GET',
  125. $targetUrl
  126. );
  127. return new MessagePage($this->version, $response, $this->solution);
  128. }
  129. /**
  130. * Constructs a MessageContext
  131. *
  132. * @param string $sid A 34 character string that uniquely identifies this
  133. * resource.
  134. */
  135. public function getContext(string $sid): MessageContext {
  136. return new MessageContext($this->version, $this->solution['conversationSid'], $sid);
  137. }
  138. /**
  139. * Provide a friendly representation
  140. *
  141. * @return string Machine friendly representation
  142. */
  143. public function __toString(): string {
  144. return '[Twilio.Conversations.V1.MessageList]';
  145. }
  146. }