Esempio n. 1
0
    def query(self, query):
        include = {v: {"$type": "keypath", "$val": v}
                   for v in list(set(query.include))}

        payload = {'database_id': self.database_id,
                   'record_type': query.record_type,
                   'predicate': query.predicate.to_dict(),
                   'count': query.count,
                   'sort': query.sort,
                   'include': include}

        if query.offset is not None:
            payload['offset'] = query.offset
        if query.limit is not None:
            payload['limit'] = query.limit
        result = self.container.send_action('record:query', payload)
        if 'error' in result:
            raise SkygearChatException(result['error']['message'])
        result = result['result']
        output = []
        for r in result:
            record = deserialize_record(r)
            if '_transient' in r:
                t = r['_transient']
                record['_transient'] = {k: deserialize_record(t[k])
                                        for k in t.keys()}
            if 'attachment' in r:
                record['attachment'] = r['attachment'].copy()
                record['attachment']['$url'] =\
                    sign_asset_url(r['attachment']['$name'])
            output.append(record)
        return output
Esempio n. 2
0
 def record(self):
     return deserialize_record({
         '_id': 'message/1',
         '_access': None,
         '_ownerID': 'user1',
         'conversation': 'conversation1',
         'body': 'hihi'
     })
Esempio n. 3
0
 def original_record(self):
     return deserialize_record({
         '_id': 'message/1',
         '_access': None,
         '_ownerID': 'user1',
         'conversation': {
             '$type': 'ref',
             '$id': 'conversation/1'
         },
         'body': 'hihi'
     })
Esempio n. 4
0
def fetch_user_record(auth_id):
    """
    Fetch the user record from Skygear Record API. The returned value
    is a user record in Record class.
    """
    container = SkygearContainer(api_key=skyoptions.masterkey)

    resp = container.send_action("record:fetch",
                                 {"ids": ['user/{}'.format(auth_id)]},
                                 plugin_request=True)
    try:
        if "error" in resp:
            raise SkygearException.from_dict(resp["error"])
    except (ValueError, TypeError, KeyError):
        raise SkygearContainer("container.send_action is buggy")
    return deserialize_record(resp['result'][0])