Open njtierney opened 5 years ago
Here it is again in ukp_crime_poly
:
# if date is used
if (is.null(date) == FALSE) {
result <- ukp_api(
glue::glue("api/crimes-street/all-crime?poly={poly_string}&date={date}")
)
# else if no date is specified
} else if (is.null(date) == TRUE) {
# get the latest date
# last_date <- ukpolice::ukp_last_update()
result <- ukp_api(
glue::glue("api/crimes-street/all-crime?poly={poly_string}")
)
Here are the main parts of all API calls
Prepare the string to pass to ukp_api
Extract the content into a dataframe
Give the columns sensible names
make lat/long numeric
reorder the columns
Perhaps part 1 can be broken up into functions like so
# this inserts e.g. "stops-street" or "crimes-street/all-crime"
# depending upon input being "stop-street"
api_add_type <- function(type){
switch()
}
# add the type of call
api_type <- api_add_type(type)
# add lat long
if (!missing(lat) && !missing(long)){
api_type <- api_add_lat_long(api_type, lat, long)
}
# add poly string
if (!missing(poly)){
api_type <- api_add_poly(api_type, poly)
}
# add date
if (!is.null(date)) {
api_type <- api_add_date(api_type, date)
}
They are both very similar:
stop_search:
crime: