Skip to content

Commit

Permalink
New api management
Browse files Browse the repository at this point in the history
  • Loading branch information
dieghernan committed Oct 21, 2021
1 parent 8bb7972 commit d1009a9
Show file tree
Hide file tree
Showing 20 changed files with 194 additions and 164 deletions.
32 changes: 21 additions & 11 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
# nominatimlite 0.1.3

- Skip API query tests on CRAN to avoid false positives.
- Skip API query tests on CRAN to avoid false positives.

- Centralize API queries on (internal) function `api_call()`.

- Queries fully honors now the [Nominatim Usage
Policy](https://operations.osmfoundation.org/policies/nominatim/). Queries
may be slower now.

# nominatimlite 0.1.2

- New internal: `nominatim_check_access()`.
- New internal: `nominatim_check_access()`.

- Adapt tests to `testthat` v3.1.0.
- Adapt tests to `testthat` v3.1.0.

# nominatimlite 0.1.1

- Adapt tests to **CRAN** checks.
- Adapt tests to **CRAN** checks.

# nominatimlite 0.1.0

- **CRAN** release.
- Adjust query rate limits to Nominatim policy.
- New `strict` argument on `geo_amenity()` and `geo_amenity_sf()`.
- Parameter `polygon` changed to `points_only`
([#8](https://github.com/dieghernan/nominatimlite/issues/8)) thanks to
@jlacko.
- Package now falls gracefully if url not reachable.
- **CRAN** release.

- Adjust query rate limits to Nominatim policy.

- New `strict` argument on `geo_amenity()` and `geo_amenity_sf()`.

- Parameter `polygon` changed to `points_only`
([#8](https://github.com/dieghernan/nominatimlite/issues/8)) thanks to
@jlacko.

- Package now falls gracefully if url not reachable.

# nominatimlite 0.0.1

Expand Down
20 changes: 6 additions & 14 deletions R/geo_address_lookup.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,14 @@ geo_address_lookup <- function(osm_ids,

json <- tempfile(fileext = ".json")

# nocov start
res <- tryCatch(
download.file(url, json, mode = "wb", quiet = isFALSE(verbose)),
warning = function(e) {
return(NULL)
},
error = function(e) {
return(NULL)
}
)
res <- api_call(url, json, isFALSE(verbose))

if (is.null(res)) {
message(url, " not reachable.", nodes)
# nocov start
if (isFALSE(res)) {
message(url, " not reachable.")
result_out <- tibble::tibble(query = paste0(type, osm_ids), a = NA, b = NA)
names(result_out) <- c("query", lat, long)
return(result_out)
return(invisible(result_out))
}
# nocov end

Expand All @@ -101,7 +93,7 @@ geo_address_lookup <- function(osm_ids,
message("No results for query ", nodes)
result_out <- tibble::tibble(query = paste0(type, osm_ids), a = NA, b = NA)
names(result_out) <- c("query", lat, long)
return(result_out)
return(invisible(result_out))
}

# Rename
Expand Down
20 changes: 6 additions & 14 deletions R/geo_address_lookup_sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,13 @@ geo_address_lookup_sf <- function(osm_ids,

json <- tempfile(fileext = ".geojson")

# nocov start
res <- tryCatch(
download.file(url, json, mode = "wb", quiet = isFALSE(verbose)),
warning = function(e) {
return(NULL)
},
error = function(e) {
return(NULL)
}
)
res <- api_call(url, json, quiet = isFALSE(verbose))

if (is.null(res)) {
message(url, " not reachable.", nodes)
# nocov start
if (isFALSE(res)) {
message(url, " not reachable.")
result_out <- data.frame(query = paste0(type, osm_ids))
return(result_out)
return(invisible(result_out))
}
# nocov end

Expand All @@ -109,7 +101,7 @@ geo_address_lookup_sf <- function(osm_ids,
if (length(names(sfobj)) == 1) {
message("No results for query ", nodes)
result_out <- data.frame(query = paste0(type, osm_ids))
return(result_out)
return(invisible(result_out))
}


Expand Down
23 changes: 6 additions & 17 deletions R/geo_amenity.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ geo_amenity <- function(bbox,
all_res <- NULL

for (i in seq_len(length(amenity))) {
if (i > 1) {
Sys.sleep(1)
}

res_single <- geo_amenity_single(
bbox = bbox,
amenity = amenity[i],
Expand Down Expand Up @@ -179,22 +175,15 @@ geo_amenity_single <- function(bbox,
json <- tempfile(fileext = ".json")


# nocov start
res <- tryCatch(
download.file(url, json, mode = "wb", quiet = isFALSE(verbose)),
warning = function(e) {
return(NULL)
},
error = function(e) {
return(NULL)
}
)

if (is.null(res)) {
res <- api_call(url, json, isFALSE(verbose))

# nocov start
if (isFALSE(res)) {
message(url, " not reachable.")
result_out <- tibble::tibble(query = amenity, a = NA, b = NA)
names(result_out) <- c("query", lat, long)
return(result_out)
return(invisible(result_out))
}
# nocov end

Expand All @@ -214,7 +203,7 @@ geo_amenity_single <- function(bbox,
message("No results for query ", amenity)
result_out <- tibble::tibble(query = amenity, a = NA, b = NA)
names(result_out) <- c("query", lat, long)
return(result_out)
return(invisible(result_out))
}

# Rename
Expand Down
22 changes: 5 additions & 17 deletions R/geo_amenity_sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ geo_amenity_sf <- function(bbox,
all_res <- NULL

for (i in seq_len(length(amenity))) {
if (i > 1) {
Sys.sleep(1)
}

res_single <- geo_amenity_sf_single(
bbox = bbox,
amenity = amenity[i],
Expand Down Expand Up @@ -163,21 +159,13 @@ geo_amenity_sf_single <- function(bbox,

json <- tempfile(fileext = ".geojson")

# nocov start
res <- tryCatch(
download.file(url, json, mode = "wb", quiet = isFALSE(verbose)),
warning = function(e) {
return(NULL)
},
error = function(e) {
return(NULL)
}
)
res <- api_call(url, json, isFALSE(verbose))

if (is.null(res)) {
# nocov start
if (isFALSE(res)) {
message(url, " not reachable.")
result_out <- data.frame(query = amenity)
return(result_out)
return(invisible(result_out))
}

# nocov end
Expand All @@ -193,7 +181,7 @@ geo_amenity_sf_single <- function(bbox,
if (length(names(sfobj)) == 1) {
message("No results for query ", amenity)
result_out <- data.frame(query = amenity)
return(result_out)
return(invisible(result_out))
}


Expand Down
22 changes: 5 additions & 17 deletions R/geo_lite.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ geo_lite <- function(address,
all_res <- NULL

for (i in seq_len(length(address))) {
if (i > 1) {
Sys.sleep(1)
}

res_single <- geo_lite_single(
address = address[i],
lat,
Expand Down Expand Up @@ -124,22 +120,14 @@ geo_lite_single <- function(address,

json <- tempfile(fileext = ".json")

# nocov start
res <- tryCatch(
download.file(url, json, mode = "wb", quiet = isFALSE(verbose)),
warning = function(e) {
return(NULL)
},
error = function(e) {
return(NULL)
}
)
res <- api_call(url, json, quiet = isFALSE(verbose))

if (is.null(res)) {
# nocov start
if (isFALSE(res)) {
message(url, " not reachable.")
result_out <- tibble::tibble(query = address, a = NA, b = NA)
names(result_out) <- c("query", lat, long)
return(result_out)
return(invisible(result_out))
}
# nocov end

Expand All @@ -160,7 +148,7 @@ geo_lite_single <- function(address,
message("No results for query ", address)
result_out <- tibble::tibble(query = address, a = NA, b = NA)
names(result_out) <- c("query", lat, long)
return(result_out)
return(invisible(result_out))
}

# Rename
Expand Down
22 changes: 6 additions & 16 deletions R/geo_lite_sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ geo_lite_sf <- function(address,
all_res <- NULL

for (i in seq_len(length(address))) {
if (i > 1) {
Sys.sleep(1)
}

res_single <- geo_lite_sf_single(
address = address[i],
limit,
Expand Down Expand Up @@ -159,21 +155,15 @@ geo_lite_sf_single <- function(address,

json <- tempfile(fileext = ".geojson")

res <- api_call(url, json, quiet = isFALSE(verbose))


# nocov start
res <- tryCatch(
download.file(url, json, mode = "wb", quiet = isFALSE(verbose)),
warning = function(e) {
return(NULL)
},
error = function(e) {
return(NULL)
}
)

if (is.null(res)) {
if (isFALSE(res)) {
message(url, " not reachable.")
result_out <- data.frame(query = address)
return(result_out)
return(invisible(result_out))
}
# nocov end

Expand All @@ -187,7 +177,7 @@ geo_lite_sf_single <- function(address,
if (length(names(sfobj)) == 1) {
message("No results for query ", address)
result_out <- data.frame(query = address)
return(result_out)
return(invisible(result_out))
}

# Prepare output
Expand Down
Loading

0 comments on commit d1009a9

Please sign in to comment.