From 2ca349602e9d75aef73a3c1b57243fc28a44fd0f Mon Sep 17 00:00:00 2001 From: jtoceflow <116841222+jtoceflow@users.noreply.github.com> Date: Fri, 29 Dec 2023 16:21:40 -0800 Subject: [PATCH 1/4] Fix authorize_url (#6) * Updates to README * OAuthScope reference updates * Removed space in outh.authorize_url to construct valid URL * Remove comma --- README.md | 18 +++++++++--------- src/webflow/oauth.py | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index dbf6b74..3832c43 100644 --- a/README.md +++ b/README.md @@ -68,12 +68,12 @@ for more details. from webflow.oauth import authorize_url from webflow import OauthScope -url = webflow.authorize_url({ - client_id = "[CLIENT ID]", - scope = OauthScope.ReadUsers, # or [OauthScope.ReadUsers, OauthScope.WriteUsers] - state = "1234567890", # optional - redirect_uri = "https://my.server.com/oauth/callback", # optional -}); +url = authorize_url( + client_id="[CLIENT ID]", + scope=OauthScope.USERS_READ, # or [OauthScope.USERS_READ, OauthScope.USERS_WRITE] + state="1234567890", # optional + redirect_uri="https://my.server.com/oauth/callback", # optional +); print(url) ``` @@ -89,7 +89,7 @@ client = Webflow( client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", code="YOUR_AUTHORIZATION_CODE", - redirect_uri = "https://my.server.com/oauth/callback", # optional + redirect_uri="https://my.server.com/oauth/callback", # optional ) ``` @@ -131,7 +131,7 @@ except webflow.BadRequestError as e: # Handle specific error ## Advanced ### Timeouts -By default requests time out after 60 seconds. You can configure this with a +By default, requests time out after 60 seconds. You can configure this with a timeout option, which accepts a float. ```python @@ -144,7 +144,7 @@ client = Webflow( ``` ### Custom HTTP client -You can override the httpx client to customize it for your use case. Some common usecases +You can override the httpx client to customize it for your use case. Some common use-cases include support for proxies and transports. ```python diff --git a/src/webflow/oauth.py b/src/webflow/oauth.py index 4de369b..ce06031 100644 --- a/src/webflow/oauth.py +++ b/src/webflow/oauth.py @@ -58,7 +58,7 @@ def authorize_url( if scope is not OMIT and isinstance(scope, str): params["scope"] = scope.value elif scope is not OMIT: - params["scope"] = ", ".join([s.value for s in scope]) # type: ignore + params["scope"] = " ".join([s.value for s in scope]) # type: ignore return f"https://webflow.com/oauth/authorize?{urllib.parse.urlencode(params)}" From 3303d94f5e78640ed215404a6a1371b4b31bb57d Mon Sep 17 00:00:00 2001 From: Deep Singhvi Date: Sat, 30 Dec 2023 06:30:42 +0530 Subject: [PATCH 2/4] Update .fernignore --- .fernignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.fernignore b/.fernignore index 94457f9..b6293ae 100644 --- a/.fernignore +++ b/.fernignore @@ -3,5 +3,4 @@ README.md assets/ -src/webflow/client.py src/webflow/oauth.py From a6e072d2d253ebe6c96dcd69b0f29a568926305b Mon Sep 17 00:00:00 2001 From: Deep Singhvi Date: Sat, 30 Dec 2023 07:01:04 +0530 Subject: [PATCH 3/4] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3832c43..98ac05c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Webflow Python Library [![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-SDK%20generated%20by%20Fern-brightgreen)](https://github.com/fern-api/fern) +[![pypi](https://img.shields.io/pypi/v/webflow.svg)](https://pypi.python.org/pypi/webflow) The Webflow Python Library provides convenient access to the Webflow API from applications written in Python. The library includes type definitions for all From 80a8228e392e7bb409ad944bc015d98a46403104 Mon Sep 17 00:00:00 2001 From: "fern-api[bot]" <115122769+fern-api[bot]@users.noreply.github.com> Date: Sat, 30 Dec 2023 22:06:55 +0530 Subject: [PATCH 4/4] :herb: Fern Regeneration -- Client constructor accepts `access_token` (#9) * SDK regeneration * update README --------- Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Co-authored-by: dsinghvi --- README.md | 43 +++++++++++++----------------- pyproject.toml | 2 +- src/webflow/client.py | 31 ++++++--------------- src/webflow/core/client_wrapper.py | 2 +- 4 files changed, 28 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 98ac05c..34a0c6c 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,7 @@ Simply import `Webflow` and start making calls to our API. from webflow.client import Webflow client = Webflow( - client_id="YOUR_CLIENT_ID", - client_secret="YOUR_CLIENT_SECRET", - code="YOUR_AUTHORIZATION_CODE" + access_token="YOUR_ACCESS_TOKEN" ) site = client.sites.get("site-id") ``` @@ -43,9 +41,7 @@ calls to our API. from webflow.client import AsyncWebflow client = AsyncWebflow( - client_id="YOUR_CLIENT_ID", - client_secret="YOUR_CLIENT_SECRET", - code="YOUR_AUTHORIZATION_CODE" + access_token="YOUR_ACCESS_TOKEN" ) async def main() -> None: @@ -70,32 +66,18 @@ from webflow.oauth import authorize_url from webflow import OauthScope url = authorize_url( - client_id="[CLIENT ID]", + client_id="YOUR_CLIENT_ID", scope=OauthScope.USERS_READ, # or [OauthScope.USERS_READ, OauthScope.USERS_WRITE] state="1234567890", # optional redirect_uri="https://my.server.com/oauth/callback", # optional -); +) print(url) ``` -### Step 2: Instantiate the client -Pass in your `client_id`, `client_secret`, `authorization_code` when instantiating -the client. Our SDK handles generating an access token and passing that to every endpoint. - -```python -from webflow.client import Webflow - -client = Webflow( - client_id="YOUR_CLIENT_ID", - client_secret="YOUR_CLIENT_SECRET", - code="YOUR_AUTHORIZATION_CODE", - redirect_uri="https://my.server.com/oauth/callback", # optional -) -``` - -If you want to generate an access token yourself, simply import the -`get_access_token` function. +### Step 2: Retrieve your acccess token +Use the `get_access_token` function and pass in your `client_id`, +`client_secret`, and `authorization_code`. ```python from webflow.oauth import get_access_token @@ -107,6 +89,17 @@ access_token = get_access_token( ) ``` +### Step 3: Instantiate the client +Instantiate the client using your access_token. + +```python +from webflow.client import Webflow + +client = Webflow( + access_token=access_token +) +``` + ## Webflow Module All of the models are nested within the Webflow module. Let Intellisense guide you! diff --git a/pyproject.toml b/pyproject.toml index 10a6dcf..9750e6b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "webflow" -version = "0.1.0b1" +version = "0.1.0b2" description = "" readme = "README.md" authors = [] diff --git a/src/webflow/client.py b/src/webflow/client.py index 63d4dbf..08638bc 100644 --- a/src/webflow/client.py +++ b/src/webflow/client.py @@ -6,7 +6,6 @@ from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from .environment import WebflowEnvironment -from .oauth import get_access_token from .resources.access_groups.client import AccessGroupsClient, AsyncAccessGroupsClient from .resources.assets.client import AssetsClient, AsyncAssetsClient from .resources.collections.client import AsyncCollectionsClient, CollectionsClient @@ -27,22 +26,15 @@ class Webflow: def __init__( self, *, - client_id: str, - client_secret: str, - code: str, - redirect_uri: typing.Optional[str] = None, + base_url: typing.Optional[str] = None, environment: WebflowEnvironment = WebflowEnvironment.DEFAULT, + access_token: typing.Union[str, typing.Callable[[], str]], timeout: typing.Optional[float] = 60, httpx_client: typing.Optional[httpx.Client] = None ): - self._token = get_access_token( - client_id=client_id, - client_secret=client_secret, - code=code, - redirect_uri=redirect_uri) self._client_wrapper = SyncClientWrapper( - base_url=_get_base_url(base_url=None, environment=environment), - access_token=self._token, + base_url=_get_base_url(base_url=base_url, environment=environment), + access_token=access_token, httpx_client=httpx.Client(timeout=timeout) if httpx_client is None else httpx_client, ) self.token = TokenClient(client_wrapper=self._client_wrapper) @@ -65,22 +57,15 @@ class AsyncWebflow: def __init__( self, *, - client_id: str, - client_secret: str, - code: str, - redirect_uri: typing.Optional[str] = None, + base_url: typing.Optional[str] = None, environment: WebflowEnvironment = WebflowEnvironment.DEFAULT, + access_token: typing.Union[str, typing.Callable[[], str]], timeout: typing.Optional[float] = 60, httpx_client: typing.Optional[httpx.AsyncClient] = None ): - self._token = get_access_token( - client_id=client_id, - client_secret=client_secret, - code=code, - redirect_uri=redirect_uri) self._client_wrapper = AsyncClientWrapper( - base_url=_get_base_url(base_url=None, environment=environment), - access_token=self._token, + base_url=_get_base_url(base_url=base_url, environment=environment), + access_token=access_token, httpx_client=httpx.AsyncClient(timeout=timeout) if httpx_client is None else httpx_client, ) self.token = AsyncTokenClient(client_wrapper=self._client_wrapper) diff --git a/src/webflow/core/client_wrapper.py b/src/webflow/core/client_wrapper.py index 5e431c1..2e7a724 100644 --- a/src/webflow/core/client_wrapper.py +++ b/src/webflow/core/client_wrapper.py @@ -14,7 +14,7 @@ def get_headers(self) -> typing.Dict[str, str]: headers: typing.Dict[str, str] = { "X-Fern-Language": "Python", "X-Fern-SDK-Name": "webflow", - "X-Fern-SDK-Version": "0.1.0b1", + "X-Fern-SDK-Version": "0.1.0b2", } headers["Authorization"] = f"Bearer {self._get_access_token()}" return headers