# Path: performanceplatform/collector/piwik/base.py
# class BaseFetcher(object):
#     def __init__(self, credentials, query):
#         self.token_auth = credentials['token_auth']
#         self.url = credentials['url']
#         self.api_method = query['api_method']
#         self.site_id = query['site_id']
#         self.query_format = 'json'
# 
#     def _request_params(self):
#         return {
#             'method': self.api_method,
#             'idSite': self.site_id,
#             'format': self.query_format,
#             'token_auth': self.token_auth
#         }
# 
#     def _make_request(self):
#         return requests_with_backoff.get(
#             url="{url}?module=API".format(url=self.url),
#             params=self._request_params()
#         )
# 
#     def fetch(self):
#         response = self._make_request()
#         response.raise_for_status()
#         return response.json()
# 
# Path: performanceplatform/utils/data_pusher.py
# class Pusher(object):
#     def __init__(self, target_data_set_config, options):
#         self.data_set_client = DataSet.from_config(target_data_set_config)
#         self.chunk_size = options.get('chunk-size', 100)
#         self.empty_data_set = options.get('empty-data-set', False)
# 
#     def push(self, data):
#         if data:
#             if self.empty_data_set:
#                 self.data_set_client.empty_data_set()
#             self.data_set_client.post(
#                 data, chunk_size=self.chunk_size)
#         else:
#             logging.info("Doing nothing - no data to push")


import sys
import pytz
from datetime import datetime
from performanceplatform.collector.piwik.base import BaseFetcher
from performanceplatform.utils.data_pusher import Pusher


class Fetcher(BaseFetcher):
    def __init__(self, credentials, query):
        super(Fetcher, self).__init__(credentials, query)
        self.last_minutes = query.get('minutes', 2)

    def _request_params(self):
        params = super(Fetcher, self)._request_params()
        params.update({'lastMinutes': self.last_minutes})
        return params


class Parser():
    def _timestamp(self):
        timezone = pytz.UTC
        timestamp = datetime.now(timezone).replace(microsecond=0)
        return timestamp.isoformat()


# Path: performanceplatform/collector/piwik/base.py
# class BaseFetcher(object):
#     def __init__(self, credentials, query):
#         self.token_auth = credentials['token_auth']
#         self.url = credentials['url']
#         self.api_method = query['api_method']
#         self.site_id = query['site_id']
#         self.query_format = 'json'
# 
#     def _request_params(self):
#         return {
#             'method': self.api_method,
#             'idSite': self.site_id,
#             'format': self.query_format,
#             'token_auth': self.token_auth
#         }
# 
#     def _make_request(self):
#         return requests_with_backoff.get(
#             url="{url}?module=API".format(url=self.url),
#             params=self._request_params()
#         )
# 
#     def fetch(self):
#         response = self._make_request()
#         response.raise_for_status()
#         return response.json()
# 
# Path: performanceplatform/utils/data_pusher.py
# class Pusher(object):
#     def __init__(self, target_data_set_config, options):
#         self.data_set_client = DataSet.from_config(target_data_set_config)
#         self.chunk_size = options.get('chunk-size', 100)
#         self.empty_data_set = options.get('empty-data-set', False)
# 
#     def push(self, data):
#         if data:
#             if self.empty_data_set:
#                 self.data_set_client.empty_data_set()
#             self.data_set_client.post(
#                 data, chunk_size=self.chunk_size)
#         else:
#             logging.info("Doing nothing - no data to push")


# Path: performanceplatform/collector/piwik/realtime.py
import sys
import pytz
from datetime import datetime
from performanceplatform.collector.piwik.base import BaseFetcher
from performanceplatform.utils.data_pusher import Pusher



class Fetcher(BaseFetcher):
    def __init__(self, credentials, query):
        super(Fetcher, self).__init__(credentials, query)
        self.last_minutes = query.get('minutes', 2)

    def _request_params(self):
        params = super(Fetcher, self)._request_params()
        params.update({'lastMinutes': self.last_minutes})
        return params


class Parser():
    def _timestamp(self):
        timezone = pytz.UTC
        timestamp = datetime.now(timezone).replace(microsecond=0)
        return timestamp.isoformat()


    def parse(self, data):