-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from zarbanio/fix/update-readme
fix(docs): update readme and docs
- Loading branch information
Showing
9 changed files
with
185 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,15 +63,15 @@ The Wallet API handles user authentication and wallet management operations. | |
The Zarban Service API provides access to core DeFi protocol operations. | ||
|
||
```python | ||
from zarban.wallet.openapi_client import DefaultApi, ApiClient, Configuration | ||
import zarban.wallet.openapi_client as wallet | ||
|
||
# Initialize the client | ||
configuration = Configuration() | ||
api_client = ApiClient(configuration) | ||
api_instance = DefaultApi(api_client) | ||
cfg = wallet.Configuration() | ||
api_client = wallet.ApiClient(cfg) | ||
auth_api = wallet.AuthApi(api_client) | ||
|
||
# Make a simple API call | ||
response = api_instance.some_method() | ||
response = auth_api.some_method() | ||
print(response) | ||
``` | ||
|
||
|
@@ -84,38 +84,35 @@ For detailed usage examples, see our [Examples Documentation](docs/examples). | |
Here's a simple example to sign up and get started with Zarban: | ||
|
||
```python | ||
from zarban.wallet.openapi_client.configuration import Configuration | ||
from zarban.wallet.openapi_client.api_client import ApiClient | ||
from zarban.wallet.openapi_client.api import DefaultApi | ||
from zarban.wallet.openapi_client.models import SignUpRequest | ||
from zarban.wallet.openapi_client.exceptions import ApiException | ||
import zarban.wallet.openapi_client as wallet | ||
|
||
|
||
def signup_example(): | ||
# Create and configure the Configuration object | ||
configuration = Configuration( | ||
host="https://wapi.zarban.io" | ||
cfg = wallet.Configuration( | ||
host="https://testwapi.zarban.io" | ||
) | ||
|
||
# Create an instance of the ApiClient with the configuration | ||
api_client = ApiClient(configuration) | ||
api_client = wallet.ApiClient(configuration=cfg) | ||
|
||
# Create an instance of the DefaultApi using the ApiClient | ||
api_instance = DefaultApi(api_client) | ||
# Create an instance of the AuthApi using the api_client | ||
auth_api = wallet.AuthApi(api_client) | ||
|
||
# Prepare the signup request data | ||
signup_request = SignUpRequest( | ||
signup_request = wallet.SignUpRequest( | ||
email="[email protected]", | ||
password="yourSecuredPassword", | ||
) | ||
|
||
try: | ||
# Call the signup API | ||
api_response = api_instance.auth_signup_post(signup_request) | ||
print("Confirmation link sent successful!") | ||
api_response = auth_api.signup_with_email_and_password(signup_request) | ||
print("Confirmation link sent successfully!") | ||
print(f"Message: {api_response.messages}") | ||
|
||
except ApiException as e: | ||
print(f"Exception when calling DefaultApi->auth_signup_post: {e}") | ||
except wallet.ApiException as e: | ||
print(f"Exception when calling auth_api->signup_with_email_and_password: {e}") | ||
print(f"Error message: {e.body}") | ||
|
||
if __name__ == "__main__": | ||
|
@@ -129,10 +126,10 @@ The SDK can be configured with various options to customize its behavior and aut | |
### Basic Configuration | ||
|
||
```python | ||
from zarban.wallet.openapi_client import Configuration | ||
import zarban.wallet.openapi_client as wallet | ||
|
||
# Basic configuration with just the host URL | ||
config = Configuration(host="https://wapi.zarban.io") | ||
cfg = wallet.Configuration(host="https://wapi.zarban.io") | ||
``` | ||
|
||
### Authentication Options | ||
|
@@ -142,7 +139,7 @@ The SDK supports multiple authentication methods: | |
1. API Key Authentication: | ||
|
||
```python | ||
config = Configuration( | ||
cfg = Configuration( | ||
host="https://wapi.zarban.io", | ||
api_key={"APIKeyAuth": "your-api-key-here"}, | ||
# Optional: Add prefix like 'Bearer' for the API key | ||
|
@@ -153,7 +150,7 @@ config = Configuration( | |
2. Basic Authentication: | ||
|
||
```python | ||
config = Configuration( | ||
cfg = Configuration( | ||
host="https://wapi.zarban.io", | ||
username="your-username", | ||
password="your-password" | ||
|
@@ -163,7 +160,7 @@ config = Configuration( | |
### Advanced Configuration | ||
|
||
```python | ||
config = Configuration( | ||
cfg = Configuration( | ||
host="https://wapi.zarban.io", | ||
api_key={"APIKeyAuth": "your-api-key-here"}, | ||
# Discard unknown properties from server responses | ||
|
@@ -185,14 +182,13 @@ config = Configuration( | |
## Error Handling | ||
|
||
```python | ||
from zarban.service.openapi_client import StableCoinSystemApi, ApiClient, Configuration | ||
from zarban.service.openapi_client.exceptions import ApiException | ||
import zarban.service.openapi_client as service | ||
|
||
try: | ||
configuration = Configuration(host="https://api.zarban.io") | ||
api_client = ApiClient(configuration) | ||
stable_coin_system_api = StableCoinSystemApi(api_client) | ||
response = StableCoinSystemApi.some_method() | ||
cfg = service.Configuration(host="https://api.zarban.io") | ||
api_client = service.ApiClient(cfg) | ||
stable_coin_system_api = service.StableCoinSystemApi(api_client) | ||
response = stable_coin_system_api.some_method() | ||
except ApiException as e: | ||
print(f"An error occurred: {e}") | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,106 +71,113 @@ pip install zarban | |
## Code Example | ||
|
||
```python | ||
from zarban.wallet.openapi_client.configuration import Configuration | ||
from zarban.wallet.openapi_client.api_client import ApiClient | ||
from zarban.wallet.openapi_client.api.default_api import DefaultApi | ||
from zarban.wallet.openapi_client.models.login_request import AuthLoginRequest | ||
from zarban.wallet.openapi_client.models.create_child_user_request import CreateChildUserRequest | ||
from zarban.wallet.openapi_client.exceptions import ApiException | ||
import zarban.wallet.openapi_client as wallet | ||
|
||
from pprint import pprint | ||
|
||
|
||
def child_creation_example(): | ||
# Initialize API client | ||
configuration = Configuration(host="https://testwapi.zarban.io") | ||
api_client = ApiClient(configuration) | ||
api = DefaultApi(api_client) | ||
cfg = wallet.Configuration(host="https://testwapi.zarban.io") | ||
api_client = wallet.ApiClient(cfg) | ||
auth_api = wallet.AuthApi(api_client) | ||
user_api = wallet.UserApi(api_client) | ||
|
||
# Constant superuser email and password | ||
SUPERUSER_EMAIL = "[email protected]" | ||
SUPERUSER_PASSWORD = "yoursecurepassword" | ||
SUPERUSER_PASSWORD = "yourSecuredPassword" | ||
|
||
try: | ||
# Superuser login | ||
login_request = AuthLoginRequest( | ||
login_request = wallet.LoginRequest( | ||
email=SUPERUSER_EMAIL, | ||
password=SUPERUSER_PASSWORD | ||
) | ||
login_response = api.auth_login_post(login_request) | ||
login_response = auth_api.login_with_email_and_password(login_request) | ||
pprint(f"Superuser login successful") | ||
|
||
# Set the access token for subsequent requests | ||
configuration.access_token = login_response.token | ||
cfg.access_token = login_response.token | ||
|
||
# Create a child user | ||
child_username = f"child_user_test" | ||
child_request = CreateChildUserRequest( | ||
child_request = wallet.CreateChildUserRequest( | ||
username=child_username | ||
) | ||
|
||
child_response = api.users_children_post(child_request) | ||
child_response =user_api.create_child_user(child_request) | ||
pprint(f"Child user created. Username: {child_response.username}") | ||
|
||
# Get child user's profile | ||
# Set the X-Child-User header in the api_client's default headers | ||
api_client.default_headers['X-Child-User'] = child_response.username | ||
|
||
# Make the profile request | ||
profile_response = api.profile_get(_request_timeout=30) | ||
profile_response = user_api.get_user_profile() | ||
|
||
pprint("Child user profile:") | ||
pprint(profile_response) | ||
|
||
# Remove the X-Child-User header after use | ||
api_client.default_headers.pop('X-Child-User', None) | ||
|
||
except ApiException as e: | ||
except wallet.ApiException as e: | ||
pprint(f"API Exception: {e}") | ||
pprint(f"Status code: {e.status}") | ||
pprint(f"Reason: {e.reason}") | ||
pprint(f"Error message: {e.body}") | ||
|
||
|
||
if __name__ == "__main__": | ||
child_creation_example() | ||
``` | ||
|
||
## Step-by-Step Explanation | ||
|
||
1. **Initialize API Client** | ||
|
||
```python | ||
configuration = Configuration(host="https://testwapi.zarban.io") | ||
api_client = ApiClient(configuration) | ||
api = DefaultApi(api_client) | ||
cfg = wallet.Configuration(host="https://testwapi.zarban.io") | ||
api_client = wallet.ApiClient(cfg) | ||
auth_api = wallet.AuthApi(api_client) | ||
user_api = wallet.UserApi(api_client) | ||
``` | ||
|
||
Sets up the API client with the test environment endpoint. | ||
|
||
2. **Superuser Authentication** | ||
|
||
```python | ||
login_request = AuthLoginRequest( | ||
email=SUPERUSER_EMAIL, | ||
password=SUPERUSER_PASSWORD | ||
) | ||
login_response = api.auth_login_post(login_request) | ||
configuration.access_token = login_response.token | ||
login_request = wallet.LoginRequest( | ||
email=SUPERUSER_EMAIL, | ||
password=SUPERUSER_PASSWORD | ||
) | ||
|
||
login_response = auth_api.login_with_email_and_password(login_request) | ||
cfg.access_token = login_response.token | ||
``` | ||
|
||
Authenticates the superuser and stores the access token. | ||
|
||
3. **Create Child User** | ||
|
||
```python | ||
child_request = CreateChildUserRequest( | ||
username=child_username | ||
) | ||
child_response = api.users_children_post(child_request) | ||
child_request = wallet.CreateChildUserRequest( | ||
username=child_username | ||
) | ||
|
||
child_response =user_api.create_child_user(child_request) | ||
``` | ||
|
||
Creates a new child user account. | ||
|
||
4. **Access Child User Profile** | ||
|
||
```python | ||
api_client.default_headers['X-Child-User'] = child_response.username | ||
profile_response = api.profile_get(_request_timeout=30) | ||
api_client.default_headers['X-Child-User'] = child_response.username | ||
profile_response = user_api.get_user_profile() | ||
``` | ||
|
||
Sets the required header and retrieves the child user's profile. | ||
|
||
## Important Headers | ||
|
@@ -198,8 +205,8 @@ def child_creation_example(): | |
|
||
```python | ||
try: | ||
child_response = api.users_children_post(child_request) | ||
except ApiException as e: | ||
child_response =user_api.create_child_user(child_request) | ||
except wallet.ApiException as e: | ||
if e.status == 400: | ||
print("Invalid request: Check username format") | ||
elif e.status == 500: | ||
|
@@ -240,5 +247,5 @@ except ApiException as e: | |
|
||
## See Also | ||
|
||
- [API Reference Documentation](../src/zarban/wallet/docs/DefaultApi.md) | ||
- [API Reference Documentation](../wallet) | ||
- [Security Best Practices](security-best-practices.md) |
Oops, something went wrong.