ListOfObjects

This commit is contained in:
Vincent Jacques
2012-02-16 22:20:51 +01:00
parent 8800d4f641
commit 7c6574db4f
2 changed files with 68 additions and 0 deletions
+24
View File
@@ -103,6 +103,12 @@ class ListOfReferences:
if self.__hasName is not None:
cls._addMethod( self.__hasName, self.__executeHas )
def __executeGet( self, obj ):
return [
self.__type( obj._github, attributes, lazy = True )
for attributes in obj._github._dataRequest( "GET", obj._baseUrl + "/" + self.__attributeName )
]
def __executeAdd( self, obj, toBeAdded ):
assert( isinstance( toBeAdded, self.__type ) )
obj._github._statusRequest( "PUT", obj._baseUrl + "/" + self.__attributeName + "/" + toBeAdded._identity )
@@ -115,12 +121,30 @@ class ListOfReferences:
assert( isinstance( toBeQueried, self.__type ) )
return obj._github._statusRequest( "GET", obj._baseUrl + "/" + self.__attributeName + "/" + toBeQueried._identity ) == 204
class ListOfObjects:
def __init__( self, attributeName, type, creatable = False ):
self.__attributeName = attributeName
self.__type = type
self.__getName = "get_" + attributeName
if creatable:
self.__createName = "create_" + attributeName
else:
self.__createName = None
def apply( self, cls ):
cls._addMethod( self.__getName, self.__executeGet )
if self.__createName is not None:
cls._addMethod( self.__createName, self.__executeCreate )
def __executeGet( self, obj ):
return [
self.__type( obj._github, attributes, lazy = True )
for attributes in obj._github._dataRequest( "GET", obj._baseUrl + "/" + self.__attributeName )
]
def __executeCreate( self, obj, **data ):
return self.__type( obj._github, obj._github._dataRequest( "POST", obj._baseUrl + "/" + self.__attributeName, data ), lazy = True )
class Editable:
def __init__( self, mandatoryParameters, optionalParameters ):
self.__mandatoryParameters = mandatoryParameters