def post(self): access_token = self.request.get("access_token") if access_token: status = self.facebook_login(access_token) else: status = self.google_login() serialization.json_dump(self.response, dict(status=status))
def _add_url(self, user): url = None try: url = super(ScriptApiUrl, self)._add_url(user) self.response.out.write(serialization.json_dump(self.response, {'status': 'ok', 'url': url.to_verbose_dict()})) except NoDeviceException: self.response.out.write(serialization.json_dump(self.response, {'status': 'no_devices'})) return url
def post(self): user = social.get_current_user() dev_id = self.request.get('device_id') default = self.request.get('default') if bool(default): device = self.set_default_device(dev_id) device = model.device_by(user, dev_id) device.name = self.request.get("name") or device.name serialization.json_dump(self.response, device.script_properties())
def get(self): dev_id = self.request.get('device_id') user = social.get_current_user() if dev_id is None or dev_id == '': devices = model.Device.filter_by_user(user).fetch(100) result = [{'id': dev.key().id(), 'name': dev.name, 'default': dev.default} for dev in devices] else: device = model.device_by(user, dev_id) result = device.script_properties() serialization.json_dump(self.response,result)
def delete(self): user = social.get_current_user() dev_id = self.request.get('device_id') device = model.device_by(user, dev_id) if device: urls = model.Url.all().filter("device =", device) urls = db.GqlQuery("SELECT __key__ FROM Url WHERE device = :1", device) db.delete(urls) device.delete() serialization.json_dump(self.response, {'status': 'ok'}) else: log.info("Unable to delete device. Device: '%s' not found", dev_id) serialization.json_dump(self.response, {'status': 'error'})
def delete(self, key): MAX_BULK = 20 log.info("Attempt to delete url: %s", key) url_keys = [key] url_keys = map(db.Key, url_keys[:MAX_BULK]) valid_urls = db.GqlQuery("SELECT * FROM Url WHERE email = :1 and __key__ in :2", self.user.email().lower(), url_keys).fetch(MAX_BULK) for url in valid_urls: url.mark_as_deleted() log.info("Valid urls: %s", valid_urls) if not valid_urls: self.response.set_status(404) return serialization.json_dump(self.response, [str(url.key()) for url in valid_urls])
def post(self): user = social.get_current_user() if not user: serialization.json_dump(self.response, dict(status="not-logged-in")) return #data = self.request.body #obj = json.loads(data) url = model.Url() url.device = None url.value = self.request.get('url') url.title = self.request.get('title') url.user = user if len(url.value) > 200: h = hashlib.sha1() h.update(url.value) url.hash = h.hexdigest() url.put() serialization.json_dump(self.response, dict(status="success")) return url #needed for tests
def _require_login(self): super(BookmarkletApiUrl, self)._require_login() self.response.out.write(serialization.json_dump(self.response, {'status': 'login_required'}))