mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-02 03:41:08 +00:00
Gists
This commit is contained in:
@@ -521,3 +521,72 @@ Repository._addAttributePolicy(
|
||||
ListGetable( [], [] )
|
||||
)
|
||||
)
|
||||
|
||||
GistComment = GithubObject(
|
||||
"GistComment",
|
||||
BaseUrl( lambda obj: "/gists/comments/" + str( obj.id ) ),
|
||||
InternalSimpleAttributes(
|
||||
"id", "url", "body", "created_at",
|
||||
"updated_at",
|
||||
),
|
||||
InternalObjectAttribute( "user", NamedUser ),
|
||||
Editable( [ "body" ], [] ),
|
||||
Deletable(),
|
||||
)
|
||||
|
||||
def __isStarred( gist ):
|
||||
return gist._github._statusRequest( "GET", gist._baseUrl + "/star", None, None ) == 204
|
||||
def __setStarred( gist ):
|
||||
gist._github._statusRequest( "PUT", gist._baseUrl + "/star", None, None )
|
||||
def __resetStarred( gist ):
|
||||
gist._github._statusRequest( "DELETE", gist._baseUrl + "/star", None, None )
|
||||
Gist = GithubObject(
|
||||
"Gist",
|
||||
BaseUrl( lambda obj: "/gists/" + str( obj.id ) ),
|
||||
InternalSimpleAttributes(
|
||||
"url", "id", "description", "public", "files", "comments", "html_url",
|
||||
"git_pull_url", "git_push_url", "created_at", "forks", "history",
|
||||
"updated_at",
|
||||
),
|
||||
InternalObjectAttribute( "user", NamedUser ),
|
||||
Editable( [], [ "description", "files" ] ),
|
||||
Deletable(),
|
||||
ExternalListOfObjects( "comments", "comment", GistComment,
|
||||
ListGetable( [], [] ),
|
||||
ElementGetable( [ "id" ], [] ),
|
||||
ElementCreatable( [ "body" ], [] ),
|
||||
),
|
||||
SeveralAttributePolicies( [
|
||||
MethodFromCallable( "is_starred", [], [], __isStarred, SimpleTypePolicy( "bool" ) ),
|
||||
MethodFromCallable( "set_starred", [], [], __setStarred, SimpleTypePolicy( None ) ),
|
||||
MethodFromCallable( "reset_starred", [], [], __resetStarred, SimpleTypePolicy( None ) ),
|
||||
], "Starring" ),
|
||||
)
|
||||
def __createFork( gist ):
|
||||
return Gist( gitst._github, gist._github._dataRequest( "POST", gist._baseUrl + "/fork", None, None ), lazy = True )
|
||||
Gist._addAttributePolicy( SeveralAttributePolicies( [
|
||||
MethodFromCallable( "create_fork", [], [], __createFork, ObjectTypePolicy( Gist ) ),
|
||||
], "Forking" ),
|
||||
)
|
||||
|
||||
NamedUser._addAttributePolicy(
|
||||
ExternalListOfObjects( "gists", "gist", Gist,
|
||||
ListGetable( [], [] ),
|
||||
)
|
||||
)
|
||||
|
||||
AuthenticatedUser._addAttributePolicy(
|
||||
ExternalListOfObjects( "gists", "gist", Gist,
|
||||
ListGetable( [], [] ),
|
||||
ElementCreatable( [ "public", "files", ], [ "description" ] ),
|
||||
url = "/gists",
|
||||
)
|
||||
)
|
||||
def __getStaredGists( user ):
|
||||
return [
|
||||
Gist( user._github, attributes, lazy = True )
|
||||
for attributes in user._github._dataRequest( "GET", "/gists/starred", None, None )
|
||||
]
|
||||
AuthenticatedUser._addAttributePolicy(
|
||||
MethodFromCallable( "get_starred_gists", [], [], __getStaredGists, SimpleTypePolicy( "list of `Gist`" ) ),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user