Repository: OpenBB-finance/OpenBBTerminal
File: openbb_platform/providers/intrinio/openbb_intrinio/models/equity_info.py (Python)

Code before:


class IntrinioEquityInfoFetcher(
    Fetcher[
        IntrinioEquityInfoQueryParams,
        List[IntrinioEquityInfoData],
    ]
):
    """Transform the query, extract and transform the data from the Intrinio endpoints."""

    @staticmethod
    def transform_query(params: Dict[str, Any]) -> IntrinioEquityInfoQueryParams:
        """Transform the query."""
        return IntrinioEquityInfoQueryParams(**params)

    @staticmethod
    async def aextract_data(
        query: IntrinioEquityInfoQueryParams,  # pylint: disable=unused-argument
        credentials: Optional[Dict[str, str]],
        **kwargs: Any,
    ) -> Dict:
        """Return the raw data from the Intrinio endpoint."""
        api_key = credentials.get("intrinio_api_key") if credentials else ""
        base_url = "https://api-v2.intrinio.com"

        async def callback(response: ClientResponse, _: Any) -> dict:
            """Return the response."""
            if response.status != 200:
                return {}

            response_data = await response.json()
            response_data["symbol"] = response.url.parts[-1]

            return response_data

        urls = [
            f"{base_url}/companies/{s.strip()}?api_key={api_key}"
            for s in query.symbol.split(",")
        ]

        return await amake_requests(urls, callback, **kwargs)

    @staticmethod
    def transform_data(
        query: IntrinioEquityInfoQueryParams,
        data: List[Dict],
        **kwargs: Any,  # pylint: disable=unused-argument
    ) -> List[IntrinioEquityInfoData]:
        """Transforms the data."""
        return [IntrinioEquityInfoData.model_validate(d) for d in data]


Review comment (refactor):
Have you considered using `openbb_intrinioutils.helpers.response_callback()` function instead of adding this new one?
Although I see you did some custom adjustment with the `response_data["symbol"] = response.url.parts[-1]` line.

Code after:
class IntrinioEquityInfoFetcher(
    Fetcher[
        IntrinioEquityInfoQueryParams,
        List[IntrinioEquityInfoData],
    ]
):
    """Transform the query, extract and transform the data from the Intrinio endpoints."""

    @staticmethod
    def transform_query(params: Dict[str, Any]) -> IntrinioEquityInfoQueryParams:
        """Transform the query."""
        return IntrinioEquityInfoQueryParams(**params)

    # pylint: disable=W0613:unused-argument
    @staticmethod
    async def aextract_data(
        query: IntrinioEquityInfoQueryParams,
        credentials: Optional[Dict[str, str]],
        **kwargs: Any,
    ) -> Dict:
        """Return the raw data from the Intrinio endpoint."""
        api_key = credentials.get("intrinio_api_key") if credentials else ""
        base_url = "https://api-v2.intrinio.com"

        urls = [
            f"{base_url}/companies/{s.strip()}?api_key={api_key}"
            for s in query.symbol.split(",")
        ]

        return await amake_requests(urls, response_callback, **kwargs)

    # pylint: disable=W0613:unused-argument
    @staticmethod
    def transform_data(
        query: IntrinioEquityInfoQueryParams,
        data: List[Dict],
        **kwargs: Any,
    ) -> List[IntrinioEquityInfoData]:
        """Transforms the data."""
        return [IntrinioEquityInfoData.model_validate(d) for d in data]