diff --git a/infrastructure/solar/google_solar_api_client.py b/infrastructure/solar/google_solar_api_client.py index 5e4698e9..4edea335 100644 --- a/infrastructure/solar/google_solar_api_client.py +++ b/infrastructure/solar/google_solar_api_client.py @@ -1,5 +1,7 @@ from typing import Any, Literal +import requests + class BuildingInsightsNotFoundError(Exception): pass @@ -11,7 +13,7 @@ class GoogleSolarApiClient: ENTITY_NOT_FOUND_ERROR: str = "Requested entity was not found." def __init__(self, api_key: str) -> None: - raise NotImplementedError + self._api_key = api_key def get_building_insights( self, @@ -19,4 +21,14 @@ class GoogleSolarApiClient: latitude: float, required_quality: Literal["HIGH", "MEDIUM", "LOW"] = "MEDIUM", ) -> dict[str, Any]: - raise NotImplementedError + insights_url = f"{self.base_url}/buildingInsights:findClosest" + params: dict[str, str] = { + "location.latitude": f"{latitude:.5f}", + "location.longitude": f"{longitude:.5f}", + "requiredQuality": required_quality, + "key": self._api_key, + } + response = requests.get(insights_url, params=params) + response.raise_for_status() + result: dict[str, Any] = response.json() + return result