new_response <- function(content, url, response) {
structure(
list(
content = content,
url = url,
response = response
),
class = "wordpress_response"
)
}
#' @export
print.wordpress_response <- function(x, ...) {
cat("<WordPress ", x$url, ">\n", sep = "")
print(to_json(x$content))
invisible(x)
}
to_json <- function(x) {
jsonlite::toJSON(x, pretty = TRUE, auto_unbox = TRUE)
}
send_request <- function(
verb,
path,
...,
.namespace = "/wp/v2",
.url = wordpress_url(),
.envir = parent.frame()
) {
url <- rest_url(path, .namespace, .url = .url, .envir = .envir)
response <- httr::VERB(
verb = verb,
url = url,
httr::user_agent("https://github.com/shunsambongi/wordpress"),
...
)
if (httr::http_type(response) != "application/json") {
abort(
"WordPress API did not return JSON",
class = "wordpress_invalid_content_type",
response = response
)
}
content <- jsonlite::fromJSON(
httr::content(response, "text"),
simplifyVector = FALSE
)
new_response(content, url, response)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.