Skip to content

Commit

Permalink
version 0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherkenny authored and cran-robot committed Nov 5, 2023
1 parent 2331cee commit 5556c37
Show file tree
Hide file tree
Showing 32 changed files with 348 additions and 99 deletions.
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: feltr
Title: Access the Felt API
Version: 0.0.2
Version: 0.0.4
Authors@R:
person(given = "Christopher T.",
family = "Kenny",
Expand All @@ -17,14 +17,15 @@ License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.2.3
Imports: cli, curl, fs, geojsonsf, httr2, jsonlite, purrr, rlang, sf,
stringr, tibble
URL: http://christophertkenny.com/feltr/
stringr, tibble, tidyr
URL: https://github.com/christopherkenny/feltr,
https://christophertkenny.com/feltr/
Suggests: httptest2, testthat (>= 3.0.0)
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2023-07-05 18:23:29 UTC; chris
Packaged: 2023-11-05 19:41:08 UTC; chris
Author: Christopher T. Kenny [aut, cre]
(<https://orcid.org/0000-0002-9386-6860>)
Maintainer: Christopher T. Kenny <christopherkenny@fas.harvard.edu>
Repository: CRAN
Date/Publication: 2023-07-06 14:00:05 UTC
Date/Publication: 2023-11-05 20:30:02 UTC
56 changes: 31 additions & 25 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
a85119eb8b0120e9b55e418813d7da1e *DESCRIPTION
a9e694f78ec01442ab117125cda3d31a *DESCRIPTION
616833dab9c77074aa2657b112f9b006 *LICENSE
49c6d2e68f787871b5180e2581a2a751 *NAMESPACE
fc8c3f4aba17dc5e5349f19f403e602b *NEWS.md
f889f13f4f86101b68895561b001531b *R/add.R
2199b979be638adaf01443069c817949 *NAMESPACE
0e1941838a7ae2a56e4f303a03121bec *NEWS.md
11654c3a6582fa75c979a0126bec76f4 *R/add.R
8fcd2188d566f0fb75a6b2a1b6c0bb44 *R/api_url.R
664bc1bbc9a7502133332dac60e4601c *R/create.R
f0e5a27a0faeae409b2a93dcdea14074 *R/delete.R
f278c9a0af3fe63ee62f618ab0fe247e *R/felt_key.R
ce4445d76f667ef40162fc32d37386c8 *R/finish_upload.R
a507a4859019128aff9522da7349af97 *R/comments.R
425fd99cd23538620f3b10d4b1c08268 *R/create.R
e6263dd45ac77d6ec32bfa47f30c283c *R/delete.R
183dcf51b5b936a92f18a011b6487a30 *R/felt_key.R
32b435983763b2124335da512f9b87de *R/finish_upload.R
d14cf3cd69beb12710970a876e364e31 *R/helpers.R
237763b046a5380d44a6dc0bfad7a468 *R/map.R
358003bfcd9a3512bb17f92d559bb7dd *R/map_elements.R
ecbdaa8a4d3478635cc95a1b4e2bf789 *R/proc.R
02478d6ea773f7ded0c72e56316e92cf *R/user.R
c8bee16add2c0cd8fb803b73fb55ea2b *README.md
6e317249d20cf6db4f16ff332547e44a *R/map.R
3caae159bf7d8de8f80438c6a10b623f *R/map_elements.R
2ce5fe7973e091479c301b490bc3f1ba *R/proc.R
7e517cf2e2fd2fc9add15eeba2f617b4 *R/style.R
91805a2193f70a2326dc24b85eadf32f *R/user.R
bc746cc83a43649ca33b24ee5c221a4d *README.md
dcafe3a9c7fc22b1830fe8c5bebde3a5 *inst/httptest2/redact.R
47024474bcdf50c357e673031273e3f4 *inst/towns.geojson
a0b9edb7109d774d7368f226d23c6d7c *man/felt_add_map_layers.Rd
65e462d0d60782227fb1d5dbcc4b281b *man/felt_add_map_layers_url.Rd
8a10e9cbd4dec730f65436b1f5b167da *man/felt_create_map.Rd
1be2c7cfda80ada35bfcbf369d93c619 *man/felt_delete_map.Rd
14471f60025ab3f70783abf1e3d688c7 *man/felt_delete_map_layer.Rd
7b6eeb77674fb869dfe52b1e77fe38e3 *man/felt_finish_upload.Rd
76f65dbdd6623811448fbae598d220b8 *man/felt_get_map.Rd
c5efa2eac855c704a6a15e8eb93834bf *man/felt_get_map_elements.Rd
ac6a20b3d829e4dd4ef3040af028a3be *man/felt_get_user.Rd
5d4852c51819d4048f274af6f2cfdb60 *man/felt_add_map_layers.Rd
744d4f45b61b48463b71d7d060480783 *man/felt_add_map_layers_url.Rd
7116d145f592773a287fb88cab37c40f *man/felt_create_map.Rd
d02cbd17bb082cf712a14a3ab726ef4f *man/felt_delete_map.Rd
247657cdfc5cdbd8ff1691487d64954e *man/felt_delete_map_layer.Rd
8f1efe35ab886a86badcc2394a48bb71 *man/felt_finish_upload.Rd
24760eda9be4e9b7d1e9e10ed1c6dee5 *man/felt_get_comments.Rd
d906eeadc26eb5d0b297ec63b29b2a8c *man/felt_get_map.Rd
1ac94ed566de7561d7baa86137a46b60 *man/felt_get_map_elements.Rd
b3e7a7dfb77501f48edcbf507c6d3ea4 *man/felt_get_style.Rd
e5d81e7f4a82f8fad994acbe81d5641a *man/felt_get_user.Rd
88f5b7d15ff04ae4b0a37e6b533e73a1 *man/felt_patch_style.Rd
d0014c782bb08375032c800c376d3d00 *man/figures/logo.png
22e89a3aad1cc54a3f97c521987c2633 *man/key.Rd
06ac6d486f81c291323f4aa8f77916a5 *man/set_felt_key.Rd
bd7fb8d3d200e42cf87b7ef8581e2840 *man/key.Rd
1f8fa48103f09e62a2cb1eece2205319 *man/set_felt_key.Rd
e09dfa175bba9ede03319f774ddcae22 *tests/testthat.R
ff3b353b55b6eaa57bec2ed603745880 *tests/testthat/add.R
b013980eae16bb9f943c1ff2f6475354 *tests/testthat/setup.R
121fdc6280a720c2a55c6e84a61d5e97 *tests/testthat/t/create/felt.com/api/v1/maps-b1286e-POST.json
058ce516e115d1b8efb611a80215afdd *tests/testthat/t/get_elements/felt.com/api/v1/maps/TBI8sDkmQjuK2GX9CSiHiUA/elements.R
661ee4e4456fd7998790598934f03259 *tests/testthat/t/user/felt.com/api/v1/user.json
4ae464b5e4c948170ffe99a9b9e0a52f *tests/testthat/test-comments.R
f060f0dae7f8431313ebd4231f9c034d *tests/testthat/test-create.R
f8f9cbf6b4b8f908ef0caa13a05b1b7c *tests/testthat/test-map.R
a283a68945923384add83c5abe272936 *tests/testthat/test-map.R
b3f9a1162626b1a99d09ca500f51c96b *tests/testthat/test-map_elements.R
d3cd84c5695fa3671622c9d9efe6f8f3 *tests/testthat/test-user.R
5 changes: 3 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ export(felt_create_map)
export(felt_delete_map)
export(felt_delete_map_layer)
export(felt_finish_upload)
export(felt_get_comments)
export(felt_get_map)
export(felt_get_map_elements)
export(felt_get_map_geojson)
export(felt_get_map_layers)
export(felt_get_map_sf)
export(felt_get_style)
export(felt_get_user)
export(felt_patch_style)
export(get_felt_key)
export(has_felt_key)
export(set_felt_key)
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# feltr 0.0.4

* Removes `felt_get_map_geojson()` and `felt_get_map_sf()`, as Felt removed these capabilities.
These will be restored in a future version, once the capabilities are available again.

# feltr 0.0.3

* Adds support for the comment export API with `felt_get_comments()`.
* Improves consistency in return values for `felt_add_map_layers_url()`.

# feltr 0.0.2

* Adds path arguments to `felt_set_key()` and `felt_get_map_sf()` to ensure compliance with CRAN policies in writing files.
Expand Down
16 changes: 13 additions & 3 deletions R/add.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
#' @return a string with the id for the created layer
#' @export
#'
#' @concept edits
#'
#' @examplesIf has_felt_key()
#' felt_add_map_layers(map_id = 'Rockland-2024-Districts-TBI8sDkmQjuK2GX9CSiHiUA',
#' layer <- felt_add_map_layers(map_id = 'Rockland-2024-Districts-TBI8sDkmQjuK2GX9CSiHiUA',
#' file_names = fs::path_package('feltr', 'towns.geojson'),
#' name = 'Towns')
#' layer
#' # and delete layer
#' felt_delete_map_layer(map_id = 'TBI8sDkmQjuK2GX9CSiHiUA', layer_id = layer)
felt_add_map_layers <- function(map_id, name = NULL, file_names = NULL,
fill_color = NULL, stroke_color = NULL) {
# don't support webhooks for now
Expand Down Expand Up @@ -64,16 +69,21 @@ felt_add_map_layers <- function(map_id, name = NULL, file_names = NULL,
#' @return a [tibble::tibble] for the created layer
#' @export
#'
#' @concept edits
#'
#' @examplesIf has_felt_key()
#' # split the URL for length reasons
#' url <- paste0(
#' 'https://www.rocklandgis.com/portal/sharing/rest/',
#' 'content/items/73fc78cb0fb04580b4788937fe5ee697/data'
#' )
#' felt_add_map_layers_url(
#' layer <- felt_add_map_layers_url(
#' map_id = 'Rockland-2024-Districts-TBI8sDkmQjuK2GX9CSiHiUA',
#' url = url,
#' name = 'Parks')
#' layer
#' # and delete the new layer
#' felt_delete_map_layer(map_id = 'TBI8sDkmQjuK2GX9CSiHiUA', layer_id = layer$id)
felt_add_map_layers_url <- function(map_id, url, name = NULL) {

body <- list(
Expand All @@ -97,6 +107,6 @@ felt_add_map_layers_url <- function(map_id, url, name = NULL) {
progress = out$data$attributes$progress,
id = out$data$id,
type = out$data$type,
relationships = out$data$relationships$datasets$data
relationships = list(out$data$relationships$datasets$data)
)
}
21 changes: 21 additions & 0 deletions R/comments.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#' Export Comments on an Existing Map
#'
#' @param map_id map identifier from url, from `https://felt.com/map/Readable-Name-map_id`
#'
#' @return a [tibble::tibble] for the map
#' @export
#'
#' @concept comments
#'
#' @examplesIf has_felt_key()
#' felt_get_comments(map_id = 'Rockland-2024-Districts-TBI8sDkmQjuK2GX9CSiHiUA')
felt_get_comments <- function(map_id) {
req <- httr2::request(base_url = api_url()) |>
httr2::req_url_path_append('maps', map_id, 'comments', 'export') |>
httr2::req_auth_bearer_token(token = get_felt_key())

req |>
httr2::req_perform() |>
httr2::resp_body_json() |>
proc_comments()
}
7 changes: 6 additions & 1 deletion R/create.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
#' @return a [tibble::tibble] for the new map
#' @export
#'
#' @concept map
#'
#' @examplesIf has_felt_key()
#' felt_create_map(title = 'feltr example')
#' map <- felt_create_map(title = 'feltr example')
#' map
#' # and delete it again
#' felt_delete_map(map_id = map$id)
felt_create_map <- function(title = NULL, basemap = NULL, layer_urls = NULL,
lat = NULL, lon = NULL, zoom = NULL) {
if (!is.null(layer_urls)) layer_urls <- as.list(layer_urls)
Expand Down
4 changes: 4 additions & 0 deletions R/delete.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#' @return response code
#' @export
#'
#' @concept edits
#'
#' @examplesIf has_felt_key()
#' layer <- felt_add_map_layers('TBI8sDkmQjuK2GX9CSiHiUA',
#' 'test', fs::path_package('feltr', 'towns.geojson'))
Expand All @@ -29,6 +31,8 @@ felt_delete_map_layer <- function(map_id, layer_id) {
#' @return response code
#' @export
#'
#' @concept map
#'
#' @examplesIf has_felt_key()
#' map <- felt_create_map(title = 'feltr example')
#' felt_delete_map(map_id = map$id)
Expand Down
4 changes: 4 additions & 0 deletions R/felt_key.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#'
#' @name key
#'
#' @concept key
#'
#' @examples
#' has_felt_key()
has_felt_key <- function() {
Expand Down Expand Up @@ -34,6 +36,8 @@ get_felt_key <- function() {
#' @return key, invisibly
#' @export
#'
#' @concept key
#'
#' @examples
#' example_env <- tempfile(fileext = '.Renviron')
#' set_felt_key('1234', r_env = example_env)
Expand Down
2 changes: 2 additions & 0 deletions R/finish_upload.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#' @return `httr2` status code
#' @export
#'
#' @concept edits
#'
#' @examplesIf has_felt_key()
#' felt_finish_upload('TBI8sDkmQjuK2GX9CSiHiUA')
felt_finish_upload <- function(map_id) {
Expand Down
35 changes: 17 additions & 18 deletions R/map.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
#' - `felt_get_map()` returns identifying information for the map
#' - `felt_get_map_layers()` returns information about each layer in the map
#' - `felt_get_map_elements()` returns the shapes for each layer in the map
#' - `felt_get_map_geojson()` downloads a geojson version of the map and returns the path
#' - `felt_get_map_sf` returns a tibble with an `sf` column of the map
#'
#' @param map_id map identifier from url, from `https://felt.com/map/Readable-Name-map_id`
#' @param path path to save map to locally as a `.geojson` file
#'
#' @return a [tibble::tibble] for the map
#' @export
#'
#' @concept get
#'
#' @examplesIf has_felt_key()
#' felt_get_map('Rockland-2024-Districts-TBI8sDkmQjuK2GX9CSiHiUA')
#' felt_get_map_layers('Rockland-2024-Districts-TBI8sDkmQjuK2GX9CSiHiUA')
#' \donttest{
#' # slower, as it has to build the shapes from the API result
#' felt_get_map_elements('Rockland-2024-Districts-TBI8sDkmQjuK2GX9CSiHiUA')
#' }
#' felt_get_map_sf('Rockland-2024-Districts-TBI8sDkmQjuK2GX9CSiHiUA')
felt_get_map <- function(map_id) {
req <- httr2::request(base_url = api_url()) |>
httr2::req_url_path_append('maps', map_id) |>
Expand All @@ -44,17 +42,18 @@ felt_get_map_layers <- function(map_id) {
proc_map_layer()
}

#' @rdname felt_get_map
#' @export
felt_get_map_geojson <- function(map_id, path = tempfile(fileext = '.geojson')) {
curl::curl_download(paste0('https://felt.com/map/', map_id, '.geojson'),
destfile = path)
}

#' @rdname felt_get_map
#' @export
felt_get_map_sf <- function(map_id, path = tempfile(fileext = '.geojson')) {
curl::curl_download(paste0('https://felt.com/map/', map_id, '.geojson'),
destfile = path) |>
sf::read_sf()
}
# #' @rdname felt_get_map
# #' @export
# #' @param path path to save map to locally as a `.geojson` file
# felt_get_map_geojson <- function(map_id, path = tempfile(fileext = '.geojson')) {
# curl::curl_download(paste0('https://felt.com/map/', map_id, '.geojson'),
# destfile = path)
# }
#
# #' @rdname felt_get_map
# #' @export
# felt_get_map_sf <- function(map_id, path = tempfile(fileext = '.geojson')) {
# curl::curl_download(paste0('https://felt.com/map/', map_id, '.geojson'),
# destfile = path) |>
# sf::read_sf()
# }
2 changes: 2 additions & 0 deletions R/map_elements.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#' @return a [tibble::tibble] for the map
#' @export
#'
#' @concept get
#'
#' @examplesIf has_felt_key()
#' felt_get_map_elements(map_id = 'Rockland-2024-Districts-TBI8sDkmQjuK2GX9CSiHiUA')
felt_get_map_elements <- function(map_id) {
Expand Down
27 changes: 27 additions & 0 deletions R/proc.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,30 @@ proc_elements <- function(l) {
links = purrr::map_chr(l$links, 'self')
)
}

proc_comments <- function(l) {
tibble::tibble(
author_email = purrr::map(l,
.f = function(x) purrr::map_chr(purrr::pluck(x, 'comments'),
function(y) purrr::pluck(y, 'authorEmail'))),
author_name = purrr::map(l,
.f = function(x) purrr::map_chr(purrr::pluck(x, 'comments'),
function(y) purrr::pluck(y, 'authorName'))),
created_at = purrr::map(l,
.f = function(x) purrr::map_chr(purrr::pluck(x, 'comments'),
function(y) purrr::pluck(y, 'createdAt'))),
comment_id = purrr::map(l,
.f = function(x) purrr::map_chr(purrr::pluck(x, 'comments'),
function(y) purrr::pluck(y, 'id'))),
comment_text = purrr::map(l,
.f = function(x) purrr::map_chr(purrr::pluck(x, 'comments'),
function(y) purrr::pluck(y, 'text'))),
id = purrr::map_chr(l, .f = function(x) purrr::pluck(x, 'id')),
is_resolved = purrr::map_lgl(l, .f = function(x) purrr::pluck(x, 'isResolved')),
lat = purrr::map_dbl(l, .f = function(x) purrr::pluck(x, 'location', 1)),
lon = purrr::map_dbl(l, .f = function(x) purrr::pluck(x, 'location', 2))
) |>
tidyr::unnest_longer(
col = c('author_email', 'author_name', 'created_at', 'comment_id', 'comment_text')
)
}

0 comments on commit 5556c37

Please sign in to comment.