From 5a101aa8fd0dc19489f5897b3478da673391ff43 Mon Sep 17 00:00:00 2001 From: Kazuya Takei Date: Sun, 28 Apr 2024 23:11:55 +0900 Subject: [PATCH] fix: Use initialized registry --- oembedpy/application.py | 2 +- oembedpy/discovery.py | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/oembedpy/application.py b/oembedpy/application.py index 1bcfeb3..572f08f 100644 --- a/oembedpy/application.py +++ b/oembedpy/application.py @@ -36,7 +36,7 @@ def fetch( ) -> Content: """Find endpoint from registry and content.""" try: - api_url, params = discovery.find_from_registry(url) + api_url, params = discovery.find_from_registry(url, self._registry) except ValueError: # TODO: Split error case? logger.warning("It is not found from registry. Try from content.") api_url, params = discovery.find_from_content(url) diff --git a/oembedpy/discovery.py b/oembedpy/discovery.py index 302e628..70efe55 100644 --- a/oembedpy/discovery.py +++ b/oembedpy/discovery.py @@ -5,7 +5,7 @@ import logging import urllib.parse -from typing import Optional, Tuple +from typing import Tuple import httpx from bs4 import BeautifulSoup @@ -50,13 +50,9 @@ def find_from_content(url: str) -> Tuple[str, RequestParameters]: def find_from_registry( - url: str, registry: Optional[ProviderRegistry] = None + url: str, registry: ProviderRegistry ) -> Tuple[str, RequestParameters]: """Find endpoint matched for content from registry.""" - if registry is None: - resp = httpx.get("https://oembed.com/providers.json") - registry = ProviderRegistry.from_dict(resp.json()) - for provider in registry.providers: api_url = provider.find_endpoint(url) if api_url: