Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize the interface to ors_pois() #35

Open
aoles opened this issue Jun 11, 2018 · 0 comments
Open

Sanitize the interface to ors_pois() #35

aoles opened this issue Jun 11, 2018 · 0 comments
Assignees
Labels
💡 enhancement New feature or request
Milestone

Comments

@aoles
Copy link
Member

aoles commented Jun 11, 2018

Modify the function interface for the sake of usability rather than strictly reflect the API. For example, abandon request argument in favor of binary summary argument, and return the category list if none arguments were provided, i.e.:

  • ors_pois("pois", ...) -> ors_pois(..., summary = FALSE) (the default)
  • ors_pois("stats", ...) -> ors_pois(..., summary = TRUE)
  • ors_pois("list") -> ors_pois()

Additionally, ease-up things by expanding the nested geometry object into separate function arguments.

Think of a more convenient representation of the category list, or a helper function to facilitate specifying filters = list(category_ids = category)) by keywords rather than ids like in the following example.

ors_pois_ids <- function (category, group) {
  pois_list = ors_pois("list")
  
  group_ids = sapply(pois_list, `[[`, 'id')
  
  category_ids = lapply(pois_list, function(x) {
    unlist(unname(x$children))
  })
  category_ids <- do.call(c, unname(category_ids))
  if (missing(category) && missing(group))
    return(list(groups = group_ids, categories = category_ids))

  res <- list()

  if (!missing(category))
    res$category_ids <- I(unname(category_ids[category]))

  if (!missing(group))
    res$category_group_ids <- I(unname(group_ids[group]))

  res
}

ors_pois(geometry = list(geojson = list(type = "Point",
                                        coordinates = c(8.8034, 53.0756)),
                         buffer = 100),
         limit = 200,
         sortby = "distance",
         filters = ors_pois_ids(c("waste_basket", "ship")))
@aoles aoles self-assigned this Jun 11, 2018
@aoles aoles added the 💡 enhancement New feature or request label Jun 11, 2018
@aoles aoles added this to To do in version 0.3.0 via automation Jun 11, 2018
@aoles aoles added this to the version 0.3.0 milestone Jun 11, 2018
@aoles aoles modified the milestones: version 0.3, version 0.4 Apr 12, 2019
@aoles aoles removed this from To do in version 0.3.0 May 13, 2019
@aoles aoles changed the title Sanitize the output of ors_pois("list") Sanitize the interface to ors_pois() May 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant