/vendor/twilio/sdk/src/Twilio/Rest/Chat/V2/Service/Channel/MemberList.php

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