blob: 8be3073233c342e953322aa7a02d84f3fde6fb66 [file] [log] [blame]
import logging
from flask import flash
import requests.exceptions
from config import URIBuilder
__author__ = 'hanl'
logging.basicConfig(level=logging.DEBUG)
def get(path="", **kwargs):
return request('get', path, **kwargs)
def post(path="", **kwargs):
path = URIBuilder().addPath(path).build()
if 'headers' in kwargs:
headers = kwargs['headers']
headers["Content-Type"] = "application/x-www-form-urlencoded"
else:
headers = {"Content-Type": "application/x-www-form-urlencoded"}
kwargs['headers'] = headers
return request('post', path, **kwargs)
def request(method, path="", **kwargs):
path = URIBuilder().addPath(path).build()
if kwargs and path is not "":
try:
response = requests.request(method, path, **kwargs)
except requests.exceptions.RequestException as e:
print e
flash("Connection to API server could not be established", "danger")
return None
print "the response %i:%s" % (response.status_code, str(response.content))
return response
return None