Ejemplo n.º 1
0
    def update_uext(self, uid, uext=None, timeout=None):
        url = UPDATE_UEXT_URL % {"appid": self._appid, "endpoint": self._endpoint}
        payload = {"apikey": self._appkey, "uid": validate_str(uid), "uext": validate_json(uext, default={})}
        res = requests.post(url, data=payload, verify=False, timeout=self._get_timeout(timeout))
        res.raise_for_status()

        return res.json()
Ejemplo n.º 2
0
    def auth(self, uid, uext=None, fids="", ss=None, timeout=None):
        url = AUTH_URL % {"appid": self._appid, "endpoint": self._endpoint}
        payload = {
            "apikey": self._appkey,
            "uid": validate_str(uid),
            "uext": validate_json(uext, default={}),
            "fids": validate_csv(fids, default=""),
            "ss": ss,
        }
        res = requests.post(url, data=payload, verify=False, timeout=self._get_timeout(timeout))
        res.raise_for_status()

        return res.json()
Ejemplo n.º 3
0
    def send_broadcast(self, data, room=None, store=None, socket=None, timeout=None):
        url = SEND_BROADCAST_URL % {"appid": self._appid, "endpoint": self._endpoint}
        payload = {
            "apikey": self._appkey,
            "data": validate_json(data),
            "room": None if room is None else validate_str(room),
            "store": None if store is None else validate_int(store),
            "socket": None if socket is None else validate_int(socket),
        }
        res = requests.post(url, data=payload, verify=False, timeout=self._get_timeout(timeout))
        res.raise_for_status()

        return res.json()
Ejemplo n.º 4
0
    def put_json(self, context, key=None, public=True, compress=False):
        _metadata = {'Content-Type': 'application/json; charset=UTF-8'}
        _json = validate_json(context)
        if compress:
            stringio = StringIO.StringIO()
            gzip_file = gzip.GzipFile(fileobj=stringio, mode='w')
            gzip_file.write(_json)
            gzip_file.close()
            _json = stringio.getvalue()
            _metadata.update({'Content-Encoding': 'gzip'})

        metadata = self._get_metadata(_metadata)
        return self.put(_json, key, metadata, public)
Ejemplo n.º 5
0
    def post_timeline(self, uid, data, room=None, pub=None, rpub=None, tag=None, timeout=None):
        url = POST_TIMELINE_URL % {"appid": self._appid, "endpoint": self._endpoint}
        payload = {
            "apikey": self._appkey,
            "uid": validate_str(uid),
            "data": validate_json(data),
            "room": None if room is None else validate_str(room),
            "pub": None if pub is None else validate_int(pub),
            "rpub": None if rpub is None else validate_int(rpub),
            "tag": None if tag is None else validate_str(tag),
        }
        res = requests.post(url, data=payload, verify=False, timeout=self._get_timeout(timeout))
        res.raise_for_status()

        return res.json()
Ejemplo n.º 6
0
    def send_unicast(
        self, uid, data, room=None, socket_room=None, fids=None, pub=None, rpub=None, tl=None, tag=None, timeout=None
    ):
        url = SEND_UNICAST_URL % {"appid": self._appid, "endpoint": self._endpoint}
        payload = {
            "apikey": self._appkey,
            "uid": validate_str(uid),
            "data": validate_json(data),
            "room": None if room is None else validate_str(room),
            "socket_room": None if socket_room is None else validate_str(socket_room),
            "fids": None if fids is None else validate_csv(fids),
            "pub": None if pub is None else validate_int(pub),
            "rpub": None if rpub is None else validate_int(rpub),
            "tl": None if tl is None else validate_int(tl),
            "tag": None if tag is None else validate_str(tag),
        }
        res = requests.post(url, data=payload, verify=False, timeout=self._get_timeout(timeout))
        res.raise_for_status()

        return res.json()