From 704018099b52559c3b78b72e119a8ab46284549a Mon Sep 17 00:00:00 2001 From: Maria Bermudez Date: Thu, 11 Jan 2018 13:17:30 -0800 Subject: [PATCH] Test SDK with Python3, update user-agent info, remove duplicate error handling --- README.md | 13 ++++++++++--- demo.py | 19 +++++++++---------- .../controllers/base_controller.py | 2 +- .../controllers/routes_controller.py | 13 ++++++------- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index e3df46c..32a69e5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/demo.py b/demo.py index cdae312..a85ad3b 100755 --- a/demo.py +++ b/demo.py @@ -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 diff --git a/flowroutenumbersandmessaging/controllers/base_controller.py b/flowroutenumbersandmessaging/controllers/base_controller.py index ed58f27..fa1dc27 100644 --- a/flowroutenumbersandmessaging/controllers/base_controller.py +++ b/flowroutenumbersandmessaging/controllers/base_controller.py @@ -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): diff --git a/flowroutenumbersandmessaging/controllers/routes_controller.py b/flowroutenumbersandmessaging/controllers/routes_controller.py index 660392d..b43c61e 100644 --- a/flowroutenumbersandmessaging/controllers/routes_controller.py +++ b/flowroutenumbersandmessaging/controllers/routes_controller.py @@ -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)