feat: document lib usage
ci/woodpecker/push/woodpecker Pipeline failed Details

This commit is contained in:
Aravinth Manivannan 2023-12-31 21:45:15 +05:30
parent 8a86893048
commit fa04803943
Signed by: realaravinth
GPG Key ID: F8F50389936984FF
3 changed files with 59 additions and 1 deletions

1
.gitignore vendored
View File

@ -160,3 +160,4 @@ cython_debug/
#.idea/
tmp/
.env
html/

View File

@ -4,7 +4,19 @@
# mcaptcha_api: Python library to interact with mCaptcha server
### Example
## Installation
```bash
pip install mcaptcha_api
```
## Usage
| Parameter | Info |
| -------------- | --------------------------------------------------------------------------------------------------------------------- |
| `instance_url` | the URL of the mCaptcha instance you are using |
| `sitekey` | The captcha identifier; can be obtained from dashboard or from widget URL (`http://hostname/widget?sitekey=<sitekey>` |
| `secret` | Account secret; can be obtained from mCaptcha dashboard account settings page |
```python
mcaptcha = MCaptcha(instance_url=INSTANCE_URL, sitekey=SITEKEY, secret=SECRET)

View File

@ -8,7 +8,41 @@ from requests import Session
class MCaptcha:
"""mCaptcha API client class
```
Attributes
----------
instance_url: str
the URL of the mCaptcha instance you are using
sitekey: str
The captcha identifier; can be obtained from dashboard
or from widget URL `http://hostname/widget?sitekey=<sitekey>`
secret: str
Account secret; can be obtained from mCaptcha dashboard
account settings page
Methods
-------
verify(token)
Verify mCaptcha authorization token presented by the visitor
"""
def __init__(self, instance_url: str, sitekey: str, secret: str):
"""
Parameters
----------
instance_url: str
the URL of the mCaptcha instance you are using
sitekey: str
The captcha identifier; can be obtained from dashboard
or from widget URL `http://hostname/widget?sitekey=<sitekey>`
secret: str
Account secret; can be obtained from mCaptcha dashboard
account settings page
"""
self.client = Session()
self.instance_url = self.__clean_url(instance_url)
self.sitekey = sitekey
@ -24,6 +58,17 @@ class MCaptcha:
return urlunparse((parsed.scheme, parsed.netloc, path, "", "", ""))
def verify(self, token: str) -> bool:
"""Verify mCaptcha authorization token presented by the visitor
Parameters
----------
token: authorization token presented by the visitor
Returns
-------
bool
indicating the validity of of the presented authorization presented
"""
payload = {"token": token, "key": self.sitekey, "secret": self.secret}
resp = self.client.post(self.verify_url, json=payload)
assert resp.status_code == 200