Skip to content

Commit

Permalink
Merge pull request #15 from Metropolitan-Council/14-update-streetligh…
Browse files Browse the repository at this point in the history
…tr-to-align-with-most-recent-api-changes

Update (version 1.2.0)
  • Loading branch information
eroten authored Dec 19, 2023
2 parents bf52f66 + b719520 commit 9eb2215
Show file tree
Hide file tree
Showing 52 changed files with 1,656 additions and 125 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
^\.github$
^README\.Rmd$
^LICENSE\.md$
^data-raw$
1 change: 1 addition & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:

strategy:
fail-fast: false
max-parallel: 1
matrix:
config:
- {os: macos-latest, r: 'release'}
Expand Down
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: streetlightR
Title: Interact with StreetLight Data's API in R
Version: 1.1.2
Date: 2023-08-21
Version: 1.2.0
Date: 2023-12-21
Authors@R: c(
person("Metropolitan Council", role = "cph"),
person("Liz", "Roten", , "liz.roten@metc.state.mn.us", role = c("cre", "aut"),
Expand All @@ -23,7 +23,7 @@ Depends:
Imports:
cli (>= 3.6.1),
dplyr (>= 1.1.2),
httr2 (>= 0.2.3),
httr2 (>= 1.0.0),
janitor (>= 2.2.0),
jsonlite (>= 1.8.7),
magrittr (>= 2.0.3),
Expand All @@ -38,6 +38,7 @@ Suggests:
VignetteBuilder:
knitr
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE, roclets = c("rd", "namespace", "collate"))
RoxygenNote: 7.2.3
Website: https://github.com/Metropolitan-Council/streetlightR/
12 changes: 12 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,25 @@ S3method(geojson_list,sf)
S3method(geojson_list,sfc)
S3method(geojson_list,sfg)
export("%>%")
export(check_analysis_review)
export(check_analysis_status)
export(check_date_range)
export(check_streetlight_api)
export(create_streetlight_analysis)
export(create_tag)
export(geojson_list)
export(get_analysis_data)
export(get_analysis_shapefile)
export(list_available_tags)
export(lookup_analysis_id)
export(remove_analysis_tag)
export(streetlight_api_key)
export(streetlight_insight)
export(tag_analysis)
export(upload_zone_set)
export(validate_parameters)
importFrom(cli,cli_abort)
importFrom(cli,cli_alert)
importFrom(cli,cli_alert_danger)
importFrom(cli,cli_alert_info)
importFrom(cli,cli_alert_success)
Expand All @@ -39,12 +48,15 @@ importFrom(httr2,resp_status_desc)
importFrom(janitor,clean_names)
importFrom(magrittr,"%>%")
importFrom(purrr,flatten)
importFrom(purrr,map2)
importFrom(readr,read_delim)
importFrom(sf,read_sf)
importFrom(sf,st_as_sf)
importFrom(sf,st_cast)
importFrom(sf,st_crs)
importFrom(sf,st_transform)
importFrom(tibble,as_tibble)
importFrom(utils,URLencode)
importFrom(utils,read.table)
importFrom(utils,unzip)
importFrom(utils,write.table)
68 changes: 68 additions & 0 deletions R/check_analysis_review.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#' Check the review status of a analysis in the StreetLight API.
#'
#' @inheritParams check_streetlight_api
#' @inheritParams lookup_analysis_id
#' @inheritParams create_streetlight_analysis
#'
#'
#' @return If successful, a list with two items
#' Otherwise, an httr2 response.
#'
#' @export
#'
#' @importFrom httr2 req_body_json req_perform req_headers req_error
#' @importFrom cli cli_warn cli_alert
#' @importFrom purrr map2
#'
check_analysis_review <- function(analysis_name = NULL,
uuid = NULL,
key = NULL) {
# check for API key access
key <- check_api_key_access(key)
# validate parameters
purrr::map2(
names(as.list(match.call())),
eval(as.list(match.call())),
validate_parameters
)

# if no uuid, lookup uuid
if (is.null(uuid)) {
uuid <- lookup_analysis_id(
analysis_name = analysis_name,
uuid = uuid
)
}

# fetch analysis status from endpoint
resp <- streetlight_insight(
key = key,
endpoint = paste0(
"analyses/",
uuid,
"/review_detail"
)
) %>%
httr2::req_headers(
"content-type" = "application/json"
) %>%
httr2::req_error(is_error = function(resp) FALSE) %>%
httr2::req_perform()


# if error message returnd, return WARNING
if (httr2::resp_status(resp) != 200) {
return(
cli::cli_warn(c(
"Review check failed with message: ",
httr2::resp_body_json(resp)
))
)
} else {
# otherwise, return succ
return(cli::cli_alert(c(
"Review check succceeded with message: ",
httr2::resp_body_json(resp)
)))
}
}
7 changes: 7 additions & 0 deletions R/check_analysis_status.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@
#'
#' @importFrom httr2 req_body_json req_perform req_headers req_error
#' @importFrom cli cli_warn
#' @importFrom purrr map2
#'
check_analysis_status <- function(analysis_name = NULL,
key = NULL,
analysis_name_ = NULL) {
# check for API key access
key <- check_api_key_access(key)
# validate parameters
purrr::map2(
names(as.list(match.call())),
eval(as.list(match.call())),
validate_parameters
)

# print warning if using analysis_name_
if (!is.null(analysis_name_)) {
Expand Down
7 changes: 7 additions & 0 deletions R/check_date_range.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@
#' @importFrom httr2 req_url_query req_perform resp_body_json
#' @importFrom tibble as_tibble
#' @importFrom dplyr mutate select
#' @importFrom purrr map2
#'
check_date_range <- function(key = NULL,
travel_mode_type = "All_Vehicles",
country = "US") {
# check for API access
key <- check_api_key_access(key)
# validate parameters
purrr::map2(
names(as.list(match.call())),
eval(as.list(match.call())),
validate_parameters
)

# fetch date ranges from endpoint
resp <- streetlight_insight(
Expand Down
Loading

0 comments on commit 9eb2215

Please sign in to comment.