def is_gist_starred(self, gist_id): url = f"/gists/{gist_id}/star" code = Response(self.delete(url), "").status_code if code == 204: return True elif code == 404: return False else: raise ErrorAPICode( f"The url:{url} returned status code: {code}. Maybe try after sometime?" )
def is_gist_starred(self, gist_id): url = "/gists/{gist_id}/star".format(gist_id=gist_id) code = Response(self.get(url), "").status_code if code == 204: return True elif code == 404: return False else: raise ErrorAPICode( "The url:{url} returned status code: {code}. Maybe try after sometime?".format( url=url, code=code ) )
def is_starred(self, owner, repo, **kwargs): url = "/user/starred/{owner}/{repo}".format(owner=owner, repo=repo) self.response = Response(self.get(url, **kwargs), "") status_code = self.response.status_code if status_code == 204: is_starred = True elif status_code == 404: is_starred = False else: raise ErrorAPICode( "url: {url} supposed to return 204 or 404 but returned {status_code}." "Maybe try after sometime?".format(url=url, status_code=status_code)) return is_starred
def is_starred(self, owner, repo): url = f"/user/starred/{owner}/{repo}" self.response = Response(self.get(url), "") status_code = self.response.status_code if status_code == 204: is_starred = True elif status_code == 404: is_starred = False else: raise ErrorAPICode( f"url: {url} supposed to return 204 or 404 but returned {status_code}." f"Maybe try after sometime?" ) return is_starred
def user_is_following(self, username, target_user): url = f"/users/{username}/following/{target_user}" self.response = Response( self.get( url, **{ "Accept": "application/vnd.github.giant-sentry-fist-preview+json" }, ), "", ) if self.response.status_code == 204: return True elif self.response.status_code == 404: return False else: raise ErrorAPICode( f"API has returned an Unexpected response code - {self.response.status_code}." f"It should either be 204 or 404.")
def is_following(self, username): url = "/users/following/{username}".format(username=username) self.response = Response( self.get( url, **{ "Accept": "application/vnd.github.giant-sentry-fist-preview+json" }, ), "", ) if self.response.status_code == 204: return True elif self.response.status_code == 404: return False else: raise ErrorAPICode( "API has returned an Unexpected response code - {status_code}." "It should either be 204 or 404.".format( status_code=self.response.status_code))
def unblock(self, username): """ Unblock a user """ url = f"/user/blocks/{username}" self.response = Response( self.delete( url, **{"Accept": "application/vnd.github.giant-sentry-fist-preview+json"}, ), "", ) if self.response.status_code == 204: return True elif self.response.status_code == 404: return False else: raise ErrorAPICode( f"API has returned an Unexpected response code - {self.response.status_code}." f"It should either be 204 or 404." )
def follow(self, username): url = f"/user/following/{username}" self.response = Response( self.put( url, **{ "Accept": "application/vnd.github.giant-sentry-fist-preview+json", "Content-Length": "0", }, ), "", ) if self.response.status_code == 204: return True elif self.response.status_code == 404: return False else: raise ErrorAPICode( f"API has returned an Unexpected response code - {self.response.status_code}." f"It should either be 204 or 404.")