def get(self): """Return data if long url already exists.""" long_url = request.args.get('url') is_valid = validate_url(long_url) if is_valid is False: return jsonify(dict(error='Invalid URL.')), 400 link = self.manager.get(long_url) if self.manager.has_expired(): return jsonify(dict(error="Link has expired")), 404 if link is None: abort(404) result = self.schema.dump(link) return jsonify(result.data), 200
def get(self): secret = request.headers.get('secret_key') short_url = request.args.get('url') is_valid = validate_url(short_url) if is_valid is False: return jsonify(dict(error='Invalid URL.')), 400 try: long_url = unshorten(short_url, secret_key=secret, query_by_code=True, request=request) result = self.schema.dump(long_url) except LinkExpired: return jsonify(dict(error="Link has expired")), 410 except URLAuthFailed: return jsonify(dict(error="Secret key not provided")), 403 except URLNotFound: return jsonify(dict(error="Invalid/Expired URL")), 404 return jsonify(result.data), 200