def decode( cls: Type[T], entity: Entity, data: Any ) -> T: if not isinstance(data, dict): raise UnexpectedResponseType(data, dict) try: if data['assets'] is None: data['assets'] = list() if data['liabilities'] is None: data['liabilities'] = list() if data['equities'] is None: data['equities'] = list() position = cls( entity=entity, balance_time=AmatinoTime.decode(data['balance_time']), generated_time=AmatinoTime.decode(data['generated_time']), global_unit_id=data['global_unit_denomination'], custom_unit_id=data['custom_unit_denomination'], assets=TreeNode.decode_many(entity, data['assets']), liabilities=TreeNode.decode_many(entity, data['liabilities']), equities=TreeNode.decode_many(entity, data['equities']), depth=data['depth'] ) except KeyError as error: raise MissingKey(error.args[0]) return position
def decode( cls: Type[T], entity: Entity, data: Any ) -> T: if not isinstance(data, dict): raise UnexpectedResponseType(data, dict) try: income = None if data['income'] is not None: income = TreeNode.decode_many(entity, data['income']) expenses = None if data['expenses'] is not None: expenses = TreeNode.decode_many(entity, data['expenses']) performance = cls( entity=entity, start_time=AmatinoTime.decode(data['start_time']), end_time=AmatinoTime.decode(data['end_time']), generated_time=AmatinoTime.decode(data['generated_time']), custom_unit_id=data['custom_unit_denomination'], global_unit_id=data['global_unit_denomination'], income=income, expenses=expenses, depth=data['depth'] ) except KeyError as error: raise MissingKey(error.args[0]) return performance
def decode(data: dict) -> T: if not isinstance(data, dict): raise ApiError('Unexpected non-dict data returned') try: transaction = cls( entity=entity, transaction_id=data['transaction_id'], transaction_time=AmatinoTime.decode( data['transaction_time']), version_time=AmatinoTime.decode(data['version_time']), description=data['description'], entries=cls._decode_entries(data['entries']), global_unit_id=data['global_unit_denomination'], custom_unit_id=data['custom_unit_denomination']) except KeyError as error: raise MissingKey(error.args[0]) return transaction
def decode(cls: Type[T], entity: Entity, data: Any) -> T: if not isinstance(data, dict): raise UnexpectedResponseType(data, dict) try: tree = cls( entity=entity, balance_time=AmatinoTime.decode(data['balance_time']), generated_time=AmatinoTime.decode(data['generated_time']), global_unit_denomination=data['global_unit_denomination'], custom_unit_denomination=data['custom_unit_denomination'], tree=TreeNode.decode_many(entity, data['tree']) ) except KeyError as error: raise MissingKey(error.args[0]) return tree
def _decode_many(cls: Type[T], entity: Entity, data: Any) -> List[T]: if not isinstance(data, list): raise UnexpectedResponseType(data, list) for balance in data: if not isinstance(balance, dict): raise UnexpectedResponseType(balance, dict) balances = list() for balance in data: balances.append( cls(entity, AmatinoTime.decode(balance['balance_time']), AmatinoTime.decode(balance['generated_time']), balance['recursive'], balance['global_unit_denomination'], balance['custom_unit_denomination'], balance['account_id'], Decimal(balance['balance']))) return balances
def _decode(cls: Type[T], entity: Entity, data: Any) -> T: if not isinstance(data, dict): raise UnexpectedResponseType(type(data), dict) try: ledger = cls(entity=entity, account_id=data['account_id'], start_time=AmatinoTime.decode(data['start_time']), end_time=AmatinoTime.decode(data['end_time']), recursive=data['recursive'], generated_time=AmatinoTime.decode( data['generated_time']), global_unit_id=data['global_unit_denomination'], custom_unit_id=data['custom_unit_denomination'], ledger_rows=Ledger._decode_rows(data['ledger_rows']), page=data['page'], number_of_pages=data['number_of_pages'], order=LedgerOrder(data['ordered_oldest_first'])) except KeyError as error: raise MissingKey(error.args[0]) return ledger
def decode(data) -> LedgerRow: if not isinstance(data, list): raise UnexpectedResponseType(data, list) row = LedgerRow(transaction_id=data[0], transaction_time=AmatinoTime.decode(data[1]), description=data[2], opposing_account_id=data[3], opposing_account_name=data[4], debit=AmatinoAmount.decode(data[5]), credit=AmatinoAmount.decode(data[6]), balance=AmatinoAmount.decode(data[7])) return row
def decode(cls: Type[T], session: Session, data: Any) -> T: if not isinstance(data, dict): raise ApiError('Unexpected data type returned: ' + str(type(data))) try: user_list = cls(page=data['page'], number_of_pages=data['number_of_pages'], generated_time=AmatinoTime.decode( data['generated_time']), state=State(data['state']), users=User.decode_many(session, data['users']), session=session) except KeyError as error: raise MissingKey(error.args[0]) return user_list