class ProjectClient: def __init__(self, api_home_url='', relations={}): self.__log = logging.getLogger(__name__) self.__log.debug("__init__(api_home_url=%s, relations=%s)" % (api_home_url, str(relations))) if "users" not in relations: relations["users"] = default_link_rel_users self.__log.warning("Using default link relation for users: %s" % default_link_rel_users) if "projects" not in relations: relations["projects"] = default_link_rel_projects self.__log.warning("Using default link relation for projects: %s" % default_link_rel_projects) self._rc = RestClient(relations) @self._rc.handle_content_type('application/json-home', 0.75) def handle_json_home0(client, resp): # parse JSON home document or other JSON directly json_home_data = resp.json() self.__log.debug("have JSON home data: %s" % (str(json_home_data))) if 'resources' in json_home_data: for rel, d in json_home_data['resources'].iteritems(): if 'href' in d: client.remember_link(resp.url, rel, d['href']) return True else: return False # Fetch and handle the API Home URL self._rc.get(api_home_url) @property def projects(self): #self._rc.relations["projects"] pass def __str__(self): return "%s with RestClient: %s" % (__name__, str(self._rc))
def get(self, command='', rest_args={}): for i in range(5): result, status = RestClient.get(self, command, rest_args) if status == 200: return result, status elif status == 429: print("Too fast") sleep(1 * i) else: print(f"status code: {status}") return result, status print("Much Too fast") return result, status