diff --git a/cf_internal b/cf_internal index 674e56d..9d04a22 160000 --- a/cf_internal +++ b/cf_internal @@ -1 +1 @@ -Subproject commit 674e56d1e6bf71be5b2ca717bf1e1fe107d327f6 +Subproject commit 9d04a22930d6a4c3ea33e625f64d5aed76d174a5 diff --git a/chainfury/client.py b/chainfury/client.py index d7a0abe..a637c4f 100644 --- a/chainfury/client.py +++ b/chainfury/client.py @@ -3,7 +3,7 @@ from functools import lru_cache from typing import Dict, Any, Tuple -from chainfury.utils import logger +from chainfury.utils import logger, CFEnv class Subway: @@ -11,6 +11,8 @@ class Subway: Simple code that allows writing APIs by `.attr.ing` them. This is inspired from gRPC style functional calls which hides the complexity of underlying networking. This is useful when you are trying to debug live server directly. + **If you want to setup a client, use the ``get_client`` function, this is not what you are looking for.** + Note: User is solely responsible for checking if the certain API endpoint exists or not. This simply wraps the API calls and does not do any validation. @@ -140,8 +142,8 @@ def get_client(prefix: str = "/api/", url="", token: str = "", trailing: str = " Example: >>> from chainfury import get_client >>> client = get_client() - >>> cf_actions = client.api.v1.fury.actions.list() - >>> cf_actions + >>> chains = client.api.chains() # GET /api/chains + >>> chains Note: The `get_client` function is a convenience function that can be used to get a client object. It is not required @@ -158,10 +160,10 @@ def get_client(prefix: str = "/api/", url="", token: str = "", trailing: str = " Returns: Subway: A Subway object that can be used to interact with the API. """ - url = url or os.environ.get("CF_URL", "") + url = url or CFEnv.CF_URL() if not url: raise ValueError("No url provided, please set CF_URL environment variable or pass url as argument") - token = token or os.environ.get("CF_TOKEN", "") + token = token or CFEnv.CF_TOKEN() if not token: raise ValueError("No token provided, please set CF_TOKEN environment variable or pass token as argument") diff --git a/chainfury/utils.py b/chainfury/utils.py index 625a60a..930c8d8 100644 --- a/chainfury/utils.py +++ b/chainfury/utils.py @@ -21,6 +21,8 @@ class CFEnv: * CF_BLOB_BUCKET: blob storage bucket name (only used for `s3` engine) * CF_BLOB_PREFIX: blob storage prefix (only used for `s3` engine) * CF_BLOB_AWS_CLOUD_FRONT: blob storage cloud front url, if not provided defaults to primary S3 URL (only used for `s3` engine) + * CF_URL: the URL of the chainfury server + * CF_TOKEN: the token to use to authenticate with the chainfury server """ CF_LOG_LEVEL = lambda: os.getenv("CF_LOG_LEVEL", "info") @@ -30,6 +32,8 @@ class CFEnv: CF_BLOB_BUCKET = lambda: os.getenv("CF_BLOB_BUCKET", "") CF_BLOB_PREFIX = lambda: os.getenv("CF_BLOB_PREFIX", "") CF_BLOB_AWS_CLOUD_FRONT = lambda: os.getenv("CF_BLOB_AWS_CLOUD_FRONT", "") + CF_URL = lambda: os.getenv("CF_URL", "") + CF_TOKEN = lambda: os.getenv("CF_TOKEN", "") def store_blob(key: str, value: bytes, engine: str = "", bucket: str = "") -> str: