From 8a7ab941cd4e93e35abb6f0ee8a1c97f8fce7fff Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Sat, 25 Feb 2012 13:26:37 +0000 Subject: [PATCH] Repository.xxx_download --- IntegrationTest.py | 4 ++++ ReferenceOfApis.md | 8 ++++---- ReferenceOfClasses.md | 11 +++++++++++ github/GithubObjects.py | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/IntegrationTest.py b/IntegrationTest.py index 4ab77209..1cc34442 100644 --- a/IntegrationTest.py +++ b/IntegrationTest.py @@ -175,6 +175,9 @@ class IntegrationTest: i.create_comment( "Commented from PyGithub" ) + # Downloads + r.create_download( "MyDownloadCreatedByPyGithub", 1000 ) + self.dumpRepository( r ) def dumpUser( self, u, doPrivateThings ): @@ -215,6 +218,7 @@ class IntegrationTest: print " Watchers:", ", ".join( u.login for u in r.get_watchers() ) print " Forks:", ", ".join( f.owner.login + "/" + f.name for f in r.get_forks() ) print " Languages:", r.get_languages() + print " Downloads:", ", ".join( d.name for d in r.get_downloads() ) print " References:", ", ".join( ref.ref + " (" + ref.object[ "sha" ][ :7 ] + ")" for ref in r.get_git_refs() ) masterCommitSha = r.get_git_ref( "refs/heads/master" ).object[ "sha" ] masterCommit = r.get_git_commit( masterCommitSha ) diff --git a/ReferenceOfApis.md b/ReferenceOfApis.md index 84f6e27b..0909f86c 100644 --- a/ReferenceOfApis.md +++ b/ReferenceOfApis.md @@ -151,13 +151,13 @@ API `/repos/:user/:repo/contributors` API `/repos/:user/:repo/downloads` ================================== -* GET: (TODO SOON) -* POST: (TODO SOON) +* GET: `Repository.get_downloads()` list of `Download` +* POST: `Repository.create_download( ... )`: `Download` API `/repos/:user/:repo/downloads/:id` ====================================== -* GET: (TODO SOON) -* DELETE: (TODO SOON) +* GET: `Repository.get_download( id )`: `Download` +* DELETE: `Download.delete()` API `/repos/:user/:repo/events` =============================== diff --git a/ReferenceOfClasses.md b/ReferenceOfClasses.md index 65e234b6..8ced2155 100644 --- a/ReferenceOfClasses.md +++ b/ReferenceOfClasses.md @@ -156,6 +156,17 @@ Issues and milestones * `create_milestone( ... )`: `Milestone`: see [API](http://developer.github.com/v3/issues/milestones/#create-a-milestone) for parameters * `get_milestone( number )`: `Milestone` +Downloads +--------- +`Repository.get_downloads()` list of `Download` +`Repository.create_download( ... )`: `Download`: see [API](http://developer.github.com/v3/repos/downloads/#create-a-new-download-part-1-create-the-resource) +`Repository.get_download( id )`: `Download` + +Class `Download` +================ +* Attributes: see [API](http://developer.github.com/v3/repos/downloads/#get-a-single-download) +* `delete()` + Class `Label` ============= * Attributes: see [API](http://developer.github.com/v3/issues/labels/#get-a-single-label) diff --git a/github/GithubObjects.py b/github/GithubObjects.py index 5370e19e..74d57a85 100644 --- a/github/GithubObjects.py +++ b/github/GithubObjects.py @@ -186,6 +186,19 @@ Issue = GithubObject( ), ) +Download = GithubObject( + "Download", + BaseUrl( lambda obj: obj._repo._baseUrl + "/downloads/" + str( obj.id ) ), + InternalSimpleAttributes( + "url", "html_url", "id", "name", "description", "size", + "download_count", "content_type", "policy", "signature", "bucket", + "accesskeyid", "path", "acl", "expirationdate", "prefix", "mime_type", + "redirect", "s3_url", "created_at", + "_repo", ### Ugly hack + ), + Deletable(), +) + __modifyAttributesForObjectsReferingRepo = lambda obj, attributes: dict( itertools.chain( attributes.iteritems(), { "_repo": obj }.iteritems() ) ) Repository = GithubObject( "Repository", @@ -242,6 +255,11 @@ Repository = GithubObject( ElementCreatable( "issue", [ "title" ], [ "body", "assignee", "milestone", "labels", ], __modifyAttributesForObjectsReferingRepo ) ), ExternalSimpleAttribute( "languages" ), + ExternalListOfObjects( "downloads", Download, + ListGetable( [], [], __modifyAttributesForObjectsReferingRepo ), + ElementGetable( "download", lambda repo, id : { "_repo": repo, "number": number } ), + ElementCreatable( "download", [ "name", "size" ], [ "description", "content_type" ], __modifyAttributesForObjectsReferingRepo ), + ) ) Repository._addAttributePolicy( InternalObjectAttribute( "parent", Repository ) ) Repository._addAttributePolicy( InternalObjectAttribute( "source", Repository ) )