Skip to content

Commit 5bf7149

Browse files
devin-ai-integration[bot]blank@buildwithfern.com
andcommitted
Refactor Agora to extend base class and update exports
- Agora and AsyncAgora now extend base classes instead of duplicating code - Export only Agora/AsyncAgora (with pool support) from main package - Add edited files to .fernignore to prevent Fern overwriting Co-Authored-By: blank@buildwithfern.com <blank@buildwithfern.com>
1 parent 6226293 commit 5bf7149

3 files changed

Lines changed: 27 additions & 97 deletions

File tree

.fernignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
# Specify files that shouldn't be modified by Fern
2+
src/agoraio/pool_client.py
3+
src/agoraio/__init__.py
4+
src/agoraio/core/domain.py

src/agoraio/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77

88
if typing.TYPE_CHECKING:
99
from . import agents, core, phone_numbers, telephony
10-
from .client import Agora, AsyncAgora
1110
from .core.domain import Area, Pool, create_pool
12-
from .pool_client import AgoraPool, AsyncAgoraPool
11+
from .pool_client import Agora, AsyncAgora
1312
from .version import __version__
1413
_dynamic_imports: typing.Dict[str, str] = {
15-
"Agora": ".client",
16-
"AgoraPool": ".pool_client",
14+
"Agora": ".pool_client",
1715
"Area": ".core.domain",
18-
"AsyncAgora": ".client",
19-
"AsyncAgoraPool": ".pool_client",
16+
"AsyncAgora": ".pool_client",
2017
"Pool": ".core.domain",
2118
"__version__": ".version",
2219
"agents": ".agents",
@@ -48,4 +45,4 @@ def __dir__():
4845
return sorted(lazy_attrs)
4946

5047

51-
__all__ = ["Agora", "AgoraPool", "Area", "AsyncAgora", "AsyncAgoraPool", "Pool", "__version__", "agents", "core", "create_pool", "phone_numbers", "telephony"]
48+
__all__ = ["Agora", "Area", "AsyncAgora", "Pool", "__version__", "agents", "core", "create_pool", "phone_numbers", "telephony"]

src/agoraio/pool_client.py

Lines changed: 20 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,15 @@
66

77
import httpx
88

9-
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
9+
from .client import Agora as BaseAgora
10+
from .client import AsyncAgora as BaseAsyncAgora
1011
from .core.domain import Area, Pool
1112

12-
if typing.TYPE_CHECKING:
13-
from .agents.client import AgentsClient, AsyncAgentsClient
14-
from .phone_numbers.client import AsyncPhoneNumbersClient, PhoneNumbersClient
15-
from .telephony.client import AsyncTelephonyClient, TelephonyClient
1613

17-
18-
class AgoraPool:
14+
class Agora(BaseAgora):
1915
"""
20-
AgoraPool is a wrapper around Agora that uses a domain pool
21-
for regional URL cycling and automatic domain selection.
16+
Agora extends the base client with domain pool support for
17+
regional URL cycling and automatic domain selection.
2218
2319
This client automatically:
2420
- Selects the best domain based on DNS resolution
@@ -46,9 +42,9 @@ class AgoraPool:
4642
4743
Examples
4844
--------
49-
from agoraio import AgoraPool, Area
45+
from agoraio import Agora, Area
5046
51-
client = AgoraPool(
47+
client = Agora(
5248
area=Area.US,
5349
username="YOUR_USERNAME",
5450
password="YOUR_PASSWORD",
@@ -67,24 +63,15 @@ def __init__(
6763
httpx_client: typing.Optional[httpx.Client] = None,
6864
):
6965
self._pool = Pool(area)
70-
_defaulted_timeout = (
71-
timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
72-
)
73-
self._client_wrapper = SyncClientWrapper(
66+
super().__init__(
7467
base_url=self._pool.get_current_url(),
7568
username=username,
7669
password=password,
7770
headers=headers,
78-
httpx_client=httpx_client
79-
if httpx_client is not None
80-
else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
81-
if follow_redirects is not None
82-
else httpx.Client(timeout=_defaulted_timeout),
83-
timeout=_defaulted_timeout,
71+
timeout=timeout,
72+
follow_redirects=follow_redirects,
73+
httpx_client=httpx_client,
8474
)
85-
self._agents: typing.Optional[AgentsClient] = None
86-
self._telephony: typing.Optional[TelephonyClient] = None
87-
self._phone_numbers: typing.Optional[PhoneNumbersClient] = None
8875

8976
@property
9077
def pool(self) -> Pool:
@@ -122,35 +109,11 @@ def _update_base_url(self) -> None:
122109
"""
123110
self._client_wrapper._base_url = self._pool.get_current_url()
124111

125-
@property
126-
def agents(self):
127-
if self._agents is None:
128-
from .agents.client import AgentsClient # noqa: E402
129-
130-
self._agents = AgentsClient(client_wrapper=self._client_wrapper)
131-
return self._agents
132-
133-
@property
134-
def telephony(self):
135-
if self._telephony is None:
136-
from .telephony.client import TelephonyClient # noqa: E402
137-
138-
self._telephony = TelephonyClient(client_wrapper=self._client_wrapper)
139-
return self._telephony
140-
141-
@property
142-
def phone_numbers(self):
143-
if self._phone_numbers is None:
144-
from .phone_numbers.client import PhoneNumbersClient # noqa: E402
145-
146-
self._phone_numbers = PhoneNumbersClient(client_wrapper=self._client_wrapper)
147-
return self._phone_numbers
148-
149112

150-
class AsyncAgoraPool:
113+
class AsyncAgora(BaseAsyncAgora):
151114
"""
152-
AsyncAgoraPool is a wrapper around AsyncAgora that uses a domain pool
153-
for regional URL cycling and automatic domain selection.
115+
AsyncAgora extends the base async client with domain pool support for
116+
regional URL cycling and automatic domain selection.
154117
155118
This client automatically:
156119
- Selects the best domain based on DNS resolution
@@ -178,9 +141,9 @@ class AsyncAgoraPool:
178141
179142
Examples
180143
--------
181-
from agoraio import AsyncAgoraPool, Area
144+
from agoraio import AsyncAgora, Area
182145
183-
client = AsyncAgoraPool(
146+
client = AsyncAgora(
184147
area=Area.US,
185148
username="YOUR_USERNAME",
186149
password="YOUR_PASSWORD",
@@ -199,24 +162,15 @@ def __init__(
199162
httpx_client: typing.Optional[httpx.AsyncClient] = None,
200163
):
201164
self._pool = Pool(area)
202-
_defaulted_timeout = (
203-
timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
204-
)
205-
self._client_wrapper = AsyncClientWrapper(
165+
super().__init__(
206166
base_url=self._pool.get_current_url(),
207167
username=username,
208168
password=password,
209169
headers=headers,
210-
httpx_client=httpx_client
211-
if httpx_client is not None
212-
else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
213-
if follow_redirects is not None
214-
else httpx.AsyncClient(timeout=_defaulted_timeout),
215-
timeout=_defaulted_timeout,
170+
timeout=timeout,
171+
follow_redirects=follow_redirects,
172+
httpx_client=httpx_client,
216173
)
217-
self._agents: typing.Optional[AsyncAgentsClient] = None
218-
self._telephony: typing.Optional[AsyncTelephonyClient] = None
219-
self._phone_numbers: typing.Optional[AsyncPhoneNumbersClient] = None
220174

221175
@property
222176
def pool(self) -> Pool:
@@ -253,27 +207,3 @@ def _update_base_url(self) -> None:
253207
Update the base URL in the client wrapper to match the pool's current URL.
254208
"""
255209
self._client_wrapper._base_url = self._pool.get_current_url()
256-
257-
@property
258-
def agents(self):
259-
if self._agents is None:
260-
from .agents.client import AsyncAgentsClient # noqa: E402
261-
262-
self._agents = AsyncAgentsClient(client_wrapper=self._client_wrapper)
263-
return self._agents
264-
265-
@property
266-
def telephony(self):
267-
if self._telephony is None:
268-
from .telephony.client import AsyncTelephonyClient # noqa: E402
269-
270-
self._telephony = AsyncTelephonyClient(client_wrapper=self._client_wrapper)
271-
return self._telephony
272-
273-
@property
274-
def phone_numbers(self):
275-
if self._phone_numbers is None:
276-
from .phone_numbers.client import AsyncPhoneNumbersClient # noqa: E402
277-
278-
self._phone_numbers = AsyncPhoneNumbersClient(client_wrapper=self._client_wrapper)
279-
return self._phone_numbers

0 commit comments

Comments
 (0)