From cacf682a85cdc37c2357df30fc241a1f1b73e5fb Mon Sep 17 00:00:00 2001 From: hrbrmstr Date: Sun, 28 Jun 2020 07:57:44 -0400 Subject: [PATCH] refreshed some functions and setup pkg for expansion --- .Rbuildignore | 2 + .gitignore | 1 + DESCRIPTION | 13 ++--- LICENSE | 2 + LICENSE.md | 21 ++++++++ NAMESPACE | 5 +- R/about-me.R | 11 ++-- R/my-posts.R | 86 ++++++++++++++++++++++++++----- R/post-stats.R | 2 +- R/pressur-package.R | 4 +- R/site-info.R | 22 +++++--- R/site-stats.R | 25 +++++---- R/util.R | 14 +++++ R/wp-post.R | 6 +++ R/wp_auth.R | 22 ++++++-- README.Rmd | 57 ++++++++++---------- README.md | 83 +++++++++++++++-------------- man/figures/README-unnamed-chunk-1-1.png | Bin 0 -> 11350 bytes man/pressur.Rd | 1 - man/wp_about_me.Rd | 15 +++--- man/wp_auth.Rd | 24 +++++++-- man/wp_get_my_posts.Rd | 23 --------- man/wp_get_posts.Rd | 56 ++++++++++++++++++++ man/wp_site_info.Rd | 15 +++--- man/wp_site_stats.Rd | 19 +++---- 25 files changed, 357 insertions(+), 172 deletions(-) create mode 100644 LICENSE create mode 100644 LICENSE.md create mode 100644 R/wp-post.R create mode 100644 man/figures/README-unnamed-chunk-1-1.png delete mode 100644 man/wp_get_my_posts.Rd create mode 100644 man/wp_get_posts.Rd diff --git a/.Rbuildignore b/.Rbuildignore index 65401da..dd22f5d 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,3 +10,5 @@ ^doc$ ^\.httr-oauth$ ^CONDUCT\.md$ +^~/\.local/wp-oauth-token$ +^LICENSE\.md$ diff --git a/.gitignore b/.gitignore index 27175f0..973d2c7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ src/*.o src/*.so src/*.dll .httr-oauth +~/.local/wp-oauth-token diff --git a/DESCRIPTION b/DESCRIPTION index 09b33b5..5a701d9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: pressur Type: Package Title: Query and Orchestrate the 'WordPress' 'API' -Version: 0.1.0 -Date: 2017-12-27 +Version: 0.2.0 +Date: 2020-06-28 Authors@R: c( person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-5670-2640")) @@ -14,18 +14,19 @@ Description: 'WordPress' has a fairly comprehensive 'API' = 3.2.0) + R (>= 3.6.0) Imports: purrr, httr, stringi, crayon, tibble, - anytime -RoxygenNote: 6.0.1.9000 + anytime, + progress +RoxygenNote: 7.1.0 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..49d554e --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +YEAR: 2020 +COPYRIGHT HOLDER: Bob Rudis diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..524f6aa --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2020 Bob Rudis + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/NAMESPACE b/NAMESPACE index a5c5fcd..edceb54 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,13 +2,14 @@ export(wp_about_me) export(wp_auth) -export(wp_get_my_posts) +export(wp_get_posts) export(wp_post_stats) export(wp_site_info) export(wp_site_stats) import(anytime) import(crayon) import(httr) +import(progress) import(purrr) import(stringi) -importFrom(tibble,data_frame) +importFrom(tibble,tibble) diff --git a/R/about-me.R b/R/about-me.R index 1ef0adb..0f26478 100644 --- a/R/about-me.R +++ b/R/about-me.R @@ -1,11 +1,12 @@ -#' Get your user information +#' Get metadata about the current user. #' -#' @md #' @references +#' @return list with user metadata #' @export -#' @examples \dontrun{ -#' wp_auth() -#' wp_about_me() +#' @examples +#' if (interactive()) { +#' wp_auth() +#' wp_about_me() #' } wp_about_me <- function() { diff --git a/R/my-posts.R b/R/my-posts.R index 0dc3f55..4fc9edf 100644 --- a/R/my-posts.R +++ b/R/my-posts.R @@ -19,22 +19,69 @@ } -#' Get all 'my' posts across all sites +#' Get all posts across all sites of the authenticated user #' -#' @md #' @references +#' @param context `edit` (default) for raw post source; `display` for HTML +#' rendered source. +#' @param author id of the author or empty (the default) for 'all authors' +#' @param after,before (POSIXct or Date object or string that can be converted to one of those) +#' Return posts dated before/after the specified datetime. +#' @param modified_after,modified_before (POSIXct or Date object) Return posts modified before/after +#' the specified datetime. +#' @param status Comma-separated list of statuses for which to query, including any of: +#' "publish", "private", "draft", "pending", "future", and "trash", or simply "any". Defaults to "publish" +#' @param search Search query checked against `title`, `content`, `category.name`, `tag.name`, +#' and `author`, and will return results sorted by relevance. Limit: 250 characters +#' @param sites Optional comma-separated list of specific site IDs to further limit results #' @param .quiet if `TRUE` then no progress information will be displayed #' @export -#' @examples \dontrun{ -#' wp_auth() -#' my_posts <- wp_get_my_posts() +#' @return data frame of posts +#' @examples +#' if (interactive()) { +#' wp_auth() +#' my_posts <- wp_get_posts() #' } -wp_get_my_posts <- function(.quiet=FALSE) { +wp_get_posts <- function(context = c("edit", "display"), + author = NULL, + after = NULL, + before = NULL, + modified_after = NULL, + modified_before = NULL, + status = NULL, + search = NULL, + sites = NULL, + .quiet=FALSE) { + + context <- match.arg(context[1], c("edit", "display")) + + if (!is.null(status)) { + match.arg( + status[1], + c("publish", "private", "draft", "pending", "future", "trash", "any") + ) -> status + } + + after <- iso_it(after[1]) + before <- iso_it(before[1]) + modified_after <- iso_it(modified_after[1]) + modified_before <- iso_it(modified_before[1]) httr::GET( url = "https://public-api.wordpress.com/rest/v1.1/me/posts", .add_bearer_token(), - httr::accept_json() + httr::accept_json(), + query = list( + context = context, + author = author[1], + after = after[1], + before = before[1], + modified_after = modified_after[1], + modified_before = modified_before[1], + status = status[1], + search = search[1], + sites = sites[1] + ) ) -> res httr::stop_for_status(res) @@ -46,12 +93,20 @@ wp_get_my_posts <- function(.quiet=FALSE) { n_pages <- ceiling(pg$found / 20) - for (idx in 2:n_pages) { - if (!.quiet) cat(crayon::green("."), sep="") - pg <- .wp_next_posts_page(pg) - .posts[[idx]] <- pg + if (n_pages > 1) { + + progress::progress_bar$new( + format = " retrieving posts [:bar:] :percent eta: :eta", + total = n_pages - 1 + ) -> .pb + + for (idx in 2:n_pages) { + if (!.quiet) .pb$tick() + pg <- .wp_next_posts_page(pg) + .posts[[idx]] <- pg + } + } - if (!.quiet) cat("\n",sep="") purrr::map_df(.posts, ~{ @@ -105,8 +160,11 @@ wp_get_my_posts <- function(.quiet=FALSE) { }) -> .posts_df - .posts_df$date <- anytime::anytime(.posts_df$date) - .posts_df$modified <- anytime::anytime(.posts_df$modified) + .date <- try(anytime::anytime(.posts_df$date), silent = TRUE) + .modified <- try(anytime::anytime(.posts_df$modified), silent = TRUE) + + if (!inherits(.date, "try-error")) .posts_df$date <- .date + if (!inherits(.modified, "try-error")) .posts_df$modified <- .modified return(.posts_df) diff --git a/R/post-stats.R b/R/post-stats.R index bb6a51e..928235c 100644 --- a/R/post-stats.R +++ b/R/post-stats.R @@ -25,7 +25,7 @@ wp_post_stats <- function(site, post_id) { .stats <- httr::content(res) - tibble::data_frame( + tibble::tibble( date = as.Date(.stats$date), views = .stats$views, years = list(.stats$years), diff --git a/R/pressur-package.R b/R/pressur-package.R index fd4bf27..70051fd 100644 --- a/R/pressur-package.R +++ b/R/pressur-package.R @@ -8,6 +8,6 @@ #' @name pressur #' @docType package #' @author Bob Rudis (bob@@rud.is) -#' @import purrr stringi httr crayon anytime -#' @importFrom tibble data_frame +#' @import purrr stringi httr crayon anytime progress +#' @importFrom tibble tibble NULL diff --git a/R/site-info.R b/R/site-info.R index dc4367b..1c9a742 100644 --- a/R/site-info.R +++ b/R/site-info.R @@ -1,19 +1,25 @@ #' Get information about a site #' -#' @md #' @references -#' @param site site id or domain -#' @note I've only had this work successfully with my blog by using the site id. +#' @param site site id or domain; if not specified, the primary site of the +#' authenticated user will be used. #' @export -#' @examples \dontrun{ -#' wp_auth() -#' me <- wp_about_me() -#' wp_site_info(me$primary_blog) +#' @examples +#' if (interactive() { +#' wp_auth() +#' wp_site_info() #' } wp_site_info <- function(site) { + if (missing(site)) { + site_url <- .pkg$me$meta$links$site[1] + } else { + site_url <- sprintf("https://public-api.wordpress.com/rest/v1.2/sites/%s", site[1]) + } + httr::GET( - url = sprintf("https://public-api.wordpress.com/rest/v1.2/sites/%s", site), + url = site_url, + .add_bearer_token(), httr::accept_json() ) -> res diff --git a/R/site-stats.R b/R/site-stats.R index 158e4cf..3c07d96 100644 --- a/R/site-stats.R +++ b/R/site-stats.R @@ -1,19 +1,26 @@ #' Get a site's stats #' -#' @md #' @references -#' @param site site id or domain -#' @note I've only had this work successfully with my blog by using the site id. +#' @param site site id or domain; if not specified, the primary site of the +#' authenticated user will be used. +#' @return list with a great deal of stats metadata. You are probably most +#' interested in the `visits` element. #' @export -#' @examples \dontrun{ -#' wp_auth() -#' me <- wp_about_me() -#' wp_site_stats(me$primary_blog) +#' @examples +#' if (interactive()) { +#' wp_auth() +#' wp_site_stats() #' } wp_site_stats <- function(site) { + if (missing(site)) { + site_stats_url <- paste0(.pkg$me$meta$links$site[1], "/stats") + } else { + site_stats_url <- sprintf("https://public-api.wordpress.com/rest/v1.2/sites/%s/stats", site[1]) + } + httr::GET( - url = sprintf("https://public-api.wordpress.com/rest/v1.1/sites/%s/stats", site), + url = site_stats_url, .add_bearer_token(), accept_json() ) -> res @@ -23,7 +30,7 @@ wp_site_stats <- function(site) { .stats <- httr::content(res) .stats$visits <- purrr::map_df(.stats$visits$data, ~purrr::set_names(.x, .stats$visits$fields)) - .stats$visits$period <- anytime::anydate(.stats$visits$period) + .stats$visits$period <- anytime::anydate(.stats$visits$period) return(.stats) diff --git a/R/util.R b/R/util.R index c9f444c..6d444cc 100644 --- a/R/util.R +++ b/R/util.R @@ -1,3 +1,17 @@ .add_bearer_token <- function() { httr::add_headers(`Authorization` = sprintf("Bearer %s", .pkg$token$credentials$access_token)) } + +iso_it <- function(x) { + + if (is.null(x)) return(x) + + if (is.character(x)) x <- anytime::anytime(x) + + if (!inherits(x, c("Date", "POSIXct"))) { + stop("Speficied object is not a Date, POSIXct, or compatible string.", call.=FALSE) + } + + anytime::iso8601(x) + +} \ No newline at end of file diff --git a/R/wp-post.R b/R/wp-post.R new file mode 100644 index 0000000..c24939e --- /dev/null +++ b/R/wp-post.R @@ -0,0 +1,6 @@ +# Create a post +# +# @export +# wp_post_new <- function() { +# +# } \ No newline at end of file diff --git a/R/wp_auth.R b/R/wp_auth.R index 6e5aaa2..cfd55cd 100644 --- a/R/wp_auth.R +++ b/R/wp_auth.R @@ -15,13 +15,24 @@ oauth_endpoint( #' #' Call this at the start of any WordPress API interaction #' -#' @md +#' After authentication, the current running environment will contain +#' a copy of the token which the remaining functions will use and +#' the token will be returned invisibly. +#' +#' @param cache either `TRUE` (to read from the default {httr} oauth cache), +#' `FALSE` (to not cache the oauth token), `NA` ({httr} will guess +#' what to do using some sensible heuristics), or a string which will +#' be used as a path to the cache file. You can use an environment +#' variable `WP_OAUTH_CACHE` to populate this value. If no value is +#' specified this value will default to `TRUE`. #' @references +#' @return oauth token (invisibly) #' @export -#' @examples \dontrun{ -#' wp_auth() +#' @examples +#' if (interactive()) { +#' wp_auth() #' } -wp_auth <- function() { +wp_auth <- function(cache = Sys.getenv("WP_OAUTH_CACHE", unset = TRUE)) { oauth2.0_token( wordpress_endpoint, @@ -31,10 +42,11 @@ wp_auth <- function() { response_type = "code", scope = "global" ), - cache = TRUE + cache = cache ) -> wordpress_token .pkg$token <- wordpress_token + .pkg$me <- wp_about_me() invisible(wordpress_token) diff --git a/README.Rmd b/README.Rmd index ae9eb81..e9cd9a1 100644 --- a/README.Rmd +++ b/README.Rmd @@ -1,17 +1,19 @@ --- output: rmarkdown::github_document +editor_options: + chunk_output_type: console --- +```{r pkg-knitr-opts, include=FALSE} +hrbrpkghelpr::global_opts() +``` -# pressur - -Query and Orchestrate the 'WordPress' 'API' - -## Description +```{r badges, results='asis', echo=FALSE, cache=FALSE} +hrbrpkghelpr::stinking_badges() +``` -'WordPress' has a fairly comprehensive 'API' -that makes it possible to perform blog orchestration ('CRUD' operations on posts, users, -sites, etc.) as well as retrieve and process blog statistics. Tools are provided to work -with the 'WordPress' 'API' functions. +```{r description, results='asis', echo=FALSE, cache=FALSE} +hrbrpkghelpr::yank_title_and_description() +``` ### `` YOU WILL O-BEY `` @@ -41,41 +43,44 @@ You are encouraged to poke around the source and contribute PRs or issues for hi The following functions are implemented: -- `wp_auth`: Authenticate to WordPress -- `wp_about_me`: Get your user information -- `wp_get_my_posts`: Get all 'my' posts across all sites -- `wp_post_stats`: Retrieve statistics for a WordPress post -- `wp_site_info`: Get information about a site -- `wp_site_stats`: Get a site's stats +```{r ingredients, results='asis', echo=FALSE, cache=FALSE} +hrbrpkghelpr::describe_ingredients() +``` ## Installation -```{r eval=FALSE} -devtools::install_github("hrbrmstr/pressur") -``` - -```{r message=FALSE, warning=FALSE, error=FALSE, include=FALSE} -options(width=120) +```{r install-ex, results='asis', echo=FALSE, cache=FALSE} +hrbrpkghelpr::install_block() ``` ## Usage -```{r message=FALSE, warning=FALSE, error=FALSE} +```{r lib-ex} library(pressur) -# current verison +# current version packageVersion("pressur") + ``` ### Basic operation ```{r} +library(hrbrthemes) +library(ggplot2) + wp_auth() -me <- wp_about_me() -dplyr::glimpse(wp_site_stats(me$primary_blog)) + +stats <- wp_site_stats() + +ggplot(stats$visits, aes(period, views)) + + geom_col(fill = ft_cols$slate) + + scale_y_comma() + + labs(x = NULL, y = "views", title = "Site Views") + + theme_ipsum_gs(grid="Y") ``` ## Code of Conduct -Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms. +Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. diff --git a/README.md b/README.md index fb353d9..44b4fd0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,19 @@ +[![Project Status: Active – The project has reached a stable, usable +state and is being actively +developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) +[![Signed +by](https://img.shields.io/badge/Keybase-Verified-brightgreen.svg)](https://keybase.io/hrbrmstr) +![Signed commit +%](https://img.shields.io/badge/Signed_Commits-100%25-lightgrey.svg) +[![Linux build +Status](https://travis-ci.org/hrbrmstr/pressur.svg?branch=master)](https://travis-ci.org/hrbrmstr/pressur) +[![Coverage +Status](https://codecov.io/gh/hrbrmstr/pressur/branch/master/graph/badge.svg)](https://codecov.io/gh/hrbrmstr/pressur) +![Minimal R +Version](https://img.shields.io/badge/R%3E%3D-3.6.0-blue.svg) +![License](https://img.shields.io/badge/License-MIT-blue.svg) + # pressur Query and Orchestrate the ‘WordPress’ ‘API’ @@ -47,9 +62,10 @@ issues for high priority items you’d like to see in the package. The following functions are implemented: + - `wp_about_me`: Get metadata about the current user. - `wp_auth`: Authenticate to WordPress - - `wp_about_me`: Get your user information - - `wp_get_my_posts`: Get all ‘my’ posts across all sites + - `wp_get_posts`: Get all posts across all sites of the authenticated + user - `wp_post_stats`: Retrieve statistics for a WordPress post - `wp_site_info`: Get information about a site - `wp_site_stats`: Get a site’s stats @@ -57,62 +73,45 @@ The following functions are implemented: ## Installation ``` r -devtools::install_github("hrbrmstr/pressur") +remotes::install_gitlab("hrbrmstr/pressur") +# or +remotes::install_github("hrbrmstr/pressur") ``` +NOTE: To use the ‘remotes’ install options you will need to have the +[{remotes} package](https://github.com/r-lib/remotes) installed. + ## Usage ``` r library(pressur) -# current verison +# current version packageVersion("pressur") +## [1] '0.2.0' ``` - ## [1] '0.1.0' - ### Basic operation ``` r +library(hrbrthemes) +library(ggplot2) + wp_auth() -me <- wp_about_me() -dplyr::glimpse(wp_site_stats(me$primary_blog)) + +stats <- wp_site_stats() + +ggplot(stats$visits, aes(period, views)) + + geom_col(fill = ft_cols$slate) + + scale_y_comma() + + labs(x = NULL, y = "views", title = "Site Views") + + theme_ipsum_gs(grid="Y") ``` - ## List of 3 - ## $ date : chr "2017-12-27" - ## $ stats :List of 24 - ## ..$ visitors_today : int 86 - ## ..$ visitors_yesterday : int 129 - ## ..$ visitors : int 203068 - ## ..$ views_today : int 151 - ## ..$ views_yesterday : int 178 - ## ..$ views_best_day : chr "2017-05-15" - ## ..$ views_best_day_total : int 3984 - ## ..$ views : int 347802 - ## ..$ comments : int 1324 - ## ..$ posts : int 445 - ## ..$ followers_blog : int 197 - ## ..$ followers_comments : int 132 - ## ..$ comments_per_month : int 16 - ## ..$ comments_most_active_recent_day: chr "2015-10-05 19:39:56" - ## ..$ comments_most_active_time : chr "N/A" - ## ..$ comments_spam : int 0 - ## ..$ categories : int 209 - ## ..$ tags : int 695 - ## ..$ shares : int 0 - ## ..$ shares_twitter : int 0 - ## ..$ shares_print : int 0 - ## ..$ shares_linkedin : int 0 - ## ..$ shares_google-plus-1 : int 0 - ## ..$ shares_email : int 0 - ## $ visits:Classes 'tbl_df', 'tbl' and 'data.frame': 30 obs. of 3 variables: - ## ..$ period : Date[1:30], format: "2017-11-28" "2017-11-29" "2017-11-30" "2017-12-01" ... - ## ..$ views : int [1:30] 364 389 451 427 432 204 353 424 573 354 ... - ## ..$ visitors: int [1:30] 253 268 300 319 325 154 254 312 399 259 ... + ## Code of Conduct -Please note that this project is released with a [Contributor Code of -Conduct](CONDUCT.md). By participating in this project you agree to -abide by its terms. +Please note that this project is released with a Contributor Code of +Conduct. By participating in this project you agree to abide by its +terms. diff --git a/man/figures/README-unnamed-chunk-1-1.png b/man/figures/README-unnamed-chunk-1-1.png new file mode 100644 index 0000000000000000000000000000000000000000..4ba3d4ad0da71ee82ed1ff56556c27b478484954 GIT binary patch literal 11350 zcmcI~c{r4B+yBfUMMz1aP)UR&RQ4%JvS!InvhQCzV;L3N>_d7j^K{NDM4`@YWYbAHbAIU1d+M17#Pft(Jix)4RK7FdMuWx5(H$6Sw+S)od zH)mjAprD`-5fOnvApZXQ?++h7I5|0uj*d=DOtiJO1qTO@jg6I;m;dmWKs;XL9S*4_;L`FtdR8-j7+BP&atgNhrgoI>fX3ERUzkK=f^XJb=Nl8IL zL1}4ea&mHsiHR5tMngkmb8~ZXaq-QYH&7^ac6L@%Q`5%A#>K@YDk@4vMa9g_thcwf zuCA`QxcL41_ib%$IyyQD2?=lCzOApX|MlzFqeqWYQ&a!?>n}q?Lu+g6XV0EBHa0pt zI~NufuCK4x)YQbs$D5d#P*G8}x3}lz<%NZXxw^Wxw6q|RNHQ|As;a7-oE$|(MIs`i z<>lqt+S;E#e;OGX1qKEV3=BMZ@?>Ua#@pNb>({SpYHCGAMc==FcXxMx{P^*gFJDSa zOTE0j{QdpQ%F3FWnvNVfLPA0!DJkjc>AAGD^zPj|2L}gjZS8`B0%m6BlP6DdaB!SH zeL6HW^ytx}A3uIgHXa%pa&vRj)6=7) zqx1FkB_<}maN$CDcz8@qOm0pt@X^xJ5)u-UkdUCEp`oClU|?Xle*HQpCudw-9632T z3WW*?2=MdsGdDN4w6yf_@E9B%MT zJ0l~*)YSC$?c4VD_IK{wk&%&s!{PMw^qrlZJUl$v+1cac<2P^KJaOVgdU|?ENy)u? z_XGq41O)}9rKQEh#Lk>K!^p@eEG*2=&)?C}Au1}GoSgjX)vFsfZajGKz-fc~Aq2t< zk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GHRxmk6aryS=UR z7)vHvnoRTQ+#BP4HyG;+HB}oCHj6ZSnQ=6vO*U433oOXon>Cp%9K##ijm@v)XpyP$ zOUH4_f$N^RF88X`L@vgo#T2^V4({MSqGjZ$TT^+saP4PpmP1e>_wLO*XebifyYY?d zhTkt*sFk>Pwc(iw_XhB*pTy=L=4-1&*`pHo3|6N6c)cp;{rO|bsDm2Nd*gL9^#pY) zXGpBS1H)RKSFmAdnu>GnUw4 z{&9Bn(v_s<2c@%39d7Y1%rR5pa~iAF!yH6nwnZN;rzO)_Kf0kW8M84W68^n?#KqS zcninTg6-0WjiQqRHtWAigSs8YG z!)(wbS9xe0LqrIdrfrmE?)60;tAjR+%BzCln6+UAj{!#D7dbde{fE^VUsk`Z>v{MErFL8z&VI2V6fxvb zvI#wJh>6&ejodDaNMg~rDFT;nbhPK}RbkuOXnmz!zH0O%Y{8MC-;BMCV-v}=qO$Nj zU?3`HcXW+OD=^ORMLIt~St=CKgI=gs%G}5njxfViL$$Y7YgL32CRD{4v9iKC<-%tJ zyY6DLhaYz15*h*-81wj}Rh>=$Vi!HTzBT5gEl1H>7P0flqIhX>-n~bWOY_KN_*h(~ z$-|?qw}TBGMA{TKQ>;h6bNls>k0^76?zjqT7sopAi0TihWvcIHEx)`i@@uVeq4YgH zsw#9R$y zhgbb_XI5Xp$dDRZ(G=RW=&&e$Bxa$`_k*KjG5X_zY`sX!sKCy`HK%Gn^}?0!F?jQ?<0cY@ zRCR%xXp1}d#M2C=> zT8)c*fYB2&TZ&S9MHZdrLHISCG+wI$sSQzd$Xb6vN7x>PP3)s?HL|9RT ziYU-cPO6J|Ij&ujwUj;*hbgV3SgtzKUOZ!4W2h+@c diff --git a/man/wp_about_me.Rd b/man/wp_about_me.Rd index ef04532..29c698b 100644 --- a/man/wp_about_me.Rd +++ b/man/wp_about_me.Rd @@ -2,19 +2,22 @@ % Please edit documentation in R/about-me.R \name{wp_about_me} \alias{wp_about_me} -\title{Get your user information} +\title{Get metadata about the current user.} \usage{ wp_about_me() } +\value{ +list with user metadata +} \description{ -Get your user information +Get metadata about the current user. } \examples{ -\dontrun{ -wp_auth() -wp_about_me() +if (interactive()) { + wp_auth() + wp_about_me() } } \references{ -\url{https://developer.wordpress.com/docs/api/1.1/get/me/} + } diff --git a/man/wp_auth.Rd b/man/wp_auth.Rd index f12fa22..36a2437 100644 --- a/man/wp_auth.Rd +++ b/man/wp_auth.Rd @@ -4,16 +4,32 @@ \alias{wp_auth} \title{Authenticate to WordPress} \usage{ -wp_auth() +wp_auth(cache = Sys.getenv("WP_OAUTH_CACHE", unset = TRUE)) +} +\arguments{ +\item{cache}{either `TRUE` (to read from the default {httr} oauth cache), +`FALSE` (to not cache the oauth token), `NA` ({httr} will guess +what to do using some sensible heuristics), or a string which will +be used as a path to the cache file. You can use an environment +variable `WP_OAUTH_CACHE` to populate this value. If no value is +specified this value will default to `TRUE`.} +} +\value{ +oauth token (invisibly) } \description{ Call this at the start of any WordPress API interaction } +\details{ +After authentication, the current running environment will contain +a copy of the token which the remaining functions will use and +the token will be returned invisibly. +} \examples{ -\dontrun{ -wp_auth() +if (interactive()) { + wp_auth() } } \references{ -\url{https://developer.wordpress.com/docs/oauth2/} + } diff --git a/man/wp_get_my_posts.Rd b/man/wp_get_my_posts.Rd deleted file mode 100644 index b47eba8..0000000 --- a/man/wp_get_my_posts.Rd +++ /dev/null @@ -1,23 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/my-posts.R -\name{wp_get_my_posts} -\alias{wp_get_my_posts} -\title{Get all 'my' posts across all sites} -\usage{ -wp_get_my_posts(.quiet = FALSE) -} -\arguments{ -\item{.quiet}{if \code{TRUE} then no progress information will be displayed} -} -\description{ -Get all 'my' posts across all sites -} -\examples{ -\dontrun{ -wp_auth() -my_posts <- wp_get_my_posts() -} -} -\references{ -\url{https://developer.wordpress.com/docs/api/1.1/get/me/posts/} -} diff --git a/man/wp_get_posts.Rd b/man/wp_get_posts.Rd new file mode 100644 index 0000000..a7c128d --- /dev/null +++ b/man/wp_get_posts.Rd @@ -0,0 +1,56 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/my-posts.R +\name{wp_get_posts} +\alias{wp_get_posts} +\title{Get all posts across all sites of the authenticated user} +\usage{ +wp_get_posts( + context = c("edit", "display"), + author = NULL, + after = NULL, + before = NULL, + modified_after = NULL, + modified_before = NULL, + status = NULL, + search = NULL, + sites = NULL, + .quiet = FALSE +) +} +\arguments{ +\item{context}{`edit` (default) for raw post source; `display` for HTML +rendered source.} + +\item{author}{id of the author or empty (the default) for 'all authors'} + +\item{after, before}{(POSIXct or Date object or string that can be converted to one of those) +Return posts dated before/after the specified datetime.} + +\item{modified_after, modified_before}{(POSIXct or Date object) Return posts modified before/after +the specified datetime.} + +\item{status}{Comma-separated list of statuses for which to query, including any of: +"publish", "private", "draft", "pending", "future", and "trash", or simply "any". Defaults to "publish"} + +\item{search}{Search query checked against `title`, `content`, `category.name`, `tag.name`, +and `author`, and will return results sorted by relevance. Limit: 250 characters} + +\item{sites}{Optional comma-separated list of specific site IDs to further limit results} + +\item{.quiet}{if `TRUE` then no progress information will be displayed} +} +\value{ +data frame of posts +} +\description{ +Get all posts across all sites of the authenticated user +} +\examples{ +if (interactive()) { + wp_auth() + my_posts <- wp_get_posts() +} +} +\references{ + +} diff --git a/man/wp_site_info.Rd b/man/wp_site_info.Rd index 6ed5321..d5efd9f 100644 --- a/man/wp_site_info.Rd +++ b/man/wp_site_info.Rd @@ -7,21 +7,18 @@ wp_site_info(site) } \arguments{ -\item{site}{site id or domain} +\item{site}{site id or domain; if not specified, the primary site of the +authenticated user will be used.} } \description{ Get information about a site } -\note{ -I've only had this work successfully with my blog by using the site id. -} \examples{ -\dontrun{ -wp_auth() -me <- wp_about_me() -wp_site_info(me$primary_blog) +if (interactive() { + wp_auth() + wp_site_info() } } \references{ -\url{https://developer.wordpress.com/docs/api/1.2/get/sites/$site/} + } diff --git a/man/wp_site_stats.Rd b/man/wp_site_stats.Rd index 2f08da2..844936d 100644 --- a/man/wp_site_stats.Rd +++ b/man/wp_site_stats.Rd @@ -7,21 +7,22 @@ wp_site_stats(site) } \arguments{ -\item{site}{site id or domain} +\item{site}{site id or domain; if not specified, the primary site of the +authenticated user will be used.} +} +\value{ +list with a great deal of stats metadata. You are probably most + interested in the `visits` element. } \description{ Get a site's stats } -\note{ -I've only had this work successfully with my blog by using the site id. -} \examples{ -\dontrun{ -wp_auth() -me <- wp_about_me() -wp_site_stats(me$primary_blog) +if (interactive()) { + wp_auth() + wp_site_stats() } } \references{ -\url{https://developer.wordpress.com/docs/api/1.1/get/sites/$site/stats/} + }