From 77ed2308a832248ac4b0e56a1af438287f27c0bf Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Sat, 25 Feb 2012 13:00:26 +0000 Subject: [PATCH] Repository.get_languages --- IntegrationTest.py | 1 + ReferenceOfApis.md | 2 +- ReferenceOfClasses.md | 1 + github/GithubObject.UnitTest.py | 12 ++++++++++++ github/GithubObject.py | 3 +++ github/GithubObjects.py | 1 + github/ObjectCapacities/Basic.py | 14 ++++++++++++++ 7 files changed, 33 insertions(+), 1 deletion(-) diff --git a/IntegrationTest.py b/IntegrationTest.py index 0410d806..4ab77209 100644 --- a/IntegrationTest.py +++ b/IntegrationTest.py @@ -214,6 +214,7 @@ class IntegrationTest: print " Contributors:", ", ".join( u.login for u in r.get_contributors() ) 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 " 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 40056d92..774b98c5 100644 --- a/ReferenceOfApis.md +++ b/ReferenceOfApis.md @@ -301,7 +301,7 @@ API `/repos/:user/:repo/labels/:id` API `/repos/:user/:repo/languages` ================================== -* GET: (TODO SOON) +* GET: `Repository.get_languages()`: dictionary of strings to integers API `/repos/:user/:repo/milestones` =================================== diff --git a/ReferenceOfClasses.md b/ReferenceOfClasses.md index 671947cc..65e234b6 100644 --- a/ReferenceOfClasses.md +++ b/ReferenceOfClasses.md @@ -105,6 +105,7 @@ Class `Repository` ================== * Attributes: see [API](http://developer.github.com/v3/repos/#get) * `edit( ... )`: see [API](http://developer.github.com/v3/repos/#edit) for parameters +* `get_languages()`: dictionary of strings to integers Collaborators ------------- diff --git a/github/GithubObject.UnitTest.py b/github/GithubObject.UnitTest.py index 53b5ddca..10e38b65 100644 --- a/github/GithubObject.UnitTest.py +++ b/github/GithubObject.UnitTest.py @@ -432,6 +432,18 @@ class GithubObjectWithMultiCapacityExternalListOfSimpleTypes( TestCaseWithGithub def myCallable( obj, mock, arg ): return mock.call( arg ) +class GithubObjectWithExternalSimpleAttribute( TestCaseWithGithubTestObject ): + GithubTestObject = GithubObject( + "GithubTestObject", + BaseUrl( lambda obj: "/test" ), + InternalSimpleAttributes( "a1", "a2" ), + ExternalSimpleAttribute( "a3" ) + ) + + def testCallMethod( self ): + self.expectDataGet( "/test/a3" ).andReturn( 72 ) + self.assertEqual( self.o.get_a3(), 72 ) + class GithubObjectWithMethodFromCallable( TestCaseWithGithubTestObject ): GithubTestObject = GithubObject( "GithubTestObject", diff --git a/github/GithubObject.py b/github/GithubObject.py index 77d55049..71e44855 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -17,6 +17,9 @@ def InternalSimpleAttributes( *attributeNames ): def InternalObjectAttribute( attributeName, type ): return InternalAttribute( attributeName, ObjectTypePolicy( type ) ) +def ExternalSimpleAttribute( attributeName ): + return ExternalAttribute( attributeName, SimpleTypePolicy() ) + def BaseUrl( baseUrl ): return AttributeFromCallable( "_baseUrl", baseUrl ) diff --git a/github/GithubObjects.py b/github/GithubObjects.py index 7e9c1de4..5370e19e 100644 --- a/github/GithubObjects.py +++ b/github/GithubObjects.py @@ -241,6 +241,7 @@ Repository = GithubObject( ElementGetable( "issue", lambda repo, number: { "_repo": repo, "number": number } ), ElementCreatable( "issue", [ "title" ], [ "body", "assignee", "milestone", "labels", ], __modifyAttributesForObjectsReferingRepo ) ), + ExternalSimpleAttribute( "languages" ), ) Repository._addAttributePolicy( InternalObjectAttribute( "parent", Repository ) ) Repository._addAttributePolicy( InternalObjectAttribute( "source", Repository ) ) diff --git a/github/ObjectCapacities/Basic.py b/github/ObjectCapacities/Basic.py index c34b0f1f..e63508df 100644 --- a/github/ObjectCapacities/Basic.py +++ b/github/ObjectCapacities/Basic.py @@ -55,6 +55,20 @@ class InternalAttribute: def apply( self, cls ): cls._addAttribute( self.__attributeName, InternalAttribute.AttributeDefinition( self.__typePolicy ) ) +class ExternalAttribute: + def __init__( self, attributeName, typePolicy ): + self.__attributeName = attributeName + self.__typePolicy = typePolicy + + def apply( self, cls ): + cls._addMethod( "get_" + self.__attributeName, self.__execute ) + + def __execute( self, obj ): + return self.__typePolicy.createLazy( + obj, + obj._github._dataRequest( "GET", obj._baseUrl + "/" + self.__attributeName, None, None ) + ) + class SeveralAttributePolicies: def __init__( self, attributePolicies ): self.__attributePolicies = attributePolicies