eskerda / pybikes

bike sharing + python = pybikes
https://citybik.es
GNU Lesser General Public License v3.0
559 stars 169 forks source link

Filters not working #754

Closed mwierzbinski closed 1 month ago

mwierzbinski commented 1 month ago

During testing the api I noticed that the filter feature is not working:

Field filtering

Fields can be filtered by adding a ?fields=list,of,fields parameter to any request. Field visibility gets only into the first document for now, but we plan on supporting lucene type parameters to allow filterings like location.city,station.*

For example http://api.citybik.es/v2/networks?fields=id,name,href will render just the name, id and API endpoint of each network

{
  "networks": [
    {
        "href": "/v2/networks/velib", 
        "id": "velib", 
        "name": "V\u00e9lib'"
    }, 
    {
        "href": "/v2/networks/valenbisi", 
        "id": "valenbisi", 
        "name": "Valenbisi"
    }, 
    {
        "href": "/v2/networks/ecobici", 
        "id": "ecobici", 
        "name": "EcoBici"
    },
    {...}
  ]
}

When I try to send url with fields I'm getting the same results as without parameters.

eskerda commented 1 month ago

We do not support field filtering anymore on the API. It was barely used and decided to scrap that feature off during a rewrite of the API.

From the top of your head, do you find any particular case on which this feature would be useful?

mwierzbinski commented 1 month ago

I think the only reason to use it is to limit the response size. In my case I was using your API for a mobile app and there was just a lot of information that its not necessary. I don't think it's crucial feature in any way.

I do have a question, is it possible to pass location as a parameter and get list sorted by nearest station?

Also can you retrieve stations in a sorted way? i.e by name?

eskerda commented 1 month ago

I do have a question, is it possible to pass location as a parameter and get list sorted by nearest station?

As in, on a specific network or any network?

Also can you retrieve stations in a sorted way? i.e by name?

In general, we decided to not provide these shortcuts that should be easily done on the client. Getting nearest station from any network is arguably different and we might provide that, but to sort a list of lat lngs on a network, to a particular lat,lng is easy to do. See https://github.com/eskerda/python-citybikes/blob/af7b7525d79e7d9f1e480b222bd452b35e8a95e1/citybikes/utils.py#L1-L25

If possible, we prefer to not deal at all with client lat/lng for privacy purposes.

eskerda commented 1 month ago

@mwierzbinski I have updated the API to accept field filtering again. Give it a try and let me know if it works for you

https://api.citybik.es/v2/networks?fields=name,location.latitude,location.longitude,href https://api.citybik.es/v2/networks/bicing?fields=name,stations.free_bikes,stations.empty_slots,stations.extra.uid