You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
540 lines
21 KiB
540 lines
21 KiB
7 years ago
|
# -*- coding: utf-8 -*-
|
||
|
|
||
|
"""
|
||
|
flowroutenumbersandmessaging.controllers.e911s_controller
|
||
|
|
||
|
This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
|
||
|
"""
|
||
|
|
||
|
from .base_controller import BaseController
|
||
|
from ..api_helper import APIHelper
|
||
|
from ..configuration import Configuration
|
||
|
from ..http.auth.basic_auth import BasicAuth
|
||
|
from ..exceptions.error_exception import ErrorException
|
||
|
|
||
|
|
||
|
class E911sController(BaseController):
|
||
|
|
||
|
"""A Controller to access Endpoints in the
|
||
|
flowroutenumbersandmessaging API."""
|
||
|
|
||
|
def list_e911s(self,
|
||
|
limit=None,
|
||
|
offset=None,
|
||
|
state=None):
|
||
|
"""Does a GET request to /v2/e911s.
|
||
|
|
||
|
Returns a list of all Central Office (exchange) codes containing
|
||
|
purchasable phone numbers.
|
||
|
|
||
|
Args:
|
||
|
limit (int, optional): Limits the number of items to retrieve. A
|
||
|
maximum of 200 items can be retrieved.
|
||
|
offset (int, optional): Offsets the list of phone numbers by your
|
||
|
specified value. For example, if you have 4 phone numbers and
|
||
|
you entered 1 as your offset value, then only 3 of your phone
|
||
|
numbers will be displayed in the response.
|
||
|
state (2 char, optional): Restricts the results to the specified
|
||
|
state.
|
||
|
|
||
|
Returns:
|
||
|
mixed: Response from the API. A JSON object of E911 Records
|
||
|
that satisfy your search criteria.
|
||
|
|
||
|
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.
|
||
|
|
||
|
"""
|
||
|
|
||
|
# Prepare query URL
|
||
|
_query_builder = Configuration.base_uri
|
||
|
_query_builder += '/v2/e911s'
|
||
|
_query_parameters = {
|
||
|
'limit': limit,
|
||
|
'offset': offset,
|
||
|
'state': state
|
||
|
}
|
||
|
_query_builder = APIHelper.append_url_with_query_parameters(_query_builder,
|
||
|
_query_parameters, Configuration.array_serialization)
|
||
|
_query_url = APIHelper.clean_url(_query_builder)
|
||
|
|
||
|
# Prepare and execute request
|
||
|
_request = self.http_client.get(_query_url)
|
||
|
BasicAuth.apply(_request)
|
||
|
_context = self.execute_request(_request)
|
||
|
|
||
|
# Endpoint and global error handling using HTTP status codes.
|
||
|
if _context.response.status_code == 401:
|
||
|
raise ErrorException('Unauthorized – There was an issue with your API credentials.', _context)
|
||
|
elif _context.response.status_code == 404:
|
||
|
raise ErrorException('The specified resource was not found', _context)
|
||
|
self.validate_response(_context)
|
||
|
|
||
|
return APIHelper.json_deserialize(_context.response.raw_body)
|
||
|
|
||
|
def get_e911(self, e911_id):
|
||
|
"""Does a GET request to /v2/e911s/<e911_id>.
|
||
|
|
||
|
Returns a record detail for the E911 Record Id specified
|
||
|
|
||
|
Args:
|
||
|
|
||
|
Returns:
|
||
|
mixed: Response from the API. A JSON object of of an E911 record
|
||
|
that satisfy your search criteria.
|
||
|
|
||
|
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.
|
||
|
|
||
|
"""
|
||
|
|
||
|
# Prepare query URL
|
||
|
_query_builder = Configuration.base_uri
|
||
|
_query_builder += '/v2/e911s/{}'.format(e911_id)
|
||
|
_query_url = APIHelper.clean_url(_query_builder)
|
||
|
|
||
|
# Prepare and execute request
|
||
|
_request = self.http_client.get(_query_url)
|
||
|
BasicAuth.apply(_request)
|
||
|
_context = self.execute_request(_request)
|
||
|
|
||
|
# Endpoint and global error handling using HTTP status codes.
|
||
|
if _context.response.status_code == 401:
|
||
|
raise ErrorException('Unauthorized – There was an issue with your API credentials.', _context)
|
||
|
elif _context.response.status_code == 404:
|
||
|
raise ErrorException('The specified resource was not found', _context)
|
||
|
self.validate_response(_context)
|
||
|
|
||
|
return APIHelper.json_deserialize(_context.response.raw_body)
|
||
|
|
||
|
def validate_address(self,
|
||
|
label,
|
||
|
first_name,
|
||
|
last_name,
|
||
|
street_name,
|
||
|
street_number,
|
||
|
city,
|
||
|
state,
|
||
|
country,
|
||
|
zip):
|
||
|
"""Does a POST request to /v2/e911s/validate.
|
||
|
|
||
|
Returns a 204 No Content on success, or a 404 with error data
|
||
|
|
||
|
Args:
|
||
|
label (string): the alias or friendly name of your entry
|
||
|
first_name (string):
|
||
|
last_name (string):
|
||
|
street_name (string):
|
||
|
street_number (string):
|
||
|
city (string):
|
||
|
state (2 character string):
|
||
|
country (string USA or Canada):
|
||
|
zip (string postal code)
|
||
|
|
||
|
Returns:
|
||
|
mixed: Response from the API. A 204 - No Content or a
|
||
|
JSON object ith error data
|
||
|
|
||
|
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.
|
||
|
|
||
|
"""
|
||
|
body = dict()
|
||
|
body['data'] = dict()
|
||
|
body['data']['type'] = 'e911'
|
||
|
body['data']['attributes'] = {}
|
||
|
body['data']['attributes']['label'] = label
|
||
|
body['data']['attributes']['first_name'] = first_name
|
||
|
body['data']['attributes']['last_name'] = last_name
|
||
|
body['data']['attributes']['street_name'] = street_name
|
||
|
body['data']['attributes']['street_number'] = street_number
|
||
|
body['data']['attributes']['city'] = city
|
||
|
body['data']['attributes']['state'] = state
|
||
|
body['data']['attributes']['country'] = country
|
||
|
body['data']['attributes']['zip'] = zip
|
||
|
|
||
|
# Prepare query URL
|
||
|
_query_builder = Configuration.base_uri
|
||
|
_query_builder += '/v2/e911s/validate'
|
||
|
|
||
|
# Return appropriate type
|
||
|
_query_url = APIHelper.clean_url(_query_builder)
|
||
|
|
||
|
# Prepare headers
|
||
|
_headers = {
|
||
|
'accept': 'application/json'
|
||
|
}
|
||
|
|
||
|
# Prepare and execute request
|
||
|
_request = self.http_client.post(_query_url, headers=_headers,
|
||
|
parameters=APIHelper.json_serialize(body))
|
||
|
BasicAuth.apply(_request)
|
||
|
_context = self.execute_request(_request)
|
||
|
|
||
|
# Endpoint and global error handling using HTTP status codes.
|
||
|
if _context.response.status_code == 401:
|
||
|
raise ErrorException('Unauthorized – There was an issue with your API credentials.', _context)
|
||
|
elif _context.response.status_code == 404:
|
||
|
raise ErrorException('The specified resource was not found', _context)
|
||
|
self.validate_response(_context)
|
||
|
|
||
|
# Return appropriate type
|
||
|
return APIHelper.json_deserialize(_context.response.raw_body)
|
||
|
|
||
|
def create_address(self,
|
||
|
label,
|
||
|
first_name,
|
||
|
last_name,
|
||
|
street_name,
|
||
|
street_number,
|
||
|
city,
|
||
|
state,
|
||
|
country,
|
||
|
zip):
|
||
|
"""Does a POST request to /v2/e911s.
|
||
|
|
||
|
Creates an address record that can then be associated with 1 or more DIDs
|
||
|
|
||
|
Args:
|
||
|
label (string): the alias or friendly name of your entry
|
||
|
first_name (string):
|
||
|
last_name (string):
|
||
|
street_name (string):
|
||
|
street_number (string):
|
||
|
city (string):
|
||
|
state (2 character string):
|
||
|
country (string USA or Canada):
|
||
|
zip (string postal code)
|
||
|
|
||
|
Returns:
|
||
|
mixed: Response from the API. A JSON object containing the new record information.
|
||
|
|
||
|
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.
|
||
|
|
||
|
"""
|
||
|
body = dict()
|
||
|
body['data'] = dict()
|
||
|
body['data']['type'] = 'e911'
|
||
|
body['data']['attributes'] = {}
|
||
|
body['data']['attributes']['label'] = label
|
||
|
body['data']['attributes']['first_name'] = first_name
|
||
|
body['data']['attributes']['last_name'] = last_name
|
||
|
body['data']['attributes']['street_name'] = street_name
|
||
|
body['data']['attributes']['street_number'] = street_number
|
||
|
body['data']['attributes']['city'] = city
|
||
|
body['data']['attributes']['state'] = state
|
||
|
body['data']['attributes']['country'] = country
|
||
|
body['data']['attributes']['zip'] = zip
|
||
|
|
||
|
# Prepare query URL
|
||
|
_query_builder = Configuration.base_uri
|
||
|
_query_builder += '/v2/e911s'
|
||
|
|
||
|
# Return appropriate type
|
||
|
_query_url = APIHelper.clean_url(_query_builder)
|
||
|
|
||
|
# Prepare headers
|
||
|
_headers = {
|
||
|
'accept': 'application/json'
|
||
|
}
|
||
|
|
||
|
# Prepare and execute request
|
||
|
_request = self.http_client.post(_query_url, headers=_headers,
|
||
|
parameters=APIHelper.json_serialize(body))
|
||
|
BasicAuth.apply(_request)
|
||
|
_context = self.execute_request(_request)
|
||
|
|
||
|
# Endpoint and global error handling using HTTP status codes.
|
||
|
if _context.response.status_code == 401:
|
||
|
raise ErrorException('Unauthorized – There was an issue with your API credentials.', _context)
|
||
|
elif _context.response.status_code == 404:
|
||
|
raise ErrorException('The specified resource was not found', _context)
|
||
|
self.validate_response(_context)
|
||
|
|
||
|
# Return appropriate type
|
||
|
return APIHelper.json_deserialize(_context.response.raw_body)
|
||
|
|
||
|
def update_address(self,
|
||
|
e911_id,
|
||
|
label=None,
|
||
|
first_name=None,
|
||
|
last_name=None,
|
||
|
street_name=None,
|
||
|
street_number=None,
|
||
|
city=None,
|
||
|
state=None,
|
||
|
country=None,
|
||
|
zip=None):
|
||
|
|
||
|
"""Does a PATCH request to /v2/e911s/<e911_id>.
|
||
|
|
||
|
Updates an existing address record and any associations it may have
|
||
|
|
||
|
Args:
|
||
|
e911_id (integer, required): the id of the e911 record to update
|
||
|
label (string, optional): the alias or friendly name of your entry
|
||
|
first_name (string, optional):
|
||
|
last_name (string, optional):
|
||
|
street_name (string, optional):
|
||
|
street_number (string, optional):
|
||
|
city (string, optional):
|
||
|
state (2 character string, optional):
|
||
|
country (string USA or Canada, optional):
|
||
|
zip (string postal code, optional)
|
||
|
|
||
|
Returns:
|
||
|
mixed: Response from the API. A JSON object containing the new record information.
|
||
|
|
||
|
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.
|
||
|
|
||
|
"""
|
||
|
cur_record = self.get_e911(e911_id)
|
||
|
record_data = cur_record
|
||
|
|
||
|
record_data['data']['attributes']['zip_code'] = str(record_data['data']['attributes']['zip'])
|
||
|
record_data['data']['attributes']['house_number'] = str(record_data['data']['attributes']['street_number'])
|
||
|
|
||
|
if label is not None:
|
||
|
record_data['data']['attributes']['label'] = label
|
||
|
if first_name is not None:
|
||
|
record_data['data']['attributes']['first_name'] = first_name
|
||
|
if last_name is not None:
|
||
|
record_data['data']['attributes']['last_name'] = last_name
|
||
|
if street_name is not None:
|
||
|
record_data['data']['attributes']['street_name'] = street_name
|
||
|
if street_number is not None:
|
||
|
record_data['data']['attributes']['street_number'] = str(street_number)
|
||
|
record_data['data']['attributes']['house_number'] = str(street_number)
|
||
|
if city is not None:
|
||
|
record_data['data']['attributes']['city'] = city
|
||
|
if state is not None:
|
||
|
record_data['data']['attributes']['state'] = state
|
||
|
if country is not None:
|
||
|
record_data['data']['attributes']['country'] = country
|
||
|
if zip is not None:
|
||
|
record_data['data']['attributes']['zip'] = str(zip)
|
||
|
record_data['data']['attributes']['zip_code'] = str(zip)
|
||
|
|
||
|
# Prepare query URL
|
||
|
_query_builder = Configuration.base_uri
|
||
|
_query_builder += '/v2/e911s/{}'.format(e911_id)
|
||
|
|
||
|
# Return appropriate type
|
||
|
_query_url = APIHelper.clean_url(_query_builder)
|
||
|
|
||
|
# Prepare headers
|
||
|
_headers = {
|
||
|
'accept': 'application/json'
|
||
|
}
|
||
|
|
||
|
# Prepare and execute request
|
||
|
_request = self.http_client.patch(_query_url, headers=_headers,
|
||
|
parameters=APIHelper.json_serialize(record_data))
|
||
|
BasicAuth.apply(_request)
|
||
|
_context = self.execute_request(_request)
|
||
|
|
||
|
# Endpoint and global error handling using HTTP status codes.
|
||
|
if _context.response.status_code == 401:
|
||
|
raise ErrorException('Unauthorized – There was an issue with your API credentials.', _context)
|
||
|
elif _context.response.status_code == 404:
|
||
|
raise ErrorException('The specified resource was not found', _context)
|
||
|
self.validate_response(_context)
|
||
|
|
||
|
# Return appropriate type
|
||
|
return APIHelper.json_deserialize(_context.response.raw_body)
|
||
|
|
||
|
def delete_address(self, e911_id):
|
||
|
"""Does a DELETE request to /v2/e911s/<e911_id>.
|
||
|
|
||
|
Removes the existing address record and any associations it may have
|
||
|
|
||
|
Args:
|
||
|
e911_id (integer, required): the id of the e911 record to update
|
||
|
|
||
|
Returns:
|
||
|
mixed: Response from the API. A 204 - No Content or a
|
||
|
JSON object ith error data
|
||
|
|
||
|
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.
|
||
|
|
||
|
"""
|
||
|
# Prepare query URL
|
||
|
_query_builder = Configuration.base_uri
|
||
|
_query_builder += '/v2/e911s/{}'.format(e911_id)
|
||
|
|
||
|
# Return appropriate type
|
||
|
_query_url = APIHelper.clean_url(_query_builder)
|
||
|
|
||
|
# Prepare headers
|
||
|
_headers = {
|
||
|
'accept': 'application/json'
|
||
|
}
|
||
|
|
||
|
# Prepare and execute request
|
||
|
_request = self.http_client.delete(_query_url, headers=_headers)
|
||
|
BasicAuth.apply(_request)
|
||
|
_context = self.execute_request(_request)
|
||
|
|
||
|
# Endpoint and global error handling using HTTP status codes.
|
||
|
if _context.response.status_code == 401:
|
||
|
raise ErrorException('Unauthorized – There was an issue with your API credentials.', _context)
|
||
|
elif _context.response.status_code == 404:
|
||
|
raise ErrorException('The specified resource was not found', _context)
|
||
|
self.validate_response(_context)
|
||
|
|
||
|
# Return appropriate type
|
||
|
return APIHelper.json_deserialize(_context.response.raw_body)
|
||
|
|
||
|
def associate(self, e911_id, did):
|
||
|
"""Does a PATCH request to /v2/numbers/<did>/relationships/e911s/<e911_id>.
|
||
|
|
||
|
Associates the specified e911 record with the specified did
|
||
|
|
||
|
Args:
|
||
|
e911_id (integer, required): the id of the e911 record to update
|
||
|
did (string, required): the phone number to associate with
|
||
|
|
||
|
Returns:
|
||
|
mixed: Response from the API. A 204 - No Content or a
|
||
|
JSON object ith error data
|
||
|
|
||
|
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.
|
||
|
|
||
|
"""
|
||
|
# Prepare query URL
|
||
|
_query_builder = Configuration.base_uri
|
||
|
_query_builder += '/v2/numbers/{}/relationships/e911s/{}'.format(did, e911_id)
|
||
|
|
||
|
# Return appropriate type
|
||
|
_query_url = APIHelper.clean_url(_query_builder)
|
||
|
|
||
|
# Prepare headers
|
||
|
_headers = {
|
||
|
'accept': 'application/json'
|
||
|
}
|
||
|
|
||
|
# Prepare and execute request
|
||
|
_request = self.http_client.patch(_query_url, headers=_headers)
|
||
|
BasicAuth.apply(_request)
|
||
|
_context = self.execute_request(_request)
|
||
|
|
||
|
# Endpoint and global error handling using HTTP status codes.
|
||
|
if _context.response.status_code == 401:
|
||
|
raise ErrorException('Unauthorized – There was an issue with your API credentials.', _context)
|
||
|
elif _context.response.status_code == 404:
|
||
|
raise ErrorException('The specified resource was not found', _context)
|
||
|
self.validate_response(_context)
|
||
|
|
||
|
# Return appropriate type
|
||
|
return APIHelper.json_deserialize(_context.response.raw_body)
|
||
|
|
||
|
def disconnect(self, e911_id, did):
|
||
|
"""Does a DELETE request to /v2/numbers/<did>/relationships/e911s/<e911_id>.
|
||
|
|
||
|
Un-Associates the specified e911 record with the specified did
|
||
|
|
||
|
Args:
|
||
|
e911_id (integer, required): the id of the e911 record to update
|
||
|
did (string, required): the phone number to associate with
|
||
|
|
||
|
Returns:
|
||
|
mixed: Response from the API. A 204 - No Content or a
|
||
|
JSON object ith error data
|
||
|
|
||
|
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.
|
||
|
|
||
|
"""
|
||
|
# Prepare query URL
|
||
|
_query_builder = Configuration.base_uri
|
||
|
_query_builder += '/v2/numbers/{}/relationships/e911s/{}'.format(did, e911_id)
|
||
|
|
||
|
# Return appropriate type
|
||
|
_query_url = APIHelper.clean_url(_query_builder)
|
||
|
|
||
|
# Prepare headers
|
||
|
_headers = {
|
||
|
'accept': 'application/json'
|
||
|
}
|
||
|
|
||
|
# Prepare and execute request
|
||
|
_request = self.http_client.delete(_query_url, headers=_headers)
|
||
|
BasicAuth.apply(_request)
|
||
|
_context = self.execute_request(_request)
|
||
|
|
||
|
# Endpoint and global error handling using HTTP status codes.
|
||
|
if _context.response.status_code == 401:
|
||
|
raise ErrorException('Unauthorized – There was an issue with your API credentials.', _context)
|
||
|
elif _context.response.status_code == 404:
|
||
|
raise ErrorException('The specified resource was not found', _context)
|
||
|
self.validate_response(_context)
|
||
|
|
||
|
# Return appropriate type
|
||
|
return APIHelper.json_deserialize(_context.response.raw_body)
|
||
|
|
||
|
def list_dids_for_e911(self, e911_id):
|
||
|
"""Does a GET request to /v2/e911s/<e911_id>/relationships/numbers
|
||
|
|
||
|
Lists all Did records associated with the specified E911 record
|
||
|
|
||
|
Args:
|
||
|
e911_id (integer, required): the id of the e911 record to query
|
||
|
|
||
|
Returns:
|
||
|
mixed: Response from the API. A JSON Object list with the associated
|
||
|
DID records
|
||
|
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.
|
||
|
|
||
|
"""
|
||
|
# Prepare query URL
|
||
|
_query_builder = Configuration.base_uri
|
||
|
_query_builder += '/v2/e911s/{}'.format(e911_id)
|
||
|
_query_url = APIHelper.clean_url(_query_builder)
|
||
|
|
||
|
# Prepare and execute request
|
||
|
_request = self.http_client.get(_query_url)
|
||
|
BasicAuth.apply(_request)
|
||
|
_context = self.execute_request(_request)
|
||
|
|
||
|
# Endpoint and global error handling using HTTP status codes.
|
||
|
if _context.response.status_code == 401:
|
||
|
raise ErrorException('Unauthorized – There was an issue with your API credentials.', _context)
|
||
|
elif _context.response.status_code == 404:
|
||
|
raise ErrorException('The specified resource was not found', _context)
|
||
|
self.validate_response(_context)
|
||
|
|
||
|
return APIHelper.json_deserialize(_context.response.raw_body)
|