Skip to content

Commit

Permalink
feat: Allow selection of method to use POST (#40)
Browse files Browse the repository at this point in the history
* feat: Allow selection of method to use POST

* fix test
  • Loading branch information
patrick-zippenfenig authored Feb 7, 2024
1 parent eb08412 commit 933dcd1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions openmeteo_requests/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class Client:
def __init__(self, session: TSession | None = None):
self.session = session or requests.Session()

def _get(self, cls: type[T], url: str, params: any) -> list[T]:
def _get(self, cls: type[T], url: str, params: any, method: str) -> list[T]:
params["format"] = "flatbuffers"

response = self.session.get(url, params=params)
response = self.session.request(method, url, params=params)
if response.status_code in [400, 429]:
response_body = response.json()
raise OpenMeteoRequestsError(response_body)
Expand All @@ -42,9 +42,9 @@ def _get(self, cls: type[T], url: str, params: any) -> list[T]:
pos += length + 4
return messages

def weather_api(self, url: str, params: any) -> list[WeatherApiResponse]:
def weather_api(self, url: str, params: any, method: str = "GET") -> list[WeatherApiResponse]:
"""Get and decode as weather api"""
return self._get(WeatherApiResponse, url, params)
return self._get(WeatherApiResponse, url, params, method)

def __del__(self):
"""cleanup"""
Expand Down
1 change: 1 addition & 0 deletions tests/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def test_fetch_all():
"hourly": ["temperature_2m", "precipitation"],
"start_date": "2023-08-01",
"end_date": "2023-08-02",
"models": "era5_seamless"
# 'timezone': 'auto',
# 'current': ['temperature_2m','precipitation'],
# 'current_weather': 1,
Expand Down

0 comments on commit 933dcd1

Please sign in to comment.