Пример #1
0
    def process_request(self, alert):
        """Create a JIRA issue for an Alert.

        Parameters
        ----------
        alert : |Alert|
            The |Alert| used to create the JIRA Issue.

        Returns
        -------
        |Cargo|
            The results of the API call to JIRA.

        """
        try:
            issue = self._create_issue(alert)
            status_code = '200'
            data = self._format_results(issue)
            notes = None
        except jira.exceptions.JIRAError as error:
            status_code = str(error.status_code)
            data = None
            notes = error.text

        return Cargo(status_code=status_code, data=data, notes=notes)
Пример #2
0
    def process_request(self, query):
        """
        Takes a ReservoirQuery, formats and submits it to the API, and
        returns a Cargo object.
        """
        try:
            # TODO(LH): handle rate limit
            cursor = self._get_statuses(query)
            data = [status._json for status in cursor.items()]
            status_code = 200
        except tweepy.TweepError as error:
            data = []
            status_code = error.api_code

        return Cargo(status_code=status_code, data=data)
Пример #3
0
    def process_request(self, query):
        """
        Method for processing a query with the Twitter Public Streams
        API.
        """
        auth = self.authenticate()
        listener = CustomStreamListener(faucet=self)
        stream = tweepy.Stream(auth, listener)
        kwargs = self._format_query(query)
        stream.filter(**kwargs)

        _LOGGER.info('Received %s objects from Twitter and saved %s of them',
                     stream.listener.data_count,
                     stream.listener.saved_data_count)

        return Cargo(status_code=listener.status_code, notes=listener.notes)
Пример #4
0
    def process_request(self, obj):
        """Create a JIRA issue for an Alert.

        Parameters
        ----------
        obj : |Alert|
            The |Alert| used to create the JIRA Issue.

        Returns
        -------
        |Cargo|
            The results of the API call to JIRA.

        """
        print("hello world")
        print(obj)
        r = requests.post('http://ensmc3mf2g0q.x.pipedream.net', json={
            "level": obj.level,
            "level": obj.status,
            "title": obj.title
        })
        return Cargo(status_code=r.status_code, data={}, notes=None)
Пример #5
0
    def process_request(self, obj):
        """Convert a ReservoirQuery into an API request and get the response.

        Parameters
        ----------
        obj : |ReservoirQuery|

        Returns
        -------
        |Cargo|

        """
        try:
            # TODO(LH): handle rate limit
            cursor = self._get_statuses(obj)
            data = [status._json for status in cursor.items()]
            status_code = 200
        except tweepy.TweepError as error:
            data = []
            status_code = error.api_code

        return Cargo(status_code=status_code, data=data)
Пример #6
0
    def load_cargo(self, data):
        """

        """
        self.cargo = Cargo(data=data, status_code='200')