diff --git a/looker_api/helpers.py b/looker_api/helpers.py index bd27e65..e69de29 100644 --- a/looker_api/helpers.py +++ b/looker_api/helpers.py @@ -1,13 +0,0 @@ -from datetime import date - -def tidy_dates(params): - """ Convert any date objects to a date string """ - - date_keys = ("from_date", "to_date", "date") - for date_key in date_keys: - if date_key in params: - if isinstance(params[date_key], date): - date_obj = params[date_key] - params[date_key] = date_obj.strftime("%Y-%m-%d") - - return params \ No newline at end of file diff --git a/looker_api/looker_api.py b/looker_api/looker_api.py index 3ca6fc8..77e6fe5 100644 --- a/looker_api/looker_api.py +++ b/looker_api/looker_api.py @@ -2,11 +2,6 @@ import requests -from helpers import tidy_dates - -ENDPOINTS_DATA = { -} - class LookerInvalidEndpoint(Exception): pass @@ -57,15 +52,15 @@ def _do_request(self, url, kwargs): status_code = r.status_code if status_code == 400: - raise StatRequestError("Bad request") + raise LookerRequestError("Bad request") elif status_code == 401: - raise StatRequestError("Unauthorized API key") + raise LookerRequestError("Unauthorized API key") elif status_code == 403: - raise StatRequestError("Usage Limit Exceeded") + raise LookerRequestError("Usage Limit Exceeded") elif status_code == 404: - raise StatRequestError("Not Found") + raise LookerRequestError("Not Found") elif status_code == 500: - raise StatRequestError("Internal Server Error") + raise LookerRequestError("Internal Server Error") response_data = r.json() @@ -84,20 +79,20 @@ def _login(self): status_code = r.status_code if status_code == 400: - raise StatRequestError("Bad request") + raise LookerRequestError("Bad request") elif status_code == 401: - raise StatRequestError("Unauthorized API key") + raise LookerRequestError("Unauthorized API key") elif status_code == 403: - raise StatRequestError("Usage Limit Exceeded") + raise LookerRequestError("Usage Limit Exceeded") elif status_code == 404: - raise StatRequestError("Not Found") + raise LookerRequestError("Not Found") elif status_code == 500: - raise StatRequestError("Internal Server Error") + raise LookerRequestError("Internal Server Error") response_data = r.json() if 'access_token' not in response_data or 'expires_in' not in response_data: - raise StatResponseError(response_data) + raise LookerResponseError(response_data) self.access_expiration = time.time() + (int(response_data['expires_in']) - 5) self.access_token = response_data['access_token'] @@ -108,27 +103,3 @@ def run_look(self, look_id, rtn_format, **kwargs): url = self._make_api_request_url(endpoint,rtn_format) return self._do_request(url, kwargs) - - def request(self, endpoint, **kwargs): - """ Make a request to the getstat.com API - - endpoint should correspond to an endpoint listed in the documentation - kawrgs should be a dictionary of query parameters for the request - """ - - if endpoint not in ENDPOINTS_DATA.keys(): - raise StatInvalidEndpoint("The endpoint {endpoint} does not exist".format(endpoint)) - - allowed_parameters = ENDPOINTS_DATA[endpoint] - illegal_paramters = [key for key in kwargs.keys() - if key not in allowed_parameters] - if illegal_paramters: - raise InvalidParameters("The parameter(s) {parameters} are not legal" - " for the endpoint `{endpoint}`".format( - parameters=illegal_paramters, - endpoint=endpoint)) - - url = self._make_api_request_url(endpoint, "/json") - kwargs = tidy_dates(kwargs) - - return self._do_request(url, kwargs) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..585fa84 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +certifi==2018.4.16 +chardet==3.0.4 +idna==2.6 +requests==2.18.4 +urllib3==1.22