/libraries/fabrik/vendor/twilio/sdk/src/Twilio/Rest/Studio/V1/Flow/ExecutionList.php

https://github.com/trob/fabrik · PHP · 175 lines · 67 code · 21 blank · 87 comment · 0 complexity · b98d987ca6acbde8fd6545c192e193cd MD5 · raw file

  1. <?php
  2. /**
  3. * This code was generated by
  4. * \ / _ _ _| _ _
  5. * | (_)\/(_)(_|\/| |(/_ v1.0.0
  6. * / /
  7. */
  8. namespace Twilio\Rest\Studio\V1\Flow;
  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 ExecutionList extends ListResource {
  16. /**
  17. * Construct the ExecutionList
  18. *
  19. * @param Version $version Version that contains the resource
  20. * @param string $flowSid The SID of the Flow
  21. * @return \Twilio\Rest\Studio\V1\Flow\ExecutionList
  22. */
  23. public function __construct(Version $version, $flowSid) {
  24. parent::__construct($version);
  25. // Path Solution
  26. $this->solution = array('flowSid' => $flowSid, );
  27. $this->uri = '/Flows/' . \rawurlencode($flowSid) . '/Executions';
  28. }
  29. /**
  30. * Streams ExecutionInstance records from the API as a generator stream.
  31. * This operation lazily loads records as efficiently as possible until the
  32. * limit
  33. * is reached.
  34. * The results are returned as a generator, so this operation is memory
  35. * efficient.
  36. *
  37. * @param array|Options $options Optional Arguments
  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 \Twilio\Stream stream of results
  47. */
  48. public function stream($options = array(), $limit = null, $pageSize = null) {
  49. $limits = $this->version->readLimits($limit, $pageSize);
  50. $page = $this->page($options, $limits['pageSize']);
  51. return $this->version->stream($page, $limits['limit'], $limits['pageLimit']);
  52. }
  53. /**
  54. * Reads ExecutionInstance 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 array|Options $options Optional Arguments
  59. * @param int $limit Upper limit for the number of records to return. read()
  60. * guarantees to never return more than limit. Default is no
  61. * limit
  62. * @param mixed $pageSize Number of records to fetch per request, when not set
  63. * will use the default value of 50 records. If no
  64. * page_size is defined but a limit is defined, read()
  65. * will attempt to read the limit with the most
  66. * efficient page size, i.e. min(limit, 1000)
  67. * @return ExecutionInstance[] Array of results
  68. */
  69. public function read($options = array(), $limit = null, $pageSize = null) {
  70. return \iterator_to_array($this->stream($options, $limit, $pageSize), false);
  71. }
  72. /**
  73. * Retrieve a single page of ExecutionInstance records from the API.
  74. * Request is executed immediately
  75. *
  76. * @param array|Options $options Optional Arguments
  77. * @param mixed $pageSize Number of records to return, defaults to 50
  78. * @param string $pageToken PageToken provided by the API
  79. * @param mixed $pageNumber Page Number, this value is simply for client state
  80. * @return \Twilio\Page Page of ExecutionInstance
  81. */
  82. public function page($options = array(), $pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) {
  83. $options = new Values($options);
  84. $params = Values::of(array(
  85. 'DateCreatedFrom' => Serialize::iso8601DateTime($options['dateCreatedFrom']),
  86. 'DateCreatedTo' => Serialize::iso8601DateTime($options['dateCreatedTo']),
  87. 'PageToken' => $pageToken,
  88. 'Page' => $pageNumber,
  89. 'PageSize' => $pageSize,
  90. ));
  91. $response = $this->version->page(
  92. 'GET',
  93. $this->uri,
  94. $params
  95. );
  96. return new ExecutionPage($this->version, $response, $this->solution);
  97. }
  98. /**
  99. * Retrieve a specific page of ExecutionInstance records from the API.
  100. * Request is executed immediately
  101. *
  102. * @param string $targetUrl API-generated URL for the requested results page
  103. * @return \Twilio\Page Page of ExecutionInstance
  104. */
  105. public function getPage($targetUrl) {
  106. $response = $this->version->getDomain()->getClient()->request(
  107. 'GET',
  108. $targetUrl
  109. );
  110. return new ExecutionPage($this->version, $response, $this->solution);
  111. }
  112. /**
  113. * Create a new ExecutionInstance
  114. *
  115. * @param string $to The Contact phone number to start a Studio Flow Execution
  116. * @param string $from The Twilio phone number to send messages or initiate
  117. * calls from during the Flow Execution
  118. * @param array|Options $options Optional Arguments
  119. * @return ExecutionInstance Newly created ExecutionInstance
  120. * @throws TwilioException When an HTTP error occurs.
  121. */
  122. public function create($to, $from, $options = array()) {
  123. $options = new Values($options);
  124. $data = Values::of(array(
  125. 'To' => $to,
  126. 'From' => $from,
  127. 'Parameters' => Serialize::jsonObject($options['parameters']),
  128. ));
  129. $payload = $this->version->create(
  130. 'POST',
  131. $this->uri,
  132. array(),
  133. $data
  134. );
  135. return new ExecutionInstance($this->version, $payload, $this->solution['flowSid']);
  136. }
  137. /**
  138. * Constructs a ExecutionContext
  139. *
  140. * @param string $sid The SID of the Execution resource to fetch
  141. * @return \Twilio\Rest\Studio\V1\Flow\ExecutionContext
  142. */
  143. public function getContext($sid) {
  144. return new ExecutionContext($this->version, $this->solution['flowSid'], $sid);
  145. }
  146. /**
  147. * Provide a friendly representation
  148. *
  149. * @return string Machine friendly representation
  150. */
  151. public function __toString() {
  152. return '[Twilio.Studio.V1.ExecutionList]';
  153. }
  154. }