Skip to content

sok.core.adapters.media_adapters.base

Base adapter classes for API response normalization.

Provides the abstract Adapter protocol and BaseAdapter class that all media-type-specific adapters inherit from.

Adapter

class Adapter

Bases: Protocol

Protocol defining the adapter interface.

All media adapters must implement these methods to normalize API responses into a consistent format.

Source

adapt_details

def adapt_details(
content_type: ContentType,
payload: Dict[str, Any],
) -> Dict[str, Any]:

Adapt detail response to normalized format.

Parameters

NameTypeDescription
content_typeContentTypeType of content.
payloadDict[str, Any]Raw API detail response.

Returns

  • Dict[str, Any]Normalized detail dictionary.
Source
def adapt_search(
content_type: ContentType,
results: List[Dict[str, Any]],
) -> Dict[str, List[Dict[str, Any]]]:

Adapt search results to normalized format.

Parameters

NameTypeDescription
content_typeContentTypeType of content being searched.
resultsList[Dict[str, Any]]Raw API search results.

Returns

  • Dict[str, List[Dict[str, Any]]]Normalized search results dictionary.
Source

BaseAdapter

class BaseAdapter

Base class for media adapters.

Provides default implementations that raise NotImplementedError, forcing subclasses to implement the required methods.

Source

adapt_details

def adapt_details(
content_type: ContentType,
payload: Dict[str, Any],
) -> Dict[str, Any]:

Adapt detail response to normalized format.

Parameters

NameTypeDescription
content_typeContentTypeType of content.
payloadDict[str, Any]Raw API detail response.

Returns

  • Dict[str, Any]Normalized detail dictionary.

Raises

  • NotImplementedErrorMust be implemented by subclass.
Source
def adapt_search(
content_type: ContentType,
results: List[Dict[str, Any]],
) -> Dict[str, List[Dict[str, Any]]]:

Adapt search results to normalized format.

Parameters

NameTypeDescription
content_typeContentTypeType of content being searched.
resultsList[Dict[str, Any]]Raw API search results.

Returns

  • Dict[str, List[Dict[str, Any]]]Normalized search results dictionary.

Raises

  • NotImplementedErrorMust be implemented by subclass.
Source
Built with Kiln