From 2659643663b555119c8bc35405dbd9ff1afdc18a Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 7 Jan 2025 08:48:35 -0600 Subject: [PATCH] Provide `is_online()` (#631) Fixes #512 --- NAMESPACE | 1 + NEWS.md | 1 + R/is-online.R | 11 ++++ _pkgdown.yml | 166 +++++++++++++++++++++++------------------------ man/is_online.Rd | 13 ++++ 5 files changed, 109 insertions(+), 83 deletions(-) create mode 100644 R/is-online.R create mode 100644 man/is_online.Rd diff --git a/NAMESPACE b/NAMESPACE index 165326b0..05a7599a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -18,6 +18,7 @@ export(curl_help) export(curl_translate) export(example_github_client) export(example_url) +export(is_online) export(iterate_with_cursor) export(iterate_with_link_url) export(iterate_with_offset) diff --git a/NEWS.md b/NEWS.md index e9fe252c..b3b1a8a1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # httr2 (development version) +* Export `is_online()` as thin wrapper around `curl::has_internet()` (#512). * `curl_translate()` now translates cookie headers to `req_cookies_set()` (#431). * `curl_transform()` will now use `req_body_json_modify()` for JSON data (#258). * `resp_stream_is_complete()` tells you if there is still data remaining to be streamed (#559). diff --git a/R/is-online.R b/R/is-online.R new file mode 100644 index 00000000..83c47d31 --- /dev/null +++ b/R/is-online.R @@ -0,0 +1,11 @@ +#' Is your computer currently online? +#' +#' This function uses some cheap heuristics to determine if your computer is +#' currently online. It's a simple wrapper around [curl::has_internet()] +#' exported from httr2 for convenience. +#' +#' @export +#' is_online() +is_online <- function() { + curl::has_internet() +} diff --git a/_pkgdown.yml b/_pkgdown.yml index a17aae11..de9d35eb 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -12,90 +12,90 @@ development: mode: auto reference: -- title: Requests - subtitle: Create and modify - contents: - - request - - req_body - - req_cookie_preserve - - req_headers - - req_method - - req_options - - req_progress - - req_proxy - - req_template - - req_timeout - - req_url - - req_user_agent - -- subtitle: Debugging/testing - contents: - - last_request - - req_dry_run - - req_verbose - - with_mock - - with_verbosity - -- subtitle: Authentication - contents: - - starts_with("req_auth") - - starts_with("req_oauth") - -- title: Perform a request - contents: - - req_perform - - req_perform_stream - - req_perform_connection - - req_perform_promise - -- subtitle: Control the process - desc: > - These functions don't modify the HTTP request that is sent to the server, - but affect the overall process of `req_perform()`. - contents: - - req_cache - - req_error - - req_throttle - - req_retry - -- title: Perform multiple requests - contents: - - req_perform_iterative - - req_perform_parallel - - req_perform_sequential - - starts_with("iterate_") - - starts_with("resps_") - -- title: Handle the response - contents: - - starts_with("resp_") - -- title: URL manipulation - contents: - - starts_with("url_") - -- title: Miscellaenous helpers - contents: - - curl_translate - - secrets - - obfuscate - -- title: OAuth - desc: > - These functions implement the low-level components of OAuth. - contents: - - starts_with("oauth_") - - -starts_with("req_oauth") + - title: Requests + subtitle: Create and modify + contents: + - request + - req_body + - req_cookie_preserve + - req_headers + - req_method + - req_options + - req_progress + - req_proxy + - req_template + - req_timeout + - req_url + - req_user_agent + + - subtitle: Debugging/testing + contents: + - last_request + - req_dry_run + - req_verbose + - with_mock + - with_verbosity + + - subtitle: Authentication + contents: + - starts_with("req_auth") + - starts_with("req_oauth") + + - title: Perform a request + contents: + - req_perform + - req_perform_stream + - req_perform_connection + - req_perform_promise + + - subtitle: Control the process + desc: > + These functions don't modify the HTTP request that is sent to the server, + but affect the overall process of `req_perform()`. + contents: + - req_cache + - req_error + - req_throttle + - req_retry + + - title: Perform multiple requests + contents: + - req_perform_iterative + - req_perform_parallel + - req_perform_sequential + - starts_with("iterate_") + - starts_with("resps_") + + - title: Handle the response + contents: + - starts_with("resp_") + + - title: URL manipulation + contents: + - starts_with("url_") + + - title: Miscellaenous helpers + contents: + - curl_translate + - is_online + - secrets + - obfuscate + + - title: OAuth + desc: > + These functions implement the low-level components of OAuth. + contents: + - starts_with("oauth_") + - -starts_with("req_oauth") articles: -- title: Using httr2 - navbar: ~ - contents: - - articles/wrapping-apis - - articles/oauth - + - title: Using httr2 + navbar: ~ + contents: + - articles/wrapping-apis + - articles/oauth news: - releases: - - text: "httr2 1.0.0" - href: https://www.tidyverse.org/blog/2023/11/httr2-1-0-0/ + releases: + - text: "httr2 1.0.0" + href: https://www.tidyverse.org/blog/2023/11/httr2-1-0-0/ diff --git a/man/is_online.Rd b/man/is_online.Rd new file mode 100644 index 00000000..205d731c --- /dev/null +++ b/man/is_online.Rd @@ -0,0 +1,13 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/is-online.R +\name{is_online} +\alias{is_online} +\title{Is your computer currently online?} +\usage{ +is_online() +} +\description{ +This function uses some cheap heuristics to determine if your computer is +currently online. It's a simple wrapper around \code{\link[curl:nslookup]{curl::has_internet()}} +exported from httr2 for convenience. +}