def delete(self, request, **kwargs): return opener.open(request, **kwargs) def read(self, request, **kwargs): return opener.open(request, **kwargs) def update(self, request, **kwargs): return opener.open(request, **kwargs) class BinaryHandler(NullHandler): pass binary_resource = resource.Resource(BinaryHandler) class ClientHandler(NullHandler): pass client_resource = resource.Resource(ClientHandler) class EncounterHandler(NullHandler): pass encounter_resource = resource.Resource(EncounterHandler)
request.full_clean() form = request.data try: messages = format_sms(form['message']) #http://api.clickatell.com/http/sendmsg?user=clark&password=4moc@mobile&api_id=3135262&to=16178770502&text=this+is+a+test for message in messages: params = urllib.urlencode({ 'user': settings.CLICKATELL_USER, 'password': settings.CLICKATELL_PASSWORD, 'api_id': settings.CLICKATELL_API, 'to': form['recipient_addr'], 'text': message }) response = urllib.urlopen(settings.CLICKATELL_URI % params).read() result = succeed('message sent to: %s' % form['recipient_addr']) except Exception as e: logging.error("Clickatell send fail: %s: %s" % (form['recipient_addr'], e)) return fail('message send fail: %s' % form['recipient_addr']) return result def read(self, request, notification_id=None): ''' Requests notifications cached and sent from this server ''' pass notification_resource = resource.Resource(NotificationHandler)
operations) for operation, op_dict in zip(operations, op_dicts): logging.debug("Printing %s" % operation) for k, v in op_dict.items(): logging.debug("%s: %s" % (k, v)) return fail("Missing required values.") return wrap class ClientHandler(BaseHandler): model = models.Client fields = ('name') client_resource = resource.Resource(ClientHandler) class StatusHandler(BaseHandler): allowed_methods = ('GET', ) def read(self, request): username = request.REQUEST.get("username", None) password = request.REQUEST.get("password", None) logging.info("Status handler checking whether username: "******"%s and password: %s are valid." % (username, password)) omrs = openmrs.OpenMRS(username, password, settings.OPENMRS_SERVER_URL) if omrs.validate_credentials(username, password): status = json.dumps({ 'api_version': "1.0",
@dispatch('POST') def create(self, request, *pargs, **kwargs): path = dispatch_reverse(_namespace, Dispatchable.CLIENT, method='create') # execute upstream request result = _opener.open(path=path, data=request.dispatch_form.dispatch_data) if re.search(_login_re, result.data['dispatch']): return SUCCESS(u'logged in to OpenMRS') else: return FAIL(u'could not log in to OpenMRS') client_resource = resource.Resource(ClientHandler) class EncounterHandler(BaseHandler): """ Handles encounter requests. """ allowed_methods = ('GET', 'POST') v_form = EncounterForm @dispatch('POST') def create(self, request, **kwargs): ''' Posts an encounter to the Sana queue in OpenMRS ''' debug_api_request(self, 'create', request) # Do an auth check first u = request.dispatch_form.data.get('username', None) p = request.dispatch_form.data.get('password', None) auth = {'username': u, 'password': p} if u and p else None
data = self.flatten_dict(getattr(request, 'GET')) host, port, path = _strip_host(data) _data = dict(list((str(k), str(v)) for k, v in data.items())) if len(_data) == 0: _data = None last = host if host else None q = urllib.urlencode(self.flatten_dict(getattr(request, 'GET'))) #return HttpResponseRedirect('/api/echo/client/?' + q ) #return HttpResponseRedirect('http://' + host ) return _open(last, port, path + '?' + q) def update(self, request, **kwargs): return _open(request, **kwargs) http_resource = resource.Resource(HTTPHandler) # path --> user --> opener _logins = {} class LoginHandler(BaseHandler): def read(self, request, **kwargs): _d = self.flatten_dict(getattr(request, 'GET')) host, port, path = _strip_host(_d) data = dict(list((str(k), str(v)) for k, v in _d.items())) if len(data) == 0: data = None return _login(host, port, path, data=data)