IncomingPhoneNumbers.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * For more information, see the
  4. * `IncomingPhoneNumbers API Resource
  5. * <http://www.twilio.com/docs/api/rest/incoming-phone-numbers#local>`_
  6. * documentation at twilio.com.
  7. */
  8. class Services_Twilio_Rest_IncomingPhoneNumbers extends Services_Twilio_ListResource {
  9. function init($client, $uri) {
  10. $this->setupSubresources(
  11. 'local',
  12. 'toll_free',
  13. 'mobile'
  14. );
  15. }
  16. function create(array $params = array()) {
  17. return parent::_create($params);
  18. }
  19. function getList($type, array $params = array())
  20. {
  21. return $this->client->retrieveData($this->uri . "/$type", $params);
  22. }
  23. /**
  24. * Return a phone number instance from its E.164 representation. If more
  25. * than one number matches the search string, returns the first one.
  26. *
  27. * Example usage:
  28. *
  29. * .. code-block:: php
  30. *
  31. * $number = $client->account->incoming_phone_numbers->getNumber('+14105551234');
  32. * echo $number->sid;
  33. *
  34. * :param string $number: The number in E.164 format, eg "+684105551234"
  35. * :return: A :php:class:`Services_Twilio_Rest_IncomingPhoneNumber` object, or null
  36. * :raises: a A :php:class:`Services_Twilio_RestException` if the number is
  37. * invalid, not provided in E.164 format or for any other API exception.
  38. */
  39. public function getNumber($number) {
  40. $page = $this->getPage(0, 1, array(
  41. 'PhoneNumber' => $number
  42. ));
  43. $items = $page->getItems();
  44. if (is_null($items) || empty($items)) {
  45. return null;
  46. }
  47. return $items[0];
  48. }
  49. }
  50. class Services_Twilio_Rest_Local extends Services_Twilio_NumberType { }
  51. class Services_Twilio_Rest_Mobile extends Services_Twilio_NumberType { }
  52. class Services_Twilio_Rest_TollFree extends Services_Twilio_NumberType { }