Closed MathewBiddle closed 2 years ago
This is a great idea. We might be able to do this by creating a response class, say res
that has
__init__
method to fetch the datadisplay
method or show_json
method to return the raw response (as we are currently doing) from the APIget_search_url
method to return the API urlget_mapper_url
method to return the corresponding OBIS mapper urlto_pandas
method (as in the list of ideas) to return a pandas dataframe with the data.That might warrant us to change just the obisutils.py
file where we render the API response.
I like the idea of creating a response class, but I suggest something like OBISQueryResult
for the name. Python convention is to begin classes with upper-case and to place them in their own module.
Here's an initial work on converting each module to its own response class keeping all the methods intact as well. And adding a get_search_url()
method to return the corresponding API URL. https://github.com/ayushanand18/pyobis/blob/response-class/pyobis/occurrences/occurrences.py
One issue I am facing is pre-commit returns a coverage 77.1% while the pytest
powered tests return 100% coverage for all modules.
pytest
pre-commit (uses interrogate)
Here's an initial work on converting each module to its own response class keeping all the methods intact as well. And adding a
get_search_url()
method to return the corresponding API URL. https://github.com/ayushanand18/pyobis/blob/response-class/pyobis/occurrences/occurrences.py
This would look something like this in the docs
Just so I understand, each module will have this method?
So, for example, taxa
would be:
from pyobis.taxa import OBISQueryresult as OQR
query = OQR()
data = query.search(scientificname="Mola mola")
api_url = query.get_search_url()
print(api_url)
and so on for the other modules?
Just so I understand, each module will have this method?
So, for example,
taxa
would be:from pyobis.taxa import OBISQueryresult as OQR query = OQR() data = query.search(scientificname="Mola mola") api_url = query.get_search_url() print(api_url)
and so on for the other modules?
You are right. Since @7yl4r mentioned that python recommends creating classes for each module in the module itself so I took up this approach (if I understood it right).
Edit: ~Additionally, we might get into trouble while rendering the get_mapper_url()
method since not all OBIS endpoints have an equivalent mapper url, and that mapper uses taxonid to fetch records with scientificname not being a criterion. We just get to search by scientificname in the GUI but at the end it renders with taxonid only. So, if a user queries through scientificname in pyobis
we might need to first fetch the taxon id from worms or any other source. For Eg. for Mola mola the OBIS url might look like https://api.obis.org/occurrence?scientificname=Mola%20mola
and for mapper it would look like https://mapper.obis.org/?taxonid=127405
.~
Let's deal with the get_mapper_url()
in #69.
For each of the modules, we should have the ability to return the API url that is configured with our identified search.
For example,
Then,
would return
This gives the user a way to investigate how their query might be not providing the expected responses.
Related to #69