def purchase(billing, number):
        """Does a PUT request to /tns/{number}.

        Purchases the telephone number indicated by the request URI, with the
        billing method indicated in the body. Allowable billing methods are
        returned in the search results for available telephone numbers.

        Args:
            billing (BillingMethod): The billing method to apply to the
                telephone number being purchased.
            number (string): Telephone number to purchase

        Returns:
            string: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI

        # Prepare query string for API call
        query_builder += "/tns/{number}"

        # Process optional template parameters
        query_builder = APIHelper.append_url_with_template_parameters(
            query_builder, {"number": number})

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "Flowroute SDK 1.0",
            "content-type": "application/json; charset=utf-8",
        }

        # Quick kwargs setting
        body = APIHelper.json_serialize(billing)

        # Prepare and invoke the API call request to fetch the response
        response = CustomAuthUtility.appendCustomAuthParams(
            method='PUT', query_url=query_url, body=body, headers=headers)

        # Error handling using HTTP status codes
        if response.code == 400:
            raise APIException("USER ERROR", 400, response.body)

        elif response.code == 500:
            raise APIException("APPLICATION/SERVER ERROR", 500, response.body)

        elif response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code,
                               response.body)

        return response.body
Beispiel #2
0
    def create_new_route(route_name, mtype, value):
        """Does a PUT request to /routes/{route_name}.

        Create a new inbound route to be used by a phone number

        Args:
            route_name (string): New unique name for the route
            mtype (string): Type of inbound route
            value (string): The value to be associated with a route.

        Returns:
            string: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/routes/{route_name}"

        # Process optional template parameters
        query_builder = APIHelper.append_url_with_template_parameters(query_builder, { 
            "route_name": route_name
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "Flowroute SDK 1.0",
            "content-type": "application/json; charset=utf-8",
        }

        body = '{"type": "%s", "value": "%s"}' % (mtype, value)

        # Prepare and invoke the API call request to fetch the response
        response = CustomAuthUtility.appendCustomAuthParams(method='PUT',
                                                            query_url=query_url,
                                                            body=body,
                                                            headers=headers)

        # Error handling using HTTP status codes
        if response.code == 400:
            raise APIException("USER ERROR", 400, response.body)

        elif response.code == 500:
            raise APIException("APPLICATION/SERVER ERROR", 500, response.body)

        elif response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body)
        
        return response.body
    def list_account_telephone_numbers(limit=None, page=None, pattern=None):
        """Does a GET request to /tns/.

        Retrieves a list of all the phone numbers on your account

        Args:
            limit (int, optional): Number of items to display (max 200)
            page (int, optional): Page to display
            pattern (string, optional): A full or partial telephone number to
                search for

        Returns:
            mixed: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI

        # Prepare query string for API call
        query_builder += "/tns/"

        # Process optional query parameters
        query_parameters = {"limit": limit, "page": page, "pattern": pattern}

        query_builder = APIHelper.append_url_with_query_parameters(
            query_builder, query_parameters)

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "Flowroute SDK 1.0",
            "accept": "application/json",
        }

        # Prepare and invoke the API call request to fetch the response
        response = CustomAuthUtility.appendCustomAuthParams(
            method='GET', query_url=query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code == 400:
            raise APIException("USER ERROR", 400, response.body)

        elif response.code == 500:
            raise APIException("APPLICATION/SERVER ERROR", 500, response.body)

        elif response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code,
                               response.body)

        return response.body
    def list_available_np_as(limit=200):
        """Does a GET request to /available-tns/npas/.

        Retrieves a list of all NPAs (area codes) that contain purchasable
        telephone numbers.

        Args:
            limit (int): Number of items to display (Max 200).

        Returns:
            mixed: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/available-tns/npas/"

        # Process optional query parameters
        query_parameters = {
            "limit": limit
        }

        query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters)

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "Flowroute SDK 1.0",
            "accept": "application/json",
        }

        # Prepare and invoke the API call request to fetch the response
        response = CustomAuthUtility.appendCustomAuthParams(method='GET',
                                                            query_url=query_url,
                                                            headers=headers)

        # Error handling using HTTP status codes
        if response.code == 400:
            raise APIException("USER ERROR", 400, response.body)

        elif response.code == 500:
            raise APIException("APPLICATION/SERVER ERROR", 500, response.body)

        elif response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body)
        
        return response.body
    def list_area_and_exchange(limit=None, npa=None, page=None):
        """Does a GET request to /available-tns/npanxxs/.

        Retrieves a list of the NPA-NXXs (area codes and exchanges) that
        contain purchasable telephone numbers.

        Args:
            limit (int, optional): Number of items to display (Max 200)
            npa (int, optional): Restricts the results to this NPA.
            page (int, optional): Page to display

        Returns:
            mixed: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI

        # Prepare query string for API call
        query_builder += "/available-tns/npanxxs/"

        # Process optional query parameters
        query_parameters = {"limit": limit, "npa": npa, "page": page}
        query_builder = APIHelper.append_url_with_query_parameters(
            query_builder, query_parameters)

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "Flowroute SDK 1.0",
            "accept": "application/json",
        }

        # Prepare and invoke the API call request to fetch the response
        response = CustomAuthUtility.appendCustomAuthParams(
            method='GET', query_url=query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code == 400:
            raise APIException("USER ERROR", 400, response.body)

        elif response.code == 500:
            raise APIException("APPLICATION/SERVER ERROR", 500, response.body)

        elif response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code,
                               response.body)

        return response.body
    def list(limit=None, page=None):
        """Does a GET request to /routes/.

        TODO: type endpoint description here.

        Args:
            limit (int, optional): Number of items to display (max 200)
            page (int, optional): Page to display if paginated

        Returns:
            mixed: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/routes/"

        # Process optional query parameters
        query_parameters = {
            "limit": limit,
            "page": page
        }
        query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters)

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "Flowroute SDK 1.0",
            "accept": "application/json",
        }

        # Prepare and invoke the API call request to fetch the response
        response = CustomAuthUtility.appendCustomAuthParams(method='GET',
                                                            query_url=query_url,
                                                            headers=headers)

        # Error handling using HTTP status codes
        if response.code == 400:
            raise APIException("USER ERROR", 400, response.body)

        elif response.code == 500:
            raise APIException("APPLICATION/SERVER ERROR", 500, response.body)

        elif response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body)
        
        return response.body
    def telephone_number_details(telephone_number):
        """Does a GET request to /tns/{telephone_number}.

        Returns the routing and billing information for the specified
        telephone number on your account

        Args:
            telephone_number (string): This is the TN for which you would like
                to retrieve configuration details for

        Returns:
            string: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/tns/{telephone_number}"

        # Process optional template parameters
        query_builder = APIHelper.append_url_with_template_parameters(query_builder, { 
            "telephone_number": telephone_number
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "Flowroute SDK 1.0",
        }

        # Prepare and invoke the API call request to fetch the response
        response = CustomAuthUtility.appendCustomAuthParams(method='GET',
                                                            query_url=query_url,
                                                            headers=headers)

        # Error handling using HTTP status codes
        if response.code == 400:
            raise APIException("USER ERROR", 400, response.body)

        elif response.code == 500:
            raise APIException("APPLICATION/SERVER ERROR", 500, response.body)

        elif response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body)
        
        return response.body
    def telephone_number_details(telephone_number):
        """Does a GET request to /tns/{telephone_number}.

        Returns the routing and billing information for the specified
        telephone number on your account

        Args:
            telephone_number (string): This is the TN for which you would like
                to retrieve configuration details for

        Returns:
            string: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI

        # Prepare query string for API call
        query_builder += "/tns/{telephone_number}"

        # Process optional template parameters
        query_builder = APIHelper.append_url_with_template_parameters(
            query_builder, {"telephone_number": telephone_number})

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "Flowroute SDK 1.0",
        }

        # Prepare and invoke the API call request to fetch the response
        response = CustomAuthUtility.appendCustomAuthParams(
            method='GET', query_url=query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code == 400:
            raise APIException("USER ERROR", 400, response.body)

        elif response.code == 500:
            raise APIException("APPLICATION/SERVER ERROR", 500, response.body)

        elif response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code,
                               response.body)

        return response.body
    def resolve_names(self):
        """Creates a dictionary representation of this object.
        
        This method converts an object to a dictionary that represents the
        format that the model should be in when passed into an API Request.
        Because of this, the generated dictionary may have different
        property names to that of the model itself.
        
        Returns:
            dict: The dictionary representing the object.
        
        """
        # Create a mapping from Model property names to API property names
        replace_names = {
            "name": "name",
        }

        retval = dict()

        return APIHelper.resolve_names(self, replace_names, retval)
    def search(limit=None,
               npa=None,
               nxx=None,
               page=None,
               ratecenter=None,
               state=None,
               tn=None):
        """Does a GET request to /available-tns/tns/.

        TODO: type endpoint description here.

        Args:
            limit (int, optional): Number of items to display (Max 200)
            npa (int, optional): Restricts the results to the three digit NPA
                (area code) specified. This is optional, unless NXX is
                present
            nxx (int, optional): Restricts the results to the three digit NXX
                (exchange) specified.
            page (int, optional): Page to display
            ratecenter (string, optional): Restricts the results to the
                ratecenter specified. If present, state is required
            state (string, optional): Restricts the results to the state
                specified. This is optional, unless ratecenter is present.
            tn (string, optional): Restricts the results to the telephone
                number specified.

        Returns:
            mixed: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/available-tns/tns/"

        # Process optional query parameters
        query_parameters = {
            "limit": limit,
            "npa": npa,
            "nxx": nxx,
            "page": page,
            "ratecenter": ratecenter,
            "state": state,
            "tn": tn
        }

        query_builder = APIHelper.append_url_with_query_parameters(query_builder, query_parameters)

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "Flowroute SDK 1.0",
            "accept": "application/json",
        }

        # Prepare and invoke the API call request to fetch the response
        response = CustomAuthUtility.appendCustomAuthParams(method='GET',
                                                            query_url=query_url,
                                                            headers=headers)

        # Error handling using HTTP status codes
        if response.code == 400:
            raise APIException("USER ERROR", 400, response.body)

        elif response.code == 500:
            raise APIException("APPLICATION/SERVER ERROR", 500, response.body)

        elif response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body)
        
        return response.body
    def search(limit=None,
               npa=None,
               nxx=None,
               page=None,
               ratecenter=None,
               state=None,
               tn=None):
        """Does a GET request to /available-tns/tns/.

        TODO: type endpoint description here.

        Args:
            limit (int, optional): Number of items to display (Max 200)
            npa (int, optional): Restricts the results to the three digit NPA
                (area code) specified. This is optional, unless NXX is
                present
            nxx (int, optional): Restricts the results to the three digit NXX
                (exchange) specified.
            page (int, optional): Page to display
            ratecenter (string, optional): Restricts the results to the
                ratecenter specified. If present, state is required
            state (string, optional): Restricts the results to the state
                specified. This is optional, unless ratecenter is present.
            tn (string, optional): Restricts the results to the telephone
                number specified.

        Returns:
            mixed: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI

        # Prepare query string for API call
        query_builder += "/available-tns/tns/"

        # Process optional query parameters
        query_parameters = {
            "limit": limit,
            "npa": npa,
            "nxx": nxx,
            "page": page,
            "ratecenter": ratecenter,
            "state": state,
            "tn": tn
        }

        query_builder = APIHelper.append_url_with_query_parameters(
            query_builder, query_parameters)

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "Flowroute SDK 1.0",
            "accept": "application/json",
        }

        # Prepare and invoke the API call request to fetch the response
        response = CustomAuthUtility.appendCustomAuthParams(
            method='GET', query_url=query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code == 400:
            raise APIException("USER ERROR", 400, response.body)

        elif response.code == 500:
            raise APIException("APPLICATION/SERVER ERROR", 500, response.body)

        elif response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code,
                               response.body)

        return response.body
    def update(number, routes):
        """Does a PATCH request to /tns/{number}.

        Updates the routing information for a telephone number on your
        account, as indicated by the specified URI. The body of the request
        requires two routes listed in order of preference (primary first and
        fail over second).

        Args:
            number (string): The telephone number who's routing you wish to
                update
            routes (list of Route): JSON string containing the The routes
                obtained from the routes resource that you would like to point
                your telephone number to.

        Returns:
            string: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI

        # Prepare query string for API call
        query_builder += "/tns/{number}"

        # Process optional template parameters
        query_builder = APIHelper.append_url_with_template_parameters(
            query_builder, {"number": number})

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "Flowroute SDK 1.0",
            "content-type": "application/json; charset=utf-8",
        }
        routes = APIHelper.json_serialize(routes)
        body = '{"routes": %s}' % routes

        # Prepare and invoke the API call request to fetch the response
        response = CustomAuthUtility.appendCustomAuthParams(
            method='PATCH', query_url=query_url, body=body, headers=headers)

        # Error handling using HTTP status codes
        if response.code == 400:
            raise APIException("USER ERROR", 400, response.body)

        elif response.code == 500:
            raise APIException("APPLICATION/SERVER ERROR", 500, response.body)

        elif response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code,
                               response.body)

        return response.body
    def purchase(billing, number):
        """Does a PUT request to /tns/{number}.

        Purchases the telephone number indicated by the request URI, with the
        billing method indicated in the body. Allowable billing methods are
        returned in the search results for available telephone numbers.

        Args:
            billing (BillingMethod): The billing method to apply to the
                telephone number being purchased.
            number (string): Telephone number to purchase

        Returns:
            string: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/tns/{number}"

        # Process optional template parameters
        query_builder = APIHelper.append_url_with_template_parameters(query_builder, { 
            "number": number
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "Flowroute SDK 1.0",
            "content-type": "application/json; charset=utf-8",
        }

        # Quick kwargs setting
        body = APIHelper.json_serialize(billing)

        # Prepare and invoke the API call request to fetch the response
        response = CustomAuthUtility.appendCustomAuthParams(method='PUT',
                                                            query_url=query_url,
                                                            body=body,
                                                            headers=headers)

        # Error handling using HTTP status codes
        if response.code == 400:
            raise APIException("USER ERROR", 400, response.body)

        elif response.code == 500:
            raise APIException("APPLICATION/SERVER ERROR", 500, response.body)

        elif response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body)
        
        return response.body
    def update(number, routes):
        """Does a PATCH request to /tns/{number}.

        Updates the routing information for a telephone number on your
        account, as indicated by the specified URI. The body of the request
        requires two routes listed in order of preference (primary first and
        fail over second).

        Args:
            number (string): The telephone number who's routing you wish to
                update
            routes (list of Route): JSON string containing the The routes
                obtained from the routes resource that you would like to point
                your telephone number to.

        Returns:
            string: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/tns/{number}"

        # Process optional template parameters
        query_builder = APIHelper.append_url_with_template_parameters(query_builder, { 
            "number": number
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "Flowroute SDK 1.0",
            "content-type": "application/json; charset=utf-8",
        }
        routes = APIHelper.json_serialize(routes)
        body = '{"routes": %s}' % routes

        # Prepare and invoke the API call request to fetch the response
        response = CustomAuthUtility.appendCustomAuthParams(method='PATCH',
                                                            query_url=query_url,
                                                            body=body,
                                                            headers=headers)

        # Error handling using HTTP status codes
        if response.code == 400:
            raise APIException("USER ERROR", 400, response.body)

        elif response.code == 500:
            raise APIException("APPLICATION/SERVER ERROR", 500, response.body)

        elif response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body)
        
        return response.body