diff --git a/R/get_github_file.R b/R/get_github_file.R index ef8eebe..99853ae 100644 --- a/R/get_github_file.R +++ b/R/get_github_file.R @@ -1,15 +1,16 @@ -#' Read in a file from the NHP Outputs app GitHub repo +#' Read in a file from a Strategy Unit GitHub repo #' +#' @param repo string. The name of the repository in which to find the file +#' @param folder string. The folder where the file is located. Set to `""` to +#' use the root folder of the repo. #' @param file string. The name of the file to read in -#' @param folder string. The folder where the file is located. `"inst"` by -#' default. Set to `""` to use the root folder of the repo. #' @returns The file contents as a stream, to be passed to a reader function #' @keywords internal -get_outputs_gh_file <- function(file, folder = "inst") { +get_su_gh_file <- function(repo, folder, file) { httr2::request("https://api.github.com") |> httr2::req_url_path_append("repos") |> httr2::req_url_path_append("The-Strategy-Unit") |> - httr2::req_url_path_append("nhp_outputs") |> + httr2::req_url_path_append(repo) |> httr2::req_url_path_append("contents") |> httr2::req_url_path_append(folder) |> httr2::req_url_path_append(file) |> @@ -21,28 +22,22 @@ get_outputs_gh_file <- function(file, folder = "inst") { } -#' Read in a file from the TPMAs GitHub repo +#' Read in a file from the NHP Outputs app GitHub repo #' -#' @param file string. The name of the file to read in -#' @param folder string. The folder where the file is located. `"reference"` by -#' default. Set to `""` to use the root folder of the repo. -#' @returns The file contents as a stream, to be passed to a reader function +#' @param ... Pass the name of the file in via `...` #' @keywords internal -get_tpmas_gh_file <- function(file, folder = "reference") { - httr2::request("https://api.github.com") |> - httr2::req_url_path_append("repos") |> - httr2::req_url_path_append("The-Strategy-Unit") |> - httr2::req_url_path_append("TPMAs") |> - httr2::req_url_path_append("contents") |> - httr2::req_url_path_append(folder) |> - httr2::req_url_path_append(file) |> - httr2::req_perform() |> - httr2::resp_check_status() |> - httr2::resp_body_json() |> - purrr::pluck("content") |> - base64enc::base64decode() +get_outputs_gh_file <- function(...) { + purrr::partial(get_su_gh_file, repo = "nhp_outputs", folder = "inst")(...) } +#' Read in a file from the TPMAs GitHub repo +#' +#' @inheritParams get_outputs_gh_file +#' @keywords internal +get_tpmas_gh_file <- function(...) { + purrr::partial(get_su_gh_file, repo = "TPMAs", folder = "reference")(...) +} + possibly_get_outputs_gh_file <- \(...) purrr::possibly(get_outputs_gh_file)(...) possibly_get_tpmas_gh_file <- \(...) purrr::possibly(get_tpmas_gh_file)(...) diff --git a/man/get_outputs_gh_file.Rd b/man/get_outputs_gh_file.Rd index 807b366..2f58760 100644 --- a/man/get_outputs_gh_file.Rd +++ b/man/get_outputs_gh_file.Rd @@ -4,16 +4,10 @@ \alias{get_outputs_gh_file} \title{Read in a file from the NHP Outputs app GitHub repo} \usage{ -get_outputs_gh_file(file, folder = "inst") +get_outputs_gh_file(...) } \arguments{ -\item{file}{string. The name of the file to read in} - -\item{folder}{string. The folder where the file is located. \code{"inst"} by -default. Set to \code{""} to use the root folder of the repo.} -} -\value{ -The file contents as a stream, to be passed to a reader function +\item{...}{Pass the name of the file in via \code{...}} } \description{ Read in a file from the NHP Outputs app GitHub repo diff --git a/man/get_su_gh_file.Rd b/man/get_su_gh_file.Rd new file mode 100644 index 0000000..4a88f43 --- /dev/null +++ b/man/get_su_gh_file.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_github_file.R +\name{get_su_gh_file} +\alias{get_su_gh_file} +\title{Read in a file from a Strategy Unit GitHub repo} +\usage{ +get_su_gh_file(repo, folder, file) +} +\arguments{ +\item{repo}{string. The name of the repository in which to find the file} + +\item{folder}{string. The folder where the file is located. Set to \code{""} to +use the root folder of the repo.} + +\item{file}{string. The name of the file to read in} +} +\value{ +The file contents as a stream, to be passed to a reader function +} +\description{ +Read in a file from a Strategy Unit GitHub repo +} +\keyword{internal} diff --git a/man/get_tpmas_gh_file.Rd b/man/get_tpmas_gh_file.Rd index bd27243..dc733ed 100644 --- a/man/get_tpmas_gh_file.Rd +++ b/man/get_tpmas_gh_file.Rd @@ -4,16 +4,10 @@ \alias{get_tpmas_gh_file} \title{Read in a file from the TPMAs GitHub repo} \usage{ -get_tpmas_gh_file(file, folder = "reference") +get_tpmas_gh_file(...) } \arguments{ -\item{file}{string. The name of the file to read in} - -\item{folder}{string. The folder where the file is located. \code{"reference"} by -default. Set to \code{""} to use the root folder of the repo.} -} -\value{ -The file contents as a stream, to be passed to a reader function +\item{...}{Pass the name of the file in via \code{...}} } \description{ Read in a file from the TPMAs GitHub repo