iobis / pyobis

OBIS Python client
https://iobis.github.io/pyobis
MIT License
14 stars 10 forks source link

Add `.get_search_url()` function to all modules #70

Closed MathewBiddle closed 2 years ago

MathewBiddle commented 2 years ago

For each of the modules, we should have the ability to return the API url that is configured with our identified search.

For example,

res = occ.search(taxonid="1363", startdepth=0, enddepth=30, geometry="POLYGON ((-180 -30, 180 -30, 180 30, -180 30, -180 -30))")

Then,

res.get_search_url()

would return

https://api.obis.org/v3/occurrence?taxonid=1363&startdepth=0&enddepth=30&geometry=POLYGON%20%28%28-180%20-30%2C%20180%20-30%2C%20180%2030%2C%20-180%2030%2C%20-180%20-30%29%29

This gives the user a way to investigate how their query might be not providing the expected responses.

Related to #69

ayushanand18 commented 2 years ago

This is a great idea. We might be able to do this by creating a response class, say res that has

ayushanand18 commented 2 years ago

That might warrant us to change just the obisutils.py file where we render the API response.

7yl4r commented 2 years ago

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.

ayushanand18 commented 2 years ago

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

ayushanand18 commented 2 years ago

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 image

pre-commit (uses interrogate) image

ayushanand18 commented 2 years ago

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 image

MathewBiddle commented 2 years ago

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?

ayushanand18 commented 2 years ago

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.~

MathewBiddle commented 2 years ago

Let's deal with the get_mapper_url() in #69.