diff --git a/github/Gist.py b/github/Gist.py new file mode 100644 index 00000000..6d029282 --- /dev/null +++ b/github/Gist.py @@ -0,0 +1,39 @@ +from GithubObject import * + +from NamedUser import NamedUser +from GistComment import GistComment + +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( gist._github, gist._github._dataRequest( "POST", gist._baseUrl() + "/fork", None, None ), lazy = True ) +Gist._addAttributePolicy( SeveralAttributePolicies( [ + MethodFromCallable( "create_fork", [], [], __createFork, ObjectTypePolicy( Gist ) ), + ], "Forking" ), +) diff --git a/github/GistComment.py b/github/GistComment.py new file mode 100644 index 00000000..ae493f7c --- /dev/null +++ b/github/GistComment.py @@ -0,0 +1,15 @@ +from GithubObject import * + +from NamedUser import NamedUser + +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(), +) diff --git a/github/GithubObjects.py b/github/GithubObjects.py index cc40170e..01619561 100644 --- a/github/GithubObjects.py +++ b/github/GithubObjects.py @@ -28,6 +28,8 @@ from PullRequest import PullRequest from RepositoryKey import RepositoryKey from Repository import Repository from Team import Team +from GistComment import GistComment +from Gist import Gist NamedUser._addAttributePolicy( ExternalListOfObjects( "orgs", "org", Organization, @@ -94,53 +96,6 @@ Repository._addAttributePolicy( ) ) -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( gist._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( [], [] ),