/libraries/fabrik/vendor/twilio/sdk/src/Twilio/Rest/Chat/V2/Service/ChannelContext.php

https://github.com/trob/fabrik · PHP · 236 lines · 124 code · 28 blank · 84 comment · 6 complexity · ccca31400023d53c57a5becb7f7ca22c 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;
  9. use Twilio\Exceptions\TwilioException;
  10. use Twilio\InstanceContext;
  11. use Twilio\Options;
  12. use Twilio\Rest\Chat\V2\Service\Channel\InviteList;
  13. use Twilio\Rest\Chat\V2\Service\Channel\MemberList;
  14. use Twilio\Rest\Chat\V2\Service\Channel\MessageList;
  15. use Twilio\Rest\Chat\V2\Service\Channel\WebhookList;
  16. use Twilio\Serialize;
  17. use Twilio\Values;
  18. use Twilio\Version;
  19. /**
  20. * @property \Twilio\Rest\Chat\V2\Service\Channel\MemberList $members
  21. * @property \Twilio\Rest\Chat\V2\Service\Channel\MessageList $messages
  22. * @property \Twilio\Rest\Chat\V2\Service\Channel\InviteList $invites
  23. * @property \Twilio\Rest\Chat\V2\Service\Channel\WebhookList $webhooks
  24. * @method \Twilio\Rest\Chat\V2\Service\Channel\MemberContext members(string $sid)
  25. * @method \Twilio\Rest\Chat\V2\Service\Channel\MessageContext messages(string $sid)
  26. * @method \Twilio\Rest\Chat\V2\Service\Channel\InviteContext invites(string $sid)
  27. * @method \Twilio\Rest\Chat\V2\Service\Channel\WebhookContext webhooks(string $sid)
  28. */
  29. class ChannelContext extends InstanceContext {
  30. protected $_members = null;
  31. protected $_messages = null;
  32. protected $_invites = null;
  33. protected $_webhooks = null;
  34. /**
  35. * Initialize the ChannelContext
  36. *
  37. * @param \Twilio\Version $version Version that contains the resource
  38. * @param string $serviceSid The SID of the Service to fetch the resource from
  39. * @param string $sid The SID of the resource
  40. * @return \Twilio\Rest\Chat\V2\Service\ChannelContext
  41. */
  42. public function __construct(Version $version, $serviceSid, $sid) {
  43. parent::__construct($version);
  44. // Path Solution
  45. $this->solution = array('serviceSid' => $serviceSid, 'sid' => $sid, );
  46. $this->uri = '/Services/' . \rawurlencode($serviceSid) . '/Channels/' . \rawurlencode($sid) . '';
  47. }
  48. /**
  49. * Fetch a ChannelInstance
  50. *
  51. * @return ChannelInstance Fetched ChannelInstance
  52. * @throws TwilioException When an HTTP error occurs.
  53. */
  54. public function fetch() {
  55. $params = Values::of(array());
  56. $payload = $this->version->fetch(
  57. 'GET',
  58. $this->uri,
  59. $params
  60. );
  61. return new ChannelInstance(
  62. $this->version,
  63. $payload,
  64. $this->solution['serviceSid'],
  65. $this->solution['sid']
  66. );
  67. }
  68. /**
  69. * Deletes the ChannelInstance
  70. *
  71. * @return boolean True if delete succeeds, false otherwise
  72. * @throws TwilioException When an HTTP error occurs.
  73. */
  74. public function delete() {
  75. return $this->version->delete('delete', $this->uri);
  76. }
  77. /**
  78. * Update the ChannelInstance
  79. *
  80. * @param array|Options $options Optional Arguments
  81. * @return ChannelInstance Updated ChannelInstance
  82. * @throws TwilioException When an HTTP error occurs.
  83. */
  84. public function update($options = array()) {
  85. $options = new Values($options);
  86. $data = Values::of(array(
  87. 'FriendlyName' => $options['friendlyName'],
  88. 'UniqueName' => $options['uniqueName'],
  89. 'Attributes' => $options['attributes'],
  90. 'DateCreated' => Serialize::iso8601DateTime($options['dateCreated']),
  91. 'DateUpdated' => Serialize::iso8601DateTime($options['dateUpdated']),
  92. 'CreatedBy' => $options['createdBy'],
  93. ));
  94. $payload = $this->version->update(
  95. 'POST',
  96. $this->uri,
  97. array(),
  98. $data
  99. );
  100. return new ChannelInstance(
  101. $this->version,
  102. $payload,
  103. $this->solution['serviceSid'],
  104. $this->solution['sid']
  105. );
  106. }
  107. /**
  108. * Access the members
  109. *
  110. * @return \Twilio\Rest\Chat\V2\Service\Channel\MemberList
  111. */
  112. protected function getMembers() {
  113. if (!$this->_members) {
  114. $this->_members = new MemberList(
  115. $this->version,
  116. $this->solution['serviceSid'],
  117. $this->solution['sid']
  118. );
  119. }
  120. return $this->_members;
  121. }
  122. /**
  123. * Access the messages
  124. *
  125. * @return \Twilio\Rest\Chat\V2\Service\Channel\MessageList
  126. */
  127. protected function getMessages() {
  128. if (!$this->_messages) {
  129. $this->_messages = new MessageList(
  130. $this->version,
  131. $this->solution['serviceSid'],
  132. $this->solution['sid']
  133. );
  134. }
  135. return $this->_messages;
  136. }
  137. /**
  138. * Access the invites
  139. *
  140. * @return \Twilio\Rest\Chat\V2\Service\Channel\InviteList
  141. */
  142. protected function getInvites() {
  143. if (!$this->_invites) {
  144. $this->_invites = new InviteList(
  145. $this->version,
  146. $this->solution['serviceSid'],
  147. $this->solution['sid']
  148. );
  149. }
  150. return $this->_invites;
  151. }
  152. /**
  153. * Access the webhooks
  154. *
  155. * @return \Twilio\Rest\Chat\V2\Service\Channel\WebhookList
  156. */
  157. protected function getWebhooks() {
  158. if (!$this->_webhooks) {
  159. $this->_webhooks = new WebhookList(
  160. $this->version,
  161. $this->solution['serviceSid'],
  162. $this->solution['sid']
  163. );
  164. }
  165. return $this->_webhooks;
  166. }
  167. /**
  168. * Magic getter to lazy load subresources
  169. *
  170. * @param string $name Subresource to return
  171. * @return \Twilio\ListResource The requested subresource
  172. * @throws TwilioException For unknown subresources
  173. */
  174. public function __get($name) {
  175. if (\property_exists($this, '_' . $name)) {
  176. $method = 'get' . \ucfirst($name);
  177. return $this->$method();
  178. }
  179. throw new TwilioException('Unknown subresource ' . $name);
  180. }
  181. /**
  182. * Magic caller to get resource contexts
  183. *
  184. * @param string $name Resource to return
  185. * @param array $arguments Context parameters
  186. * @return \Twilio\InstanceContext The requested resource context
  187. * @throws TwilioException For unknown resource
  188. */
  189. public function __call($name, $arguments) {
  190. $property = $this->$name;
  191. if (\method_exists($property, 'getContext')) {
  192. return \call_user_func_array(array($property, 'getContext'), $arguments);
  193. }
  194. throw new TwilioException('Resource does not have a context');
  195. }
  196. /**
  197. * Provide a friendly representation
  198. *
  199. * @return string Machine friendly representation
  200. */
  201. public function __toString() {
  202. $context = array();
  203. foreach ($this->solution as $key => $value) {
  204. $context[] = "$key=$value";
  205. }
  206. return '[Twilio.Chat.V2.ChannelContext ' . \implode(' ', $context) . ']';
  207. }
  208. }