def update(self: T, name: Optional[str] = None, am_type: Optional[AMType] = None, parent: Optional[T] = None, description: Optional[str] = None, denomination: Optional[Denomination] = None, counterparty: Optional[Entity] = None, color: Optional[Color] = None) -> 'Account': """ Update this Account with new metadata. """ arguments = Account.UpdateArguments(self, name, am_type, parent, description, denomination, counterparty, color) data = DataPackage.from_object(arguments) parameters = UrlParameters(entity_id=self.entity.id_) request = ApiRequest(path=Account._PATH, method=HTTPMethod.PUT, credentials=self.entity.session, data=data, url_parameters=parameters) account = Account._decode(self.entity, request.response_data) if account.id_ != self.id_: raise ApiError('Returned Account ID does not match request ID') return account
def create(cls: Type[T], entity: Entity, name: str, am_type: AMType, denomination: Denomination, description: Optional[str] = None, parent: Optional[T] = None, counter_party: Optional[Entity] = None, color: Optional[Color] = None) -> T: arguments = Account.CreateArguments(name, description, am_type, parent, denomination, counter_party, color) data = DataPackage.from_object(arguments) parameters = UrlParameters(entity_id=entity.id_) request = ApiRequest(path=Account._PATH, method=HTTPMethod.POST, credentials=entity.session, data=data, url_parameters=parameters) account = cls._decode(entity, request.response_data) return account
def update( self, name: Optional[str] = None, description: Optional[str] = None, owner: Optional[User] = None, permissions_graph: Optional[PermissionsGraph] = None) -> 'Entity': """ Modify data describing this Entity. Returns this Entity, the Entity instance is not modified in place. """ owner_id = None if owner is not None: owner_id = owner.id_ update_arguments = Entity.UpdateArguments( self, name=name, description=description, owner_id=owner_id, permissions_graph=permissions_graph) data_package = DataPackage.from_object(data=update_arguments) request = ApiRequest(path=Entity.PATH, method=HTTPMethod.PUT, credentials=self._session, data=data_package, url_parameters=None) updated_entity = Entity.decode(request.response_data, self.session) return updated_entity
def create( cls: Type[T], entity: Entity, name: str, code: str, exponent: int, description: Optional[str] = None, priority: Optional[int] = None ) -> T: arguments = CustomUnit.CreationArguments( code, name, exponent, priority, description ) parameters = UrlParameters(entity_id=entity.id_) request = ApiRequest( path=CustomUnit._PATH, credentials=entity.session, method=HTTPMethod.POST, data=DataPackage.from_object(arguments), url_parameters=parameters ) return CustomUnit._decode(entity, request.response_data)
def retrieve(cls: Type[T], entity: Entity, account: Account, order: LedgerOrder = LedgerOrder.YOUNGEST_FIRST, page: int = 1, start_time: Optional[datetime] = None, end_time: Optional[datetime] = None, denomination: Optional[Denomination] = None) -> T: """ Retrieve a Ledger for the supplied account. Optionally specify order, page, denomination, start time, and end time. """ if not isinstance(entity, Entity): raise TypeError('entity must be of type `Entity`') arguments = Ledger.RetrieveArguments(account, order, page, start_time, end_time, denomination) data = DataPackage(object_data=arguments, override_listing=True) parameters = UrlParameters(entity_id=entity.id_) request = ApiRequest(path=cls._PATH, method=HTTPMethod.GET, credentials=entity.session, data=data, url_parameters=parameters) return cls._decode(entity, request.response_data)
def create_many( cls: Type[T], session: Session, arguments: List[K] ) -> List[T]: """Return many newly created Users""" if not isinstance(session, Session): raise TypeError('session must be of type Session') if not isinstance(arguments, list): raise TypeError( 'arguments must be of type List[User.CreateArguments]' ) if False in [isinstance(a, User.CreateArguments) for a in arguments]: raise TypeError( 'arguments must be of type List[User.CreateArguments]' ) request = ApiRequest( path=cls._PATH, method=HTTPMethod.POST, credentials=session, data=DataPackage(list_data=arguments), url_parameters=None ) return cls.decode_many(session, request.response_data)
def update(self: T, time: Optional[datetime] = None, entries: Optional[List[Entry]] = None, denomination: Optional[Denomination] = None, description: Optional[str] = None) -> T: """Replace existing transaction data with supplied data.""" arguments = Transaction.UpdateArguments(self, time, entries, denomination, description) data = DataPackage.from_object(arguments) parameters = UrlParameters(entity_id=self.entity.id_) request = ApiRequest(path=Transaction._PATH, method=HTTPMethod.PUT, credentials=self.entity.session, data=data, url_parameters=parameters) transaction = Transaction._decode(self.entity, request.response_data) if transaction.id_ != self.id_: raise ApiError('Mismatched response Trasaction ID - Fatal') return transaction
def retrieve_many(cls: Type[T], entity: Entity, ids: List[int], denomination: Denomination) -> List[T]: """Return many retrieved Transactions""" if not isinstance(entity, Entity): raise TypeError('entity must be of type `Entity`') if not isinstance(ids, list): raise TypeError('ids must be of type `list`') if False in [isinstance(i, int) for i in ids]: raise TypeError('ids must be of type `int`') parameters = UrlParameters(entity_id=entity.id_) data = DataPackage(list_data=[ cls.RetrieveArguments(i, denomination, None) for i in ids ]) request = ApiRequest(path=Transaction._PATH, method=HTTPMethod.GET, credentials=entity.session, data=data, url_parameters=parameters) transactions = cls.decode_many(entity, request.response_data) return transactions
def update( self, name: Optional[str] = None, code: Optional[str] = None, priority: Optional[int] = None, description: Optional[str] = None, exponent: Optional[str] = None ) -> None: """ Replace existing Custom Unit data with supplied data. Parameters not supplied will default to existing values. """ if name is None: name = self.name if code is None: code = self.code if priority is None: priority = self.priority if description is None: description = self.description if exponent is None: exponent = self.exponent assert isinstance(code, str) assert isinstance(priority, int) assert isinstance(description, str) assert isinstance(exponent, int) arguments = CustomUnit.UpdateArguments( self.id_, code, name, exponent, priority, description ) parameters = UrlParameters(entity_id=self.entity.id_) request = ApiRequest( path=self._PATH, method=HTTPMethod.PUT, data=DataPackage.from_object(arguments), url_parameters=parameters, credentials=self.entity.session ) return CustomUnit._decode( self.entity, request.response_data )
def _create(cls: Type[T], user_id: Optional[int], email: Optional[str], secret: str) -> T: new_arguments = NewSessionArguments(secret, email, user_id) request_data = DataPackage(object_data=new_arguments, override_listing=True) request = ApiRequest(path=cls._PATH, method=HTTPMethod.POST, data=request_data) entity = cls._decode(request.response_data) return entity
def create(cls: Type[T], session: Session, name: str, description: Optional[str], region: Optional[Region] = None) -> T: new_entity_arguments = cls.CreateArguments(name, description, region) request_data = DataPackage.from_object(new_entity_arguments) request = ApiRequest(Entity.PATH, HTTPMethod.POST, session, request_data, None, False) created_entity = cls.decode(request.response_data, session) return created_entity
def retrieve_many(cls: Type[T], entity: Entity, arguments: List[K]) -> List[T]: """Retrieve several Balances.""" if not isinstance(entity, Entity): raise TypeError('entity must be of type `Entity`') if False in [isinstance(a, cls.RetrieveArguments) for a in arguments]: raise TypeError( 'arguments must be of type List[Balance.RetrieveArguments]') data = DataPackage(list_data=arguments) parameters = UrlParameters(entity_id=entity.id_) request = ApiRequest(path=cls.PATH, method=HTTPMethod.GET, credentials=entity.session, data=data, url_parameters=parameters) return cls._decode_many(entity, request.response_data)
def _retrieve(cls: Type[T], entity: Entity, arguments: K) -> T: """Retrieve a Position""" if not isinstance(entity, Entity): raise TypeError('entity must be of type `Entity`') if not isinstance(arguments, cls.RetrieveArguments): raise TypeError( 'arguments must be of type Position.RetrieveArguments' ) data = DataPackage(object_data=arguments, override_listing=True) parameters = UrlParameters(entity_id=entity.id_) request = ApiRequest( path=cls._PATH, method=HTTPMethod.GET, credentials=entity.session, data=data, url_parameters=parameters ) return cls.decode(entity, request.response_data)
def create( cls: Type[T], entity: Entity, time: datetime, entries: List[Entry], denomination: Denomination, description: Optional[str] = None, ) -> T: arguments = Transaction.CreateArguments(time, entries, denomination, description) data = DataPackage.from_object(arguments) parameters = UrlParameters(entity_id=entity.id_) request = ApiRequest(path=Transaction._PATH, method=HTTPMethod.POST, credentials=entity.session, data=data, url_parameters=parameters) transaction = cls._decode(entity, request.response_data) return transaction