Skip to content

Commit

Permalink
refactor: Improve code, add doc
Browse files Browse the repository at this point in the history
Signed-off-by: Dephilia <[email protected]>
  • Loading branch information
Dephilia committed Feb 18, 2025
1 parent 8251404 commit fbc4eda
Show file tree
Hide file tree
Showing 10 changed files with 989 additions and 356 deletions.
28 changes: 7 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,15 @@ Light plurk + Oauth Library
pip install poaurk
```

# Example
## Examples

## Authorize and get profile
You can find example usage in the `examples/` directory.

```python
import asyncio
### Running the Basic Authentication Example

import aiohttp
from poaurk import OauthCred, PlurkOAuth
1. Setup environ var for POAURK_TEST_KEY, POAURK_TEST_SECRET
2. Run the script:

cred = OauthCred(customer_key='your key from plurk',
customer_secret='your secret from plurk',
token='optional token',
token_secret='optional token secret'
)


async def main():
async with aiohttp.ClientSession() as session:
oauth = PlurkOAuth(cred, session)
await oauth.authorize()

r = await oauth.request('/APP/Timeline/getPlurk', {'plurk_id': '123'})
print(r)
asyncio.run(main())
```bash
python examples/basic_auth.py
```
6 changes: 0 additions & 6 deletions api.keys.example

This file was deleted.

40 changes: 40 additions & 0 deletions examples/basic_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import asyncio
import os

from aiohttp import ClientSession

from poaurk import OAuthCred, PlurkOAuth


async def main() -> None:
oauth_cred = OAuthCred(
os.environ["POAURK_TEST_KEY"], os.environ["POAURK_TEST_SECRET"], None, None
)

async with ClientSession() as session:
plurk_oauth = PlurkOAuth(oauth_cred, session)

# Step 1: Get request token
await plurk_oauth.get_request_token()
print(f"Request Token: {oauth_cred.token}")
print(f"Token Secret: {oauth_cred.token_secret}")

# Step 2: Get verification URL
verifier_url = plurk_oauth.get_verifier_url()
print(f"Visit this URL to authorize: {verifier_url}")

# Step 3: Get user input for verifier code
verifier_code = await plurk_oauth.get_verifier()

# Step 4: Get access token
await plurk_oauth.get_access_token(verifier_code)
print(f"Access Token: {oauth_cred.token}")
print(f"Access Token Secret: {oauth_cred.token_secret}")

# Step 5: Test request
app_users_me = await plurk_oauth.request("/APP/Users/me")
print(app_users_me)


if __name__ == "__main__":
asyncio.run(main())
42 changes: 14 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,42 +1,28 @@
[project]
name = "poaurk"
version = "0.4.0"
dynamic = ["version", "readme"]
description = "Light Plurk API 2.0 Oauth Library"
authors = [
{ name = "Dephilia", email = "[email protected]" }
]
dependencies = [
"aiohttp>=3.9.3",
"oauthlib>=3.2.2",
]
readme = "README.md"
authors = [{ name = "Dephilia", email = "[email protected]" }]
dependencies = ["aiofiles>=24.1.0", "aiohttp>=3.9.3", "oauthlib>=3.2.2"]
requires-python = ">= 3.10"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.rye]
managed = true
dev-dependencies = [
"pytest>=8.1.1",
"pytest-aiohttp>=1.0.5",
"mypy>=1.9.0",
"ruff-lsp>=0.0.53",
"ruff>=0.4.4",
"pyright>=1.1.362"
]
[dependency-groups]
dev = ["pytest>=8.3.4", "pytest-asyncio>=0.25.3"]

[tool.hatch.metadata]
allow-direct-references = true
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[tool.hatch.build.targets.wheel]
packages = ["src/poaurk"]
[tool.setuptools.dynamic]
version = {attr = "setuptools_scm.get_version"}
readme = {file = "README.md", content-type = "text/markdown"}

[tool.ruff.lint]
select = ["E", "W", "N", "D", "F", "PL", "UP", "I"]

[tool.pyright]
exclude = [ ".venv" ]
venvPath = "."
venv = ".venv"

[tool.pytest.ini_options]
asyncio_mode = "auto"
75 changes: 0 additions & 75 deletions requirements-dev.lock

This file was deleted.

30 changes: 0 additions & 30 deletions requirements.lock

This file was deleted.

5 changes: 3 additions & 2 deletions src/poaurk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Python Plurk Oauth Library."""
from .oauth import OauthCred, PlurkOAuth

__all__ = ["PlurkOAuth", "OauthCred"]
from .oauth import CliUserInteraction, OAuthCred, PlurkOAuth

__all__ = ["CliUserInteraction", "OAuthCred", "PlurkOAuth"]
Loading

0 comments on commit fbc4eda

Please sign in to comment.