def __init__(self, username, password, client_id, base_uri="", logger="", output_dir=""): """ Initialises with user name and password """ self.api_username = username self.api_password = password self.client_id = client_id if (logger != ""): global log log = logger if ( output_dir != ""): self.out_dir = output_dir log.debug("Setting username and password")
def get_response(self, response): """ Handles the response """ if (response == ""): log.info("Empty Response") raise SchmapAPIException(7000) elif (response.startswith("<!DOCTYPE HTML")): log.debug("No the expected response") raise SchmapAPIException(7001) else: try: json_response = json.loads(response) except json.decoder.JSONDecodeError, e: raise SchmapAPIException(7003) try: if (json_response['code'] == 0): return json_response else: raise SchmapAPIException(json_response['code']) except KeyError,e: raise SchmapAPIException(7000)
def set_crendentials(self, username, password): """ Sets the credentials """ self.api_username = username self.api_password = password log.debug("Setting credentitals")
def save_to_file(self, response,filename): """ Save data to file with a file name """ try: os.mkdir(self.out_dir) except OSError, e: log.debug("Folder already exists, "+ str(e))