service
¶
Classes:
-
BaseService–Base service which is inheritated by other services.
Classes¶
BaseService
¶
BaseService(
support_bbox: bool = False,
support_limit: bool = False,
support_offset: bool = False,
support_convert: bool = False,
support_booking: bool = False,
)
Base service which is inheritated by other services.
Warning
Do not use this directly.
The following attributes are used to define which paramets are supported by a service.
Attributes:
-
support_bbox(bool) –Support for
bboxas parameter. -
support_limit(bool) –Support for
limitas parameter. -
support_offset(bool) –Support for
offsetas parameter. -
support_convert(bool) –Support for
convertas parameter.
Examples:
Custom service base in BaseService.
For this the two schemas MyHutSource and MyInfoHutConvert need to be defined as well.
from typing import Any
from hut_services.core.schema.geo import BBox
from hut_services import BaseService, HutSchema
# TODO: define this somewhere:
from my_service.schema import MyHutSource, MyInfoHutConvert
class MyService(BaseService[MyHutSource]):
def __init__(self, request_url: str = "http://hut.info"):
super().__init__(support_bbox=True,
support_limit=True,
support_offset=True,
support_convert=True)
self.request_url = request_url
def get_huts_from_source(
self, bbox: BBox | None = None, limit: int = 1,
offset: int = 0, **kwargs: Any
) -> list[MyHutSource]:
src_huts = httpx.get(self.request_url)
return [MyHutSource(**h) for h in src_huts]
def convert(self, src: MyHutSource) -> HutSchema:
return MyInfoHutConvert(source=src.source_data).get_hut()
Classes:
-
MethodNotImplementedError–Method is not implemented exception.
Methods:
-
clear_all_cache–Clears the cache of all services!
-
get_huts_from_source–Get all huts from source.
-
convert–Convert one hut from source to
HutSchema. -
get_huts–Get all huts form source and converts them.
-
get_bookings–Get bookings for a list of huts.
Attributes:
-
support_bbox(bool) – -
support_limit(bool) – -
support_offset(bool) – -
support_convert(bool) – -
support_booking(bool) –
Attributes¶
Classes¶
MethodNotImplementedError
¶
MethodNotImplementedError(obj: BaseService, method: str)
Method is not implemented exception.
Parameters:
-
(obj¶BaseService) –Service object (e.g.
MyService). -
(method¶str) –Method which is not implemented.
Functions¶
Functions¶
get_huts_from_source
¶
convert
¶
convert(
src: Mapping | Any, include_photos: bool = True
) -> HutSchema
get_huts
¶
get_huts(
bbox: BBox | None = None,
limit: int = 1,
offset: int = 0,
include_photos: bool = True,
**kwargs: Any,
) -> list[HutSchema]
Get all huts form source and converts them.
Calls get_huts_from_source()
and convert().
Returns:
-
list[HutSchema]–Converted huts from source.
get_bookings
¶
get_bookings(
date: datetime | date | Literal["now"] | None = None,
days: int | None = None,
source_ids: list[int | str] | None = None,
lang: str = "de",
request_interval: float | None = None,
) -> dict[int | str, HutBookingsSchema]
Get bookings for a list of huts.
Parameters:
-
(date¶datetime | date | Literal['now'] | None, default:None) –Start daye for the bookings
-
(days¶int | None, default:None) –Duration in days
-
(source_ids¶list[int | str] | None, default:None) –A list of ids to return (source id, not the hut id), if set to
Noneall are returned -
(lang¶str, default:'de') –Language for the response
-
(request_interval¶float | None, default:None) –Interval between requests (if each huts needs a request)
Returns:
-
dict[int | str, HutBookingsSchema]–A dictionary with the bookings (key = source id).