def __get_api_call(self, path):
        response.headers['Expires'] = (datetime.datetime.utcnow() +
                                       datetime.timedelta(seconds=10)
                                       ).strftime('%a, %d %b %Y %H:%M:%S GMT')
        response.headers['Access-Control-Allow-Origin'] = '*'

        result = {}
        parameters = path.strip('/').split('/')

        action = parameters[0]
        del (parameters[0])

        if 'switches' == action:
            result = self.__terrariumEngine.get_switches(parameters)

        elif 'doors' == action:
            if len(parameters) > 0 and parameters[0] == 'status':
                result = {'status': self.__terrariumEngine.get_doors_status()}
            else:
                result = self.__terrariumEngine.get_doors()

        elif 'profile' == action:
            result = self.__terrariumEngine.get_profile()

        elif 'calendar' == action:
            if 'ical' in parameters:
                response.headers['Content-Type'] = 'text/calendar'
                response.headers[
                    'Content-Disposition'] = 'attachment; filename=terrariumpi.ical.ics'

            response.headers['Content-Type'] = 'application/json'
            result = json.dumps(
                self.__terrariumEngine.get_calendar(
                    parameters, **{
                        'start': request.query.get('start'),
                        'end': request.query.get('end')
                    }))

        elif 'sensors' == action:
            result = self.__terrariumEngine.get_sensors(parameters)

        elif 'webcams' == action:
            result = self.__terrariumEngine.get_webcams(parameters)

        elif 'audio' == action:
            if len(parameters) > 0 and parameters[0] == 'files':
                del (parameters[0])
                result = self.__terrariumEngine.get_audio_files(parameters)
            elif len(parameters) > 0 and parameters[0] == 'playing':
                del (parameters[0])
                result = self.__terrariumEngine.get_audio_playing()
            elif len(parameters) > 0 and parameters[0] == 'hardware':
                del (parameters[0])
                result = {
                    'audiohardware': terrariumAudioPlayer.get_sound_cards()
                }
            else:
                result = self.__terrariumEngine.get_audio_playlists(parameters)

        elif 'environment' == action:
            result = self.__terrariumEngine.get_environment(parameters)

        elif 'weather' == action:
            result = self.__terrariumEngine.get_weather(parameters)

        elif 'uptime' == action:
            result = self.__terrariumEngine.get_uptime()

        elif 'power_usage' == action:
            result = self.__terrariumEngine.get_power_usage_water_flow(
            )['power']

        elif 'water_usage' == action:
            result = self.__terrariumEngine.get_power_usage_water_flow(
            )['water']

        elif 'system' == action:
            result = self.__terrariumEngine.get_system_stats()

        elif 'config' == action:
            # TODO: New way of data processing.... fix other config options
            result = self.__terrariumEngine.get_config(
                parameters[0] if len(parameters) == 1 else None)

        elif 'history' == action or 'export' == action:
            response.headers['Expires'] = (
                datetime.datetime.utcnow() + datetime.timedelta(minutes=1)
            ).strftime('%a, %d %b %Y %H:%M:%S GMT')
            if 'export' == action:
                parameters.append('all')
            result = self.__terrariumEngine.get_history(parameters)

            if 'export' == action:
                csv = ''
                export_name = 'error'
                for datatype in result:
                    for dataid in result[datatype]:
                        export_name = datatype + '_' + dataid + '.csv'
                        # Header
                        fields = list(result[datatype][dataid].keys())
                        if 'totals' in fields:
                            fields.remove('totals')
                        csv = '"' + '","'.join(['timestamp'] + fields) + "\"\n"

                        for counter in range(
                                0, len(result[datatype][dataid][fields[0]])):
                            # Timestamp
                            row = [
                                datetime.datetime.fromtimestamp(
                                    int(
                                        str(
                                            int(result[datatype][dataid][
                                                fields[0]][counter][0] /
                                                1000)))).strftime(
                                                    '%Y-%m-%d %H:%M:%S')
                            ]
                            for field in fields:
                                # Row values
                                row.append(
                                    str(result[datatype][dataid][field]
                                        [counter][1]))

                            csv += '"' + '","'.join(row) + "\"\n"

                response.headers['Content-Type'] = 'application/csv'
                response.headers[
                    'Content-Disposition'] = 'attachment; filename=' + export_name
                return csv

        return result
    def __get_api_call(self, path):
        response.headers['Expires'] = (datetime.datetime.utcnow() +
                                       datetime.timedelta(minutes=1)
                                       ).strftime('%a, %d %b %Y %H:%M:%S GMT')
        response.headers['Access-Control-Allow-Origin'] = '*'

        result = {}
        parameters = path.strip('/').split('/')

        action = parameters[0]
        del (parameters[0])

        if 'switches' == action:
            result = self.__terrariumEngine.get_switches(parameters)

        elif 'profile' == action:
            result = self.__terrariumEngine.get_profile()

        elif 'doors' == action:
            if len(parameters) > 0 and parameters[0] == 'status':
                result = {'doors': self.__terrariumEngine.door_status()}
            else:
                result = self.__terrariumEngine.get_doors()

        elif 'sensors' == action:
            result = self.__terrariumEngine.get_sensors(parameters)

        elif 'webcams' == action:
            result = self.__terrariumEngine.get_webcams(parameters)

        elif 'audio' == action:
            if len(parameters) > 0 and parameters[0] == 'files':
                del (parameters[0])
                result = self.__terrariumEngine.get_audio_files(parameters)
            elif len(parameters) > 0 and parameters[0] == 'playing':
                del (parameters[0])
                result = self.__terrariumEngine.get_audio_playing()
            elif len(parameters) > 0 and parameters[0] == 'hardware':
                del (parameters[0])
                result = {
                    'audiohardware': terrariumAudioPlayer.get_sound_cards()
                }
            else:
                result = self.__terrariumEngine.get_audio_playlists(parameters)

        elif 'environment' == action:
            result = self.__terrariumEngine.get_environment(parameters)

        elif 'weather' == action:
            result = self.__terrariumEngine.get_weather(parameters)

        elif 'uptime' == action:
            result = self.__terrariumEngine.get_uptime()

        elif 'power_usage' == action:
            result = self.__terrariumEngine.get_power_usage_water_flow(
            )['power']

        elif 'water_usage' == action:
            result = self.__terrariumEngine.get_power_usage_water_flow(
            )['water']

        elif 'system' == action:
            result = self.__terrariumEngine.get_system_stats()

        elif 'history' == action:
            response.headers['Expires'] = (
                datetime.datetime.utcnow() + datetime.timedelta(minutes=5)
            ).strftime('%a, %d %b %Y %H:%M:%S GMT')
            result = self.__terrariumEngine.get_history(parameters)

        elif 'config' == action:
            result = self.__terrariumEngine.get_config(
                parameters[0] if len(parameters) == 1 else None)

        return result