Exemplo n.º 1
0
def paper(paper_id: str, version: str) -> Response:
    """Document metadata endpoint."""
    data, status_code, headers = api.paper(f"{paper_id}v{version}")
    response_data = serialize.as_json(data["results"])
    headers.update({"Content-type": JSON})
    response: Response = make_response(response_data, status_code, headers)
    return response
Exemplo n.º 2
0
 def test_to_json(self):
     """Just your run-of-the-mill arXiv document generates valid JSON."""
     document = mocks.document()
     srlzd = serialize.as_json(document)
     res = jsonschema.RefResolver(
         "file://%s/" % os.path.abspath(os.path.dirname(self.SCHEMA_PATH)),
         None,
     )
     self.assertIsNone(
         jsonschema.validate(json.loads(srlzd), self.schema, resolver=res))
Exemplo n.º 3
0
 def test_to_json(self):
     """Just your run-of-the-mill arXiv document generates valid JSON."""
     document = mocks.document()
     meta = {"start": 0, "size": 50, "end": 50, "total": 500202}
     document_set = {"results": [document], "metadata": meta}
     srlzd = serialize.as_json(document_set)
     res = jsonschema.RefResolver(
         "file://%s/" % os.path.abspath(os.path.dirname(self.SCHEMA_PATH)),
         None,
     )
     self.assertIsNone(
         jsonschema.validate(json.loads(srlzd), self.schema, resolver=res))
Exemplo n.º 4
0
def search() -> Response:
    """Main query endpoint."""
    logger.debug("Got query: %s", request.args)
    data, status_code, headers = api.search(request.args)
    # requested = request.accept_mimetypes.best_match([JSON, ATOM_XML])
    # if requested == ATOM_XML:
    #     return serialize.as_atom(data), status, headers
    response_data = serialize.as_json(data["results"], query=data["query"])

    headers.update({"Content-type": JSON})
    response: Response = make_response(response_data, status_code, headers)
    return response