<s> from Mollie . API . Client import * <EOL> from Mollie . API . Error import * <EOL> from Mollie . API . Object import * <EOL> import json <EOL> class Base ( object ) : <EOL> REST_CREATE = Client . HTTP_POST <EOL> REST_UPDATE = Client . HTTP_POST <EOL> REST_READ = Client . HTTP_GET <EOL> REST_LIST = Client . HTTP_GET <EOL> REST_DELETE = Client . HTTP_DELETE <EOL> DEFAULT_LIMIT = <NUM_LIT:10> <EOL> def __init__ ( self , client ) : <EOL> self . client = client <EOL> def getResourceObject ( self , result ) : <EOL> raise NotImplementedError ( ) <EOL> def getResourceName ( self ) : <EOL> return self . __class__ . __name__ . lower ( ) <EOL> def rest_create ( self , data , params = None ) : <EOL> path = self . getResourceName ( ) <EOL> result = self . performApiCall ( self . REST_CREATE , path , data , params ) <EOL> return self . getResourceObject ( result ) <EOL> def rest_read ( self , resource_id , params = None ) : <EOL> path = self . getResourceName ( ) + '<STR_LIT:/>' + str ( resource_id ) <EOL> result = self . performApiCall ( self . REST_READ , path , None , params ) <EOL> return self . getResourceObject ( result ) <EOL> def rest_update ( self , resource_id , data , params = None ) : <EOL> path = self . getResourceName ( ) + '<STR_LIT:/>' + str ( resource_id ) <EOL> result = self . performApiCall ( self . REST_UPDATE , path , data , params ) <EOL> return self . getResourceObject ( result ) <EOL> def rest_delete ( self , resource_id , params = None ) : <EOL> path = self . getResourceName ( ) + '<STR_LIT:/>' + str ( resource_id ) <EOL> return self . performApiCall ( self . REST_DELETE , path , None , params ) <EOL> def rest_list ( self , params = None ) : <EOL> path = self . getResourceName ( ) <EOL> result = self . performApiCall ( self . REST_LIST , path , None , params ) <EOL> return List ( result , self . getResourceObject ( { } ) . __class__ ) <EOL> def create ( self , data ) : <EOL> try : <EOL> data = json . dumps ( data ) <EOL> except Exception as e : <EOL> raise Error ( '<STR_LIT>' % e . message ) <EOL> return self . rest_create ( data ) <EOL> def get ( self , resource_id ) : <EOL> return self . rest_read ( resource_id ) <EOL> def update ( self , resource_id , data ) : <EOL> try : <EOL> data = json . dumps ( data ) <EOL> except Exception as e : <EOL> raise Error ( '<STR_LIT>' % e . message ) <EOL> return self . rest_update ( resource_id , data ) <EOL> def delete ( self , resource_id ) : <EOL> return self . rest_delete ( resource_id ) <EOL> def all ( self , offset = <NUM_LIT:0> , count = DEFAULT_LIMIT ) : <EOL> return self . rest_list ( { <EOL> '<STR_LIT>' : offset , <EOL> '<STR_LIT:count>' : count <EOL> } ) <EOL> def performApiCall ( self , http_method , path , data = None , params = None ) : <EOL> body = self . client . performHttpCall ( http_method , path , data , params ) <EOL> try : <EOL> result = body . json ( ) <EOL> except Exception as e : <EOL> raise Error ( '<STR_LIT>' % body ) <EOL> if '<STR_LIT:error>' in result : <EOL> error = Error ( '<STR_LIT>' % ( result [ '<STR_LIT:error>' ] [ '<STR_LIT:type>' ] , result [ '<STR_LIT:error>' ] [ '<STR_LIT:message>' ] ) ) <EOL> if '<STR_LIT>' in result [ '<STR_LIT:error>' ] : <EOL> error . field = result [ '<STR_LIT:error>' ] [ '<STR_LIT>' ] <EOL> raise error <EOL> return result </s>
