Skip to content

Commit 8316353

Browse files
feat(api): api update
1 parent f372eaa commit 8316353

File tree

4 files changed

+211
-45
lines changed

4 files changed

+211
-45
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 12
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/hyperspell%2Fhyperspell-4066d19206db91d6b4e638e78240ed568844eb3065b073126f0161fc95c39adc.yml
3-
openapi_spec_hash: 13b1fddffd88cb50d29b54280f58e526
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/hyperspell%2Fhyperspell-e89c764e4c847e7825e07bdb7e927a99b29548a8864069365d50974e8d4518fe.yml
3+
openapi_spec_hash: fadd50b9f0b9675cbf5c16c318feef2f
44
config_hash: 708fccba2f2a32fb068841e612b05ee3

src/hyperspell/_client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,20 @@ def qs(self) -> Querystring:
126126
@property
127127
@override
128128
def auth_headers(self) -> dict[str, str]:
129+
return {**self._api_key, **self._as_user}
130+
131+
@property
132+
def _api_key(self) -> dict[str, str]:
129133
api_key = self.api_key
130134
return {"Authorization": f"Bearer {api_key}"}
131135

136+
@property
137+
def _as_user(self) -> dict[str, str]:
138+
user_id = self.user_id
139+
if user_id is None:
140+
return {}
141+
return {"X-As-User": user_id}
142+
132143
@property
133144
@override
134145
def default_headers(self) -> dict[str, str | Omit]:
@@ -308,9 +319,20 @@ def qs(self) -> Querystring:
308319
@property
309320
@override
310321
def auth_headers(self) -> dict[str, str]:
322+
return {**self._api_key, **self._as_user}
323+
324+
@property
325+
def _api_key(self) -> dict[str, str]:
311326
api_key = self.api_key
312327
return {"Authorization": f"Bearer {api_key}"}
313328

329+
@property
330+
def _as_user(self) -> dict[str, str]:
331+
user_id = self.user_id
332+
if user_id is None:
333+
return {}
334+
return {"X-As-User": user_id}
335+
314336
@property
315337
@override
316338
def default_headers(self) -> dict[str, str | Omit]:

tests/conftest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def pytest_collection_modifyitems(items: list[pytest.Function]) -> None:
3131
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
3232

3333
api_key = "My API Key"
34+
user_id = "My User ID"
3435

3536

3637
@pytest.fixture(scope="session")
@@ -39,7 +40,7 @@ def client(request: FixtureRequest) -> Iterator[Hyperspell]:
3940
if not isinstance(strict, bool):
4041
raise TypeError(f"Unexpected fixture parameter type {type(strict)}, expected {bool}")
4142

42-
with Hyperspell(base_url=base_url, api_key=api_key, _strict_response_validation=strict) as client:
43+
with Hyperspell(base_url=base_url, api_key=api_key, user_id=user_id, _strict_response_validation=strict) as client:
4344
yield client
4445

4546

@@ -49,5 +50,7 @@ async def async_client(request: FixtureRequest) -> AsyncIterator[AsyncHyperspell
4950
if not isinstance(strict, bool):
5051
raise TypeError(f"Unexpected fixture parameter type {type(strict)}, expected {bool}")
5152

52-
async with AsyncHyperspell(base_url=base_url, api_key=api_key, _strict_response_validation=strict) as client:
53+
async with AsyncHyperspell(
54+
base_url=base_url, api_key=api_key, user_id=user_id, _strict_response_validation=strict
55+
) as client:
5356
yield client

0 commit comments

Comments
 (0)