# Path: performanceplatform/collector/ga/lib/helper.py
# def create_client(credentials):
#     if "CLIENT_SECRETS" in credentials and "STORAGE_PATH" in credentials:
#         return from_secrets_file(
#             credentials['CLIENT_SECRETS'],
#             storage_path=credentials['STORAGE_PATH'],
#             http_client=HttpWithBackoff(),
#             ga_hook=track_ga_api_usage,
#         )
#     elif "ACCOUNT_NAME" in credentials:
#         return from_private_key(
#             credentials['ACCOUNT_NAME'],
#             private_key_path=credentials['PRIVATE_KEY'],
#             storage_path=credentials['STORAGE_PATH'],
#             http_client=HttpWithBackoff(),
#             ga_hook=track_ga_api_usage,
#         )
#     else:
#         return from_credentials_db(
#             credentials['CLIENT_SECRETS']['installed'],
#             credentials['OAUTH2_CREDENTIALS'],
#             http_client=HttpWithBackoff(),
#             ga_hook=track_ga_api_usage,
#         )
# 
# Path: performanceplatform/utils/datetimeutil.py
# def to_datetime(a_date):
#     if type(a_date) == datetime:
#         return a_date.replace(tzinfo=pytz.UTC)
#     return datetime.combine(a_date, time(0)).replace(tzinfo=pytz.UTC)


import base64
from datetime import date, timedelta
from performanceplatform.collector.ga.lib.helper import create_client
from performanceplatform.client import DataSet
from performanceplatform.utils.datetimeutil \
    import to_datetime


ga_date_keys = ['day', 'month', 'year']


def parse_query(query):
    if 'metric' not in query or not query['metric']:
        raise Exception('Metric required')
    else:

# Path: performanceplatform/collector/ga/lib/helper.py
# def create_client(credentials):
#     if "CLIENT_SECRETS" in credentials and "STORAGE_PATH" in credentials:
#         return from_secrets_file(
#             credentials['CLIENT_SECRETS'],
#             storage_path=credentials['STORAGE_PATH'],
#             http_client=HttpWithBackoff(),
#             ga_hook=track_ga_api_usage,
#         )
#     elif "ACCOUNT_NAME" in credentials:
#         return from_private_key(
#             credentials['ACCOUNT_NAME'],
#             private_key_path=credentials['PRIVATE_KEY'],
#             storage_path=credentials['STORAGE_PATH'],
#             http_client=HttpWithBackoff(),
#             ga_hook=track_ga_api_usage,
#         )
#     else:
#         return from_credentials_db(
#             credentials['CLIENT_SECRETS']['installed'],
#             credentials['OAUTH2_CREDENTIALS'],
#             http_client=HttpWithBackoff(),
#             ga_hook=track_ga_api_usage,
#         )
# 
# Path: performanceplatform/utils/datetimeutil.py
# def to_datetime(a_date):
#     if type(a_date) == datetime:
#         return a_date.replace(tzinfo=pytz.UTC)
#     return datetime.combine(a_date, time(0)).replace(tzinfo=pytz.UTC)


# Path: performanceplatform/collector/ga/trending.py
import base64
from datetime import date, timedelta
from performanceplatform.collector.ga.lib.helper import create_client
from performanceplatform.client import DataSet
from performanceplatform.utils.datetimeutil \
    import to_datetime



ga_date_keys = ['day', 'month', 'year']


def parse_query(query):
    if 'metric' not in query or not query['metric']:
        raise Exception('Metric required')
    else:

        if 'dimensions' in query: