PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/twilio/sdk/src/Twilio/Rest/IpMessaging/V1/ServiceContext.php

https://gitlab.com/D-apos-software/Alcesac
PHP | 223 lines | 129 code | 25 blank | 69 comment | 5 complexity | c5486e0317075c6399403f61de394393 MD5 | raw file
  1. <?php
  2. /**
  3. * This code was generated by
  4. * \ / _ _ _| _ _
  5. * | (_)\/(_)(_|\/| |(/_ v1.0.0
  6. * / /
  7. */
  8. namespace Twilio\Rest\IpMessaging\V1;
  9. use Twilio\Exceptions\TwilioException;
  10. use Twilio\InstanceContext;
  11. use Twilio\ListResource;
  12. use Twilio\Options;
  13. use Twilio\Rest\IpMessaging\V1\Service\ChannelList;
  14. use Twilio\Rest\IpMessaging\V1\Service\RoleList;
  15. use Twilio\Rest\IpMessaging\V1\Service\UserList;
  16. use Twilio\Serialize;
  17. use Twilio\Values;
  18. use Twilio\Version;
  19. /**
  20. * @property ChannelList $channels
  21. * @property RoleList $roles
  22. * @property UserList $users
  23. * @method \Twilio\Rest\IpMessaging\V1\Service\ChannelContext channels(string $sid)
  24. * @method \Twilio\Rest\IpMessaging\V1\Service\RoleContext roles(string $sid)
  25. * @method \Twilio\Rest\IpMessaging\V1\Service\UserContext users(string $sid)
  26. */
  27. class ServiceContext extends InstanceContext {
  28. protected $_channels;
  29. protected $_roles;
  30. protected $_users;
  31. /**
  32. * Initialize the ServiceContext
  33. *
  34. * @param Version $version Version that contains the resource
  35. * @param string $sid The sid
  36. */
  37. public function __construct(Version $version, $sid) {
  38. parent::__construct($version);
  39. // Path Solution
  40. $this->solution = ['sid' => $sid, ];
  41. $this->uri = '/Services/' . \rawurlencode($sid) . '';
  42. }
  43. /**
  44. * Fetch the ServiceInstance
  45. *
  46. * @return ServiceInstance Fetched ServiceInstance
  47. * @throws TwilioException When an HTTP error occurs.
  48. */
  49. public function fetch(): ServiceInstance {
  50. $payload = $this->version->fetch('GET', $this->uri);
  51. return new ServiceInstance($this->version, $payload, $this->solution['sid']);
  52. }
  53. /**
  54. * Delete the ServiceInstance
  55. *
  56. * @return bool True if delete succeeds, false otherwise
  57. * @throws TwilioException When an HTTP error occurs.
  58. */
  59. public function delete(): bool {
  60. return $this->version->delete('DELETE', $this->uri);
  61. }
  62. /**
  63. * Update the ServiceInstance
  64. *
  65. * @param array|Options $options Optional Arguments
  66. * @return ServiceInstance Updated ServiceInstance
  67. * @throws TwilioException When an HTTP error occurs.
  68. */
  69. public function update(array $options = []): ServiceInstance {
  70. $options = new Values($options);
  71. $data = Values::of([
  72. 'FriendlyName' => $options['friendlyName'],
  73. 'DefaultServiceRoleSid' => $options['defaultServiceRoleSid'],
  74. 'DefaultChannelRoleSid' => $options['defaultChannelRoleSid'],
  75. 'DefaultChannelCreatorRoleSid' => $options['defaultChannelCreatorRoleSid'],
  76. 'ReadStatusEnabled' => Serialize::booleanToString($options['readStatusEnabled']),
  77. 'ReachabilityEnabled' => Serialize::booleanToString($options['reachabilityEnabled']),
  78. 'TypingIndicatorTimeout' => $options['typingIndicatorTimeout'],
  79. 'ConsumptionReportInterval' => $options['consumptionReportInterval'],
  80. 'Notifications.NewMessage.Enabled' => Serialize::booleanToString($options['notificationsNewMessageEnabled']),
  81. 'Notifications.NewMessage.Template' => $options['notificationsNewMessageTemplate'],
  82. 'Notifications.AddedToChannel.Enabled' => Serialize::booleanToString($options['notificationsAddedToChannelEnabled']),
  83. 'Notifications.AddedToChannel.Template' => $options['notificationsAddedToChannelTemplate'],
  84. 'Notifications.RemovedFromChannel.Enabled' => Serialize::booleanToString($options['notificationsRemovedFromChannelEnabled']),
  85. 'Notifications.RemovedFromChannel.Template' => $options['notificationsRemovedFromChannelTemplate'],
  86. 'Notifications.InvitedToChannel.Enabled' => Serialize::booleanToString($options['notificationsInvitedToChannelEnabled']),
  87. 'Notifications.InvitedToChannel.Template' => $options['notificationsInvitedToChannelTemplate'],
  88. 'PreWebhookUrl' => $options['preWebhookUrl'],
  89. 'PostWebhookUrl' => $options['postWebhookUrl'],
  90. 'WebhookMethod' => $options['webhookMethod'],
  91. 'WebhookFilters' => Serialize::map($options['webhookFilters'], function($e) { return $e; }),
  92. 'Webhooks.OnMessageSend.Url' => $options['webhooksOnMessageSendUrl'],
  93. 'Webhooks.OnMessageSend.Method' => $options['webhooksOnMessageSendMethod'],
  94. 'Webhooks.OnMessageUpdate.Url' => $options['webhooksOnMessageUpdateUrl'],
  95. 'Webhooks.OnMessageUpdate.Method' => $options['webhooksOnMessageUpdateMethod'],
  96. 'Webhooks.OnMessageRemove.Url' => $options['webhooksOnMessageRemoveUrl'],
  97. 'Webhooks.OnMessageRemove.Method' => $options['webhooksOnMessageRemoveMethod'],
  98. 'Webhooks.OnChannelAdd.Url' => $options['webhooksOnChannelAddUrl'],
  99. 'Webhooks.OnChannelAdd.Method' => $options['webhooksOnChannelAddMethod'],
  100. 'Webhooks.OnChannelDestroy.Url' => $options['webhooksOnChannelDestroyUrl'],
  101. 'Webhooks.OnChannelDestroy.Method' => $options['webhooksOnChannelDestroyMethod'],
  102. 'Webhooks.OnChannelUpdate.Url' => $options['webhooksOnChannelUpdateUrl'],
  103. 'Webhooks.OnChannelUpdate.Method' => $options['webhooksOnChannelUpdateMethod'],
  104. 'Webhooks.OnMemberAdd.Url' => $options['webhooksOnMemberAddUrl'],
  105. 'Webhooks.OnMemberAdd.Method' => $options['webhooksOnMemberAddMethod'],
  106. 'Webhooks.OnMemberRemove.Url' => $options['webhooksOnMemberRemoveUrl'],
  107. 'Webhooks.OnMemberRemove.Method' => $options['webhooksOnMemberRemoveMethod'],
  108. 'Webhooks.OnMessageSent.Url' => $options['webhooksOnMessageSentUrl'],
  109. 'Webhooks.OnMessageSent.Method' => $options['webhooksOnMessageSentMethod'],
  110. 'Webhooks.OnMessageUpdated.Url' => $options['webhooksOnMessageUpdatedUrl'],
  111. 'Webhooks.OnMessageUpdated.Method' => $options['webhooksOnMessageUpdatedMethod'],
  112. 'Webhooks.OnMessageRemoved.Url' => $options['webhooksOnMessageRemovedUrl'],
  113. 'Webhooks.OnMessageRemoved.Method' => $options['webhooksOnMessageRemovedMethod'],
  114. 'Webhooks.OnChannelAdded.Url' => $options['webhooksOnChannelAddedUrl'],
  115. 'Webhooks.OnChannelAdded.Method' => $options['webhooksOnChannelAddedMethod'],
  116. 'Webhooks.OnChannelDestroyed.Url' => $options['webhooksOnChannelDestroyedUrl'],
  117. 'Webhooks.OnChannelDestroyed.Method' => $options['webhooksOnChannelDestroyedMethod'],
  118. 'Webhooks.OnChannelUpdated.Url' => $options['webhooksOnChannelUpdatedUrl'],
  119. 'Webhooks.OnChannelUpdated.Method' => $options['webhooksOnChannelUpdatedMethod'],
  120. 'Webhooks.OnMemberAdded.Url' => $options['webhooksOnMemberAddedUrl'],
  121. 'Webhooks.OnMemberAdded.Method' => $options['webhooksOnMemberAddedMethod'],
  122. 'Webhooks.OnMemberRemoved.Url' => $options['webhooksOnMemberRemovedUrl'],
  123. 'Webhooks.OnMemberRemoved.Method' => $options['webhooksOnMemberRemovedMethod'],
  124. 'Limits.ChannelMembers' => $options['limitsChannelMembers'],
  125. 'Limits.UserChannels' => $options['limitsUserChannels'],
  126. ]);
  127. $payload = $this->version->update('POST', $this->uri, [], $data);
  128. return new ServiceInstance($this->version, $payload, $this->solution['sid']);
  129. }
  130. /**
  131. * Access the channels
  132. */
  133. protected function getChannels(): ChannelList {
  134. if (!$this->_channels) {
  135. $this->_channels = new ChannelList($this->version, $this->solution['sid']);
  136. }
  137. return $this->_channels;
  138. }
  139. /**
  140. * Access the roles
  141. */
  142. protected function getRoles(): RoleList {
  143. if (!$this->_roles) {
  144. $this->_roles = new RoleList($this->version, $this->solution['sid']);
  145. }
  146. return $this->_roles;
  147. }
  148. /**
  149. * Access the users
  150. */
  151. protected function getUsers(): UserList {
  152. if (!$this->_users) {
  153. $this->_users = new UserList($this->version, $this->solution['sid']);
  154. }
  155. return $this->_users;
  156. }
  157. /**
  158. * Magic getter to lazy load subresources
  159. *
  160. * @param string $name Subresource to return
  161. * @return ListResource The requested subresource
  162. * @throws TwilioException For unknown subresources
  163. */
  164. public function __get(string $name): ListResource {
  165. if (\property_exists($this, '_' . $name)) {
  166. $method = 'get' . \ucfirst($name);
  167. return $this->$method();
  168. }
  169. throw new TwilioException('Unknown subresource ' . $name);
  170. }
  171. /**
  172. * Magic caller to get resource contexts
  173. *
  174. * @param string $name Resource to return
  175. * @param array $arguments Context parameters
  176. * @return InstanceContext The requested resource context
  177. * @throws TwilioException For unknown resource
  178. */
  179. public function __call(string $name, array $arguments): InstanceContext {
  180. $property = $this->$name;
  181. if (\method_exists($property, 'getContext')) {
  182. return \call_user_func_array(array($property, 'getContext'), $arguments);
  183. }
  184. throw new TwilioException('Resource does not have a context');
  185. }
  186. /**
  187. * Provide a friendly representation
  188. *
  189. * @return string Machine friendly representation
  190. */
  191. public function __toString(): string {
  192. $context = [];
  193. foreach ($this->solution as $key => $value) {
  194. $context[] = "$key=$value";
  195. }
  196. return '[Twilio.IpMessaging.V1.ServiceContext ' . \implode(' ', $context) . ']';
  197. }
  198. }