Beispiel #1
0
 def execute(self):
     """Execute an HTTP request using `requests` library."""
     self.resp = None
     if self.method == "GET":
         self.resp = self._session.get(
             self.url, params=self.params, headers=self.headers)
     elif self.method == "POST":
         self.resp = self._session.post(self.url, params=self.params,
                                        headers=self.headers, json=self.body)
     else:
         utils.getLogger().warning("UNSUPPORTED METHOD: {}", self.method)
Beispiel #2
0
 def execute(self):
     """Execute an HTTP request using `requests` library."""
     self.resp = None
     if self.method == "GET":
         self.resp = self._session.get(self.url,
                                       params=self.params,
                                       headers=self.headers)
     elif self.method == "POST":
         self.resp = self._session.post(self.url,
                                        params=self.params,
                                        headers=self.headers,
                                        json=self.body)
     else:
         utils.getLogger().warning("UNSUPPORTED METHOD: {}", self.method)
Beispiel #3
0
    def importBatch(self, projectId, deviceId, dataStore):
        """Wraps API call `POST /imports?fmt=table`

        Sends data to the iobeam backend to be stored.

        Params:
            projectId - Project ID the data belongs to
            deviceId - Device ID the data belongs to
            dataStore - A `DataStore` object containing the the data to be imported

        Returns:
            A tuple where the first item is the success of all of the requests (True if
            all succeed, False otherwise); the second item is any error message or None
            if successful.

        Raises:
            ValueError - If validity checks fail for the token, project id, or device id.
        """
        utils.checkValidProjectId(projectId)
        utils.checkValidProjectToken(self.token)
        utils.checkValidDeviceId(deviceId)
        if dataStore is None or len(dataStore) == 0:
            utils.getLogger().warning("Attempted to send with no data")
            return (True, None)
        endpoint = self.makeEndpoint("imports")

        reqs = ImportService._makeListOfBatchReqs(projectId, deviceId,
                                                  dataStore)
        success = True
        extra = None
        for req in reqs:
            r = self.requester().post(endpoint).token(self.token) \
                .setParam("fmt", "table") \
                .setBody(req)
            r.execute()
            success = success and (r.getResponseCode() == 200)
            if r.getResponseCode() != 200:
                extra = r.getResponse()

        return (success, extra)
Beispiel #4
0
    def importBatch(self, projectId, deviceId, dataStore):
        """Wraps API call `POST /imports?fmt=table`

        Sends data to the iobeam backend to be stored.

        Params:
            projectId - Project ID the data belongs to
            deviceId - Device ID the data belongs to
            dataStore - A `DataStore` object containing the the data to be imported

        Returns:
            A tuple where the first item is the success of all of the requests (True if
            all succeed, False otherwise); the second item is any error message or None
            if successful.

        Raises:
            ValueError - If validity checks fail for the token, project id, or device id.
        """
        utils.checkValidProjectId(projectId)
        utils.checkValidProjectToken(self.token)
        utils.checkValidDeviceId(deviceId)
        if dataStore is None or len(dataStore) == 0:
            utils.getLogger().warning("Attempted to send with no data")
            return (True, None)
        endpoint = self.makeEndpoint("imports")

        reqs = ImportService._makeListOfBatchReqs(projectId, deviceId, dataStore)
        success = True
        extra = None
        for req in reqs:
            r = self.requester().post(endpoint).token(self.token) \
                .setParam("fmt", "table") \
                .setBody(req)
            r.execute()
            success = success and (r.getResponseCode() == 200)
            if r.getResponseCode() != 200:
                extra = r.getResponse()

        return (success, extra)