Skip to content

Commit

Permalink
Merge pull request #2 from Trevypants/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Trevypants authored May 18, 2024
2 parents 3188ec6 + 4589be4 commit f79c771
Show file tree
Hide file tree
Showing 73 changed files with 5,062 additions and 3,332 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ jobs:
#-----------------------------------------------
- name: 🧪 Run tests
if: always()
env:
CREDENTIALS_JSON: ${{ secrets.PYTEST_CREDENTIALS }}
run: |
source $VENV
echo $CREDENTIALS_JSON | base64 -d > ./tests/test_creds.json
poetry run pytest
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ __pycache__
*/keys/*.json
.env
test_init.py
.vscode
.vscode
credentials/**
test_init.py
**.json
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ setup:
$(MAKE) setup-dev

### Commands to run the tests ###
test-gen-creds:
@poetry run pyrevolut auth-manual --credentials-json tests/test_creds.json

test-lint:
@echo "Running lint tests..."
@poetry run ruff check
Expand Down
58 changes: 36 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ pip install TO-BE-DEFINED
### Basic Usage

```python
from pyrevolut.client import Client, Environment
from pyrevolut.client import Client

ACCESS_TOKEN = "YOUR-ACCESS-TOKEN"
REFRESH_TOKEN = "YOUR-REFRESH-TOKEN"
CREDS_JSON_LOC = "path/to/creds.json"

client = Client(
access_token=ACCESS_TOKEN,
refresh_token=REFRESH_TOKEN,
environment=Environment.SANDBOX,
creds_loc=CREDS_JSON_LOC,
sandbox=True,
)

# Initialize the client
Expand All @@ -35,42 +33,38 @@ client.close()

# You can also use the client as a context manager
with Client(
access_token=ACCESS_TOKEN,
refresh_token=REFRESH_TOKEN,
environment=Environment.SANDBOX
creds_loc=CREDS_JSON_LOC,
sandbox=True
) as client:
accounts = client.Accounts.get_all_accounts()
```

### Advanced Usage

It is possible to use the client asynchronously by using the `async` keyword.
All synchronous methods have an asynchronous counterpart with the `a` prefix.
It is possible to use the client library asynchronously by using the `AsyncClient` object.

```python
import asyncio
from pyrevolut.client import Client, Environment
from pyrevolut.client import AsyncClient

ACCESS_TOKEN = "YOUR-ACCESS-TOKEN"
REFRESH_TOKEN = "YOUR-REFRESH-TOKEN"
CREDS_JSON_LOC = "path/to/creds.json"

client = Client(
access_token=ACCESS_TOKEN,
refresh_token=REFRESH_TOKEN,
environment=Environment.SANDBOX,
client = AsyncClient(
creds_loc=CREDS_JSON_LOC,
sandbox=True,
)

# Run without context manager
async def run():
await client.aopen() # <-- Note the `a` prefix
accounts = await client.Accounts.aget_all_accounts() # <-- Note the `a` prefix
await client.aclose() # <-- Note the `a` prefix
await client.open()
accounts = await client.Accounts.get_all_accounts()
await client.close()
return accounts

# Run with context manager
async def run_context_manager():
async with client:
accounts = await client.Accounts.aget_all_accounts() # <-- Note the `a` prefix
accounts = await client.Accounts.get_all_accounts()
return accounts

# List all accounts for the authenticated user
Expand All @@ -79,6 +73,26 @@ accounts_context_manager = asyncio.run(run_context_manager())

```

## Authentication

In order to make use of the Revolut Business API, you will need to go through several steps to authenticate your application. The basic guide can be found [here](https://developer.revolut.com/docs/guides/manage-accounts/get-started/make-your-first-api-request). We have provided a simple CLI tool to help you generate the necessary credentials. This tool follows the steps outlined in the guide.

```bash

pyrevolut auth-manual

```

Alternatively, you can use call the CLI via Python.

```bash

python -m pyrevolut auth-manual

```

Upon completion, you will have a `.json` file that you can use to authenticate your application.

## API Support Status

The SDK currently supports the following APIs:
Expand Down
136 changes: 126 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ description = ""
authors = ["Trevor Visser <trevor.visser@gmail.com>"]
readme = "README.md"

[tool.poetry.scripts]
pyrevolut = "pyrevolut.cli.main:app"

[tool.poetry.dependencies]
python = "^3.11"
httpx = "^0.27.0"
Expand All @@ -13,11 +16,15 @@ pydantic-extra-types = "^2.7.0"
pycountry = "^23.12.11"
phonenumbers = "^8.13.36"
pendulum = "^3.0.0"
pyjwt = { extras = ["crypto"], version = "^2.8.0" }
cryptography = "^42.0.7"
authlib = "^1.3.0"
typer = "^0.12.3"

[tool.poetry.group.dev.dependencies]
pre-commit = "^3.7.0"
commitizen = "^3.24.0"
ipykernel = "^6.29.4"
commitizen = "^3.25.0"

[tool.poetry.group.test.dependencies]
pytest-asyncio = "^0.21.0"
Expand Down
2 changes: 1 addition & 1 deletion pyrevolut/api/accounts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"""

# flake8: noqa: F401
from .endpoint import EndpointAccounts
from .endpoint import EndpointAccountsSync, EndpointAccountsAsync
Loading

0 comments on commit f79c771

Please sign in to comment.