Skip to content

Commit

Permalink
Updated type hints, made contents rely on functionality from http_hel…
Browse files Browse the repository at this point in the history
…pers
  • Loading branch information
MarcoHuebner authored and pmayd committed Sep 4, 2022
1 parent ca2d060 commit 98ba2c2
Showing 1 changed file with 9 additions and 32 deletions.
41 changes: 9 additions & 32 deletions src/pygenesis/destatis.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Module provides functions to work with the GENESIS REST-API."""
import requests

from pygenesis.config import load_config
from pygenesis.http_helper import get_response_from_endpoint

config = load_config()


def get_metadata(endpoint: str, name: str):
def get_metadata(endpoint: str, name: str) -> str:
"""Method for downloading metadata from www-genesis.destatis.de.
Method supports the following endpoints:
Expand All @@ -22,44 +21,30 @@ def get_metadata(endpoint: str, name: str):
name (str): Unique name of the object.
Returns:
dict: Content of "Object" response.
str: Content of "Object" response.
"""
url = f"{config['GENESIS API']['base_url']}metadata/{endpoint}"

params = {
"username": config["GENESIS API"]["username"],
"password": config["GENESIS API"]["password"],
"name": name,
}

response = requests.request("GET", url, params=params, verify=False)

return response.json()
return get_response_from_endpoint("metadata", endpoint, params).text


def get_catalogue(endpoint: str, params: dict):
def get_catalogue(endpoint: str, params: dict) -> dict:
"""Method for downloading catalogue data from www-genesis.destatis.de.
Args:
endpoint (str): One of the supported endpoints, e.g. cubes.
params (dict): The query parameter as defined by the API.
Returns:
list: A list of hits in the catalog matching the query parameter.
dict: JSON formated response for the given query parameters.
"""
url = f"{config['GENESIS API']['base_url']}catalogue/{endpoint}"

params |= {
"username": config["GENESIS API"]["username"],
"password": config["GENESIS API"]["password"],
}

response = requests.request("GET", url, params=params, verify=False)
return get_response_from_endpoint("catalogue", endpoint, params).json()

return response.json()


def get_cubefile(params: dict):
def get_cubefile(params: dict) -> str:
"""Method for downloading cube files from www-genesis.destatis.de.
Args:
Expand All @@ -68,13 +53,5 @@ def get_cubefile(params: dict):
Returns:
str: The content of the cubefile.
"""
url = f"{config['GENESIS API']['base_url']}data/cubefile"

params |= {
"username": config["GENESIS API"]["username"],
"password": config["GENESIS API"]["password"],
}

response = requests.request("GET", url, params=params, verify=False)

return response.text
return get_response_from_endpoint("data", "cubefile", params).text

0 comments on commit 98ba2c2

Please sign in to comment.