openstreetmap / openstreetmap-website

The Rails application that powers OpenStreetMap
https://www.openstreetmap.org/
GNU General Public License v2.0
2.21k stars 916 forks source link

Feature request: Add support for user preferences to be returned as JSON formatted response (API 0.6) #3160

Closed donalhunt closed 3 years ago

donalhunt commented 3 years ago

Discovered that while the /api/0.6/user/details endpoint will provide a json response, the /api/0.6/user/preferences endpoint does not. :(

GET /api/0.6/user/details with "Accept: application/json" header: {"user":{"id":12345,"display_name":"firstname surname","account_created":"1970-01-01T18:18:36Z","description":"","contributor_terms":{"agreed":true,"pd":false},"img":{"href":"https://www.gravatar.com/avatar/00000000000000000000000000.jpg"},"roles":[],"changesets":{"count":0},"traces":{"count":0},"blocks":{"received":{"count":0,"active":0}},"languages":["en-GB", "en"],"messages":{"received":{"count":0,"unread":0},"sent":{"count":0}}}}

GET /api/0.6/user/preferences with "Accept: application/json" header:

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="OpenStreetMap server" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
  <preferences>
<preference k="diary.default_language" v="en"/>
  </preferences>
</osm>

Looking at the codebase, this doesn't look particular hard to implement but I wanted to a) flag it as an issue and b) check if it would be worthwhile investing the time implementing it (e.g. by submitting a PR).

gravitystorm commented 3 years ago

Yep, at the moment only some of the API calls have json responses. I'm happy to see PRs to include more of the endpoints, or ideally all of them.

migurski commented 3 years ago

Can you point toward an example that we can copy, Andy?

mmd-osm commented 3 years ago

This user added some JSON stuff back in Sep 2020, and earlier: https://github.com/openstreetmap/openstreetmap-website/commits?author=mmd-osm

That’s all you need to know to get started.