/vendor/twilio/sdk/src/Twilio/Rest/Autopilot/V1/AssistantContext.php

https://gitlab.com/D-apos-software/Alcesac · PHP · 254 lines · 123 code · 35 blank · 96 comment · 10 complexity · 703214489beb2080e71a6adcfe5b987c MD5 · raw file

  1. <?php
  2. /**
  3. * This code was generated by
  4. * \ / _ _ _| _ _
  5. * | (_)\/(_)(_|\/| |(/_ v1.0.0
  6. * / /
  7. */
  8. namespace Twilio\Rest\Autopilot\V1;
  9. use Twilio\Exceptions\TwilioException;
  10. use Twilio\InstanceContext;
  11. use Twilio\ListResource;
  12. use Twilio\Options;
  13. use Twilio\Rest\Autopilot\V1\Assistant\DefaultsList;
  14. use Twilio\Rest\Autopilot\V1\Assistant\DialogueList;
  15. use Twilio\Rest\Autopilot\V1\Assistant\FieldTypeList;
  16. use Twilio\Rest\Autopilot\V1\Assistant\ModelBuildList;
  17. use Twilio\Rest\Autopilot\V1\Assistant\QueryList;
  18. use Twilio\Rest\Autopilot\V1\Assistant\StyleSheetList;
  19. use Twilio\Rest\Autopilot\V1\Assistant\TaskList;
  20. use Twilio\Rest\Autopilot\V1\Assistant\WebhookList;
  21. use Twilio\Serialize;
  22. use Twilio\Values;
  23. use Twilio\Version;
  24. /**
  25. * 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.
  26. *
  27. * @property FieldTypeList $fieldTypes
  28. * @property TaskList $tasks
  29. * @property ModelBuildList $modelBuilds
  30. * @property QueryList $queries
  31. * @property StyleSheetList $styleSheet
  32. * @property DefaultsList $defaults
  33. * @property DialogueList $dialogues
  34. * @property WebhookList $webhooks
  35. * @method \Twilio\Rest\Autopilot\V1\Assistant\FieldTypeContext fieldTypes(string $sid)
  36. * @method \Twilio\Rest\Autopilot\V1\Assistant\TaskContext tasks(string $sid)
  37. * @method \Twilio\Rest\Autopilot\V1\Assistant\ModelBuildContext modelBuilds(string $sid)
  38. * @method \Twilio\Rest\Autopilot\V1\Assistant\QueryContext queries(string $sid)
  39. * @method \Twilio\Rest\Autopilot\V1\Assistant\StyleSheetContext styleSheet()
  40. * @method \Twilio\Rest\Autopilot\V1\Assistant\DefaultsContext defaults()
  41. * @method \Twilio\Rest\Autopilot\V1\Assistant\DialogueContext dialogues(string $sid)
  42. * @method \Twilio\Rest\Autopilot\V1\Assistant\WebhookContext webhooks(string $sid)
  43. */
  44. class AssistantContext extends InstanceContext {
  45. protected $_fieldTypes;
  46. protected $_tasks;
  47. protected $_modelBuilds;
  48. protected $_queries;
  49. protected $_styleSheet;
  50. protected $_defaults;
  51. protected $_dialogues;
  52. protected $_webhooks;
  53. /**
  54. * Initialize the AssistantContext
  55. *
  56. * @param Version $version Version that contains the resource
  57. * @param string $sid The unique string that identifies the resource
  58. */
  59. public function __construct(Version $version, $sid) {
  60. parent::__construct($version);
  61. // Path Solution
  62. $this->solution = ['sid' => $sid, ];
  63. $this->uri = '/Assistants/' . \rawurlencode($sid) . '';
  64. }
  65. /**
  66. * Fetch the AssistantInstance
  67. *
  68. * @return AssistantInstance Fetched AssistantInstance
  69. * @throws TwilioException When an HTTP error occurs.
  70. */
  71. public function fetch(): AssistantInstance {
  72. $payload = $this->version->fetch('GET', $this->uri);
  73. return new AssistantInstance($this->version, $payload, $this->solution['sid']);
  74. }
  75. /**
  76. * Update the AssistantInstance
  77. *
  78. * @param array|Options $options Optional Arguments
  79. * @return AssistantInstance Updated AssistantInstance
  80. * @throws TwilioException When an HTTP error occurs.
  81. */
  82. public function update(array $options = []): AssistantInstance {
  83. $options = new Values($options);
  84. $data = Values::of([
  85. 'FriendlyName' => $options['friendlyName'],
  86. 'LogQueries' => Serialize::booleanToString($options['logQueries']),
  87. 'UniqueName' => $options['uniqueName'],
  88. 'CallbackUrl' => $options['callbackUrl'],
  89. 'CallbackEvents' => $options['callbackEvents'],
  90. 'StyleSheet' => Serialize::jsonObject($options['styleSheet']),
  91. 'Defaults' => Serialize::jsonObject($options['defaults']),
  92. 'DevelopmentStage' => $options['developmentStage'],
  93. ]);
  94. $payload = $this->version->update('POST', $this->uri, [], $data);
  95. return new AssistantInstance($this->version, $payload, $this->solution['sid']);
  96. }
  97. /**
  98. * Delete the AssistantInstance
  99. *
  100. * @return bool True if delete succeeds, false otherwise
  101. * @throws TwilioException When an HTTP error occurs.
  102. */
  103. public function delete(): bool {
  104. return $this->version->delete('DELETE', $this->uri);
  105. }
  106. /**
  107. * Access the fieldTypes
  108. */
  109. protected function getFieldTypes(): FieldTypeList {
  110. if (!$this->_fieldTypes) {
  111. $this->_fieldTypes = new FieldTypeList($this->version, $this->solution['sid']);
  112. }
  113. return $this->_fieldTypes;
  114. }
  115. /**
  116. * Access the tasks
  117. */
  118. protected function getTasks(): TaskList {
  119. if (!$this->_tasks) {
  120. $this->_tasks = new TaskList($this->version, $this->solution['sid']);
  121. }
  122. return $this->_tasks;
  123. }
  124. /**
  125. * Access the modelBuilds
  126. */
  127. protected function getModelBuilds(): ModelBuildList {
  128. if (!$this->_modelBuilds) {
  129. $this->_modelBuilds = new ModelBuildList($this->version, $this->solution['sid']);
  130. }
  131. return $this->_modelBuilds;
  132. }
  133. /**
  134. * Access the queries
  135. */
  136. protected function getQueries(): QueryList {
  137. if (!$this->_queries) {
  138. $this->_queries = new QueryList($this->version, $this->solution['sid']);
  139. }
  140. return $this->_queries;
  141. }
  142. /**
  143. * Access the styleSheet
  144. */
  145. protected function getStyleSheet(): StyleSheetList {
  146. if (!$this->_styleSheet) {
  147. $this->_styleSheet = new StyleSheetList($this->version, $this->solution['sid']);
  148. }
  149. return $this->_styleSheet;
  150. }
  151. /**
  152. * Access the defaults
  153. */
  154. protected function getDefaults(): DefaultsList {
  155. if (!$this->_defaults) {
  156. $this->_defaults = new DefaultsList($this->version, $this->solution['sid']);
  157. }
  158. return $this->_defaults;
  159. }
  160. /**
  161. * Access the dialogues
  162. */
  163. protected function getDialogues(): DialogueList {
  164. if (!$this->_dialogues) {
  165. $this->_dialogues = new DialogueList($this->version, $this->solution['sid']);
  166. }
  167. return $this->_dialogues;
  168. }
  169. /**
  170. * Access the webhooks
  171. */
  172. protected function getWebhooks(): WebhookList {
  173. if (!$this->_webhooks) {
  174. $this->_webhooks = new WebhookList($this->version, $this->solution['sid']);
  175. }
  176. return $this->_webhooks;
  177. }
  178. /**
  179. * Magic getter to lazy load subresources
  180. *
  181. * @param string $name Subresource to return
  182. * @return ListResource The requested subresource
  183. * @throws TwilioException For unknown subresources
  184. */
  185. public function __get(string $name): ListResource {
  186. if (\property_exists($this, '_' . $name)) {
  187. $method = 'get' . \ucfirst($name);
  188. return $this->$method();
  189. }
  190. throw new TwilioException('Unknown subresource ' . $name);
  191. }
  192. /**
  193. * Magic caller to get resource contexts
  194. *
  195. * @param string $name Resource to return
  196. * @param array $arguments Context parameters
  197. * @return InstanceContext The requested resource context
  198. * @throws TwilioException For unknown resource
  199. */
  200. public function __call(string $name, array $arguments): InstanceContext {
  201. $property = $this->$name;
  202. if (\method_exists($property, 'getContext')) {
  203. return \call_user_func_array(array($property, 'getContext'), $arguments);
  204. }
  205. throw new TwilioException('Resource does not have a context');
  206. }
  207. /**
  208. * Provide a friendly representation
  209. *
  210. * @return string Machine friendly representation
  211. */
  212. public function __toString(): string {
  213. $context = [];
  214. foreach ($this->solution as $key => $value) {
  215. $context[] = "$key=$value";
  216. }
  217. return '[Twilio.Autopilot.V1.AssistantContext ' . \implode(' ', $context) . ']';
  218. }
  219. }