All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bandwidth.phonenumberlookup.controllers.APIController Maven / Gradle / Ivy

Go to download

The official client SDK for Bandwidth's Voice, Messaging, MFA, and WebRTC APIs

There is a newer version: 12.0.1
Show newest version
/*
 * BandwidthLib
 *
 * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
 */

package com.bandwidth.phonenumberlookup.controllers;

import com.bandwidth.ApiHelper;
import com.bandwidth.AuthManager;
import com.bandwidth.Configuration;
import com.bandwidth.Server;
import com.bandwidth.controllers.BaseController;
import com.bandwidth.exceptions.ApiException;
import com.bandwidth.http.Headers;
import com.bandwidth.http.client.HttpCallback;
import com.bandwidth.http.client.HttpClient;
import com.bandwidth.http.client.HttpContext;
import com.bandwidth.http.request.HttpRequest;
import com.bandwidth.http.response.ApiResponse;
import com.bandwidth.http.response.HttpResponse;
import com.bandwidth.http.response.HttpStringResponse;
import com.bandwidth.phonenumberlookup.exceptions.AccountsTnlookup400ErrorException;
import com.bandwidth.phonenumberlookup.models.OrderRequest;
import com.bandwidth.phonenumberlookup.models.OrderResponse;
import com.bandwidth.phonenumberlookup.models.OrderStatus;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.io.IOException;
import java.util.AbstractMap.SimpleEntry;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

/**
 * This class lists all the endpoints of the groups.
 */
public final class APIController extends BaseController {

    /**
     * Initializes the controller.
     * @param config    Configurations added in client.
     * @param httpClient    Send HTTP requests and read the responses.
     * @param authManagers    Apply authorization to requests.
     */
    public APIController(Configuration config, HttpClient httpClient,
            Map authManagers) {
        super(config, httpClient, authManagers);
    }

    /**
     * Initializes the controller with HTTPCallback.
     * @param config    Configurations added in client.
     * @param httpClient    Send HTTP requests and read the responses.
     * @param authManagers    Apply authorization to requests.
     * @param httpCallback    Callback to be called before and after the HTTP call.
     */
    public APIController(Configuration config, HttpClient httpClient,
            Map authManagers, HttpCallback httpCallback) {
        super(config, httpClient, authManagers, httpCallback);
    }

    /**
     * Create a TN Lookup Order.
     * @param  accountId  Required parameter: The ID of the Bandwidth account that the user belongs
     *         to.
     * @param  body  Required parameter: Example:
     * @return    Returns the OrderResponse wrapped in ApiResponse response from the API call
     * @throws    ApiException    Represents error response from the server.
     * @throws    IOException    Signals that an I/O exception of some sort has occurred.
     */
    public ApiResponse createLookupRequest(
            final String accountId,
            final OrderRequest body) throws ApiException, IOException {
        HttpRequest request = buildCreateLookupRequestRequest(accountId, body);
        authManagers.get("phoneNumberLookup").apply(request);

        HttpResponse response = getClientInstance().execute(request, false);
        HttpContext context = new HttpContext(request, response);

        return handleCreateLookupRequestResponse(context);
    }

    /**
     * Create a TN Lookup Order.
     * @param  accountId  Required parameter: The ID of the Bandwidth account that the user belongs
     *         to.
     * @param  body  Required parameter: Example:
     * @return    Returns the OrderResponse wrapped in ApiResponse response from the API call
     */
    public CompletableFuture> createLookupRequestAsync(
            final String accountId,
            final OrderRequest body) {
        return makeHttpCallAsync(() -> buildCreateLookupRequestRequest(accountId, body),
            req -> authManagers.get("phoneNumberLookup").applyAsync(req)
                .thenCompose(request -> getClientInstance()
                        .executeAsync(request, false)),
            context -> handleCreateLookupRequestResponse(context));
    }

    /**
     * Builds the HttpRequest object for createLookupRequest.
     */
    private HttpRequest buildCreateLookupRequestRequest(
            final String accountId,
            final OrderRequest body) throws JsonProcessingException {
        //the base uri for api requests
        String baseUri = config.getBaseUri(Server.PHONENUMBERLOOKUPDEFAULT);

        //prepare query string for API call
        final StringBuilder queryBuilder = new StringBuilder(baseUri
                + "/accounts/{accountId}/tnlookup");

        //process template parameters
        Map> templateParameters = new HashMap<>();
        templateParameters.put("accountId",
                new SimpleEntry(accountId, false));
        ApiHelper.appendUrlWithTemplateParameters(queryBuilder, templateParameters);

        //load all headers for the outgoing API request
        Headers headers = new Headers();
        headers.add("user-agent", BaseController.userAgent);
        headers.add("accept", "application/json");
        headers.add("content-type", "application/json");

        //prepare and invoke the API call request to fetch the response
        String bodyJson = ApiHelper.serialize(body);
        HttpRequest request = getClientInstance().postBody(queryBuilder, headers, null, bodyJson);

        // Invoke the callback before request if its not null
        if (getHttpCallback() != null) {
            getHttpCallback().onBeforeRequest(request);
        }

        return request;
    }

    /**
     * Processes the response for createLookupRequest.
     * @return An object of type OrderResponse
     */
    private ApiResponse handleCreateLookupRequestResponse(
            HttpContext context) throws ApiException, IOException {
        HttpResponse response = context.getResponse();

        //invoke the callback after response if its not null
        if (getHttpCallback() != null) {
            getHttpCallback().onAfterResponse(context);
        }

        //Error handling using HTTP status codes
        int responseCode = response.getStatusCode();

        if (responseCode == 400) {
            throw new AccountsTnlookup400ErrorException("Bad Request. Ensure that your request payload is properly formatted and that the telephone numbers used are valid.", context);
        }
        if (responseCode == 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.", context);
        }
        if (responseCode == 415) {
            throw new ApiException("Invalid content-type. Ensure that your content-type header is set to application/json.", context);
        }
        if (responseCode == 429) {
            throw new ApiException("Too Many Requests. Reduce the amount of requests that you are sending in order to avoid receiving this status code.", context);
        }
        if (responseCode == 500) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 501) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 502) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 503) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 504) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 505) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 506) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 507) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 508) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 509) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 510) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 511) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 512) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 513) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 514) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 515) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 516) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 517) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 518) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 519) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 520) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 521) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 522) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 523) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 524) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 525) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 526) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 527) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 528) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 529) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 530) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 531) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 532) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 533) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 534) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 535) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 536) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 537) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 538) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 539) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 540) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 541) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 542) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 543) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 544) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 545) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 546) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 547) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 548) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 549) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 550) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 551) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 552) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 553) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 554) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 555) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 556) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 557) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 558) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 559) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 560) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 561) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 562) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 563) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 564) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 565) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 566) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 567) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 568) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 569) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 570) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 571) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 572) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 573) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 574) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 575) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 576) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 577) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 578) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 579) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 580) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 581) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 582) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 583) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 584) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 585) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 586) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 587) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 588) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 589) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 590) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 591) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 592) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 593) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 594) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 595) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 596) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 597) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 598) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 599) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        //handle errors defined at the API level
        validateResponse(response, context);

        //extract result from the http response
        String responseBody = ((HttpStringResponse) response).getBody();
        OrderResponse result = ApiHelper.deserialize(responseBody,
                OrderResponse.class);

        return new ApiResponse(response.getStatusCode(), response.getHeaders(), result);
    }

    /**
     * Query an existing TN Lookup Order.
     * @param  accountId  Required parameter: The ID of the Bandwidth account that the user belongs
     *         to.
     * @param  requestId  Required parameter: Example:
     * @return    Returns the OrderStatus wrapped in ApiResponse response from the API call
     * @throws    ApiException    Represents error response from the server.
     * @throws    IOException    Signals that an I/O exception of some sort has occurred.
     */
    public ApiResponse getLookupRequestStatus(
            final String accountId,
            final String requestId) throws ApiException, IOException {
        HttpRequest request = buildGetLookupRequestStatusRequest(accountId, requestId);
        authManagers.get("phoneNumberLookup").apply(request);

        HttpResponse response = getClientInstance().execute(request, false);
        HttpContext context = new HttpContext(request, response);

        return handleGetLookupRequestStatusResponse(context);
    }

    /**
     * Query an existing TN Lookup Order.
     * @param  accountId  Required parameter: The ID of the Bandwidth account that the user belongs
     *         to.
     * @param  requestId  Required parameter: Example:
     * @return    Returns the OrderStatus wrapped in ApiResponse response from the API call
     */
    public CompletableFuture> getLookupRequestStatusAsync(
            final String accountId,
            final String requestId) {
        return makeHttpCallAsync(() -> buildGetLookupRequestStatusRequest(accountId, requestId),
            req -> authManagers.get("phoneNumberLookup").applyAsync(req)
                .thenCompose(request -> getClientInstance()
                        .executeAsync(request, false)),
            context -> handleGetLookupRequestStatusResponse(context));
    }

    /**
     * Builds the HttpRequest object for getLookupRequestStatus.
     */
    private HttpRequest buildGetLookupRequestStatusRequest(
            final String accountId,
            final String requestId) {
        //the base uri for api requests
        String baseUri = config.getBaseUri(Server.PHONENUMBERLOOKUPDEFAULT);

        //prepare query string for API call
        final StringBuilder queryBuilder = new StringBuilder(baseUri
                + "/accounts/{accountId}/tnlookup/{requestId}");

        //process template parameters
        Map> templateParameters = new HashMap<>();
        templateParameters.put("accountId",
                new SimpleEntry(accountId, false));
        templateParameters.put("requestId",
                new SimpleEntry(requestId, false));
        ApiHelper.appendUrlWithTemplateParameters(queryBuilder, templateParameters);

        //load all headers for the outgoing API request
        Headers headers = new Headers();
        headers.add("user-agent", BaseController.userAgent);
        headers.add("accept", "application/json");

        //prepare and invoke the API call request to fetch the response
        HttpRequest request = getClientInstance().get(queryBuilder, headers, null, null);

        // Invoke the callback before request if its not null
        if (getHttpCallback() != null) {
            getHttpCallback().onBeforeRequest(request);
        }

        return request;
    }

    /**
     * Processes the response for getLookupRequestStatus.
     * @return An object of type OrderStatus
     */
    private ApiResponse handleGetLookupRequestStatusResponse(
            HttpContext context) throws ApiException, IOException {
        HttpResponse response = context.getResponse();

        //invoke the callback after response if its not null
        if (getHttpCallback() != null) {
            getHttpCallback().onAfterResponse(context);
        }

        //Error handling using HTTP status codes
        int responseCode = response.getStatusCode();

        if (responseCode == 400) {
            throw new ApiException("Bad Request. Ensure that you have set the requestId as a URL path parameter.", context);
        }
        if (responseCode == 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.", context);
        }
        if (responseCode == 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.", context);
        }
        if (responseCode == 429) {
            throw new ApiException("Too Many Requests. Reduce the amount of requests that you are sending in order to avoid receiving this status code.", context);
        }
        if (responseCode == 500) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 501) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 502) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 503) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 504) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 505) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 506) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 507) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 508) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 509) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 510) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 511) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 512) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 513) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 514) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 515) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 516) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 517) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 518) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 519) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 520) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 521) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 522) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 523) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 524) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 525) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 526) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 527) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 528) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 529) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 530) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 531) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 532) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 533) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 534) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 535) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 536) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 537) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 538) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 539) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 540) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 541) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 542) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 543) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 544) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 545) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 546) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 547) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 548) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 549) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 550) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 551) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 552) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 553) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 554) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 555) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 556) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 557) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 558) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 559) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 560) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 561) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 562) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 563) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 564) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 565) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 566) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 567) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 568) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 569) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 570) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 571) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 572) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 573) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 574) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 575) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 576) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 577) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 578) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 579) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 580) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 581) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 582) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 583) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 584) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 585) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 586) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 587) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 588) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 589) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 590) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 591) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 592) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 593) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 594) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 595) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 596) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 597) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 598) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        if (responseCode == 599) {
            throw new ApiException("Unexpected error. Please contact Bandwidth Support if your requests are receiving this status code for an extended period of time.", context);
        }
        //handle errors defined at the API level
        validateResponse(response, context);

        //extract result from the http response
        String responseBody = ((HttpStringResponse) response).getBody();
        OrderStatus result = ApiHelper.deserialize(responseBody,
                OrderStatus.class);

        return new ApiResponse(response.getStatusCode(), response.getHeaders(), result);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy