Skip to content

Commit 7cdbb3a

Browse files
committed
fix issue with root_url parameter
1 parent d560900 commit 7cdbb3a

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

mystbin/client.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ class Client:
4646
session: Optional[:class:`aiohttp.ClientSession`]
4747
The session to use for the HTTP requests.
4848
If not provided, a new session will be created.
49-
api_base: :class:`str`
50-
The base URL for the mystbin instance.
51-
Defaults to ``mystb.in``.
49+
root_url: :class:`str`
50+
The root URL for the mystbin instance.
51+
Defaults to ``https://mystb.in``.
5252
"""
5353

5454
__slots__ = ("http",)
5555

56-
def __init__(self, *, session: ClientSession | None = None, api_base: str = "mystb.in") -> None:
57-
self.http: HTTPClient = HTTPClient(session=session, api_base=api_base)
56+
def __init__(self, *, session: ClientSession | None = None, root_url: str = "https://mystb.in") -> None:
57+
self.http: HTTPClient = HTTPClient(session=session, root_url=root_url)
5858

5959
async def __aenter__(self) -> Self:
6060
return self

mystbin/http.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -130,29 +130,28 @@ def __init__(self, verb: SupportedHTTPVerb, path: str, **params: Any) -> None:
130130

131131
class HTTPClient:
132132
__slots__ = (
133-
"_async",
134133
"_locks",
135134
"_owns_session",
136135
"_session",
137136
"_token",
138-
"api_base",
137+
"root_url",
139138
"user_agent",
140139
)
141140

142-
def __init__(self, *, session: aiohttp.ClientSession | None = None, api_base: str | None = None) -> None:
141+
def __init__(self, *, session: aiohttp.ClientSession | None = None, root_url: str | None = None) -> None:
143142
self._session: aiohttp.ClientSession | None = session
144143
self._owns_session: bool = False
145144
self._locks: weakref.WeakValueDictionary[str, asyncio.Lock] = weakref.WeakValueDictionary()
146145
user_agent = "mystbin.py (https://github.com/PythonistaGuild/mystbin.py {0}) Python/{1[0]}.{1[1]} aiohttp/{2}"
147146
self.user_agent: str = user_agent.format(__version__, sys.version_info, aiohttp.__version__)
148-
self._resolve_api(api_base)
147+
self._resolve_api(root_url)
149148

150-
def _resolve_api(self, api_base: str | None, /) -> None:
151-
if api_base:
152-
Route.API_BASE = f"https://{api_base}/api"
153-
self.api_base = Route.API_BASE
149+
def _resolve_api(self, root_url: str | None, /) -> None:
150+
if root_url:
151+
Route.API_BASE = root_url + "api" if root_url.endswith("/") else root_url + "/api"
152+
self.root_url = root_url + ("/" if not root_url.endswith("/") else "")
154153
else:
155-
self.api_base = "https://mystb.in/api"
154+
self.root_url = "https://mystb.in/"
156155

157156
async def close(self) -> None:
158157
if self._session and self._owns_session:

0 commit comments

Comments
 (0)