diff --git a/IntegrationTest.py b/IntegrationTest.py index e4582233..033b0954 100644 --- a/IntegrationTest.py +++ b/IntegrationTest.py @@ -72,7 +72,7 @@ class ReplayingHttpsConnection: self.__file.readline() expectation = self.__file.readline().strip() if expectation != verb + " " + url + " " + str( headers ) + " " + input: - print expectation, "!=", verb + " " + url + " " + str( headers ) + " " + input + print "Expected [", expectation, "] but got [", verb + " " + url + " " + str( headers ) + " " + input, "]" raise RecordReplayException( "This test has been changed since last record. Please re-run this script with argument '--record'" ) def getresponse( self ): @@ -335,7 +335,6 @@ class IntegrationTest: t.delete() self.printList( "Teams", o.get_teams(), lambda t: t.name ) - # @todo Custom url /events instead of /user/events def testEvents( self ): self.printList( "User events", self.g.get_user( self.cobayeUser ).get_events(), lambda e: e.type ) self.printList( "User public events", self.g.get_user( self.cobayeUser ).get_public_events(), lambda e: e.type ) @@ -366,37 +365,37 @@ class IntegrationTest: self.printList( "Followers", u.get_followers(), lambda f: f.login ) # @todo custom url /gists instead of /user/gists - # def testGists( self ): - # u = self.g.get_user() - # self.printList( "Gists", u.get_gists(), lambda g: g.description ) - # g = u.create_gist( public = True, description = "Gist created by PyGithub", files = { "foo.bar": { "content": "This gist was created by PyGithub" } } ) - # self.printList( "Gists", u.get_gists(), lambda g: g.description ) - # g.edit( description = "Gist edited by PyGithub" ) - # self.printList( "Gists", u.get_gists(), lambda g: g.description ) + def testGists( self ): + u = self.g.get_user() + self.printList( "Gists", u.get_gists(), lambda g: g.description ) + g = u.create_gist( public = True, description = "Gist created by PyGithub", files = { "foo.bar": { "content": "This gist was created by PyGithub" } } ) + self.printList( "Gists", u.get_gists(), lambda g: g.description ) + g.edit( description = "Gist edited by PyGithub" ) + self.printList( "Gists", u.get_gists(), lambda g: g.description ) - # self.printList( "Starred gists", u.get_starred_gists(), lambda g: g.description ) - # g.set_starred() - # assert g.is_starred() - # self.printList( "Starred gists", u.get_starred_gists(), lambda g: g.description ) - # g.reset_starred() - # self.printList( "Starred gists", u.get_starred_gists(), lambda g: g.description ) + self.printList( "Starred gists", u.get_starred_gists(), lambda g: g.description ) + g.set_starred() + assert g.is_starred() + self.printList( "Starred gists", u.get_starred_gists(), lambda g: g.description ) + g.reset_starred() + self.printList( "Starred gists", u.get_starred_gists(), lambda g: g.description ) - # self.printList( "Gist comments", g.get_comments(), lambda c: c.body ) - # c = g.create_comment( "Comment created by PyGithub" ) - # self.printList( "Gist comments", g.get_comments(), lambda c: c.body ) - # c.edit( "Comment edited by PyGithub" ) - # self.printList( "Gist comments", g.get_comments(), lambda c: c.body ) - # sameComment = g.get_comment( c.id ) - # c.delete() - # self.printList( "Gist comments", g.get_comments(), lambda c: c.body ) + self.printList( "Gist comments", g.get_comments(), lambda c: c.body ) + c = g.create_comment( "Comment created by PyGithub" ) + self.printList( "Gist comments", g.get_comments(), lambda c: c.body ) + c.edit( "Comment edited by PyGithub" ) + self.printList( "Gist comments", g.get_comments(), lambda c: c.body ) + sameComment = g.get_comment( c.id ) + c.delete() + self.printList( "Gist comments", g.get_comments(), lambda c: c.body ) - # otherGist = self.g.get_gist( 1965703 ).create_fork() # Origin gist picked up randomly - # self.printList( "Gists", u.get_gists(), lambda g: g.description or "None" ) - # otherGist.delete() - # self.printList( "Gists", u.get_gists(), lambda g: g.description ) + otherGist = self.g.get_gist( 1965703 ).create_fork() # Origin gist picked up randomly + self.printList( "Gists", u.get_gists(), lambda g: g.id ) + otherGist.delete() + self.printList( "Gists", u.get_gists(), lambda g: g.description ) - # g.delete() - # self.printList( "Gists", u.get_gists(), lambda g: g.description ) + g.delete() + self.printList( "Gists", u.get_gists(), lambda g: g.description ) def testGistsAll( self ): self.printList( "Gists", self.g.get_gists(), lambda g: g.description ) diff --git a/JsonDescriptionOfGithubApiV3/description.000.human_readable.json b/JsonDescriptionOfGithubApiV3/description.000.human_readable.json index cefa7daf..5226b55f 100644 --- a/JsonDescriptionOfGithubApiV3/description.000.human_readable.json +++ b/JsonDescriptionOfGithubApiV3/description.000.human_readable.json @@ -95,7 +95,13 @@ ] }, "getElement": { - "parameter": { "name": "name", "type": "string" } + "parameter": { "name": "name", "type": "string" }, + "url": [ + { "type": "constant", "value": "https://api.github.com/repos/" }, + { "type": "attribute", "value": [ "login" ] }, + { "type": "constant", "value": "/" }, + { "type": "argument", "value": [ "name" ] } + ] }, "createElement": { "mandatoryParameters": [ @@ -163,7 +169,10 @@ "optionalParameters": [ { "name": "description", "type": "string" } ] - } + }, + "url": [ + { "type": "constant", "value": "https://api.github.com/gists" } + ] } ], "additionalMethods": [ @@ -207,7 +216,14 @@ { "name": [ "get", "starred", "gists" ], "group": "gists", - "type": "list:Gist" + "type": "list:Gist", + "request": { + "verb": "GET", + "url": [ + { "type": "constant", "value": "https://api.github.com/gists/starred" } + ], + "information": "status" + } } ] }, @@ -381,7 +397,11 @@ "type": "GistComment", "getList": true, "getElement": { - "parameter": { "name": "id", "type": "@todo" } + "parameter": { "name": "id", "type": "@todo" }, + "url": [ + { "type": "constant", "value": "https://api.github.com/gists/comments/" }, + { "type": "argument", "value": [ "id" ] } + ] }, "createElement": { "mandatoryParameters": [ @@ -394,22 +414,54 @@ { "name": [ "is", "starred" ], "group": "starring", - "type": "bool" + "type": "bool", + "request": { + "verb": "GET", + "url": [ + { "type": "attribute", "value": [ "url" ] }, + { "type": "constant", "value": "/star" } + ], + "information": "status" + } }, { "name": [ "reset", "starred" ], "group": "starring", - "type": "void" + "type": "void", + "request": { + "verb": "DELETE", + "url": [ + { "type": "attribute", "value": [ "url" ] }, + { "type": "constant", "value": "/star" } + ], + "information": "status" + } }, { "name": [ "set", "starred" ], "group": "starring", - "type": "void" + "type": "void", + "request": { + "verb": "PUT", + "url": [ + { "type": "attribute", "value": [ "url" ] }, + { "type": "constant", "value": "/star" } + ], + "information": "status" + } }, { "name": [ "create", "fork" ], "group": "forking", - "type": "Gist" + "type": "Gist", + "request": { + "verb": "POST", + "url": [ + { "type": "attribute", "value": [ "url" ] }, + { "type": "constant", "value": "/fork" } + ], + "information": "status" + } } ] }, @@ -753,7 +805,13 @@ ] }, "getElement": { - "parameter": { "name": "name", "type": "string" } + "parameter": { "name": "name", "type": "string" }, + "url": [ + { "type": "constant", "value": "https://api.github.com/repos/" }, + { "type": "attribute", "value": [ "login" ] }, + { "type": "constant", "value": "/" }, + { "type": "argument", "value": [ "name" ] } + ] } }, { @@ -895,7 +953,13 @@ ] }, "getElement": { - "parameter": { "name": "name", "type": "string" } + "parameter": { "name": "name", "type": "string" }, + "url": [ + { "type": "constant", "value": "https://api.github.com/repos/" }, + { "type": "attribute", "value": [ "login" ] }, + { "type": "constant", "value": "/" }, + { "type": "argument", "value": [ "name" ] } + ] }, "createElement": { "mandatoryParameters": [ diff --git a/JsonDescriptionOfGithubApiV3/description.001.normalized.json b/JsonDescriptionOfGithubApiV3/description.001.normalized.json index af44c348..ad8ec0c1 100644 --- a/JsonDescriptionOfGithubApiV3/description.001.normalized.json +++ b/JsonDescriptionOfGithubApiV3/description.001.normalized.json @@ -1374,15 +1374,9 @@ ], "request": { "url": [ - { - "type": "attribute", - "value": [ - "url" - ] - }, { "type": "constant", - "value": "/gists" + "value": "https://api.github.com/gists" } ], "information": "status", @@ -1415,15 +1409,9 @@ "mandatoryParameters": [], "request": { "url": [ - { - "type": "attribute", - "value": [ - "url" - ] - }, { "type": "constant", - "value": "/gists" + "value": "https://api.github.com/gists" } ], "information": "data", @@ -1554,6 +1542,16 @@ "gists" ], "mandatoryParameters": [], + "request": { + "url": [ + { + "type": "constant", + "value": "https://api.github.com/gists/starred" + } + ], + "information": "status", + "verb": "GET" + }, "isMutation": false, "optionalParameters": [], "type": { @@ -2633,19 +2631,9 @@ ], "request": { "url": [ - { - "type": "attribute", - "value": [ - "url" - ] - }, { "type": "constant", - "value": "/comments" - }, - { - "type": "constant", - "value": "/" + "value": "https://api.github.com/gists/comments/" }, { "type": "argument", @@ -2703,6 +2691,22 @@ "starred" ], "mandatoryParameters": [], + "request": { + "url": [ + { + "type": "attribute", + "value": [ + "url" + ] + }, + { + "type": "constant", + "value": "/star" + } + ], + "information": "status", + "verb": "GET" + }, "isMutation": false, "optionalParameters": [], "type": { @@ -2718,6 +2722,22 @@ "starred" ], "mandatoryParameters": [], + "request": { + "url": [ + { + "type": "attribute", + "value": [ + "url" + ] + }, + { + "type": "constant", + "value": "/star" + } + ], + "information": "status", + "verb": "DELETE" + }, "isMutation": false, "optionalParameters": [], "type": { @@ -2733,6 +2753,22 @@ "starred" ], "mandatoryParameters": [], + "request": { + "url": [ + { + "type": "attribute", + "value": [ + "url" + ] + }, + { + "type": "constant", + "value": "/star" + } + ], + "information": "status", + "verb": "PUT" + }, "isMutation": false, "optionalParameters": [], "type": { @@ -2748,6 +2784,22 @@ "fork" ], "mandatoryParameters": [], + "request": { + "url": [ + { + "type": "attribute", + "value": [ + "url" + ] + }, + { + "type": "constant", + "value": "/fork" + } + ], + "information": "status", + "verb": "POST" + }, "isMutation": false, "optionalParameters": [], "type": { diff --git a/JsonDescriptionOfGithubApiV3/normalize.py b/JsonDescriptionOfGithubApiV3/normalize.py index 93def005..5844b26a 100644 --- a/JsonDescriptionOfGithubApiV3/normalize.py +++ b/JsonDescriptionOfGithubApiV3/normalize.py @@ -72,7 +72,7 @@ class Function: def __init__( self, desc, *additionalDescs ): for additionalDesc in additionalDescs: desc.update( additionalDesc ) - checkKeys( desc, [ "name", "type", "group" ], [ "isMutation", "mandatoryParameters", "optionalParameters", "variadicParameter", "parameter", "request" ] ) # @todo Move request to mandatoryKeys + checkKeys( desc, [ "name", "type", "group" ], [ "url", "isMutation", "mandatoryParameters", "optionalParameters", "variadicParameter", "parameter", "request" ] ) # @todo Move request to mandatoryKeys self.name = desc[ "name" ] self.type = Type( desc[ "type" ] ) @@ -169,37 +169,24 @@ class Collection: assert desc[ "deleteList" ] is True self.methods.append( Function( { "name": [ "delete" ] + name, "type": "void", "group": desc[ "name" ] } ) ) if "getElement" in desc: - - # @todo Generalize - if desc[ "name" ] == "repos": - hack = { - "request": { - "verb": "GET", - "url": [ - { "type": "constant", "value": "https://api.github.com/repos/" }, - { "type": "attribute", "value": [ "login" ] }, - { "type": "constant", "value": "/" }, - { "type": "argument", "value": [ "name" ] }, - ], - "information": "data", - } - } + if "url" in desc[ "getElement" ]: + urlForGetElement = desc[ "getElement" ][ "url" ] else: - hack = { - "request": { - "verb": "GET", - "url": self.__url + [ - { "type": "constant", "value": "/" }, - { "type": "argument", "value": [ desc[ "getElement" ][ "parameter" ][ "name" ] ] }, - ], - "information": "data", - } - } + urlForGetElement = self.__url + [ + { "type": "constant", "value": "/" }, + { "type": "argument", "value": [ desc[ "getElement" ][ "parameter" ][ "name" ] ] }, + ] self.methods.append( Function( desc[ "getElement" ], { "name": [ "get", desc[ "singularName" ] ], "type": desc[ "type" ], "group": desc[ "name" ], "mandatoryParameters": [ desc[ "getElement" ][ "parameter" ] ] }, - hack + { + "request": { + "verb": "GET", + "url": urlForGetElement, + "information": "data", + } + } ) ) if "getList" in desc: self.methods.append( Function( diff --git a/github/Github.py b/github/Github.py index f5165cbf..1eaae474 100644 --- a/github/Github.py +++ b/github/Github.py @@ -31,7 +31,11 @@ class Github: return GithubObjects.Organization.Organization( self.__requester, attributes, lazy = False ) def get_gist( self, id ): - return GithubObjects.Gist.Gist( self.__requester, { "id": id }, lazy = False ) + attributes = { + "url": "https://api.github.com/gists/" + str( id ), + "id": id, + } + return GithubObjects.Gist.Gist( self.__requester, attributes, lazy = False ) def get_gists( self ): status, headers, data = self.__requester.request( "GET", "https://api.github.com/gists/public", None, None ) diff --git a/github/GithubObjects/AuthenticatedUser.py b/github/GithubObjects/AuthenticatedUser.py index 431b7bda..18a69ff2 100644 --- a/github/GithubObjects/AuthenticatedUser.py +++ b/github/GithubObjects/AuthenticatedUser.py @@ -210,7 +210,7 @@ class AuthenticatedUser( object ): post_parameters[ "description" ] = description status, headers, data = self.__requester.request( "POST", - str( self.url ) + "/gists", + "https://api.github.com/gists", None, post_parameters ) @@ -357,7 +357,7 @@ class AuthenticatedUser( object ): def get_gists( self ): status, headers, data = self.__requester.request( "GET", - str( self.url ) + "/gists", + "https://api.github.com/gists", None, None ) @@ -457,7 +457,18 @@ class AuthenticatedUser( object ): ) def get_starred_gists( self ): - pass + status, headers, data = self.__requester.request( + "GET", + "https://api.github.com/gists/starred", + None, + None + ) + return PaginatedList.PaginatedList( + Gist.Gist, + self.__requester, + headers, + data + ) def get_watched( self ): status, headers, data = self.__requester.request( diff --git a/github/GithubObjects/Gist.py b/github/GithubObjects/Gist.py index 0d3831cc..c3ec1533 100644 --- a/github/GithubObjects/Gist.py +++ b/github/GithubObjects/Gist.py @@ -103,7 +103,13 @@ class Gist( object ): return GistComment.GistComment( self.__requester, data, lazy = True ) def create_fork( self ): - pass + status, headers, data = self.__requester.request( + "POST", + str( self.url ) + "/fork", + None, + None + ) + return Gist( self.__requester, data, lazy = True ) def delete( self ): status, headers, data = self.__requester.request( @@ -131,7 +137,7 @@ class Gist( object ): def get_comment( self, id ): status, headers, data = self.__requester.request( "GET", - str( self.url ) + "/comments" + "/" + str( id ), + "https://api.github.com/gists/comments/" + str( id ), None, None ) @@ -152,13 +158,29 @@ class Gist( object ): ) def is_starred( self ): - pass + status, headers, data = self.__requester.request( + "GET", + str( self.url ) + "/star", + None, + None + ) + return status == 204 def reset_starred( self ): - pass + status, headers, data = self.__requester.request( + "DELETE", + str( self.url ) + "/star", + None, + None + ) def set_starred( self ): - pass + status, headers, data = self.__requester.request( + "PUT", + str( self.url ) + "/star", + None, + None + ) def __initAttributes( self ): self.__comments = None