E911 Controller and demo

e911_addr
Chris Lacina 7 years ago
parent 224e2f414c
commit 4c7654d613
  1. 75
      e911_demo.py
  2. 539
      flowroutenumbersandmessaging/controllers/e911s_controller.py
  3. 7
      flowroutenumbersandmessaging/flowroutenumbersandmessaging_client.py

@ -0,0 +1,75 @@
#!/usr/bin/env python
import pprint
from flowroutenumbersandmessaging.flowroutenumbersandmessaging_client import FlowroutenumbersandmessagingClient
# Instantiate API client and create controllers for Numbers and E911s
client = FlowroutenumbersandmessagingClient()
numbers_controller = client.numbers
e911s_controller = client.e911s
print("--List E911 Records")
limit = 10
offset = None
result = e911s_controller.list_e911s(limit, offset)
pprint.pprint(result)
print("--Validate an Address")
result = e911s_controller.validate_address(
label="Test Address",
first_name="Chris",
last_name="Smith",
street_name="3rd Ave",
street_number="1182",
city="Seattle",
state="WA",
country="USA",
zip="98101")
pprint.pprint(result)
print("--Get Details for a specific E911 Record")
result = e911s_controller.get_e911(11476)
pprint.pprint(result)
print("--Create and Validate an Address")
result = e911s_controller.create_address(
label="E911 Test",
first_name="Chris",
last_name="Smith",
street_name="3rd Ave",
street_number="1182",
city="Seattle",
state="WA",
country="USA",
zip="98101")
pprint.pprint(result)
# Pull the ID from the newly created record
record_id = result['data']['id']
print("--Update an E911 Address")
result = e911s_controller.update_address(record_id, last_name='Wiley')
pprint.pprint(result)
# Get our DIDs
did_list = numbers_controller.list_account_phone_numbers()
did = did_list['data'][0]['attributes']['value']
# Get our E911s
e911_list = e911s_controller.list_e911s()
e911_id = e911_list['data'][0]['id']
# Associate them
print("--Associate an E911 Record and a DID")
result = e911s_controller.associate(e911_id, did)
pprint.pprint(result)
# Diss-Associate them
print("--Un-associate the address")
result = e911s_controller.disconnect(e911_id, did)
pprint.pprint(result)
print("--Delete an E911 Address")
result = e911s_controller.delete_address(e911_id)
pprint.pprint(result)

@ -0,0 +1,539 @@
# -*- 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)

@ -10,6 +10,8 @@ from .configuration import Configuration
from .controllers.numbers_controller import NumbersController
from .controllers.routes_controller import RoutesController
from .controllers.messages_controller import MessagesController
from .controllers.e911s_controller import E911sController
class FlowroutenumbersandmessagingClient(object):
@ -27,6 +29,9 @@ class FlowroutenumbersandmessagingClient(object):
def messages(self):
return MessagesController()
@lazy_property
def e911s(self):
return E911sController()
def __init__(self,
basic_auth_user_name = None,
@ -35,5 +40,3 @@ class FlowroutenumbersandmessagingClient(object):
Configuration.basic_auth_user_name = basic_auth_user_name
if basic_auth_password != None:
Configuration.basic_auth_password = basic_auth_password

Loading…
Cancel
Save