Skip to content

Commit

Permalink
Unify functions for querying user details into osm_get_user_details()
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaspons committed Dec 18, 2023
1 parent b574829 commit ea1ccc3
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 66 deletions.
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export(osm_delete_gpx)
export(osm_delete_note)
export(osm_delete_object)
export(osm_details_logged_user)
export(osm_details_user)
export(osm_details_users)
export(osm_diff_upload_changeset)
export(osm_download_changeset)
export(osm_feed_notes)
Expand All @@ -41,6 +39,7 @@ export(osm_get_metadata_gpx)
export(osm_get_objects)
export(osm_get_points_gps)
export(osm_get_preferences_user)
export(osm_get_user_details)
export(osm_hide_comment_changeset_discussion)
export(osm_history_object)
export(osm_list_gpxs)
Expand Down
26 changes: 26 additions & 0 deletions R/osm_get_user_details.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#' Details of users
#'
#' @param user_id The ids of the users to retrieve the details for, represented by a numeric or a character value (not
#' the display names).
#' @param format Format of the output. Can be `R` (default), `xml`, or `json`.
#'
#' @return
#' @family users' functions
#' @export
#'
#' @examples
#' \dontrun{
#' usrs <- osm_details_users(user_ids = c(1, 24, 44, 45, 46, 48, 49, 50))
#' usrs
#' }
osm_get_user_details <- function(user_id, format = c("R", "xml", "json")) {
format <- match.arg(format)

if (length(user_id) == 1) {
out <- osm_details_user(user_id = user_id, format = format)
} else {
out <- osm_details_users(user_ids = user_id, format = format)
}

return(out)
}
8 changes: 4 additions & 4 deletions R/osmapi_user_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
#' @param format Format of the output. Can be `R` (default), `xml`, or `json`.
#'
#' @return
#' @family users' functions
#' @export
# @family users' functions
#' @noRd
#'
#' @examples
#' \dontrun{
Expand Down Expand Up @@ -141,8 +141,8 @@ osm_details_user <- function(user_id, format = c("R", "xml", "json")) {
#' @param format Format of the output. Can be `R` (default), `xml`, or `json`.
#'
#' @return
#' @family users' functions
#' @export
# @family users' functions
#' @noRd
#'
#' @examples
#' \dontrun{
Expand Down
5 changes: 2 additions & 3 deletions man/osm_details_logged_user.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 0 additions & 29 deletions man/osm_details_user.Rd

This file was deleted.

3 changes: 1 addition & 2 deletions man/osm_get_preferences_user.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions man/osm_details_users.Rd → man/osm_get_user_details.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?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/">
<user id="11725140" display_name="jmaspons" account_created="2020-08-28T20:22:40Z">
<description></description>
<description>[Fòrums d'OSM](https://community.openstreetmap.org/u/jmaspons) - [Wiki d'OSM](https://wiki.openstreetmap.org/wiki/User:Jmaspons) - [OSM help](https://help.openstreetmap.org/users/23509/jmaspons)</description>
<contributor-terms agreed="true"/>
<img href="https://www.openstreetmap.org/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsiZGF0YSI6MzI3NjExMDUsInB1ciI6ImJsb2JfaWQifX0=--e51481680572af88f4292d4979957d058e824344/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJqcGciLCJyZXNpemVfdG9fbGltaXQiOlsxMDAsMTAwXX0sInB1ciI6InZhcmlhdGlvbiJ9fQ==--71e417a328c02e35ec87b6c7cd4e4524c74e4ec8/me.jpg"/>
<roles>
</roles>
<changesets count="25348"/>
<changesets count="26851"/>
<traces count="26"/>
<blocks>
<received count="0" active="0"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ I mainly map footpaths and other out-of-town things. Also see related profile o

There are some bits and pieces (including [two](https://github.com/SomeoneElseOSM/SomeoneElse-style) [parts](https://github.com/SomeoneElseOSM/openstreetmap-carto-AJT) of an OSM-Carto-derived rendering style designed for out-of-town England and Wales) over at [Github](https://github.com/SomeoneElseOSM) that look like [this](https://map.atownsend.org.uk/maps/map/map.html). There are some wiki pages behind [here](https://wiki.openstreetmap.org/wiki/User:SomeoneElse) (mostly to do with tileserver setup).

I'm a member of the [Data Working Group](http://wiki.openstreetmap.org/wiki/Data_working_group) (that's what the blue star above means), but if you've you've got any issues to raise with the DWG the [group email address](http://wiki.osmfoundation.org/wiki/Data_Working_Group#Contact) is the best one to use.
I'm a member of the [Data Working Group](http://wiki.openstreetmap.org/wiki/Data_working_group) (that's what the blue star above means), but if you've got any issues to raise with the DWG the [group email address](http://wiki.osmfoundation.org/wiki/Data_Working_Group#Contact) is the best one to use.

Other related accounts are [SomeoneElse2](http://www.openstreetmap.org/user/SomeoneElse2). [SomeoneElseSC](https://www.openstreetmap.org/user/SomeoneElseSC) and [SomeoneElse_Revert](http://www.openstreetmap.org/user/SomeoneElse_Revert), which is mainly used where people have requested that I help with reversions.

</description>
The "User id" of this account is "61942". I mention that because there have been a few attempts over the years to impersonate DWG members, including me, using names such as "SomeoneEIse" (with a capital "i" instead of a lower case "l") and others with various UTF-8 versions of characters that look similar to, but are not, regular ascii characters.</description>
<contributor-terms agreed="true"/>
<roles>
<moderator/>
</roles>
<changesets count="29842"/>
<traces count="5930"/>
<changesets count="43837"/>
<traces count="6011"/>
<blocks>
<received count="0" active="0"/>
<issued count="2691" active="847"/>
<issued count="10321" active="8376"/>
</blocks>
</user>
</osm>
53 changes: 53 additions & 0 deletions tests/testthat/mock_details_users/osm.org/api/0.6/users-48e738.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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/">
<user id="61942" display_name="SomeoneElse" account_created="2008-08-24T23:21:40Z">
<description>I live near York (UK), though I do occasionally [venture further afield](http://yosmhm.neis-one.org/?zoom=6&amp;lat=53.08324&amp;lon=-2.42578&amp;layers=B000TTF&amp;u=SomeoneElse).
I mainly map footpaths and other out-of-town things. Also see related profile on
&lt;a rel="me" href="https://en.osm.town/@SomeoneElse"&gt;Mastodon&lt;/a&gt;.

There are some bits and pieces (including [two](https://github.com/SomeoneElseOSM/SomeoneElse-style) [parts](https://github.com/SomeoneElseOSM/openstreetmap-carto-AJT) of an OSM-Carto-derived rendering style designed for out-of-town England and Wales) over at [Github](https://github.com/SomeoneElseOSM) that look like [this](https://map.atownsend.org.uk/maps/map/map.html). There are some wiki pages behind [here](https://wiki.openstreetmap.org/wiki/User:SomeoneElse) (mostly to do with tileserver setup).

I'm a member of the [Data Working Group](http://wiki.openstreetmap.org/wiki/Data_working_group) (that's what the blue star above means), but if you've got any issues to raise with the DWG the [group email address](http://wiki.osmfoundation.org/wiki/Data_Working_Group#Contact) is the best one to use.

Other related accounts are [SomeoneElse2](http://www.openstreetmap.org/user/SomeoneElse2). [SomeoneElseSC](https://www.openstreetmap.org/user/SomeoneElseSC) and [SomeoneElse_Revert](http://www.openstreetmap.org/user/SomeoneElse_Revert), which is mainly used where people have requested that I help with reversions.

The "User id" of this account is "61942". I mention that because there have been a few attempts over the years to impersonate DWG members, including me, using names such as "SomeoneEIse" (with a capital "i" instead of a lower case "l") and others with various UTF-8 versions of characters that look similar to, but are not, regular ascii characters.</description>
<contributor-terms agreed="true"/>
<roles>
<moderator/>
</roles>
<changesets count="43837"/>
<traces count="6011"/>
<blocks>
<received count="0" active="0"/>
<issued count="10321" active="8376"/>
</blocks>
</user>
<user id="564990" display_name="mavl" account_created="2011-12-05T15:23:13Z">
<description>Занимаюсь Тюменской областью (Россия). Родной город – Заводоуковск. Также эта учётная запись была использована рабочей группой по данным (например, для откатов пакетов правок).
Je mappe Oblast de Tioumen (Russie). Ma ville natale est Zavodooukovsk. Aussi ce compte d'utilisateur été utilisé par le Data Working Group (par exemple, pour les retours des groupes des modifications).
I map Tyumen Oblast (Russia). My native town is Zavodoukovsk. Also this account was used by Data Working Group (for example, the reverts of the changesets).
=============================================================
*Забытые страницы сайта:*

https://www.openstreetmap.org/fixthemap
https://www.openstreetmap.org/user_blocks
https://www.openstreetmap.org/redactions

*Некоторые настройки сервера:*

https://www.openstreetmap.org/api/versions
https://www.openstreetmap.org/api/capabilities</description>
<contributor-terms agreed="true"/>
<img href="https://www.openstreetmap.org/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsiZGF0YSI6NDIzOTY2LCJwdXIiOiJibG9iX2lkIn19--3b784f4dde057612c331d651f52ebe6584b66df2/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJnaWYiLCJyZXNpemVfdG9fbGltaXQiOlsxMDAsMTAwXX0sInB1ciI6InZhcmlhdGlvbiJ9fQ==--84f2f91a334e8f265fc5bf85e4ea3c7805f829f8/osm-000.gif"/>
<roles>
<moderator/>
</roles>
<changesets count="6794"/>
<traces count="257"/>
<blocks>
<received count="0" active="0"/>
<issued count="547" active="192"/>
</blocks>
</user>
</osm>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<contributor-terms agreed="true"/>
<roles>
</roles>
<changesets count="1114"/>
<changesets count="1142"/>
<traces count="23"/>
<blocks>
<received count="0" active="0"/>
Expand All @@ -16,7 +16,7 @@
<contributor-terms agreed="true"/>
<roles>
</roles>
<changesets count="536"/>
<changesets count="538"/>
<traces count="64"/>
<blocks>
<received count="0" active="0"/>
Expand Down Expand Up @@ -54,7 +54,7 @@ mm-&amp;lt;date&amp;gt;-mtk.gpx - maemo mapper + BT-Q1000 (MTK Chip)</descript
<contributor-terms agreed="true"/>
<roles>
</roles>
<changesets count="795"/>
<changesets count="796"/>
<traces count="426"/>
<blocks>
<received count="0" active="0"/>
Expand Down
18 changes: 11 additions & 7 deletions tests/testthat/test-user_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ class_columns <- list(
## Details of a user: `GET /api/0.6/user/#id` ----

test_that("osm_details_user works", {
usr <- list()
with_mock_dir("mock_details_user", {
usr <- osm_details_user(user_id = "11725140")
usr$usr <- osm_get_user_details(user_id = "11725140")
usr$mod <- osm_get_user_details(user_id = 61942)
})

expect_s3_class(usr, "data.frame")
expect_named(usr, column_users)
lapply(usr, expect_s3_class, "data.frame")
lapply(usr, function(x) expect_named(x, column_users))

mapply(function(x, cl) expect_true(inherits(x, cl)), x = usr, cl = class_columns[names(usr)])
lapply(usr, lapply, function(x) {
mapply(function(y, cl) expect_true(inherits(y, cl)), y = x, cl = class_columns[names(x)])
})

# Check that time is extracted, otherwise it's 00:00:00 in local time
expect_false(strftime(as.POSIXct(usr$account_created), format = "%M:%S") == "00:00")
lapply(usr, function(x) expect_false(all(strftime(as.POSIXct(x$account_created), format = "%M:%S") == "00:00")))
})


Expand All @@ -33,8 +37,8 @@ test_that("osm_details_user works", {
test_that("osm_details_users works", {
usrs <- list()
with_mock_dir("mock_details_users", {
usrs$usrs <- osm_details_users(user_ids = c(1, 24, 44, 45, 46, 48, 49, 50))
usrs$mod <- osm_details_users(user_ids = 61942)
usrs$usrs <- osm_get_user_details(user_id = c(1, 24, 44, 45, 46, 48, 49, 50))
usrs$mod <- osm_get_user_details(user_id = c(61942, 564990))
})

lapply(usrs, expect_s3_class, "data.frame")
Expand Down

0 comments on commit ea1ccc3

Please sign in to comment.