def retrieve_bank_accounts( client: ApiClient, company_id: str, **kwargs ) -> Generator[List[BankAccount], None, None]: r"""Retrieve pages of all connected bank accounts for a business. Can be filtered by providing a bank_id. :param client: Live or Sandbox API Client :type client: ApiClient :param company_id: Identifier of the Company :param **kwargs: See below :Keyword Arguments: *bank_id* (('int'')) Unique identifier for the bank :yield: Pages of BankAccounts :rtype: Generator[List[BankAccount], None, None] """ yield from _get_paged_response( client=client, url=accounts, cls=BankAccount, param_keys=("bank_id",), company_id=company_id, **kwargs, )
def retrieve_bank_transactions( client: ApiClient, company_id: str, **kwargs ) -> Generator[List[BankTransaction], None, None]: r"""Retrieve pages of bank transactions for all connected accounts. Transactions can be filtered by bank_id, account_id, from and to. :param client: Live or Sandbox API Client :type client: ApiClient :param company_id: Identifier of the Company :type company_id: str :param **kwargs: See below :Keyword Arguments: *bank_id* (('int'')) Unique identifier for the bank *account_id* (('str'')) String Unique identifier for the bank account *from* filter transactions posted on or after from date *to* filter transactions posted on or before to date :yield: Pages of BankTransactions :rtype: Generator[List[BankTransaction], None, None] """ yield from _get_paged_response( client=client, url=transactions, cls=BankTransaction, param_keys=[ "bank_id", "account_id", "from", "to", ], company_id=company_id, **kwargs, )
def create_companies( client: ApiClient, companies: List[NewCompany] ) -> Generator[List[CreateResponse], None, None]: r"""Create new companies. :param client: the client to use for the api call :type client: ApiClient :param companies: new companies to add :type companies: List[NewCompany] :yield: response from fractal with new companies :rtype: Generator[List[CreateResponse], None, None] Usage:: >>> from fractal_python import company >>> jl = company.new_company(name="Julia Labs", crn="12387305") >>> jr = company.new_company(name="Julia Research", crn="12075072") >>> company.create_companies(client=client, companies=[jl,jr]) """ body = '{"values": ' + json.dumps(companies, cls=_NewCompanyEncoder) + "}" yield from _get_paged_response( client=client, url=f"{COMPANY_ENDPOINT}", cls=CreateResponse, data=body, method="POST", )
def get_companies(client: ApiClient, **kwargs) -> Generator[List[Company], None, None]: r"""Retrieve existing companies. Can be filtered by externa_id and crn. :param client: the client to use for the api call :type client: ApiClient :param **kwargs: See below :Keyword Arguments: *external_id* (('str'')) Unique identifier for the bank account *crn* (('str')) Unique identifier for the forecast :yield: pages of Companies objects :rtype: Generator[List[Company], None, None] Usage:: >>> from fractal_python import company >>> companies = [x for y in company.get_companies(client) for x in y] """ yield from _get_paged_response( client=client, url=f"{COMPANY_ENDPOINT}", cls=Company, param_keys=[ "external_id", "crn", ], **kwargs, )
def get_forecasted_balances( client: ApiClient, company_id: str, **kwargs) -> Generator[List[ForecastedBalance], None, None]: r"""Get all forecasted balances linked to the provided forecast id. Can filter on bank_id, account_id, forecast_id, from and to :param client: Live or Sandbox API Client :type client: ApiClient :param company_id: Identifier of the Company :type company_id: str :param **kwargs: See below :Keyword Arguments: *bank_id* (('int'')) Unique identifier for the bank *account_id* (('str'')) Unique identifier for the bank account *forecast_id* (('str')) Unique identifier for the forecast *from* filter transactions posted on or after from date *to* filter transactions posted on or before to date :yield: pages of ForecastedBalance objects :rtype: Generator[List[ForecastedBalance], None, None] """ yield from _get_paged_response( client=client, url=balances, cls=ForecastedBalance, param_keys=FORECASTED_PARAMS, company_id=company_id, **kwargs, )
def retrieve_banks(client: ApiClient) -> Generator[List[Bank], None, None]: r"""Retrieve all banks. :param client: the client to use for the api call :type client: ApiClient :yield: Page of Banks :rtype: Generator[List[Bank], None, None] Usage:: >>> banks =[x for y in banking.retrieve_banks(client) for x in y] """ yield from _get_paged_response( client=client, url=banks_endpoint, cls=Bank, param_keys=None, company_id=None )
def retrieve_merchants( client: ApiClient) -> Generator[List[Merchant], None, None]: r"""Retrieve pages of all the merchants that are currently categorised by Fractal. Merchant id and the merchant name are returned in the response. :param client: Live or Sandbox API Client :type client: ApiClient :yield: Pages of Merchants :rtype: Generator[List[Merchant], None, None] """ yield from _get_paged_response(client=client, url=merchants, cls=Merchant, param_keys=None, company_id=None)
def retrieve_categories( client: ApiClient) -> Generator[List[Category], None, None]: r"""Retrieve pages of all the categories that Fractal currently supports. Category id and the category name are returned in the response. :param client: Live or Sandbox API Client :type client: ApiClient :yield: A generator of pages of categories :rtype: Generator[List[Category], None, None] """ yield from _get_paged_response(client=client, url=categories, cls=Category, param_keys=None, company_id=None)
def retrieve_bank_consents( client: ApiClient, bank_id: int, company_id: Optional[str] = None ) -> Generator[List[BankConsent], None, None]: r"""Retrieve consents by bank id and company id. :param client: the client to use for the api call :type client: ApiClient :param bank_id: the id of the bank to filter on :type bank_id: int :param company_id: the id of the company to filter on, defaults to None :type company_id: str, optional :yield: Page of Bank Consents :rtype: Generator[List[BankConsent], None, None] """ url = f"{banks_endpoint}/{bank_id}/{consents}" yield from _get_paged_response( client=client, url=url, cls=BankConsent, param_keys=[], company_id=company_id )
def get_forecasts(client: ApiClient, company_id: str, **kwargs) -> Generator[List[Forecast], None, None]: r"""Get all forecasts for the company. :param client: Live or Sandbox API Client :type client: ApiClient :param company_id: Identifier of the Company :type company_id: str :param **kwargs: See below :Keyword Arguments: *bank_id* (('int'')) Unique identifier for the bank *account_id* (('str'')) Unique identifier for the bank account :yield: Pages of Forecast objects :rtype: Generator[List[Forecast], None, None] """ yield from _get_paged_response( client=client, url=forecasts, cls=Forecast, param_keys=BANK_ACCOUNT_PARAMS, company_id=company_id, **kwargs, )