diff --git a/src/BandwidthClient.php b/src/BandwidthClient.php index 8aad560..e350c32 100644 --- a/src/BandwidthClient.php +++ b/src/BandwidthClient.php @@ -22,6 +22,7 @@ public function __construct($config) private $messaging; private $twoFactorAuth; + private $phoneNumberLookup; private $voice; private $webRtc; @@ -49,6 +50,18 @@ public function getTwoFactorAuth() return $this->twoFactorAuth; } + /** + * Provides access to PhoneNumberLookup client + * @return PhoneNumberLookup\PhoneNumberLookupClient + */ + public function getPhoneNumberLookup() + { + if ($this->phoneNumberLookup == null) { + $this->phoneNumberLookup = new PhoneNumberLookup\PhoneNumberLookupClient($this->config); + } + return $this->phoneNumberLookup; + } + /** * Provides access to Voice client * @return Voice\VoiceClient diff --git a/src/Configuration.php b/src/Configuration.php index 7094a77..267b8ad 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -43,6 +43,18 @@ class Configuration */ private $twoFactorAuthBasicAuthPassword = 'TODO: Replace'; + /** + * The username to use with basic authentication + * @var string + */ + private $phoneNumberLookupBasicAuthUserName = 'TODO: Replace'; + + /** + * The password to use with basic authentication + * @var string + */ + private $phoneNumberLookupBasicAuthPassword = 'TODO: Replace'; + /** * The username to use with basic authentication * @var string @@ -96,6 +108,12 @@ public function __construct($configOptions = null) if (isset($configOptions['twoFactorAuthBasicAuthPassword'])) { $this->twoFactorAuthBasicAuthPassword = $configOptions['twoFactorAuthBasicAuthPassword']; } + if (isset($configOptions['phoneNumberLookupBasicAuthUserName'])) { + $this->phoneNumberLookupBasicAuthUserName = $configOptions['phoneNumberLookupBasicAuthUserName']; + } + if (isset($configOptions['phoneNumberLookupBasicAuthPassword'])) { + $this->phoneNumberLookupBasicAuthPassword = $configOptions['phoneNumberLookupBasicAuthPassword']; + } if (isset($configOptions['voiceBasicAuthUserName'])) { $this->voiceBasicAuthUserName = $configOptions['voiceBasicAuthUserName']; } @@ -135,6 +153,12 @@ public function getConfigurationMap() if (isset($this->twoFactorAuthBasicAuthPassword)) { $configMap['twoFactorAuthBasicAuthPassword'] = $this->twoFactorAuthBasicAuthPassword; } + if (isset($this->phoneNumberLookupBasicAuthUserName)) { + $configMap['phoneNumberLookupBasicAuthUserName'] = $this->phoneNumberLookupBasicAuthUserName; + } + if (isset($this->phoneNumberLookupBasicAuthPassword)) { + $configMap['phoneNumberLookupBasicAuthPassword'] = $this->phoneNumberLookupBasicAuthPassword; + } if (isset($this->voiceBasicAuthUserName)) { $configMap['voiceBasicAuthUserName'] = $this->voiceBasicAuthUserName; } @@ -187,6 +211,18 @@ public function getTwoFactorAuthBasicAuthPassword() return $this->twoFactorAuthBasicAuthPassword; } + // Getter for phoneNumberLookupBasicAuthUserName + public function getPhoneNumberLookupBasicAuthUserName() + { + return $this->phoneNumberLookupBasicAuthUserName; + } + + // Getter for phoneNumberLookupBasicAuthPassword + public function getPhoneNumberLookupBasicAuthPassword() + { + return $this->phoneNumberLookupBasicAuthPassword; + } + // Getter for voiceBasicAuthUserName public function getVoiceBasicAuthUserName() { @@ -248,6 +284,7 @@ public function getBaseUri($server = Servers::DEFAULT_) Servers::DEFAULT_ => 'api.bandwidth.com', Servers::MESSAGINGDEFAULT => 'https://messaging.bandwidth.com/api/v2', Servers::TWOFACTORAUTHDEFAULT => 'https://mfa.bandwidth.com/api/v1', + Servers::PHONENUMBERLOOKUPDEFAULT => 'https://numbers.bandwidth.com/api/v1', Servers::VOICEDEFAULT => 'https://voice.bandwidth.com', Servers::WEBRTCDEFAULT => 'https://api.webrtc.bandwidth.com/v1', ), @@ -255,6 +292,7 @@ public function getBaseUri($server = Servers::DEFAULT_) Servers::DEFAULT_ => '{base_url}', Servers::MESSAGINGDEFAULT => '{base_url}', Servers::TWOFACTORAUTHDEFAULT => '{base_url}', + Servers::PHONENUMBERLOOKUPDEFAULT => '{base_url}', Servers::VOICEDEFAULT => '{base_url}', Servers::WEBRTCDEFAULT => '{base_url}', ), diff --git a/src/PhoneNumberLookup/Controllers/APIController.php b/src/PhoneNumberLookup/Controllers/APIController.php new file mode 100644 index 0000000..bc4d90d --- /dev/null +++ b/src/PhoneNumberLookup/Controllers/APIController.php @@ -0,0 +1,1829 @@ + $accountId, + )); + + //validate and preprocess url + $_queryUrl = APIHelper::cleanUrl($this->config->getBaseUri(Servers::PHONENUMBERLOOKUPDEFAULT) . $_queryBuilder); + + //prepare headers + $_headers = array ( + 'user-agent' => BaseController::USER_AGENT, + 'Accept' => 'application/json', + 'content-type' => 'application/json; charset=utf-8' + ); + + //json encode body + $_bodyJson = Request\Body::Json($body); + + //set HTTP basic auth parameters + Request::auth($this->config->getPhoneNumberLookupBasicAuthUserName(), $this->config->getPhoneNumberLookupBasicAuthPassword()); + + $_httpRequest = new HttpRequest(HttpMethod::POST, $_headers, $_queryUrl); + + //call on-before Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + // Set request timeout + Request::timeout($this->config->getTimeout()); + + // and invoke the API call request to fetch the response + $response = Request::post($_queryUrl, $_headers, $_bodyJson); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //Error handling using HTTP status codes + if ($response->code == 400) { + throw new Exceptions\AccountsTnlookup400ErrorException( + 'Bad Request. Ensure that your request payload is properly formatted and that the telephone numbers ' . + 'used are valid.', + $_httpContext + ); + } + + if ($response->code == 401) { + throw new APIException( + 'Unauthorized. Ensure that you are using the proper credentials for the environment you are ' . + 'accessing, your user has the proper role assigned to it, and that your Bandwidth account is' . + 'enabled for TN Lookup access.', + $_httpContext + ); + } + + if ($response->code == 415) { + throw new APIException( + 'Invalid content-type. Ensure that your content-type header is set to application/json.', + $_httpContext + ); + } + + if ($response->code == 429) { + throw new APIException( + 'Too Many Requests. Reduce the amount of requests that you are sending in order to avoid receiving ' . + 'this status code.', + $_httpContext + ); + } + + if ($response->code == 500) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 501) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 502) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 503) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 504) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 505) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 506) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 507) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 508) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 509) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 510) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 511) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 512) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 513) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 514) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 515) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 516) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 517) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 518) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 519) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 520) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 521) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 522) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 523) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 524) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 525) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 526) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 527) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 528) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 529) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 530) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 531) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 532) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 533) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 534) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 535) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 536) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 537) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 538) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 539) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 540) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 541) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 542) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 543) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 544) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 545) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 546) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 547) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 548) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 549) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 550) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 551) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 552) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 553) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 554) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 555) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 556) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 557) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 558) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 559) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 560) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 561) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 562) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 563) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 564) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 565) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 566) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 567) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 568) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 569) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 570) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 571) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 572) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 573) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 574) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 575) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 576) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 577) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 578) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 579) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 580) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 581) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 582) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 583) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 584) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 585) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 586) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 587) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 588) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 589) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 590) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 591) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 592) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 593) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 594) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 595) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 596) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 597) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 598) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 599) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + $mapper = $this->getJsonMapper(); + $deserializedResponse = $mapper->mapClass( + $response->body, + 'BandwidthLib\\PhoneNumberLookup\\Models\\OrderResponse' + ); + return new ApiResponse($response->code, $response->headers, $deserializedResponse); + } + + /** + * Query an existing TN Lookup Order + * + * @param string $accountId The ID of the Bandwidth account that the user belongs to. + * @param string $requestId TODO: type description here + * @return ApiResponse response from the API call + * @throws APIException Thrown if API call fails + */ + public function getLookupRequestStatus( + $accountId, + $requestId + ) { + + //prepare query string for API call + $_queryBuilder = '/accounts/{accountId}/tnlookup/{requestId}'; + + //process optional query parameters + $_queryBuilder = APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array ( + 'accountId' => $accountId, + 'requestId' => $requestId, + )); + + //validate and preprocess url + $_queryUrl = APIHelper::cleanUrl($this->config->getBaseUri(Servers::PHONENUMBERLOOKUPDEFAULT) . $_queryBuilder); + + //prepare headers + $_headers = array ( + 'user-agent' => BaseController::USER_AGENT, + 'Accept' => 'application/json' + ); + + //set HTTP basic auth parameters + Request::auth($this->config->getPhoneNumberLookupBasicAuthUserName(), $this->config->getPhoneNumberLookupBasicAuthPassword()); + + $_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl); + + //call on-before Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + // Set request timeout + Request::timeout($this->config->getTimeout()); + + // and invoke the API call request to fetch the response + $response = Request::get($_queryUrl, $_headers); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //Error handling using HTTP status codes + if ($response->code == 400) { + throw new APIException( + 'Bad Request. Ensure that you have set the requestId as a URL path parameter.', + $_httpContext + ); + } + + if ($response->code == 401) { + throw new APIException( + 'Unauthorized. Ensure that you are using the proper credentials for the environment you are ' . + 'accessing, your user has the proper role assigned to it, and that your Bandwidth account is' . + 'enabled for TN Lookup access.', + $_httpContext + ); + } + + if ($response->code == 404) { + throw new APIException( + 'RequestId not found. Ensure that the requestId used in the URL path is valid and maps to a ' . + 'previous request that was submitted.', + $_httpContext + ); + } + + if ($response->code == 429) { + throw new APIException( + 'Too Many Requests. Reduce the amount of requests that you are sending in order to avoid receiving ' . + 'this status code.', + $_httpContext + ); + } + + if ($response->code == 500) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 501) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 502) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 503) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 504) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 505) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 506) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 507) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 508) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 509) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 510) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 511) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 512) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 513) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 514) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 515) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 516) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 517) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 518) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 519) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 520) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 521) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 522) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 523) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 524) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 525) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 526) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 527) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 528) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 529) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 530) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 531) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 532) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 533) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 534) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 535) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 536) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 537) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 538) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 539) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 540) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 541) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 542) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 543) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 544) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 545) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 546) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 547) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 548) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 549) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 550) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 551) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 552) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 553) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 554) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 555) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 556) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 557) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 558) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 559) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 560) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 561) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 562) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 563) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 564) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 565) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 566) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 567) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 568) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 569) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 570) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 571) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 572) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 573) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 574) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 575) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 576) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 577) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 578) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 579) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 580) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 581) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 582) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 583) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 584) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 585) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 586) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 587) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 588) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 589) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 590) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 591) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 592) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 593) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 594) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 595) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 596) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 597) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 598) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + if ($response->code == 599) { + throw new APIException( + 'Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code ' . + 'for an extended period of time.', + $_httpContext + ); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + $mapper = $this->getJsonMapper(); + $deserializedResponse = $mapper->mapClass( + $response->body, + 'BandwidthLib\\PhoneNumberLookup\\Models\\OrderStatus' + ); + return new ApiResponse($response->code, $response->headers, $deserializedResponse); + } +} diff --git a/src/PhoneNumberLookup/Exceptions/AccountsTnlookup400ErrorException.php b/src/PhoneNumberLookup/Exceptions/AccountsTnlookup400ErrorException.php new file mode 100644 index 0000000..d1e5ba8 --- /dev/null +++ b/src/PhoneNumberLookup/Exceptions/AccountsTnlookup400ErrorException.php @@ -0,0 +1,38 @@ +tns = func_get_arg(0); + } + } + + /** + * Encode this object to JSON + */ + public function jsonSerialize() + { + $json = array(); + $json['tns'] = isset($this->tns) ? + array_values($this->tns) : null; + + return array_filter($json); + } +} diff --git a/src/PhoneNumberLookup/Models/OrderResponse.php b/src/PhoneNumberLookup/Models/OrderResponse.php new file mode 100644 index 0000000..7735ac6 --- /dev/null +++ b/src/PhoneNumberLookup/Models/OrderResponse.php @@ -0,0 +1,50 @@ +requestId = func_get_arg(0); + $this->status = func_get_arg(1); + } + } + + /** + * Encode this object to JSON + */ + public function jsonSerialize() + { + $json = array(); + $json['requestId'] = $this->requestId; + $json['status'] = $this->status; + + return array_filter($json); + } +} diff --git a/src/PhoneNumberLookup/Models/OrderStatus.php b/src/PhoneNumberLookup/Models/OrderStatus.php new file mode 100644 index 0000000..8e6bc8b --- /dev/null +++ b/src/PhoneNumberLookup/Models/OrderStatus.php @@ -0,0 +1,71 @@ +requestId = func_get_arg(0); + $this->status = func_get_arg(1); + $this->failedTelephoneNumbers = func_get_arg(2); + $this->result = func_get_arg(3); + } + } + + /** + * Encode this object to JSON + */ + public function jsonSerialize() + { + $json = array(); + $json['requestId'] = $this->requestId; + $json['status'] = $this->status; + $json['failedTelephoneNumbers'] = + isset($this->failedTelephoneNumbers) ? + array_values($this->failedTelephoneNumbers) : null; + $json['result'] = isset($this->result) ? + array_values($this->result) : null; + + return array_filter($json); + } +} diff --git a/src/PhoneNumberLookup/Models/Result.php b/src/PhoneNumberLookup/Models/Result.php new file mode 100644 index 0000000..43c1f9e --- /dev/null +++ b/src/PhoneNumberLookup/Models/Result.php @@ -0,0 +1,114 @@ +responseCode = func_get_arg(0); + $this->message = func_get_arg(1); + $this->e164Format = func_get_arg(2); + $this->formatted = func_get_arg(3); + $this->country = func_get_arg(4); + $this->lineType = func_get_arg(5); + $this->lineProvider = func_get_arg(6); + $this->mobileCountryCode = func_get_arg(7); + $this->mobileNetworkCode = func_get_arg(8); + } + } + + /** + * Encode this object to JSON + */ + public function jsonSerialize() + { + $json = array(); + $json['Response Code'] = $this->responseCode; + $json['Message'] = $this->message; + $json['E.164 Format'] = $this->e164Format; + $json['Formatted'] = $this->formatted; + $json['Country'] = $this->country; + $json['Line Type'] = $this->lineType; + $json['Line Provider'] = $this->lineProvider; + $json['Mobile Country Code'] = $this->mobileCountryCode; + $json['Mobile Network Code'] = $this->mobileNetworkCode; + + return array_filter($json); + } +} diff --git a/src/PhoneNumberLookup/PhoneNumberLookupClient.php b/src/PhoneNumberLookup/PhoneNumberLookupClient.php new file mode 100644 index 0000000..71c560c --- /dev/null +++ b/src/PhoneNumberLookup/PhoneNumberLookupClient.php @@ -0,0 +1,37 @@ +config = $config; + } + + + private $client; + + /** + * Provides access to API controller + * @return Controllers\APIController + */ + public function getClient() + { + if ($this->client == null) { + $this->client = new Controllers\APIController($this->config); + } + return $this->client; + } +} diff --git a/src/Servers.php b/src/Servers.php index 519ae0f..3ce0453 100644 --- a/src/Servers.php +++ b/src/Servers.php @@ -27,6 +27,11 @@ class Servers */ const TWOFACTORAUTHDEFAULT = "TwoFactorAuthDefault"; + /** + * TODO: Write general description for this element + */ + const PHONENUMBERLOOKUPDEFAULT = "PhoneNumberLookupDefault"; + /** * TODO: Write general description for this element */ diff --git a/src/WebRtc/Models/DeviceApiVersionEnum.php b/src/WebRtc/Models/DeviceApiVersionEnum.php index 3ae64f8..2fa087c 100644 --- a/src/WebRtc/Models/DeviceApiVersionEnum.php +++ b/src/WebRtc/Models/DeviceApiVersionEnum.php @@ -15,10 +15,10 @@ class DeviceApiVersionEnum /** * TODO: Write general description for this element */ - const V3 = "v3"; + const V3 = "V3"; /** * TODO: Write general description for this element */ - const V2 = "v2"; + const V2 = "V2"; } diff --git a/tests/ApiTest.php b/tests/ApiTest.php index fd57197..0f71fe0 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -22,7 +22,9 @@ protected function setUp(): void { 'voiceBasicAuthUserName' => getenv("USERNAME"), 'voiceBasicAuthPassword' => getenv("PASSWORD"), 'twoFactorAuthBasicAuthUserName' => getenv("USERNAME"), - 'twoFactorAuthBasicAuthPassword' => getenv("PASSWORD") + 'twoFactorAuthBasicAuthPassword' => getenv("PASSWORD"), + 'phoneNumberLookupBasicAuthUserName' => getenv("USERNAME"), + 'phoneNumberLookupBasicAuthPassword' => getenv("PASSWORD") ) ); $this->bandwidthClient = new BandwidthLib\BandwidthClient($config); @@ -141,4 +143,15 @@ public function testMfaVerify() { $response = $this->bandwidthClient->getTwoFactorAuth()->getMFA()->createVerifyTwoFactor(getenv("ACCOUNT_ID"), $body); $this->assertTrue(is_bool($response->getResult()->valid)); } + + public function testTnLookup() { + $body = new BandwidthLib\PhoneNumberLookup\Models\OrderRequest(); + $body->tns = [getenv("PHONE_NUMBER_OUTBOUND")]; + $createResponse = $this->bandwidthClient->getPhoneNumberLookup()->getClient()->createLookupRequest(getenv("ACCOUNT_ID"), $body); + $this->assertTrue(strlen($createResponse->getResult()->requestId) > 0); + + $requestId = $createResponse->getResult()->requestId; + $getResponse = $this->bandwidthClient->getPhoneNumberLookup()->getClient()->getLookupRequestStatus(getenv("ACCOUNT_ID"), $requestId); + $this->assertTrue(strlen($getResponse->getResult()->status) > 0); + } }