Browse Source

refreshed some functions and setup pkg for expansion

master
boB Rudis 4 years ago
parent
commit
cacf682a85
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 2
      .Rbuildignore
  2. 1
      .gitignore
  3. 13
      DESCRIPTION
  4. 2
      LICENSE
  5. 21
      LICENSE.md
  6. 5
      NAMESPACE
  7. 11
      R/about-me.R
  8. 86
      R/my-posts.R
  9. 2
      R/post-stats.R
  10. 4
      R/pressur-package.R
  11. 22
      R/site-info.R
  12. 25
      R/site-stats.R
  13. 14
      R/util.R
  14. 6
      R/wp-post.R
  15. 22
      R/wp_auth.R
  16. 57
      README.Rmd
  17. 83
      README.md
  18. BIN
      man/figures/README-unnamed-chunk-1-1.png
  19. 1
      man/pressur.Rd
  20. 15
      man/wp_about_me.Rd
  21. 24
      man/wp_auth.Rd
  22. 23
      man/wp_get_my_posts.Rd
  23. 56
      man/wp_get_posts.Rd
  24. 15
      man/wp_site_info.Rd
  25. 19
      man/wp_site_stats.Rd

2
.Rbuildignore

@ -10,3 +10,5 @@
^doc$ ^doc$
^\.httr-oauth$ ^\.httr-oauth$
^CONDUCT\.md$ ^CONDUCT\.md$
^~/\.local/wp-oauth-token$
^LICENSE\.md$

1
.gitignore

@ -7,3 +7,4 @@ src/*.o
src/*.so src/*.so
src/*.dll src/*.dll
.httr-oauth .httr-oauth
~/.local/wp-oauth-token

13
DESCRIPTION

@ -1,8 +1,8 @@
Package: pressur Package: pressur
Type: Package Type: Package
Title: Query and Orchestrate the 'WordPress' 'API' Title: Query and Orchestrate the 'WordPress' 'API'
Version: 0.1.0 Version: 0.2.0
Date: 2017-12-27 Date: 2020-06-28
Authors@R: c( Authors@R: c(
person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"), person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-5670-2640")) comment = c(ORCID = "0000-0001-5670-2640"))
@ -14,18 +14,19 @@ Description: 'WordPress' has a fairly comprehensive 'API' <https://developer.wor
with the 'WordPress' 'API' functions. with the 'WordPress' 'API' functions.
URL: https://github.com/hrbrmstr/pressur URL: https://github.com/hrbrmstr/pressur
BugReports: https://github.com/hrbrmstr/pressur/issues BugReports: https://github.com/hrbrmstr/pressur/issues
License: AGPL License: MIT + file LICENSE
Encoding: UTF-8 Encoding: UTF-8
Suggests: Suggests:
testthat, testthat,
covr covr
Depends: Depends:
R (>= 3.2.0) R (>= 3.6.0)
Imports: Imports:
purrr, purrr,
httr, httr,
stringi, stringi,
crayon, crayon,
tibble, tibble,
anytime anytime,
RoxygenNote: 6.0.1.9000 progress
RoxygenNote: 7.1.0

2
LICENSE

@ -0,0 +1,2 @@
YEAR: 2020
COPYRIGHT HOLDER: Bob Rudis

21
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.

5
NAMESPACE

@ -2,13 +2,14 @@
export(wp_about_me) export(wp_about_me)
export(wp_auth) export(wp_auth)
export(wp_get_my_posts) export(wp_get_posts)
export(wp_post_stats) export(wp_post_stats)
export(wp_site_info) export(wp_site_info)
export(wp_site_stats) export(wp_site_stats)
import(anytime) import(anytime)
import(crayon) import(crayon)
import(httr) import(httr)
import(progress)
import(purrr) import(purrr)
import(stringi) import(stringi)
importFrom(tibble,data_frame) importFrom(tibble,tibble)

11
R/about-me.R

@ -1,11 +1,12 @@
#' Get your user information #' Get metadata about the current user.
#' #'
#' @md
#' @references <https://developer.wordpress.com/docs/api/1.1/get/me/> #' @references <https://developer.wordpress.com/docs/api/1.1/get/me/>
#' @return list with user metadata
#' @export #' @export
#' @examples \dontrun{ #' @examples
#' wp_auth() #' if (interactive()) {
#' wp_about_me() #' wp_auth()
#' wp_about_me()
#' } #' }
wp_about_me <- function() { wp_about_me <- function() {

86
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 <https://developer.wordpress.com/docs/api/1.1/get/me/posts/> #' @references <https://developer.wordpress.com/docs/api/1.1/get/me/posts/>
#' @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 #' @param .quiet if `TRUE` then no progress information will be displayed
#' @export #' @export
#' @examples \dontrun{ #' @return data frame of posts
#' wp_auth() #' @examples
#' my_posts <- wp_get_my_posts() #' 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( httr::GET(
url = "https://public-api.wordpress.com/rest/v1.1/me/posts", url = "https://public-api.wordpress.com/rest/v1.1/me/posts",
.add_bearer_token(), .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 ) -> res
httr::stop_for_status(res) httr::stop_for_status(res)
@ -46,12 +93,20 @@ wp_get_my_posts <- function(.quiet=FALSE) {
n_pages <- ceiling(pg$found / 20) n_pages <- ceiling(pg$found / 20)
for (idx in 2:n_pages) { if (n_pages > 1) {
if (!.quiet) cat(crayon::green("."), sep="")
pg <- .wp_next_posts_page(pg) progress::progress_bar$new(
.posts[[idx]] <- pg 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, ~{ purrr::map_df(.posts, ~{
@ -105,8 +160,11 @@ wp_get_my_posts <- function(.quiet=FALSE) {
}) -> .posts_df }) -> .posts_df
.posts_df$date <- anytime::anytime(.posts_df$date) .date <- try(anytime::anytime(.posts_df$date), silent = TRUE)
.posts_df$modified <- anytime::anytime(.posts_df$modified) .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) return(.posts_df)

2
R/post-stats.R

@ -25,7 +25,7 @@ wp_post_stats <- function(site, post_id) {
.stats <- httr::content(res) .stats <- httr::content(res)
tibble::data_frame( tibble::tibble(
date = as.Date(.stats$date), date = as.Date(.stats$date),
views = .stats$views, views = .stats$views,
years = list(.stats$years), years = list(.stats$years),

4
R/pressur-package.R

@ -8,6 +8,6 @@
#' @name pressur #' @name pressur
#' @docType package #' @docType package
#' @author Bob Rudis (bob@@rud.is) #' @author Bob Rudis (bob@@rud.is)
#' @import purrr stringi httr crayon anytime #' @import purrr stringi httr crayon anytime progress
#' @importFrom tibble data_frame #' @importFrom tibble tibble
NULL NULL

22
R/site-info.R

@ -1,19 +1,25 @@
#' Get information about a site #' Get information about a site
#' #'
#' @md
#' @references <https://developer.wordpress.com/docs/api/1.2/get/sites/$site/> #' @references <https://developer.wordpress.com/docs/api/1.2/get/sites/$site/>
#' @param site site id or domain #' @param site site id or domain; if not specified, the primary site of the
#' @note I've only had this work successfully with my blog by using the site id. #' authenticated user will be used.
#' @export #' @export
#' @examples \dontrun{ #' @examples
#' wp_auth() #' if (interactive() {
#' me <- wp_about_me() #' wp_auth()
#' wp_site_info(me$primary_blog) #' wp_site_info()
#' } #' }
wp_site_info <- function(site) { 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( httr::GET(
url = sprintf("https://public-api.wordpress.com/rest/v1.2/sites/%s", site), url = site_url,
.add_bearer_token(),
httr::accept_json() httr::accept_json()
) -> res ) -> res

25
R/site-stats.R

@ -1,19 +1,26 @@
#' Get a site's stats #' Get a site's stats
#' #'
#' @md
#' @references <https://developer.wordpress.com/docs/api/1.1/get/sites/$site/stats/> #' @references <https://developer.wordpress.com/docs/api/1.1/get/sites/$site/stats/>
#' @param site site id or domain #' @param site site id or domain; if not specified, the primary site of the
#' @note I've only had this work successfully with my blog by using the site id. #' authenticated user will be used.
#' @return list with a great deal of stats metadata. You are probably most
#' interested in the `visits` element.
#' @export #' @export
#' @examples \dontrun{ #' @examples
#' wp_auth() #' if (interactive()) {
#' me <- wp_about_me() #' wp_auth()
#' wp_site_stats(me$primary_blog) #' wp_site_stats()
#' } #' }
wp_site_stats <- function(site) { 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( httr::GET(
url = sprintf("https://public-api.wordpress.com/rest/v1.1/sites/%s/stats", site), url = site_stats_url,
.add_bearer_token(), .add_bearer_token(),
accept_json() accept_json()
) -> res ) -> res
@ -23,7 +30,7 @@ wp_site_stats <- function(site) {
.stats <- httr::content(res) .stats <- httr::content(res)
.stats$visits <- purrr::map_df(.stats$visits$data, ~purrr::set_names(.x, .stats$visits$fields)) .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) return(.stats)

14
R/util.R

@ -1,3 +1,17 @@
.add_bearer_token <- function() { .add_bearer_token <- function() {
httr::add_headers(`Authorization` = sprintf("Bearer %s", .pkg$token$credentials$access_token)) 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)
}

6
R/wp-post.R

@ -0,0 +1,6 @@
# Create a post
#
# @export
# wp_post_new <- function() {
#
# }

22
R/wp_auth.R

@ -15,13 +15,24 @@ oauth_endpoint(
#' #'
#' Call this at the start of any WordPress API interaction #' 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 <https://developer.wordpress.com/docs/oauth2/> #' @references <https://developer.wordpress.com/docs/oauth2/>
#' @return oauth token (invisibly)
#' @export #' @export
#' @examples \dontrun{ #' @examples
#' wp_auth() #' if (interactive()) {
#' wp_auth()
#' } #' }
wp_auth <- function() { wp_auth <- function(cache = Sys.getenv("WP_OAUTH_CACHE", unset = TRUE)) {
oauth2.0_token( oauth2.0_token(
wordpress_endpoint, wordpress_endpoint,
@ -31,10 +42,11 @@ wp_auth <- function() {
response_type = "code", response_type = "code",
scope = "global" scope = "global"
), ),
cache = TRUE cache = cache
) -> wordpress_token ) -> wordpress_token
.pkg$token <- wordpress_token .pkg$token <- wordpress_token
.pkg$me <- wp_about_me()
invisible(wordpress_token) invisible(wordpress_token)

57
README.Rmd

@ -1,17 +1,19 @@
--- ---
output: rmarkdown::github_document output: rmarkdown::github_document
editor_options:
chunk_output_type: console
--- ---
```{r pkg-knitr-opts, include=FALSE}
hrbrpkghelpr::global_opts()
```
# pressur ```{r badges, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::stinking_badges()
Query and Orchestrate the 'WordPress' 'API' ```
## Description
'WordPress' has a fairly comprehensive 'API' <https://developer.wordpress.com/> ```{r description, results='asis', echo=FALSE, cache=FALSE}
that makes it possible to perform blog orchestration ('CRUD' operations on posts, users, hrbrpkghelpr::yank_title_and_description()
sites, etc.) as well as retrieve and process blog statistics. Tools are provided to work ```
with the 'WordPress' 'API' functions.
### `<dalek_voice>` YOU WILL O-BEY `</dalek_voice>` ### `<dalek_voice>` YOU WILL O-BEY `</dalek_voice>`
@ -41,41 +43,44 @@ You are encouraged to poke around the source and contribute PRs or issues for hi
The following functions are implemented: The following functions are implemented:
- `wp_auth`: Authenticate to WordPress ```{r ingredients, results='asis', echo=FALSE, cache=FALSE}
- `wp_about_me`: Get your user information hrbrpkghelpr::describe_ingredients()
- `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
## Installation ## Installation
```{r eval=FALSE} ```{r install-ex, results='asis', echo=FALSE, cache=FALSE}
devtools::install_github("hrbrmstr/pressur") hrbrpkghelpr::install_block()
```
```{r message=FALSE, warning=FALSE, error=FALSE, include=FALSE}
options(width=120)
``` ```
## Usage ## Usage
```{r message=FALSE, warning=FALSE, error=FALSE} ```{r lib-ex}
library(pressur) library(pressur)
# current verison # current version
packageVersion("pressur") packageVersion("pressur")
``` ```
### Basic operation ### Basic operation
```{r} ```{r}
library(hrbrthemes)
library(ggplot2)
wp_auth() 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 ## 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.

83
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 # pressur
Query and Orchestrate the ‘WordPress’ ‘API’ 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: The following functions are implemented:
- `wp_about_me`: Get metadata about the current user.
- `wp_auth`: Authenticate to WordPress - `wp_auth`: Authenticate to WordPress
- `wp_about_me`: Get your user information - `wp_get_posts`: Get all posts across all sites of the authenticated
- `wp_get_my_posts`: Get all ‘my’ posts across all sites user
- `wp_post_stats`: Retrieve statistics for a WordPress post - `wp_post_stats`: Retrieve statistics for a WordPress post
- `wp_site_info`: Get information about a site - `wp_site_info`: Get information about a site
- `wp_site_stats`: Get a site’s stats - `wp_site_stats`: Get a site’s stats
@ -57,62 +73,45 @@ The following functions are implemented:
## Installation ## Installation
``` r ``` 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 ## Usage
``` r ``` r
library(pressur) library(pressur)
# current verison # current version
packageVersion("pressur") packageVersion("pressur")
## [1] '0.2.0'
``` ```
## [1] '0.1.0'
### Basic operation ### Basic operation
``` r ``` r
library(hrbrthemes)
library(ggplot2)
wp_auth() 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 <img src="man/figures/README-unnamed-chunk-1-1.png" width="672" />
## $ 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 ## Code of Conduct
Please note that this project is released with a [Contributor Code of Please note that this project is released with a Contributor Code of
Conduct](CONDUCT.md). By participating in this project you agree to Conduct. By participating in this project you agree to abide by its
abide by its terms. terms.

BIN
man/figures/README-unnamed-chunk-1-1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

1
man/pressur.Rd

@ -3,7 +3,6 @@
\docType{package} \docType{package}
\name{pressur} \name{pressur}
\alias{pressur} \alias{pressur}
\alias{pressur-package}
\title{Query and Orchestrate the 'WordPress' 'API'} \title{Query and Orchestrate the 'WordPress' 'API'}
\description{ \description{
'WordPress' has a fairly comprehensive 'API' <https://developer.wordpress.com/> 'WordPress' has a fairly comprehensive 'API' <https://developer.wordpress.com/>

15
man/wp_about_me.Rd

@ -2,19 +2,22 @@
% Please edit documentation in R/about-me.R % Please edit documentation in R/about-me.R
\name{wp_about_me} \name{wp_about_me}
\alias{wp_about_me} \alias{wp_about_me}
\title{Get your user information} \title{Get metadata about the current user.}
\usage{ \usage{
wp_about_me() wp_about_me()
} }
\value{
list with user metadata
}
\description{ \description{
Get your user information Get metadata about the current user.
} }
\examples{ \examples{
\dontrun{ if (interactive()) {
wp_auth() wp_auth()
wp_about_me() wp_about_me()
} }
} }
\references{ \references{
\url{https://developer.wordpress.com/docs/api/1.1/get/me/} <https://developer.wordpress.com/docs/api/1.1/get/me/>
} }

24
man/wp_auth.Rd

@ -4,16 +4,32 @@
\alias{wp_auth} \alias{wp_auth}
\title{Authenticate to WordPress} \title{Authenticate to WordPress}
\usage{ \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{ \description{
Call this at the start of any WordPress API interaction 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{ \examples{
\dontrun{ if (interactive()) {
wp_auth() wp_auth()
} }
} }
\references{ \references{
\url{https://developer.wordpress.com/docs/oauth2/} <https://developer.wordpress.com/docs/oauth2/>
} }

23
man/wp_get_my_posts.Rd

@ -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/}
}

56
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{
<https://developer.wordpress.com/docs/api/1.1/get/me/posts/>
}

15
man/wp_site_info.Rd

@ -7,21 +7,18 @@
wp_site_info(site) wp_site_info(site)
} }
\arguments{ \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{ \description{
Get information about a site Get information about a site
} }
\note{
I've only had this work successfully with my blog by using the site id.
}
\examples{ \examples{
\dontrun{ if (interactive() {
wp_auth() wp_auth()
me <- wp_about_me() wp_site_info()
wp_site_info(me$primary_blog)
} }
} }
\references{ \references{
\url{https://developer.wordpress.com/docs/api/1.2/get/sites/$site/} <https://developer.wordpress.com/docs/api/1.2/get/sites/$site/>
} }

19
man/wp_site_stats.Rd

@ -7,21 +7,22 @@
wp_site_stats(site) wp_site_stats(site)
} }
\arguments{ \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{ \description{
Get a site's stats Get a site's stats
} }
\note{
I've only had this work successfully with my blog by using the site id.
}
\examples{ \examples{
\dontrun{ if (interactive()) {
wp_auth() wp_auth()
me <- wp_about_me() wp_site_stats()
wp_site_stats(me$primary_blog)
} }
} }
\references{ \references{
\url{https://developer.wordpress.com/docs/api/1.1/get/sites/$site/stats/} <https://developer.wordpress.com/docs/api/1.1/get/sites/$site/stats/>
} }

Loading…
Cancel
Save