Пример #1
0
    def createStream(self, qi_stream):
        if qi_stream is None:
            return

        if not isinstance(qi_stream, QiStream):
            return
   
        conn = http.HTTPConnection(self.url)
        conn.request("POST", "/qi/streams", qi_stream.toString(), self.__qi_headers())

        response = conn.getresponse()
     
        if response.status == 302:
            url =  urlparse(response.getheader("Location"))
            response.close()

            conn.request("GET", url.path, headers = self.__qi_headers())
            response = conn.getresponse()

        if response.status == 200 or response.status == 201:
            stream = QiStream.fromString(response.read().decode())
            conn.close()
            return stream
        else:
            conn.close()
            raise QiError("Failed to create QiStream, {stream_id}. {status}:{reason}".
                          format(stream_id = qi_stream.Id, status = response.status, reason = response.reason))
Пример #2
0
    def getStreams(self, tenant_id, namespace_id):
        self.__getToken()
        conn = http.HTTPSConnection(self.url)

        conn.request(
            "GET",
            self.__streamsBase.format(tenant_id=tenant_id, namespace_id=namespace_id),
            headers=self.__qi_headers(),
        )
        response = conn.getresponse()

        if response.status != 200:
            conn.close()
            raise QiError(
                "Failed to get QiStreams. {status}:{reason}".format(status=response.status, reason=response.reason)
            )

        streamssresponse = response.read().decode()
        conn.close()
        streamsslist = json.loads(streamssresponse)
        returnlist = []
        for streamdict in streamsslist:
            returnlist.append(QiStream.fromDictionary(streamdict))

        return returnlist
Пример #3
0
    def getStream(self, stream_id):
        conn = http.HTTPConnection(self.url)
        
        conn.request("GET", "/qi/streams/" + stream_id, headers = self.__qi_headers())
        response = conn.getresponse()

        if response.status != 200:            
            conn.close()
            raise QiError("Failed to get QiStream {stream_id}. {status}:{reason}".
                          format(stream_id = stream_id, status = response.status, reason = response.reason))
        
        streamResponse = response.read().decode()
        conn.close()
        return QiStream.fromDictionary(json.loads(streamResponse))        
Пример #4
0
    def getStream(self, tenant_id, namespace_id, stream_id):
        self.__getToken()
        conn = http.HTTPSConnection(self.url)
        
        conn.request("GET", self.__streamsBase.format(tenant_id = tenant_id, namespace_id = namespace_id) + '/' + stream_id, headers = self.__qi_headers())
        response = conn.getresponse()

        if response.status != 200:            
            conn.close()
            raise QiError("Failed to get QiStream {stream_id}. {status}:{reason}".
                          format(stream_id = stream_id, status = response.status, reason = response.reason))
        
        streamResponse = response.read().decode()
        conn.close()
        return QiStream.fromDictionary(json.loads(streamResponse))        
Пример #5
0
    def getStreams(self):
        conn = http.HTTPConnection(self.url)
        
        conn.request("GET", "/qi/streams/", headers = self.__qi_headers())
        response = conn.getresponse()

        if response.status != 200:            
            conn.close()
            raise QiError("Failed to get QiStreams. {status}:{reason}".
                          format(status = response.status, reason = response.reason))
        
        streamssresponse = response.read().decode()
        conn.close()
        streamsslist = json.loads(streamssresponse)
        returnlist = []
        for streamdict in streamsslist:
            returnlist.append(QiStream.fromDictionary(streamdict))
        
        return returnlist