Test SDK with Python3, update user-agent info, remove duplicate error handling

e911_addr
Maria Bermudez 7 years ago
parent 3bf1e99f9f
commit 704018099b
  1. 13
      README.md
  2. 19
      demo.py
  3. 2
      flowroutenumbersandmessaging/controllers/base_controller.py
  4. 13
      flowroutenumbersandmessaging/controllers/routes_controller.py

@ -21,7 +21,8 @@ Requirements
------------
* Flowroute [API credentials](https://manage.flowroute.com/accounts/preferences/api/)
* [Python](https://www.python.org/downloads/) 2.x or higher
* [Python](https://www.python.org/downloads/) `2 >=2.7.9` or `3 >=3.4`
* * *
Installation
@ -32,9 +33,15 @@ Installation
* via SSH: `git@github.com:flowroute/flowroute-numbers-messaging-python.git`
2. Switch to the newly-created `flowroute-numbers-messaging-python` directory. Version 3 of the Flowroute SDK for Python comes with a requirements file listing the required Python libraries. Click [here](https://packaging.python.org/installing/#requirements-files) to learn more about different ways to install Python packages. Depending on your `pip` permissions, you may be required to preface each `pip` command with `sudo`.
2. Switch to the newly-created `flowroute-numbers-messaging-python` directory. To build and install the required modules, run the following:
`python setup.py install`
3. Version 3 of the Flowroute SDK for Python comes with a requirements file listing the required Python libraries. Click [here](https://packaging.python.org/installing/#requirements-files) to learn more about different ways to install Python packages. `pip` is already installed if you're using `Python 2 >=2.7.9` or `Python 3 >=3.4`. This SDK has been tested with both `2.7.9` and `3.6.4`. To see which version of `pip` is installed on your machine, run the following:
`pip --version`
Depending on your `pip` permissions, you may be required to preface each `pip` command with `sudo`.
`pip install -r requirements.txt`
`pip3 install -r requirements.txt`
* * *
Usage

@ -4,7 +4,6 @@ import os
import json
import random
import string
import requests
from flowroutenumbersandmessaging.flowroutenumbersandmessaging_client import FlowroutenumbersandmessagingClient
from flowroutenumbersandmessaging.models import *
from flowroutenumbersandmessaging.models.new_route import NewRoute
@ -68,7 +67,7 @@ number_id = result['data'][0]['id']
result = numbers_controller.list_phone_number_details(number_id)
pprint.pprint(result)
print ("---Create an Inbound Route")
print("---Create an Inbound Route")
# Function to generate six-charac random string
def id_generator(size=6, chars=string.ascii_lowercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
@ -104,12 +103,12 @@ request_body = '{ \
} \
}'
print ("---Update Primary Voice Route")
print("---Update Primary Voice Route")
result = routes_controller.update_primary_voice_route(number_id, request_body)
if result is None:
print "204: No Content"
print("204: No Content")
else:
print result
print (result)
request_body = '{ \
"data": { \
@ -118,12 +117,12 @@ request_body = '{ \
} \
}'
print ("---Update Failover Voice Route")
print("---Update Failover Voice Route")
result = routes_controller.update_failover_voice_route(number_id, request_body)
if result is None:
print "204: No Content"
print("204: No Content")
else:
print result
print (result)
request_body = '{ \
"data": { \
@ -138,11 +137,11 @@ request_body = '{ \
} \
}'
print ("---Send A Message")
print("---Send A Message")
#result = messages_controller.send_a_message(request_body)
#pprint.pprint(result)
print ("---Look Up A Set Of Messages")
print("---Look Up A Set Of Messages")
start_date = "2017-12-01"
end_date = "2018-01-08"
limit = 2

@ -32,7 +32,7 @@ class BaseController(object):
http_call_back = None
global_headers = {
'user-agent': 'Flowroute SDK v3'
'user-agent': 'Flowroute SDK v3.0'
}
def __init__(self, client=None, call_back=None):

@ -47,8 +47,8 @@ class RoutesController(BaseController):
# Prepare headers
_headers = {
'accept': 'application/vnd.api+json',
'content-type': 'application/vnd.api+json; charset=utf-8'
'accept': 'application/json',
'content-type': 'application/json; charset=utf-8'
}
# Prepare and execute request
@ -58,13 +58,14 @@ class RoutesController(BaseController):
# 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)
raise ErrorException('401 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)
raise ErrorException('403 Forbidden – The server understood the request but refuses to authorize it.', _context)
elif _context.response.status_code == 404:
raise ErrorException('The specified resource was not found', _context)
raise ErrorException('404 The specified resource was not found', _context)
self.validate_response(_context)
# Return appropriate type
return APIHelper.json_deserialize(_context.response.raw_body)
@ -118,8 +119,6 @@ class RoutesController(BaseController):
raise APIException('Unauthorized', _context)
elif _context.response.status_code == 404:
raise APIException('Not Found', _context)
elif _context.response.status_code <> 200:
raise ErrorException('Unspecified error occurred', _context)
self.validate_response(_context)
return APIHelper.json_deserialize(_context.response.raw_body)

Loading…
Cancel
Save