Skip to content

Commit

Permalink
feat: added accounts endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevypants committed May 16, 2024
1 parent e3078e0 commit 0e91d93
Show file tree
Hide file tree
Showing 13 changed files with 1,372 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pyrevolut/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Module that contains the API classes."""

# flake8: noqa: F401, F403
from .accounts import *
7 changes: 7 additions & 0 deletions pyrevolut/api/accounts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Get the balances, full banking details, and other details of your business accounts.
Reference link: https://developer.revolut.com/docs/business/accounts
"""

# flake8: noqa: F401
from .endpoint import EndpointAccounts
from .enums import EnumAccountState, EnumPaymentScheme, EnumTimeUnit
190 changes: 190 additions & 0 deletions pyrevolut/api/accounts/endpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
from uuid import UUID
from httpx import Response

from pyrevolut.api.common import BaseEndpoint

from .retrieve_all_accounts import RetrieveAllAccounts
from .retrieve_an_account import RetrieveAnAccount
from .retrieve_full_bank_details import RetrieveFullBankDetails


class EndpointAccounts(BaseEndpoint):
"""The Accounts API
Get the balances, full banking details, and other details of your business accounts.
"""

def get_all_accounts(
self,
**kwargs,
):
"""
Get a list of all your accounts.
Parameters
----------
None
Returns
-------
list
The list of all your accounts
"""
endpoint = RetrieveAllAccounts
path = endpoint.ROUTE
params = endpoint.Params()

response = self.client.get(
path=path,
params=params,
**kwargs,
)

return [endpoint.Response(**resp) for resp in response.json()]

def get_account(
self,
account_id: UUID,
**kwargs,
):
"""
Get the information about one of your accounts. Specify the account by its ID.
Parameters
----------
account_id : UUID
The account ID.
Returns
-------
dict
The information about the account
"""
endpoint = RetrieveAnAccount
path = endpoint.ROUTE.format(account_id=account_id)
params = endpoint.Params()

response: Response = self.client.get(
path=path,
params=params,
**kwargs,
)

return endpoint.Response(**response.json()).model_dump()

def get_full_bank_details(
self,
account_id: UUID,
**kwargs,
):
"""
Get all the bank details of one of your accounts. Specify the account by its ID.
Parameters
----------
account_id : UUID
The account ID.
Returns
-------
dict
The bank details of the account
"""
endpoint = RetrieveFullBankDetails
path = endpoint.ROUTE.format(account_id=account_id)
params = endpoint.Params()

response: Response = self.client.get(
path=path,
params=params,
**kwargs,
)

return endpoint.Response(**response.json()).model_dump()

async def aget_all_accounts(
self,
**kwargs,
):
"""
Get a list of all your accounts.
Parameters
----------
None
Returns
-------
list
The list of all your accounts
"""
endpoint = RetrieveAllAccounts
path = endpoint.ROUTE
params = endpoint.Params()

response = await self.client.aget(
path=path,
params=params,
**kwargs,
)

return [endpoint.Response(**resp) for resp in response.json()]

async def aget_account(
self,
account_id: UUID,
**kwargs,
):
"""
Get the information about one of your accounts. Specify the account by its ID.
Parameters
----------
account_id : UUID
The account ID.
Returns
-------
dict
The information about the account
"""
endpoint = RetrieveAnAccount
path = endpoint.ROUTE.format(account_id=account_id)
params = endpoint.Params()

response: Response = await self.client.aget(
path=path,
params=params,
**kwargs,
)

return endpoint.Response(**response.json()).model_dump()

async def aget_full_bank_details(
self,
account_id: UUID,
**kwargs,
):
"""
Get all the bank details of one of your accounts. Specify the account by its ID.
Parameters
----------
account_id : UUID
The account ID.
Returns
-------
dict
The bank details of the account
"""
endpoint = RetrieveFullBankDetails
path = endpoint.ROUTE.format(account_id=account_id)
params = endpoint.Params()

response: Response = await self.client.aget(
path=path,
params=params,
**kwargs,
)

return endpoint.Response(**response.json()).model_dump()
31 changes: 31 additions & 0 deletions pyrevolut/api/accounts/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from enum import StrEnum


class EnumAccountState(StrEnum):
"""Account state enum"""

ACTIVE = "active"
INACTIVE = "inactive"


class EnumPaymentScheme(StrEnum):
"""Payment scheme enum"""

CHAPS = "chaps"
BACS = "bacs"
FASTER_PAYMENTS = "faster_payments"
SEPA = "sepa"
SWIFT = "swift"
ACH = "ach"
ELIXIR = "elixir"
SORBNET = "sorbnet"
NICS = "nics"
RIX = "rix"
SUMCLEARING = "sumclearing"


class EnumTimeUnit(StrEnum):
"""Time unit enum"""

DAYS = "days"
HOURS = "hours"
64 changes: 64 additions & 0 deletions pyrevolut/api/accounts/retrieve_all_accounts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from typing import Annotated
from uuid import UUID
from decimal import Decimal

from pydantic import BaseModel, Field
from pydantic_extra_types.currency_code import Currency

from pyrevolut.utils import DateTime
from .enums import EnumAccountState


class RetrieveAllAccounts:
"""
Get a list of all your accounts.
"""

ROUTE = "/accounts"

class Params(BaseModel):
"""
Query parameters for the endpoint.
"""

pass

class Response(BaseModel):
"""
Response model for the endpoint.
"""

id: Annotated[
UUID,
Field(description="The account ID."),
]
name: Annotated[
str,
Field(description="The account name."),
]
balance: Annotated[
Decimal,
Field(description="The current balance on the account."),
]
currency: Annotated[
Currency,
Field(description="ISO 4217 currency code in upper case."),
]
state: Annotated[
EnumAccountState,
Field(description="Indicates the state of the account."),
]
public: Annotated[
bool,
Field(
description="Indicates whether the account is visible to other businesses on Revolut."
),
]
created_at: Annotated[
DateTime,
Field(description="The date and time the account was created in ISO 8601 format."),
]
updated_at: Annotated[
DateTime,
Field(description="The date and time the account was last updated in ISO 8601 format."),
]
64 changes: 64 additions & 0 deletions pyrevolut/api/accounts/retrieve_an_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from typing import Annotated
from uuid import UUID
from decimal import Decimal

from pydantic import BaseModel, Field
from pydantic_extra_types.currency_code import Currency

from pyrevolut.utils import DateTime
from .enums import EnumAccountState


class RetrieveAnAccount:
"""
Get the information about one of your accounts. Specify the account by its ID.
"""

ROUTE = "/accounts/{account_id}"

class Params(BaseModel):
"""
Query parameters for the endpoint.
"""

pass

class Response(BaseModel):
"""
Response model for the endpoint.
"""

id: Annotated[
UUID,
Field(description="The account ID."),
]
name: Annotated[
str,
Field(description="The account name."),
]
balance: Annotated[
Decimal,
Field(description="The current balance on the account."),
]
currency: Annotated[
Currency,
Field(description="ISO 4217 currency code in upper case."),
]
state: Annotated[
EnumAccountState,
Field(description="Indicates the state of the account."),
]
public: Annotated[
bool,
Field(
description="Indicates whether the account is visible to other businesses on Revolut."
),
]
created_at: Annotated[
DateTime,
Field(description="The date and time the account was created in ISO 8601 format."),
]
updated_at: Annotated[
DateTime,
Field(description="The date and time the account was last updated in ISO 8601 format."),
]
Loading

0 comments on commit 0e91d93

Please sign in to comment.