Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 7
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openint%2Fopenint-1774a01e29ee20fa16ce371374b9a675da3d1a0a5d3cb911a4acf067d3c7351e.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openint%2Fopenint-ed263d82a28e8475a7ebc5eaa4dfe53255fcd3342d12ec956bf331b169407b3b.yml
15 changes: 2 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,23 @@ pip install --pre openint
The full API of this library can be found in [api.md](api.md).

```python
import os
from openint import Openint

client = Openint(
api_key=os.environ.get("OPENINT_API_KEY"), # This is the default and can be omitted
)
client = Openint()

response = client.get_connection()
print(response.items)
```

While you can provide an `api_key` keyword argument,
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
to add `OPENINT_API_KEY="My API Key"` to your `.env` file
so that your API Key is not stored in source control.

## Async usage

Simply import `AsyncOpenint` instead of `Openint` and use `await` with each API call:

```python
import os
import asyncio
from openint import AsyncOpenint

client = AsyncOpenint(
api_key=os.environ.get("OPENINT_API_KEY"), # This is the default and can be omitted
)
client = AsyncOpenint()


async def main() -> None:
Expand Down
54 changes: 8 additions & 46 deletions src/openint/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,6 @@ def __init__(
def qs(self) -> Querystring:
return Querystring(array_format="comma")

@property
@override
def auth_headers(self) -> dict[str, str]:
api_key = self.api_key
if api_key is None:
return {}
return {"Authorization": f"Bearer {api_key}"}

@property
@override
def default_headers(self) -> dict[str, str | Omit]:
Expand All @@ -145,17 +137,6 @@ def default_headers(self) -> dict[str, str | Omit]:
**self._custom_headers,
}

@override
def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
if self.api_key and headers.get("Authorization"):
return
if isinstance(custom_headers.get("Authorization"), Omit):
return

raise TypeError(
'"Could not resolve authentication method. Expected the api_key to be set. Or for the `Authorization` headers to be explicitly omitted"'
)

def copy(
self,
*,
Expand Down Expand Up @@ -246,7 +227,6 @@ def create_magic_link(
self,
*,
customer_id: str,
email: str,
connection_id: Optional[str] | NotGiven = NOT_GIVEN,
connector_names: Optional[
Literal[
Expand Down Expand Up @@ -306,6 +286,7 @@ def create_magic_link(
]
]
| NotGiven = NOT_GIVEN,
email: str | NotGiven = NOT_GIVEN,
redirect_url: Optional[str] | NotGiven = NOT_GIVEN,
theme: Optional[Literal["light", "dark"]] | NotGiven = NOT_GIVEN,
validity_in_seconds: float | NotGiven = NOT_GIVEN,
Expand All @@ -321,10 +302,10 @@ def create_magic_link(
Create a magic link for connecting integrations

Args:
email: The email address of the customer

connector_names: Filter integrations by comma separated connector names

email: The email address of the customer

redirect_url: Where to send user to after connect / if they press back button

theme: Magic Link display theme
Expand All @@ -346,9 +327,9 @@ def create_magic_link(
body=maybe_transform(
{
"customer_id": customer_id,
"email": email,
"connection_id": connection_id,
"connector_names": connector_names,
"email": email,
"redirect_url": redirect_url,
"theme": theme,
"validity_in_seconds": validity_in_seconds,
Expand Down Expand Up @@ -819,14 +800,6 @@ def __init__(
def qs(self) -> Querystring:
return Querystring(array_format="comma")

@property
@override
def auth_headers(self) -> dict[str, str]:
api_key = self.api_key
if api_key is None:
return {}
return {"Authorization": f"Bearer {api_key}"}

@property
@override
def default_headers(self) -> dict[str, str | Omit]:
Expand All @@ -836,17 +809,6 @@ def default_headers(self) -> dict[str, str | Omit]:
**self._custom_headers,
}

@override
def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
if self.api_key and headers.get("Authorization"):
return
if isinstance(custom_headers.get("Authorization"), Omit):
return

raise TypeError(
'"Could not resolve authentication method. Expected the api_key to be set. Or for the `Authorization` headers to be explicitly omitted"'
)

def copy(
self,
*,
Expand Down Expand Up @@ -937,7 +899,6 @@ async def create_magic_link(
self,
*,
customer_id: str,
email: str,
connection_id: Optional[str] | NotGiven = NOT_GIVEN,
connector_names: Optional[
Literal[
Expand Down Expand Up @@ -997,6 +958,7 @@ async def create_magic_link(
]
]
| NotGiven = NOT_GIVEN,
email: str | NotGiven = NOT_GIVEN,
redirect_url: Optional[str] | NotGiven = NOT_GIVEN,
theme: Optional[Literal["light", "dark"]] | NotGiven = NOT_GIVEN,
validity_in_seconds: float | NotGiven = NOT_GIVEN,
Expand All @@ -1012,10 +974,10 @@ async def create_magic_link(
Create a magic link for connecting integrations

Args:
email: The email address of the customer

connector_names: Filter integrations by comma separated connector names

email: The email address of the customer

redirect_url: Where to send user to after connect / if they press back button

theme: Magic Link display theme
Expand All @@ -1037,9 +999,9 @@ async def create_magic_link(
body=await async_maybe_transform(
{
"customer_id": customer_id,
"email": email,
"connection_id": connection_id,
"connector_names": connector_names,
"email": email,
"redirect_url": redirect_url,
"theme": theme,
"validity_in_seconds": validity_in_seconds,
Expand Down
6 changes: 3 additions & 3 deletions src/openint/types/client_create_magic_link_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
class ClientCreateMagicLinkParams(TypedDict, total=False):
customer_id: Required[str]

email: Required[str]
"""The email address of the customer"""

connection_id: Optional[str]

connector_names: Optional[
Expand Down Expand Up @@ -75,6 +72,9 @@ class ClientCreateMagicLinkParams(TypedDict, total=False):
]
"""Filter integrations by comma separated connector names"""

email: str
"""The email address of the customer"""

redirect_url: Optional[str]
"""Where to send user to after connect / if they press back button"""

Expand Down
10 changes: 2 additions & 8 deletions tests/api_resources/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def test_path_params_check_connection(self, client: Openint) -> None:
def test_method_create_magic_link(self, client: Openint) -> None:
client_ = client.create_magic_link(
customer_id="x",
email="dev@stainless.com",
)
assert_matches_type(CreateMagicLinkResponse, client_, path=["response"])

Expand All @@ -81,9 +80,9 @@ def test_method_create_magic_link(self, client: Openint) -> None:
def test_method_create_magic_link_with_all_params(self, client: Openint) -> None:
client_ = client.create_magic_link(
customer_id="x",
email="dev@stainless.com",
connection_id="connection_id",
connector_names="aircall",
email="dev@stainless.com",
redirect_url="redirect_url",
theme="light",
validity_in_seconds=0,
Expand All @@ -96,7 +95,6 @@ def test_method_create_magic_link_with_all_params(self, client: Openint) -> None
def test_raw_response_create_magic_link(self, client: Openint) -> None:
response = client.with_raw_response.create_magic_link(
customer_id="x",
email="dev@stainless.com",
)

assert response.is_closed is True
Expand All @@ -109,7 +107,6 @@ def test_raw_response_create_magic_link(self, client: Openint) -> None:
def test_streaming_response_create_magic_link(self, client: Openint) -> None:
with client.with_streaming_response.create_magic_link(
customer_id="x",
email="dev@stainless.com",
) as response:
assert not response.is_closed
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
Expand Down Expand Up @@ -384,7 +381,6 @@ async def test_path_params_check_connection(self, async_client: AsyncOpenint) ->
async def test_method_create_magic_link(self, async_client: AsyncOpenint) -> None:
client = await async_client.create_magic_link(
customer_id="x",
email="dev@stainless.com",
)
assert_matches_type(CreateMagicLinkResponse, client, path=["response"])

Expand All @@ -393,9 +389,9 @@ async def test_method_create_magic_link(self, async_client: AsyncOpenint) -> Non
async def test_method_create_magic_link_with_all_params(self, async_client: AsyncOpenint) -> None:
client = await async_client.create_magic_link(
customer_id="x",
email="dev@stainless.com",
connection_id="connection_id",
connector_names="aircall",
email="dev@stainless.com",
redirect_url="redirect_url",
theme="light",
validity_in_seconds=0,
Expand All @@ -408,7 +404,6 @@ async def test_method_create_magic_link_with_all_params(self, async_client: Asyn
async def test_raw_response_create_magic_link(self, async_client: AsyncOpenint) -> None:
response = await async_client.with_raw_response.create_magic_link(
customer_id="x",
email="dev@stainless.com",
)

assert response.is_closed is True
Expand All @@ -421,7 +416,6 @@ async def test_raw_response_create_magic_link(self, async_client: AsyncOpenint)
async def test_streaming_response_create_magic_link(self, async_client: AsyncOpenint) -> None:
async with async_client.with_streaming_response.create_magic_link(
customer_id="x",
email="dev@stainless.com",
) as response:
assert not response.is_closed
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
Expand Down
11 changes: 2 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,14 @@ def pytest_collection_modifyitems(items: list[pytest.Function]) -> None:

base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")

api_key = "My API Key"
customer_token = "GENERATED_CUSTOMER_TOKEN"


@pytest.fixture(scope="session")
def client(request: FixtureRequest) -> Iterator[Openint]:
strict = getattr(request, "param", True)
if not isinstance(strict, bool):
raise TypeError(f"Unexpected fixture parameter type {type(strict)}, expected {bool}")

with Openint(
base_url=base_url, api_key=api_key, customer_token=customer_token, _strict_response_validation=strict
) as client:
with Openint(base_url=base_url, _strict_response_validation=strict) as client:
yield client


Expand All @@ -50,7 +45,5 @@ async def async_client(request: FixtureRequest) -> AsyncIterator[AsyncOpenint]:
if not isinstance(strict, bool):
raise TypeError(f"Unexpected fixture parameter type {type(strict)}, expected {bool}")

async with AsyncOpenint(
base_url=base_url, api_key=api_key, customer_token=customer_token, _strict_response_validation=strict
) as client:
async with AsyncOpenint(base_url=base_url, _strict_response_validation=strict) as client:
yield client
Loading