Esempio n. 1
0
    def get_activities(self, ids=None, foreign_id_times=None):
        """
        Retrieves activities by their ID or foreign_id + time combination

        ids: list of activity IDs
        foreign_id_time: list of tuples (foreign_id, time)
        """
        auth_token = self.create_jwt_token("activities", "*", feed_id="*")

        if ids is None and foreign_id_times is None:
            raise TypeError(
                "One the parameters ids or foreign_id_time must be provided and not None"
            )

        if ids is not None and foreign_id_times is not None:
            raise TypeError(
                "At most one of the parameters ids or foreign_id_time must be provided"
            )

        query_params = {}

        if ids is not None:
            query_params["ids"] = ",".join(ids)

        if foreign_id_times is not None:
            validate_foreign_id_time(foreign_id_times)
            foreign_ids, timestamps = zip(*foreign_id_times)
            timestamps = map(_datetime_encoder, timestamps)
            query_params["foreign_ids"] = ",".join(foreign_ids)
            query_params["timestamps"] = ",".join(timestamps)

        return self.get("activities/", auth_token, params=query_params)
Esempio n. 2
0
    def get_activities(self, ids=None, foreign_id_times=None):
        """
        Retrieves activities by their ID or foreign_id + time combination

        ids: list of activity IDs
        foreign_id_time: list of tuples (foreign_id, time)
        """
        auth_token = self.create_jwt_token("activities", "*", feed_id="*")

        if ids is None and foreign_id_times is None:
            raise TypeError(
                "One the parameters ids or foreign_id_time must be provided and not None"
            )

        if ids is not None and foreign_id_times is not None:
            raise TypeError(
                "At most one of the parameters ids or foreign_id_time must be provided"
            )

        query_params = {}

        if ids is not None:
            query_params["ids"] = ",".join(ids)

        if foreign_id_times is not None:
            validate_foreign_id_time(foreign_id_times)
            foreign_ids, timestamps = zip(*foreign_id_times)
            timestamps = map(_datetime_encoder, timestamps)
            query_params["foreign_ids"] = ",".join(foreign_ids)
            query_params["timestamps"] = ",".join(timestamps)

        return self.get("activities/", auth_token, params=query_params)
Esempio n. 3
0
    def get_activities(self, ids=None, foreign_id_times=None):
        '''
        Retrieves activities by their ID or foreign_id + time combination

        ids: list of activity IDs
        foreign_id_time: list of tuples (foreign_id, time)
        '''
        auth_token = self.create_jwt_token('activities', '*', feed_id='*')

        if ids is None and foreign_id_times is None:
            raise TypeError(
                'One the parameters ids or foreign_id_time must be provided and not None'
            )

        if ids is not None and foreign_id_times is not None:
            raise TypeError(
                'At most one of the parameters ids or foreign_id_time must be provided'
            )

        query_params = {}

        if ids is not None:
            query_params['ids'] = ','.join(ids)

        if foreign_id_times is not None:
            validate_foreign_id_time(foreign_id_times)
            foreign_ids, timestamps = zip(*foreign_id_times)
            timestamps = map(_datetime_encoder, timestamps)
            query_params['foreign_ids'] = ','.join(foreign_ids)
            query_params['timestamps'] = ','.join(timestamps)

        return self.get('activities/', auth_token, params=query_params)
    def get_activities(self,
                       ids=None,
                       foreign_id_times=None,
                       enrich=False,
                       reactions=None,
                       **params):
        """
        Retrieves activities by their ID or foreign_id + time combination

        Pass enrich and reactions options for enrichment

        ids: list of activity IDs
        foreign_id_time: list of tuples (foreign_id, time)
        """
        auth_token = self.create_jwt_token("activities", "*", feed_id="*")

        if ids is None and foreign_id_times is None:
            raise TypeError(
                "One the parameters ids or foreign_id_time must be provided and not None"
            )

        if ids is not None and foreign_id_times is not None:
            raise TypeError(
                "At most one of the parameters ids or foreign_id_time must be provided"
            )

        endpoint = "activities/"
        if enrich or reactions is not None:
            endpoint = "enrich/" + endpoint

        query_params = {**params}

        if ids is not None:
            query_params["ids"] = ",".join(ids)

        if foreign_id_times is not None:
            validate_foreign_id_time(foreign_id_times)
            foreign_ids, timestamps = zip(*foreign_id_times)
            timestamps = map(_datetime_encoder, timestamps)
            query_params["foreign_ids"] = ",".join(foreign_ids)
            query_params["timestamps"] = ",".join(timestamps)

        query_params.update(get_reaction_params(reactions))

        return self.get(endpoint, auth_token, params=query_params)