/libraries/fabrik/vendor/twilio/sdk/src/Twilio/Rest/Preview/Understand/Assistant/QueryList.php

https://github.com/trob/fabrik · PHP · 182 lines · 69 code · 21 blank · 92 comment · 0 complexity · 0bff96fbe3aef41740fe00c7eb37a84d MD5 · raw file

  1. <?php
  2. /**
  3. * This code was generated by
  4. * \ / _ _ _| _ _
  5. * | (_)\/(_)(_|\/| |(/_ v1.0.0
  6. * / /
  7. */
  8. namespace Twilio\Rest\Preview\Understand\Assistant;
  9. use Twilio\Exceptions\TwilioException;
  10. use Twilio\ListResource;
  11. use Twilio\Options;
  12. use Twilio\Values;
  13. use Twilio\Version;
  14. /**
  15. * PLEASE NOTE that this class contains preview products that are subject to change. Use them with caution. If you currently do not have developer preview access, please contact help@twilio.com.
  16. */
  17. class QueryList extends ListResource {
  18. /**
  19. * Construct the QueryList
  20. *
  21. * @param Version $version Version that contains the resource
  22. * @param string $assistantSid The unique ID of the parent Assistant.
  23. * @return \Twilio\Rest\Preview\Understand\Assistant\QueryList
  24. */
  25. public function __construct(Version $version, $assistantSid) {
  26. parent::__construct($version);
  27. // Path Solution
  28. $this->solution = array('assistantSid' => $assistantSid, );
  29. $this->uri = '/Assistants/' . \rawurlencode($assistantSid) . '/Queries';
  30. }
  31. /**
  32. * Streams QueryInstance records from the API as a generator stream.
  33. * This operation lazily loads records as efficiently as possible until the
  34. * limit
  35. * is reached.
  36. * The results are returned as a generator, so this operation is memory
  37. * efficient.
  38. *
  39. * @param array|Options $options Optional Arguments
  40. * @param int $limit Upper limit for the number of records to return. stream()
  41. * guarantees to never return more than limit. Default is no
  42. * limit
  43. * @param mixed $pageSize Number of records to fetch per request, when not set
  44. * will use the default value of 50 records. If no
  45. * page_size is defined but a limit is defined, stream()
  46. * will attempt to read the limit with the most
  47. * efficient page size, i.e. min(limit, 1000)
  48. * @return \Twilio\Stream stream of results
  49. */
  50. public function stream($options = array(), $limit = null, $pageSize = null) {
  51. $limits = $this->version->readLimits($limit, $pageSize);
  52. $page = $this->page($options, $limits['pageSize']);
  53. return $this->version->stream($page, $limits['limit'], $limits['pageLimit']);
  54. }
  55. /**
  56. * Reads QueryInstance records from the API as a list.
  57. * Unlike stream(), this operation is eager and will load `limit` records into
  58. * memory before returning.
  59. *
  60. * @param array|Options $options Optional Arguments
  61. * @param int $limit Upper limit for the number of records to return. read()
  62. * guarantees to never return more than limit. Default is no
  63. * limit
  64. * @param mixed $pageSize Number of records to fetch per request, when not set
  65. * will use the default value of 50 records. If no
  66. * page_size is defined but a limit is defined, read()
  67. * will attempt to read the limit with the most
  68. * efficient page size, i.e. min(limit, 1000)
  69. * @return QueryInstance[] Array of results
  70. */
  71. public function read($options = array(), $limit = null, $pageSize = null) {
  72. return \iterator_to_array($this->stream($options, $limit, $pageSize), false);
  73. }
  74. /**
  75. * Retrieve a single page of QueryInstance records from the API.
  76. * Request is executed immediately
  77. *
  78. * @param array|Options $options Optional Arguments
  79. * @param mixed $pageSize Number of records to return, defaults to 50
  80. * @param string $pageToken PageToken provided by the API
  81. * @param mixed $pageNumber Page Number, this value is simply for client state
  82. * @return \Twilio\Page Page of QueryInstance
  83. */
  84. public function page($options = array(), $pageSize = Values::NONE, $pageToken = Values::NONE, $pageNumber = Values::NONE) {
  85. $options = new Values($options);
  86. $params = Values::of(array(
  87. 'Language' => $options['language'],
  88. 'ModelBuild' => $options['modelBuild'],
  89. 'Status' => $options['status'],
  90. 'PageToken' => $pageToken,
  91. 'Page' => $pageNumber,
  92. 'PageSize' => $pageSize,
  93. ));
  94. $response = $this->version->page(
  95. 'GET',
  96. $this->uri,
  97. $params
  98. );
  99. return new QueryPage($this->version, $response, $this->solution);
  100. }
  101. /**
  102. * Retrieve a specific page of QueryInstance records from the API.
  103. * Request is executed immediately
  104. *
  105. * @param string $targetUrl API-generated URL for the requested results page
  106. * @return \Twilio\Page Page of QueryInstance
  107. */
  108. public function getPage($targetUrl) {
  109. $response = $this->version->getDomain()->getClient()->request(
  110. 'GET',
  111. $targetUrl
  112. );
  113. return new QueryPage($this->version, $response, $this->solution);
  114. }
  115. /**
  116. * Create a new QueryInstance
  117. *
  118. * @param string $language An ISO language-country string of the sample.
  119. * @param string $query A user-provided string that uniquely identifies this
  120. * resource as an alternative to the sid. It can be up to
  121. * 2048 characters long.
  122. * @param array|Options $options Optional Arguments
  123. * @return QueryInstance Newly created QueryInstance
  124. * @throws TwilioException When an HTTP error occurs.
  125. */
  126. public function create($language, $query, $options = array()) {
  127. $options = new Values($options);
  128. $data = Values::of(array(
  129. 'Language' => $language,
  130. 'Query' => $query,
  131. 'Tasks' => $options['tasks'],
  132. 'ModelBuild' => $options['modelBuild'],
  133. 'Field' => $options['field'],
  134. ));
  135. $payload = $this->version->create(
  136. 'POST',
  137. $this->uri,
  138. array(),
  139. $data
  140. );
  141. return new QueryInstance($this->version, $payload, $this->solution['assistantSid']);
  142. }
  143. /**
  144. * Constructs a QueryContext
  145. *
  146. * @param string $sid A 34 character string that uniquely identifies this
  147. * resource.
  148. * @return \Twilio\Rest\Preview\Understand\Assistant\QueryContext
  149. */
  150. public function getContext($sid) {
  151. return new QueryContext($this->version, $this->solution['assistantSid'], $sid);
  152. }
  153. /**
  154. * Provide a friendly representation
  155. *
  156. * @return string Machine friendly representation
  157. */
  158. public function __toString() {
  159. return '[Twilio.Preview.Understand.QueryList]';
  160. }
  161. }