def __get_users_by_user_ids(user_ids): container = _get_container() database = Database(container, '') predicate = Predicate(_id__in=user_ids) query = Query('user', predicate=predicate, limit=10000) users = database.query(query) return [serialize_record(u) for u in users]
def save(self, arg, atomic=False): if not isinstance(arg, list): arg = [arg] records = [serialize_record(item) if isinstance(item, Record) else item for item in arg] return self.container.send_action('record:save', { 'database_id': self.database_id, 'records': records, 'atomic': atomic })
def publish_typing_lambda(conversation_id, evt, at): if evt not in ['begin', 'pause', 'finished']: raise SkygearChatException('Typing event is invalid') try: # FIXME: datetime format should be from py-skygear dt = datetime.strptime(at, '%Y-%m-%dT%H:%M:%S.%fZ') except ValueError: raise SkygearChatException('Event time is not in correct format') c = Conversation.fetch_one(conversation_id) serialized_conversation = serialize_record(c) participant_ids = serialized_conversation['participant_ids'] send_typing_started_hook(serialized_conversation, participant_ids, evt) return publish_typing(c, evt, dt)
def save_user_record(user_record): """ Save the user record to Skygear Record API. """ container = SkygearContainer(api_key=skyoptions.masterkey) resp = container.send_action("record:save", {"records": [serialize_record(user_record)]}, 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")