Final touches to demo, update routes_controller header info

e911_addr
Maria Bermudez 7 years ago
parent 0a2ae1807f
commit 0fbff17691
  1. 16
      demo.py
  2. 6
      flowroutenumbersandmessaging/controllers/routes_controller.py

@ -11,9 +11,11 @@ from flowroutenumbersandmessaging.models.new_route import NewRoute
print("Number/Route Management v2 & Messaging v2.1 Demo") print("Number/Route Management v2 & Messaging v2.1 Demo")
# Set up your api credentials # Set up your api credentials and test mobile number for outbound SMS or MMS
basic_auth_user_name = os.environ.get('FR_ACCESS_KEY') basic_auth_user_name = os.environ.get('FR_ACCESS_KEY')
basic_auth_password = os.environ.get('FR_SECRET_KEY') basic_auth_password = os.environ.get('FR_SECRET_KEY')
mobile_number = "YOUR_MOBILE_NUMBER"
# Instantiate API client and create controllers for Numbers, Messages, and Routes # Instantiate API client and create controllers for Numbers, Messages, and Routes
client = FlowroutenumbersandmessagingClient(basic_auth_user_name, basic_auth_password) client = FlowroutenumbersandmessagingClient(basic_auth_user_name, basic_auth_password)
@ -105,7 +107,7 @@ request_body = '{ \
"data": { \ "data": { \
"type": "message", \ "type": "message", \
"attributes": { \ "attributes": { \
"to": "12067392634", \ "to": "' + str(mobile_number) + '", \
"from": "' + str(number_id) + '", \ "from": "' + str(number_id) + '", \
"body": "hello there", \ "body": "hello there", \
"is_mms": "true", \ "is_mms": "true", \
@ -119,8 +121,8 @@ print ("---Send A Message")
#pprint.pprint(result) #pprint.pprint(result)
print ("---Look Up A Set Of Messages") print ("---Look Up A Set Of Messages")
start_date = '2017-12-01' start_date = "2017-12-01"
end_date = '2018-01-08' end_date = "2018-01-08"
result = messages_controller.look_up_a_set_of_messages(start_date, end_date) result = messages_controller.look_up_a_set_of_messages(start_date, end_date)
pprint.pprint(result) pprint.pprint(result)
@ -135,6 +137,8 @@ print ("---Create an Inbound Route")
def id_generator(size=6, chars=string.ascii_lowercase + string.digits): def id_generator(size=6, chars=string.ascii_lowercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size)) return ''.join(random.choice(chars) for _ in range(size))
new_route = id_generator() + '.sonsofodin.com' new_route = id_generator() + '.sonsofodin.com'
alias = "new route"
for i in range(10): alias += str(i)
print new_route print new_route
request_body = '{ \ request_body = '{ \
"data": { \ "data": { \
@ -142,9 +146,9 @@ request_body = '{ \
"attributes": { \ "attributes": { \
"route_type": "host", \ "route_type": "host", \
"value": "' + new_route +'", \ "value": "' + new_route +'", \
"alias": "test_route_id" \ "alias": "' + alias + '" \
} \ } \
} \ } \
}' }'
result = routes_controller.create_an_inbound_route(request_body) result = routes_controller.create_an_inbound_route(request_body)
print "New Route Created" print result

@ -30,7 +30,7 @@ class RoutesController(BaseController):
body (NewRoute): The new inbound route to be created. body (NewRoute): The new inbound route to be created.
Returns: Returns:
string: Response from the API. CREATED mixed: Response from the API. CREATED
Raises: Raises:
APIException: When an error occurs while fetching the data from APIException: When an error occurs while fetching the data from
@ -47,6 +47,7 @@ class RoutesController(BaseController):
# Prepare headers # Prepare headers
_headers = { _headers = {
'accept': 'application/vnd.api+json',
'content-type': 'application/vnd.api+json; charset=utf-8' 'content-type': 'application/vnd.api+json; charset=utf-8'
} }
@ -54,11 +55,12 @@ class RoutesController(BaseController):
_request = self.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(json.loads(body))) _request = self.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(json.loads(body)))
BasicAuth.apply(_request) BasicAuth.apply(_request)
_context = self.execute_request(_request) _context = self.execute_request(_request)
print _context.response.status_code
# Endpoint and global error handling using HTTP status codes. # Endpoint and global error handling using HTTP status codes.
if _context.response.status_code == 401: if _context.response.status_code == 401:
raise ErrorException('Unauthorized – There was an issue with your API credentials.', _context) raise ErrorException('Unauthorized – There was an issue with your API credentials.', _context)
elif _context.response.status_code == 403:
raise ErrorException('Forbidden – The server understood the request but refuses to authorize it.', _context)
elif _context.response.status_code == 404: elif _context.response.status_code == 404:
raise ErrorException('The specified resource was not found', _context) raise ErrorException('The specified resource was not found', _context)
self.validate_response(_context) self.validate_response(_context)

Loading…
Cancel
Save