예제 #1
0
    def getStatistics(self,
                      configId=None,
                      interval=None,
                      start=None,
                      end=None,
                      config_name=None,
                      language=None,
                      app=None,
                      group=None):
        """ Returns usage statistics
        """
        if not (interval or start or end):
            raise SemantriaError(
                'One of interval, start or end must be specified')
        if interval and (interval.lower()
                         not in ["hour", "day", "week", "month", "year"]):
            raise SemantriaError(
                'Unknown value for interval: {}. Expected hour, day, week, month or year'
                .format(interval))

        params = {
            'config_id': configId,
            'config_name': config_name,
            'interval': interval,
            'from': start,
            'to': end,
            'language': language,
            'app': app,
            'group': group
        }
        url = self.makeUrl('/statistics', params=params)

        return self._runRequest("GET", url, "get_statistics")
예제 #2
0
 def cancelCollection(self, collection_id, config_id=None):
     if not collection_id:
         raise SemantriaError(
             'Parameter \'collection_id\' must not be empty')
     collection_id = url_quote(collection_id, safe='')
     url = self.makeUrl('/collection/{0}'.format(collection_id), config_id)
     return self._runRequest("DELETE", url)
예제 #3
0
    def cancelCollection(self, coll_id, config_id=None):
        if not coll_id:
            raise SemantriaError('Parameter not found: %s' % coll_id)
        if config_id:
            url = '{0}/collection/{1}.{2}?config_id={3}'.format(
                self.host, coll_id, self.format, config_id)
        else:
            url = '{0}/collection/{1}.{2}'.format(self.host, coll_id,
                                                  self.format)

        return self._runRequest("DELETE", url)
예제 #4
0
    def cancelDocument(self, doc_id, config_id=None):
        if not doc_id:
            raise SemantriaError('Parameter not found: %s' % doc_id)

        if config_id:
            url = '{0}/document/{1}.{2}?config_id={3}'.format(
                self.host, doc_id, self.format, config_id)
        else:
            url = '{0}/document/{1}.{2}'.format(self.host, doc_id, self.format)

        return self._runRequest("DELETE", url)
예제 #5
0
    def getCollection(self, coll_id, config_id=None):
        if not coll_id:
            raise SemantriaError('Parameter not found: %s' % coll_id)

        coll_id = url_quote(coll_id, safe='')

        if config_id:
            url = '{0}/collection/{1}.{2}?config_id={3}'.format(self.host, coll_id, self.format, config_id)
        else:
            url = '{0}/collection/{1}.{2}'.format(self.host, coll_id, self.format)

        return self._runRequest("GET", url, "get_collection")
예제 #6
0
    def getDocument(self, doc_id, config_id=None):
        if not doc_id:
            raise SemantriaError('Parameter not found: %s' % doc_id)

        doc_id = url_quote(doc_id, safe='')

        if config_id:
            url = '{0}/document/{1}.{2}?config_id={3}'.format(self.host, doc_id, self.format, config_id)
        else:
            url = '{0}/document/{1}.{2}'.format(self.host, doc_id, self.format)

        return self._runRequest("GET", url, "get_document")
예제 #7
0
    def serialize(self, obj):
        if isinstance(obj, dict) and "cloned" in obj:
            if isinstance(obj["cloned"], dict):
                item = obj["cloned"]
                item["template"] = item["config_id"]
                del item["config_id"]
                obj["added"].append(item)
            elif isinstance(obj["cloned"], list):
                for item in obj["cloned"]:
                    item["template"] = item["config_id"]
                    del item["config_id"]
                    obj["added"].append(item)
            else:
                raise SemantriaError('Unsupported object type: %s' % obj)

            del obj["cloned"]

        #encoder = json.JSONEncoder()
        return json.dumps(obj)
예제 #8
0
 def registerSerializer(self, serializer):
     if serializer:
         self.serializer = serializer
         self.format = serializer.gettype()
     else:
         raise SemantriaError('Parameter not found: %s' % serializer)
예제 #9
0
 def cancelDocument(self, doc_id, config_id=None):
     if not doc_id:
         raise SemantriaError('Parameter \'doc_id\' must not be empty')
     doc_id = url_quote(doc_id, safe='')
     url = self.makeUrl('/document/{0}'.format(doc_id), config_id)
     return self._runRequest("DELETE", url)
예제 #10
0
 def cloneConfiguration(self, name, template):
     if not name:
         raise SemantriaError('Parameter \'name\' must not be empty')
     items = {"name": name, "template": template}
     return self.addConfigurations(items)
예제 #11
0
 def registerSerializer(self, serializer):
     if not serializer:
         raise SemantriaError('Parameter \'serializer\' must not be empty')
     self.serializer = serializer
     self.format = serializer.gettype()