Client.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. <?php
  2. /**
  3. * This code was generated by
  4. * \ / _ _ _| _ _
  5. * | (_)\/(_)(_|\/| |(/_ v1.0.0
  6. * / /
  7. */
  8. namespace Twilio\Rest;
  9. use Twilio\Exceptions\ConfigurationException;
  10. use Twilio\Exceptions\TwilioException;
  11. use Twilio\Http\Client as HttpClient;
  12. use Twilio\Http\CurlClient;
  13. use Twilio\VersionInfo;
  14. /**
  15. * A client for accessing the Twilio API.
  16. *
  17. * @property \Twilio\Rest\Accounts accounts
  18. * @property \Twilio\Rest\Api api
  19. * @property \Twilio\Rest\Chat chat
  20. * @property \Twilio\Rest\Fax fax
  21. * @property \Twilio\Rest\IpMessaging ipMessaging
  22. * @property \Twilio\Rest\Lookups lookups
  23. * @property \Twilio\Rest\Monitor monitor
  24. * @property \Twilio\Rest\Notify notify
  25. * @property \Twilio\Rest\Preview preview
  26. * @property \Twilio\Rest\Pricing pricing
  27. * @property \Twilio\Rest\Proxy proxy
  28. * @property \Twilio\Rest\Taskrouter taskrouter
  29. * @property \Twilio\Rest\Trunking trunking
  30. * @property \Twilio\Rest\Video video
  31. * @property \Twilio\Rest\Messaging messaging
  32. * @property \Twilio\Rest\Wireless wireless
  33. * @property \Twilio\Rest\Sync sync
  34. * @property \Twilio\Rest\Studio studio
  35. * @property \Twilio\Rest\Api\V2010\AccountInstance account
  36. * @property \Twilio\Rest\Api\V2010\Account\AddressList addresses
  37. * @property \Twilio\Rest\Api\V2010\Account\ApplicationList applications
  38. * @property \Twilio\Rest\Api\V2010\Account\AuthorizedConnectAppList authorizedConnectApps
  39. * @property \Twilio\Rest\Api\V2010\Account\AvailablePhoneNumberCountryList availablePhoneNumbers
  40. * @property \Twilio\Rest\Api\V2010\Account\CallList calls
  41. * @property \Twilio\Rest\Api\V2010\Account\ConferenceList conferences
  42. * @property \Twilio\Rest\Api\V2010\Account\ConnectAppList connectApps
  43. * @property \Twilio\Rest\Api\V2010\Account\IncomingPhoneNumberList incomingPhoneNumbers
  44. * @property \Twilio\Rest\Api\V2010\Account\KeyList keys
  45. * @property \Twilio\Rest\Api\V2010\Account\MessageList messages
  46. * @property \Twilio\Rest\Api\V2010\Account\NewKeyList newKeys
  47. * @property \Twilio\Rest\Api\V2010\Account\NewSigningKeyList newSigningKeys
  48. * @property \Twilio\Rest\Api\V2010\Account\NotificationList notifications
  49. * @property \Twilio\Rest\Api\V2010\Account\OutgoingCallerIdList outgoingCallerIds
  50. * @property \Twilio\Rest\Api\V2010\Account\QueueList queues
  51. * @property \Twilio\Rest\Api\V2010\Account\RecordingList recordings
  52. * @property \Twilio\Rest\Api\V2010\Account\SigningKeyList signingKeys
  53. * @property \Twilio\Rest\Api\V2010\Account\SipList sip
  54. * @property \Twilio\Rest\Api\V2010\Account\ShortCodeList shortCodes
  55. * @property \Twilio\Rest\Api\V2010\Account\TokenList tokens
  56. * @property \Twilio\Rest\Api\V2010\Account\TranscriptionList transcriptions
  57. * @property \Twilio\Rest\Api\V2010\Account\UsageList usage
  58. * @property \Twilio\Rest\Api\V2010\Account\ValidationRequestList validationRequests
  59. * @method \Twilio\Rest\Api\V2010\AccountContext accounts(string $sid)
  60. * @method \Twilio\Rest\Api\V2010\Account\AddressContext addresses(string $sid)
  61. * @method \Twilio\Rest\Api\V2010\Account\ApplicationContext applications(string $sid)
  62. * @method \Twilio\Rest\Api\V2010\Account\AuthorizedConnectAppContext authorizedConnectApps(string $connectAppSid)
  63. * @method \Twilio\Rest\Api\V2010\Account\AvailablePhoneNumberCountryContext availablePhoneNumbers(string $countryCode)
  64. * @method \Twilio\Rest\Api\V2010\Account\CallContext calls(string $sid)
  65. * @method \Twilio\Rest\Api\V2010\Account\ConferenceContext conferences(string $sid)
  66. * @method \Twilio\Rest\Api\V2010\Account\ConnectAppContext connectApps(string $sid)
  67. * @method \Twilio\Rest\Api\V2010\Account\IncomingPhoneNumberContext incomingPhoneNumbers(string $sid)
  68. * @method \Twilio\Rest\Api\V2010\Account\KeyContext keys(string $sid)
  69. * @method \Twilio\Rest\Api\V2010\Account\MessageContext messages(string $sid)
  70. * @method \Twilio\Rest\Api\V2010\Account\NotificationContext notifications(string $sid)
  71. * @method \Twilio\Rest\Api\V2010\Account\OutgoingCallerIdContext outgoingCallerIds(string $sid)
  72. * @method \Twilio\Rest\Api\V2010\Account\QueueContext queues(string $sid)
  73. * @method \Twilio\Rest\Api\V2010\Account\RecordingContext recordings(string $sid)
  74. * @method \Twilio\Rest\Api\V2010\Account\SigningKeyContext signingKeys(string $sid)
  75. * @method \Twilio\Rest\Api\V2010\Account\ShortCodeContext shortCodes(string $sid)
  76. * @method \Twilio\Rest\Api\V2010\Account\TranscriptionContext transcriptions(string $sid)
  77. */
  78. class Client {
  79. const ENV_ACCOUNT_SID = "TWILIO_ACCOUNT_SID";
  80. const ENV_AUTH_TOKEN = "TWILIO_AUTH_TOKEN";
  81. protected $username;
  82. protected $password;
  83. protected $accountSid;
  84. protected $region;
  85. protected $httpClient;
  86. protected $_account;
  87. protected $_accounts = null;
  88. protected $_api = null;
  89. protected $_chat = null;
  90. protected $_fax = null;
  91. protected $_ipMessaging = null;
  92. protected $_lookups = null;
  93. protected $_monitor = null;
  94. protected $_notify = null;
  95. protected $_preview = null;
  96. protected $_pricing = null;
  97. protected $_proxy = null;
  98. protected $_taskrouter = null;
  99. protected $_trunking = null;
  100. protected $_video = null;
  101. protected $_messaging = null;
  102. protected $_wireless = null;
  103. protected $_sync = null;
  104. protected $_studio = null;
  105. /**
  106. * Initializes the Twilio Client
  107. *
  108. * @param string $username Username to authenticate with
  109. * @param string $password Password to authenticate with
  110. * @param string $accountSid Account Sid to authenticate with, defaults to
  111. * $username
  112. * @param string $region Region to send requests to, defaults to no region
  113. * selection
  114. * @param \Twilio\Http\Client $httpClient HttpClient, defaults to CurlClient
  115. * @param mixed[] $environment Environment to look for auth details, defaults
  116. * to $_ENV
  117. * @return \Twilio\Rest\Client Twilio Client
  118. * @throws ConfigurationException If valid authentication is not present
  119. */
  120. public function __construct($username = null, $password = null, $accountSid = null, $region = null, HttpClient $httpClient = null, $environment = null) {
  121. if (is_null($environment)) {
  122. $environment = $_ENV;
  123. }
  124. if ($username) {
  125. $this->username = $username;
  126. } else {
  127. if (array_key_exists(self::ENV_ACCOUNT_SID, $environment)) {
  128. $this->username = $environment[self::ENV_ACCOUNT_SID];
  129. }
  130. }
  131. if ($password) {
  132. $this->password = $password;
  133. } else {
  134. if (array_key_exists(self::ENV_AUTH_TOKEN, $environment)) {
  135. $this->password = $environment[self::ENV_AUTH_TOKEN];
  136. }
  137. }
  138. if (!$this->username || !$this->password) {
  139. throw new ConfigurationException("Credentials are required to create a Client");
  140. }
  141. $this->accountSid = $accountSid ?: $this->username;
  142. $this->region = $region;
  143. if ($httpClient) {
  144. $this->httpClient = $httpClient;
  145. } else {
  146. $this->httpClient = new CurlClient();
  147. }
  148. }
  149. /**
  150. * Makes a request to the Twilio API using the configured http client
  151. * Authentication information is automatically added if none is provided
  152. *
  153. * @param string $method HTTP Method
  154. * @param string $uri Fully qualified url
  155. * @param string[] $params Query string parameters
  156. * @param string[] $data POST body data
  157. * @param string[] $headers HTTP Headers
  158. * @param string $username User for Authentication
  159. * @param string $password Password for Authentication
  160. * @param int $timeout Timeout in seconds
  161. * @return \Twilio\Http\Response Response from the Twilio API
  162. */
  163. public function request($method, $uri, $params = array(), $data = array(), $headers = array(), $username = null, $password = null, $timeout = null) {
  164. $username = $username ? $username : $this->username;
  165. $password = $password ? $password : $this->password;
  166. $headers['User-Agent'] = 'twilio-php/' . VersionInfo::string() .
  167. ' (PHP ' . phpversion() . ')';
  168. $headers['Accept-Charset'] = 'utf-8';
  169. if ($method == 'POST' && !array_key_exists('Content-Type', $headers)) {
  170. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  171. }
  172. if (!array_key_exists('Accept', $headers)) {
  173. $headers['Accept'] = 'application/json';
  174. }
  175. if ($this->region) {
  176. list($head, $tail) = explode('.', $uri, 2);
  177. if (strpos($tail, $this->region) !== 0) {
  178. $uri = implode('.', array($head, $this->region, $tail));
  179. }
  180. }
  181. return $this->getHttpClient()->request(
  182. $method,
  183. $uri,
  184. $params,
  185. $data,
  186. $headers,
  187. $username,
  188. $password,
  189. $timeout
  190. );
  191. }
  192. /**
  193. * Retrieve the Username
  194. *
  195. * @return string Current Username
  196. */
  197. public function getUsername() {
  198. return $this->username;
  199. }
  200. /**
  201. * Retrieve the Password
  202. *
  203. * @return string Current Password
  204. */
  205. public function getPassword() {
  206. return $this->password;
  207. }
  208. /**
  209. * Retrieve the AccountSid
  210. *
  211. * @return string Current AccountSid
  212. */
  213. public function getAccountSid() {
  214. return $this->accountSid;
  215. }
  216. /**
  217. * Retrieve the Region
  218. *
  219. * @return string Current Region
  220. */
  221. public function getRegion() {
  222. return $this->region;
  223. }
  224. /**
  225. * Retrieve the HttpClient
  226. *
  227. * @return \Twilio\Http\Client Current HttpClient
  228. */
  229. public function getHttpClient() {
  230. return $this->httpClient;
  231. }
  232. /**
  233. * Set the HttpClient
  234. *
  235. * @param \Twilio\Http\Client $httpClient HttpClient to use
  236. */
  237. public function setHttpClient(HttpClient $httpClient) {
  238. $this->httpClient = $httpClient;
  239. }
  240. /**
  241. * Access the Accounts Twilio Domain
  242. *
  243. * @return \Twilio\Rest\Accounts Accounts Twilio Domain
  244. */
  245. protected function getAccounts() {
  246. if (!$this->_accounts) {
  247. $this->_accounts = new Accounts($this);
  248. }
  249. return $this->_accounts;
  250. }
  251. /**
  252. * Access the Api Twilio Domain
  253. *
  254. * @return \Twilio\Rest\Api Api Twilio Domain
  255. */
  256. protected function getApi() {
  257. if (!$this->_api) {
  258. $this->_api = new Api($this);
  259. }
  260. return $this->_api;
  261. }
  262. /**
  263. * @return \Twilio\Rest\Api\V2010\AccountContext Account provided as the
  264. * authenticating account
  265. */
  266. public function getAccount() {
  267. return $this->api->v2010->account;
  268. }
  269. /**
  270. * @return \Twilio\Rest\Api\V2010\Account\AddressList
  271. */
  272. protected function getAddresses() {
  273. return $this->api->v2010->account->addresses;
  274. }
  275. /**
  276. * @param string $sid The sid
  277. * @return \Twilio\Rest\Api\V2010\Account\AddressContext
  278. */
  279. protected function contextAddresses($sid) {
  280. return $this->api->v2010->account->addresses($sid);
  281. }
  282. /**
  283. * @return \Twilio\Rest\Api\V2010\Account\ApplicationList
  284. */
  285. protected function getApplications() {
  286. return $this->api->v2010->account->applications;
  287. }
  288. /**
  289. * @param string $sid Fetch by unique Application Sid
  290. * @return \Twilio\Rest\Api\V2010\Account\ApplicationContext
  291. */
  292. protected function contextApplications($sid) {
  293. return $this->api->v2010->account->applications($sid);
  294. }
  295. /**
  296. * @return \Twilio\Rest\Api\V2010\Account\AuthorizedConnectAppList
  297. */
  298. protected function getAuthorizedConnectApps() {
  299. return $this->api->v2010->account->authorizedConnectApps;
  300. }
  301. /**
  302. * @param string $connectAppSid The connect_app_sid
  303. * @return \Twilio\Rest\Api\V2010\Account\AuthorizedConnectAppContext
  304. */
  305. protected function contextAuthorizedConnectApps($connectAppSid) {
  306. return $this->api->v2010->account->authorizedConnectApps($connectAppSid);
  307. }
  308. /**
  309. * @return \Twilio\Rest\Api\V2010\Account\AvailablePhoneNumberCountryList
  310. */
  311. protected function getAvailablePhoneNumbers() {
  312. return $this->api->v2010->account->availablePhoneNumbers;
  313. }
  314. /**
  315. * @param string $countryCode The country_code
  316. * @return \Twilio\Rest\Api\V2010\Account\AvailablePhoneNumberCountryContext
  317. */
  318. protected function contextAvailablePhoneNumbers($countryCode) {
  319. return $this->api->v2010->account->availablePhoneNumbers($countryCode);
  320. }
  321. /**
  322. * @return \Twilio\Rest\Api\V2010\Account\CallList
  323. */
  324. protected function getCalls() {
  325. return $this->api->v2010->account->calls;
  326. }
  327. /**
  328. * @param string $sid Call Sid that uniquely identifies the Call to fetch
  329. * @return \Twilio\Rest\Api\V2010\Account\CallContext
  330. */
  331. protected function contextCalls($sid) {
  332. return $this->api->v2010->account->calls($sid);
  333. }
  334. /**
  335. * @return \Twilio\Rest\Api\V2010\Account\ConferenceList
  336. */
  337. protected function getConferences() {
  338. return $this->api->v2010->account->conferences;
  339. }
  340. /**
  341. * @param string $sid Fetch by unique conference Sid
  342. * @return \Twilio\Rest\Api\V2010\Account\ConferenceContext
  343. */
  344. protected function contextConferences($sid) {
  345. return $this->api->v2010->account->conferences($sid);
  346. }
  347. /**
  348. * @return \Twilio\Rest\Api\V2010\Account\ConnectAppList
  349. */
  350. protected function getConnectApps() {
  351. return $this->api->v2010->account->connectApps;
  352. }
  353. /**
  354. * @param string $sid Fetch by unique connect-app Sid
  355. * @return \Twilio\Rest\Api\V2010\Account\ConnectAppContext
  356. */
  357. protected function contextConnectApps($sid) {
  358. return $this->api->v2010->account->connectApps($sid);
  359. }
  360. /**
  361. * @return \Twilio\Rest\Api\V2010\Account\IncomingPhoneNumberList
  362. */
  363. protected function getIncomingPhoneNumbers() {
  364. return $this->api->v2010->account->incomingPhoneNumbers;
  365. }
  366. /**
  367. * @param string $sid Fetch by unique incoming-phone-number Sid
  368. * @return \Twilio\Rest\Api\V2010\Account\IncomingPhoneNumberContext
  369. */
  370. protected function contextIncomingPhoneNumbers($sid) {
  371. return $this->api->v2010->account->incomingPhoneNumbers($sid);
  372. }
  373. /**
  374. * @return \Twilio\Rest\Api\V2010\Account\KeyList
  375. */
  376. protected function getKeys() {
  377. return $this->api->v2010->account->keys;
  378. }
  379. /**
  380. * @param string $sid The sid
  381. * @return \Twilio\Rest\Api\V2010\Account\KeyContext
  382. */
  383. protected function contextKeys($sid) {
  384. return $this->api->v2010->account->keys($sid);
  385. }
  386. /**
  387. * @return \Twilio\Rest\Api\V2010\Account\MessageList
  388. */
  389. protected function getMessages() {
  390. return $this->api->v2010->account->messages;
  391. }
  392. /**
  393. * @param string $sid Fetch by unique message Sid
  394. * @return \Twilio\Rest\Api\V2010\Account\MessageContext
  395. */
  396. protected function contextMessages($sid) {
  397. return $this->api->v2010->account->messages($sid);
  398. }
  399. /**
  400. * @return \Twilio\Rest\Api\V2010\Account\NewKeyList
  401. */
  402. protected function getNewKeys() {
  403. return $this->api->v2010->account->newKeys;
  404. }
  405. /**
  406. * @return \Twilio\Rest\Api\V2010\Account\NewSigningKeyList
  407. */
  408. protected function getNewSigningKeys() {
  409. return $this->api->v2010->account->newSigningKeys;
  410. }
  411. /**
  412. * @return \Twilio\Rest\Api\V2010\Account\NotificationList
  413. */
  414. protected function getNotifications() {
  415. return $this->api->v2010->account->notifications;
  416. }
  417. /**
  418. * @param string $sid Fetch by unique notification Sid
  419. * @return \Twilio\Rest\Api\V2010\Account\NotificationContext
  420. */
  421. protected function contextNotifications($sid) {
  422. return $this->api->v2010->account->notifications($sid);
  423. }
  424. /**
  425. * @return \Twilio\Rest\Api\V2010\Account\OutgoingCallerIdList
  426. */
  427. protected function getOutgoingCallerIds() {
  428. return $this->api->v2010->account->outgoingCallerIds;
  429. }
  430. /**
  431. * @param string $sid Fetch by unique outgoing-caller-id Sid
  432. * @return \Twilio\Rest\Api\V2010\Account\OutgoingCallerIdContext
  433. */
  434. protected function contextOutgoingCallerIds($sid) {
  435. return $this->api->v2010->account->outgoingCallerIds($sid);
  436. }
  437. /**
  438. * @return \Twilio\Rest\Api\V2010\Account\QueueList
  439. */
  440. protected function getQueues() {
  441. return $this->api->v2010->account->queues;
  442. }
  443. /**
  444. * @param string $sid Fetch by unique queue Sid
  445. * @return \Twilio\Rest\Api\V2010\Account\QueueContext
  446. */
  447. protected function contextQueues($sid) {
  448. return $this->api->v2010->account->queues($sid);
  449. }
  450. /**
  451. * @return \Twilio\Rest\Api\V2010\Account\RecordingList
  452. */
  453. protected function getRecordings() {
  454. return $this->api->v2010->account->recordings;
  455. }
  456. /**
  457. * @param string $sid Fetch by unique recording Sid
  458. * @return \Twilio\Rest\Api\V2010\Account\RecordingContext
  459. */
  460. protected function contextRecordings($sid) {
  461. return $this->api->v2010->account->recordings($sid);
  462. }
  463. /**
  464. * @return \Twilio\Rest\Api\V2010\Account\SigningKeyList
  465. */
  466. protected function getSigningKeys() {
  467. return $this->api->v2010->account->signingKeys;
  468. }
  469. /**
  470. * @param string $sid The sid
  471. * @return \Twilio\Rest\Api\V2010\Account\SigningKeyContext
  472. */
  473. protected function contextSigningKeys($sid) {
  474. return $this->api->v2010->account->signingKeys($sid);
  475. }
  476. /**
  477. * @return \Twilio\Rest\Api\V2010\Account\SipList
  478. */
  479. protected function getSip() {
  480. return $this->api->v2010->account->sip;
  481. }
  482. /**
  483. * @return \Twilio\Rest\Api\V2010\Account\ShortCodeList
  484. */
  485. protected function getShortCodes() {
  486. return $this->api->v2010->account->shortCodes;
  487. }
  488. /**
  489. * @param string $sid Fetch by unique short-code Sid
  490. * @return \Twilio\Rest\Api\V2010\Account\ShortCodeContext
  491. */
  492. protected function contextShortCodes($sid) {
  493. return $this->api->v2010->account->shortCodes($sid);
  494. }
  495. /**
  496. * @return \Twilio\Rest\Api\V2010\Account\TokenList
  497. */
  498. protected function getTokens() {
  499. return $this->api->v2010->account->tokens;
  500. }
  501. /**
  502. * @return \Twilio\Rest\Api\V2010\Account\TranscriptionList
  503. */
  504. protected function getTranscriptions() {
  505. return $this->api->v2010->account->transcriptions;
  506. }
  507. /**
  508. * @param string $sid Fetch by unique transcription SID
  509. * @return \Twilio\Rest\Api\V2010\Account\TranscriptionContext
  510. */
  511. protected function contextTranscriptions($sid) {
  512. return $this->api->v2010->account->transcriptions($sid);
  513. }
  514. /**
  515. * @return \Twilio\Rest\Api\V2010\Account\UsageList
  516. */
  517. protected function getUsage() {
  518. return $this->api->v2010->account->usage;
  519. }
  520. /**
  521. * @return \Twilio\Rest\Api\V2010\Account\ValidationRequestList
  522. */
  523. protected function getValidationRequests() {
  524. return $this->api->v2010->account->validationRequests;
  525. }
  526. /**
  527. * Access the Chat Twilio Domain
  528. *
  529. * @return \Twilio\Rest\Chat Chat Twilio Domain
  530. */
  531. protected function getChat() {
  532. if (!$this->_chat) {
  533. $this->_chat = new Chat($this);
  534. }
  535. return $this->_chat;
  536. }
  537. /**
  538. * Access the Fax Twilio Domain
  539. *
  540. * @return \Twilio\Rest\Fax Fax Twilio Domain
  541. */
  542. protected function getFax() {
  543. if (!$this->_fax) {
  544. $this->_fax = new Fax($this);
  545. }
  546. return $this->_fax;
  547. }
  548. /**
  549. * Access the IpMessaging Twilio Domain
  550. *
  551. * @return \Twilio\Rest\IpMessaging IpMessaging Twilio Domain
  552. */
  553. protected function getIpMessaging() {
  554. if (!$this->_ipMessaging) {
  555. $this->_ipMessaging = new IpMessaging($this);
  556. }
  557. return $this->_ipMessaging;
  558. }
  559. /**
  560. * Access the Lookups Twilio Domain
  561. *
  562. * @return \Twilio\Rest\Lookups Lookups Twilio Domain
  563. */
  564. protected function getLookups() {
  565. if (!$this->_lookups) {
  566. $this->_lookups = new Lookups($this);
  567. }
  568. return $this->_lookups;
  569. }
  570. /**
  571. * Access the Monitor Twilio Domain
  572. *
  573. * @return \Twilio\Rest\Monitor Monitor Twilio Domain
  574. */
  575. protected function getMonitor() {
  576. if (!$this->_monitor) {
  577. $this->_monitor = new Monitor($this);
  578. }
  579. return $this->_monitor;
  580. }
  581. /**
  582. * Access the Notify Twilio Domain
  583. *
  584. * @return \Twilio\Rest\Notify Notify Twilio Domain
  585. */
  586. protected function getNotify() {
  587. if (!$this->_notify) {
  588. $this->_notify = new Notify($this);
  589. }
  590. return $this->_notify;
  591. }
  592. /**
  593. * Access the Preview Twilio Domain
  594. *
  595. * @return \Twilio\Rest\Preview Preview Twilio Domain
  596. */
  597. protected function getPreview() {
  598. if (!$this->_preview) {
  599. $this->_preview = new Preview($this);
  600. }
  601. return $this->_preview;
  602. }
  603. /**
  604. * Access the Pricing Twilio Domain
  605. *
  606. * @return \Twilio\Rest\Pricing Pricing Twilio Domain
  607. */
  608. protected function getPricing() {
  609. if (!$this->_pricing) {
  610. $this->_pricing = new Pricing($this);
  611. }
  612. return $this->_pricing;
  613. }
  614. /**
  615. * Access the Proxy Twilio Domain
  616. *
  617. * @return \Twilio\Rest\Proxy Proxy Twilio Domain
  618. */
  619. protected function getProxy() {
  620. if (!$this->_proxy) {
  621. $this->_proxy = new Proxy($this);
  622. }
  623. return $this->_proxy;
  624. }
  625. /**
  626. * Access the Taskrouter Twilio Domain
  627. *
  628. * @return \Twilio\Rest\Taskrouter Taskrouter Twilio Domain
  629. */
  630. protected function getTaskrouter() {
  631. if (!$this->_taskrouter) {
  632. $this->_taskrouter = new Taskrouter($this);
  633. }
  634. return $this->_taskrouter;
  635. }
  636. /**
  637. * Access the Trunking Twilio Domain
  638. *
  639. * @return \Twilio\Rest\Trunking Trunking Twilio Domain
  640. */
  641. protected function getTrunking() {
  642. if (!$this->_trunking) {
  643. $this->_trunking = new Trunking($this);
  644. }
  645. return $this->_trunking;
  646. }
  647. /**
  648. * Access the Video Twilio Domain
  649. *
  650. * @return \Twilio\Rest\Video Video Twilio Domain
  651. */
  652. protected function getVideo() {
  653. if (!$this->_video) {
  654. $this->_video = new Video($this);
  655. }
  656. return $this->_video;
  657. }
  658. /**
  659. * Access the Messaging Twilio Domain
  660. *
  661. * @return \Twilio\Rest\Messaging Messaging Twilio Domain
  662. */
  663. protected function getMessaging() {
  664. if (!$this->_messaging) {
  665. $this->_messaging = new Messaging($this);
  666. }
  667. return $this->_messaging;
  668. }
  669. /**
  670. * Access the Wireless Twilio Domain
  671. *
  672. * @return \Twilio\Rest\Wireless Wireless Twilio Domain
  673. */
  674. protected function getWireless() {
  675. if (!$this->_wireless) {
  676. $this->_wireless = new Wireless($this);
  677. }
  678. return $this->_wireless;
  679. }
  680. /**
  681. * Access the Sync Twilio Domain
  682. *
  683. * @return \Twilio\Rest\Sync Sync Twilio Domain
  684. */
  685. protected function getSync() {
  686. if (!$this->_sync) {
  687. $this->_sync = new Sync($this);
  688. }
  689. return $this->_sync;
  690. }
  691. /**
  692. * Access the Studio Twilio Domain
  693. *
  694. * @return \Twilio\Rest\Studio Studio Twilio Domain
  695. */
  696. protected function getStudio() {
  697. if (!$this->_studio) {
  698. $this->_studio = new Studio($this);
  699. }
  700. return $this->_studio;
  701. }
  702. /**
  703. * Magic getter to lazy load domains
  704. *
  705. * @param string $name Domain to return
  706. * @return \Twilio\Domain The requested domain
  707. * @throws TwilioException For unknown domains
  708. */
  709. public function __get($name) {
  710. $method = 'get' . ucfirst($name);
  711. if (method_exists($this, $method)) {
  712. return $this->$method();
  713. }
  714. throw new TwilioException('Unknown domain ' . $name);
  715. }
  716. /**
  717. * Magic call to lazy load contexts
  718. *
  719. * @param string $name Context to return
  720. * @param mixed[] $arguments Context to return
  721. * @return \Twilio\InstanceContext The requested context
  722. * @throws TwilioException For unknown contexts
  723. */
  724. public function __call($name, $arguments) {
  725. $method = 'context' . ucfirst($name);
  726. if (method_exists($this, $method)) {
  727. return call_user_func_array(array($this, $method), $arguments);
  728. }
  729. throw new TwilioException('Unknown context ' . $name);
  730. }
  731. /**
  732. * Provide a friendly representation
  733. *
  734. * @return string Machine friendly representation
  735. */
  736. public function __toString() {
  737. return '[Client ' . $this->getAccountSid() . ']';
  738. }
  739. /**
  740. * Validates connection to new SSL certificate endpoint
  741. *
  742. * @param CurlClient $client
  743. * @throws TwilioException if request fails
  744. */
  745. public function validateSslCertificate($client) {
  746. $response = $client->request('GET', 'https://api.twilio.com:8443');
  747. if ($response->getStatusCode() < 200 || $response->getStatusCode() > 300) {
  748. throw new TwilioException("Failed to validate SSL certificate");
  749. }
  750. }
  751. }