Skip to content

Commit

Permalink
Merge pull request #104 from spsanderson/development
Browse files Browse the repository at this point in the history
Fixes #102
  • Loading branch information
spsanderson authored May 23, 2024
2 parents 60de1fe + de2f39d commit 2fd014c
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export(fetch_cms_data)
export(fetch_provider_data)
export(get_cms_meta_data)
export(get_provider_meta_data)
export(is_valid_url)
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# healthyR.data (development version)

## Breaking Changes
None

## New Function
1. Fix #102 - Add function `is_valid_url()`

## Minor Fixes and Improvements
1. Fix #101 - Fixed `fetch_cms_data()` to handle all types of data presented, not
just API data. Now appropriately handles both API and non-API data such as, .csv,
vnd.ms-excel and .zip files.

# healthyR.data 1.1.0

## Breaking Changes
Expand Down
36 changes: 36 additions & 0 deletions R/utils-valid-url.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#' Check if a URL is valid
#'
#' @family Utility
#'
#' @author Steven P. Sanderson II, MPH
#'
#' @details The function uses the `httr2::url_parse` function to parse the URL
#' and checks if the parsed URL contains a scheme and a hostname. If either
#' is missing, the URL is considered invalid.
#'
#' @description
#' This function validates a URL by checking the presence of a scheme and a
#' hostname in the parsed URL.
#'
#' @param .url A character string representing the URL to be checked.
#'
#' @return A logical value: `TRUE` if the URL is valid, `FALSE` otherwise.
#'
#' @examples
#' is_valid_url("https://www.example.com") # TRUE
#' is_valid_url("not_a_url") # FALSE
#'
#' @name is_valid_url
NULL

#' @rdname is_valid_url
#' @export
is_valid_url <- function(url) {
parsed_url <- httr2::url_parse(url)
# Check if the parsed URL has a scheme and a host
if (is.null(parsed_url$scheme) || is.null(parsed_url$hostname)) {
return(FALSE)
} else {
return(TRUE)
}
}
32 changes: 32 additions & 0 deletions man/is_valid_url.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2fd014c

Please sign in to comment.