def lambda_handler(event, context): try: dvc = device.deserialize(event["device"]) usr = user.User.get(event["id"]) except: return respond("400", device.Device(-1, "").serialize()) if not all(x is not None for x in [dvc, usr]): return respond("400", device.Device(-1, "").serialize()) id = dvc.post(usr) dvc.id = id return respond("200", dvc.serialize())
def confirm_help(userid): session_attributes = {"id": userid} card_title = "Confirm" speech_output = "Help is on the way, !" # If the user either does not reply to the welcome message or says something # that is not understood, they will be prompted again with this text. reprompt_text = "Please verify if you need help." should_end_session = True json_string = json.dumps({ "devicetype": "alexa", "messagetype": "input", "userid": userid }) temp_device = device.Device(-1, json_string) citizen_uri = "https://prbw36cvje.execute-api.us-east-1.amazonaws.com/dev/device/user" # headers_citizen = {"device": json.dumps(temp_device.working_serializer(), cls=JsonSerializer)} ctz = user.User.serialize( requests.get(citizen_uri).text) #, headers=headers_citizen).text print("Citizen? " + ctz) # headers_alarm = {"citizen": ctz_json} alarm_uri = "https://prbw36cvje.execute-api.us-east-1.amazonaws.com/dev/citizen//alarm" print("Post Alarm: " + requests.post(alarm_uri).text) return build_response( session_attributes, build_speechlet_response(card_title, speech_output, reprompt_text, should_end_session))
def instantiate_from(self, filename): datadir = os.environ.get('FHIR_UNITTEST_DATADIR') or \ os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'fhir-parser', 'downloads')) with io.open(os.path.join(datadir, filename), 'r', encoding='utf-8') as handle: js = json.load(handle) self.assertEqual("Device", js["resourceType"]) return device.Device(js)
def testDevice2(self): inst = self.instantiate_from("device-example.json") self.assertIsNotNone(inst, "Must have instantiated a Device instance") self.implDevice2(inst) js = inst.as_json() self.assertEqual("Device", js["resourceType"]) inst2 = device.Device(js) self.implDevice2(inst2)
def lambda_handler(event, context): try: dvc = deserialize(event["device"]) except: return respond("400", event["device"]) if not dvc: return respond("400", event["device"]) dvc.delete() return respond("200", device.Device(-1, "").serialize())
def make_device(self, data): return device.Device(data["id"], data["devicetype"])
#!/usr/bin/env python # -*- coding: utf-8 -*- from bottle import request, response, install, HTTPError from bottle import get, post, delete, put, run from bottle_rest import json_to_params from bottlejwt import JwtPlugin from model import device from model import user dev = device.Device('ysto.db') u = user.User('ysto.db') install(JwtPlugin(u.validation, 'secret', algorithm='HS256')) @get('/') def about(): response.headers['Content-Type'] = 'application/json' response.headers['Cache-Control'] = 'no-cache' return {'about': 'ysto-API', 'versao': '2.0.0'} @get('/devices', auth=1) def devices(): response.headers['Content-Type'] = 'application/json' response.headers['Cache-Control'] = 'no-cache' return dev.all()