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 pygleif/api/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Entity(BaseSchema):
registered_at: RegisteredAt
status: str
successor_entities: list[Any]
sub_category: str | None | None = None
sub_category: str | None = None
successor_entity: GeneralEntity
transliteraded_other_names: list[Any] | None = None

Expand Down
22 changes: 12 additions & 10 deletions pygleif/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,32 @@ class HttpErrorCodes(IntEnum):
class PyGleifBase(ABC):
"""Base class for a GLEIF API request."""

BASE_URL = "https://api.gleif.org/api/v1/lei-records/"
TIMEOUT_SECOND = 10 # 10 seconds

search_string: str

@property
def json_response(self) -> dict[Any, Any]:
"""Return JSON response."""
full_url = f"{self.BASE_URL}{self.search_string}"
try:
with request.urlopen(
full_url,
f"https://api.gleif.org/api/v1/lei-records/{self.search_string}",
timeout=self.TIMEOUT_SECOND,
) as fdesc:
return cast(dict[Any, Any], json.loads(fdesc.read()))
) as response:
return cast(dict[Any, Any], json.loads(response.read()))
except error.HTTPError as e:
if e.code == HttpErrorCodes.NOT_FOUND:
raise PyGLEIFApiError(f"Resource {full_url} not found")
else:
raise PyGLEIFApiError(f"HTTP Error encountered: {e.code}")
msg = "Resource not found"
raise PyGLEIFApiError(msg) from e

msg = f"HTTP Error encountered: {e.code}"
raise PyGLEIFApiError(msg) from e
except error.URLError as e:
raise PyGLEIFApiError(f"URL Error encountered: {e.reason}")
msg = f"URL Error encountered: {e.reason}"
raise PyGLEIFApiError(msg) from e
except Exception as e:
raise PyGLEIFApiError(f"An unexpected error occurred: {e!s}")
msg = f"An unexpected error occurred: {e!s}"
raise PyGLEIFApiError(msg) from e

@property
@abstractmethod
Expand Down
26 changes: 1 addition & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,7 @@ exclude = [
target-version = "py311"

lint.select = [
"C", # complexity
"C4", # flake8-comprehensions
"D", # docstrings
"E", # pycodestyle
"F", # pyflakes/autoflake
"FA", # flake8-future-annotations
"I", # isort
"ICN001", # import concentions; {name} should be imported as {asname}
"PTH", # flake8-use-pathlib
"PLC", # pylint
"PLE", # pylint
"PLR", # pylint
"PLW", # pylint
"RUF", # Ruff-specific rules
"RUF100", # unused-noqa
"SIM", # flake8-simplify
"SIM117", # Merge with-statements that use the same scope
"SIM201", # Use {left} != {right} instead of not {left} == {right}
"SIM212", # Use {a} if {a} else {b} instead of {b} if not {a} else {a}
"SIM300", # Yoda conditions. Use 'age == 42' instead of '42 == age'.
"SIM401", # Use get from dict with default instead of an if block
"TCH", # flake8-type-checking
"T20", # flake8-print
"UP", # pyupgrade
"W", # pycodestyle
"ALL"
]

line-length = 88
Expand Down
2 changes: 1 addition & 1 deletion script/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
]:
gleif: PyGleif = PyGleif(entity)
print( # noqa: T201
gleif.response.data.attributes.registration.initial_registration_date
gleif.response.data.attributes.registration.initial_registration_date,
)