/libraries/fabrik/vendor/twilio/sdk/src/Twilio/Rest/Chat/V2/Service/Channel/MessageList.php

https://github.com/trob/fabrik · PHP · 188 lines · 80 code · 21 blank · 87 comment · 0 complexity · 4550490e3bcb94c7ca4f9f29c36cedf4 MD5 · raw file

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