Skip to content

Commit

Permalink
feat: implement login (#212)
Browse files Browse the repository at this point in the history
* Implement Account login

* Update example

* Add mocks for API tests
  • Loading branch information
disrupted authored Dec 15, 2024
1 parent b06b673 commit a8169a3
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 151 deletions.
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ Contributions are welcome to translate the rest of the fields.

```python
from things_cloud import ThingsClient
from things_cloud.api.account import Account, Credentials
from things_cloud.models import TodoItem

ACCOUNT = "<your-account-id>"
# current head index of Cloud database (if you know it)
OFFSET = 1234
# otherwise
OFFSET = None
EMAIL = os.environ["THINGS_EMAIL"]
PASSWORD = os.environ["THINGS_PASSWORD"]

things = ThingsClient(ACCOUNT, initial_offset=OFFSET)
credentials = Credentials(email=EMAIL, password=PASSWORD)
account = Account.login(credentials)
things = ThingsClient(account)
# create a new project
project = TodoItem(title="Things Cloud Project").as_project()
# push to Things Cloud
Expand All @@ -40,7 +40,21 @@ todo.today()
things.commit(todo)
```

See [main.py](main.py).
## Example

See [main.py](./main.py).

1. Install dependencies

```sh
poetry install
```

2. Pass your Things Cloud credentials as environment examples to run the example

```sh
[email protected] THINGS_PASSWORD=your-password python main.py
```

### Progress

Expand Down
10 changes: 7 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import os
from time import sleep

from pydantic import SecretStr
from structlog import get_logger

from things_cloud import ThingsClient
from things_cloud.api.account import Account, Credentials
from things_cloud.models import TodoItem

log = get_logger()

ACCOUNT = os.environ["THINGS_ACCOUNT"]
OFFSET = int(os.environ.get("THINGS_OFFSET", 0))
EMAIL = os.environ["THINGS_EMAIL"]
PASSWORD = os.environ["THINGS_PASSWORD"]


def main():
things = ThingsClient(ACCOUNT, initial_offset=OFFSET)
credentials = Credentials(email=EMAIL, password=SecretStr(PASSWORD))
account = Account.login(credentials)
things = ThingsClient(account)

# create a new project
project = TodoItem(title="Things Cloud Project").as_project()
Expand Down
168 changes: 55 additions & 113 deletions poetry.lock

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

6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ orjson = "^3.10.12"
shortuuid = "^1.0.13"
httpx = "^0.28.1"
structlog = "^24.4.0"
attrs = "^24.2.0"
cattrs = "^24.1.2"
pydantic = "^2.10.3"
pydantic = { extras = ["email"], version = "^2.10.3" }

[tool.poetry.group.dev.dependencies]
pytest = "^8.3.4"
pytest-mock = "^3.14.0"
pytest-asyncio = "^0.25.0"
pytest-cov = "^6.0.0"
pytest-clarity = "^1.0.1"
pytest-httpx = "^0.35.0"
freezegun = "^1.5.1"
pre-commit = "^4.0.1"
virtualenv = "^20.28.0" # HACK: fix pre-commit: ModuleNotFoundError: No module named 'distutils'
Expand Down
Loading

0 comments on commit a8169a3

Please sign in to comment.