APIManager
- class ramose.APIManager(conf_files)[source]
Bases:
objectThis is the constructor of the APIManager class. It takes in input a list of API configuration files, each defined according to the Hash Format and following a particular structure, and stores all the operations defined within a dictionary. The structure of each item in the dictionary of the operations is defined as follows:
- {
- “/api/v1/references/(.+)”: {
“sparql”: “PREFIX …”, “method”: “get”, …
}
In particular, each key in the dictionary identifies the full URL of a particular API operation, and it is used so as to understand with operation should be called once an API call is done. The object associated as value of this key is the transformation of the related operation defined in the input Hash Format file into a dictionary.
In addition, it also defines additional structure, such as the functions to be used for interpreting the values returned by a SPARQL query, some operations that can be used for filtering the results, and the HTTP methods to call for making the request to the SPARQL endpoint specified in the configuration file.
- __max_size_csv()
- static nor_api_url(i, b='')[source]
This method takes an API operation object and an optional base URL (e.g. “/api/v1”) as input and returns the URL composed by the base URL plus the API URL normalised according to specific rules. In particular, these normalisation rules takes the operation URL (e.g. “#url /citations/{oci}”) and the specification of the shape of all the parameters between brackets in the URL (e.g. “#oci str([0-9]+-[0-9]+)”), and returns a new operation URL where the parameters have been substituted with the regular expressions defining them (e.g. “/citations/([0-9]+-[0-9]+)”). This URL will be used by RAMOSE for matching the particular API calls with the specific operation to execute.
- best_match(u)[source]
This method takes an URL of an API call in input and find the API operation URL and the related configuration that best match with the API call, if any.
- get_op(op_complete_url)[source]
This method returns a new object of type Operation which represent the operation specified by the input URL (parameter ‘op_complete_url)’. In case no operation can be found according by checking the configuration files available in the APIManager, a tuple with an HTTP error code and a message is returned instead.