def get_response(status, content): """This method checks the status code and returns respective response message or exception. Args: status(str): Response status code. content(dict): Dictionary containing code and message. Returns: dict: Response message Raises: Books Exception: If status is not '200' or '201'. """ resp = json.loads(content) response = convert(resp) if status != '200' and status != '201': raise BooksException(response) else: return response
def getfile(self, url, details, query=None): """This method is used to make get request for the given url and query string. Args: url(str): Url passed by the user. details(dict): Dictionary containing authtoken and organization id. query(dict, optional): Additional parameters. Default to None. Returns: dict: Dictionary containing response content. """ url = url + '?' + form_query_string(details) if query is not None: url += '&' + form_query_string(query) headers = { 'Accept': \ 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Content-type': 'application/x-www-form-urlencoded', 'User-Agent': 'ZohoBooks-Python-Wrappers/1.0', 'Accept-Charset': 'UTF-8' } http, headers = get_http_connection(url) resp, content = http.request(url, 'GET', headers=headers) if resp['status'] == '200' or resp['status'] == '201': attachment = resp['content-disposition'] regex = search(r'".*"',attachment) filename = regex.group().strip('"') if regex is not None else \ 'attachment.' + query['accept'] file_location = "/home/likewise-open/ZOHOCORP/chitra-2327/Downloads/" file_name = open(file_location + filename, "w") file_name.write(content) file_name.close() return file_name else: raise BooksException(convert(json.loads(content)))