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. 9
      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/) * 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 Installation
@ -32,9 +33,15 @@ Installation
* via SSH: `git@github.com:flowroute/flowroute-numbers-messaging-python.git` * 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 Usage

@ -4,7 +4,6 @@ import os
import json import json
import random import random
import string import string
import requests
from flowroutenumbersandmessaging.flowroutenumbersandmessaging_client import FlowroutenumbersandmessagingClient from flowroutenumbersandmessaging.flowroutenumbersandmessaging_client import FlowroutenumbersandmessagingClient
from flowroutenumbersandmessaging.models import * from flowroutenumbersandmessaging.models import *
from flowroutenumbersandmessaging.models.new_route import NewRoute from flowroutenumbersandmessaging.models.new_route import NewRoute
@ -107,9 +106,9 @@ request_body = '{ \
print("---Update Primary Voice Route") print("---Update Primary Voice Route")
result = routes_controller.update_primary_voice_route(number_id, request_body) result = routes_controller.update_primary_voice_route(number_id, request_body)
if result is None: if result is None:
print "204: No Content" print("204: No Content")
else: else:
print result print (result)
request_body = '{ \ request_body = '{ \
"data": { \ "data": { \
@ -121,9 +120,9 @@ request_body = '{ \
print("---Update Failover Voice Route") print("---Update Failover Voice Route")
result = routes_controller.update_failover_voice_route(number_id, request_body) result = routes_controller.update_failover_voice_route(number_id, request_body)
if result is None: if result is None:
print "204: No Content" print("204: No Content")
else: else:
print result print (result)
request_body = '{ \ request_body = '{ \
"data": { \ "data": { \

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

@ -47,8 +47,8 @@ class RoutesController(BaseController):
# Prepare headers # Prepare headers
_headers = { _headers = {
'accept': 'application/vnd.api+json', 'accept': 'application/json',
'content-type': 'application/vnd.api+json; charset=utf-8' 'content-type': 'application/json; charset=utf-8'
} }
# Prepare and execute request # Prepare and execute request
@ -58,13 +58,14 @@ class RoutesController(BaseController):
# 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('401 Unauthorized – There was an issue with your API credentials.', _context)
elif _context.response.status_code == 403: 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: 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) self.validate_response(_context)
# Return appropriate type # Return appropriate type
return APIHelper.json_deserialize(_context.response.raw_body) return APIHelper.json_deserialize(_context.response.raw_body)
@ -118,8 +119,6 @@ class RoutesController(BaseController):
raise APIException('Unauthorized', _context) raise APIException('Unauthorized', _context)
elif _context.response.status_code == 404: elif _context.response.status_code == 404:
raise APIException('Not Found', _context) raise APIException('Not Found', _context)
elif _context.response.status_code <> 200:
raise ErrorException('Unspecified error occurred', _context)
self.validate_response(_context) self.validate_response(_context)
return APIHelper.json_deserialize(_context.response.raw_body) return APIHelper.json_deserialize(_context.response.raw_body)

Loading…
Cancel
Save