Skip to content

Commit

Permalink
CRAN checks + general cleanup; move to https API as required by pastebin
Browse files Browse the repository at this point in the history
  • Loading branch information
hrbrmstr committed Jul 29, 2017
1 parent 7778df2 commit 274e578
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 105 deletions.
10 changes: 6 additions & 4 deletions DESCRIPTION
@@ -1,22 +1,24 @@
Package: pastebin
Type: Package
Title: Tools to Work with the 'pastebin' API
Version: 0.1.0
Date: 2017-02-05
Version: 0.1.1
Date: 2017-06-27
Author: Bob Rudis (bob@@rud.is)
Maintainer: Bob Rudis <bob@rud.is>
Description: Tools to work with the 'pastebin' API.
URL: http://github.com/hrbrmstr/pastebin
URL: https://github.com/hrbrmstr/pastebin
BugReports: https://github.com/hrbrmstr/pastebin/issues
License: AGPL
Suggests:
testthat
Depends:
R (>= 3.2.0)
Imports:
dplyr,
stats,
purrr,
httr,
jsonlite,
tibble,
xml2
RoxygenNote: 6.0.0
RoxygenNote: 6.0.1
2 changes: 2 additions & 0 deletions NAMESPACE
Expand Up @@ -10,7 +10,9 @@ export(new_paste)
export(pastebin_api_key)
import(httr)
import(purrr)
importFrom(dplyr,mutate)
importFrom(jsonlite,fromJSON)
importFrom(stats,setNames)
importFrom(tibble,as_tibble)
importFrom(xml2,read_html)
importFrom(xml2,xml_children)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
@@ -1,2 +1,6 @@
0.2.0
* Cleanup/CRAN checks
* Move to https API as required by pastebin

0.1.0
* Initial release
5 changes: 4 additions & 1 deletion R/aaa.r
@@ -1 +1,4 @@
globalVariables(c("paste_date", "paste_size", "paste_private", "paste_hits"))
globalVariables(
c(".", "paste_expire_date", "paste_date", "paste_size",
"paste_private", "paste_hits")
)
13 changes: 5 additions & 8 deletions R/get-paste-metadata.r
@@ -1,16 +1,13 @@
#' Get paste metadata
#'
#' @md
#' @param x paste id
#' @param use_scraping_api if a pro member, set this to `TRUE`, otherwise leave it `FALSE`
#' and be kind to their servers lest ye be banned.
#' @param include_metadata if `use_scraping_api` is `TRUE` and this is `TRUE`, the returned
#' `list` will include metadata
#' @references [Scraping API](http://pastebin.com/api_scraping_faq)
#' @param paste_id paste id
#' @references [Scraping API](https://pastebin.com/api_scraping_faq)
#' @export
get_paste_metadata <- function(x) {
get_paste_metadata <- function(paste_id) {

res <- httr::GET("http://pastebin.com/api_scrape_item_meta.php", query=list(i=x))
res <- httr::GET("https://pastebin.com/api_scrape_item_meta.php",
query=list(i=paste_id))

httr::stop_for_status(res)

Expand Down
8 changes: 4 additions & 4 deletions R/get-paste.r
Expand Up @@ -11,26 +11,26 @@
#' in one call context and a `character` vector in another may be OK interactively
#' bit it creates a situation where you need to write `if` logic to handle
#' programmatically. Use [toString] to extract just the paste body
#' @references [Scraping API](http://pastebin.com/api_scraping_faq)
#' @references [Scraping API](https://pastebin.com/api_scraping_faq)
#' @export
get_paste <- function(x, use_scraping_api=FALSE, include_metadata=FALSE) {

meta <- NULL

if (!use_scraping_api) {

res <- httr::GET(sprintf("http://pastebin.com/raw/%s", x))
res <- httr::GET(sprintf("https://pastebin.com/raw/%s", x))
httr::stop_for_status(res)
paste_text <- httr::content(res, as="text", encoding="UTF-8")

} else {

res <- httr::GET("http://pastebin.com/api_scrape_item.php",
res <- httr::GET("https://pastebin.com/api_scrape_item.php",
query=list(i=x))
httr::stop_for_status(res)
paste_text <- httr::content(res, as="text", encoding="UTF-8")

if (include_metadata) meta <- get_paste_metadat(x)
if (include_metadata) meta <- get_paste_metadata(x)

}

Expand Down
4 changes: 2 additions & 2 deletions R/get-recent-pastes.r
Expand Up @@ -3,7 +3,7 @@
#' @md
#' @param limit number of recent pastes to fetch. Limit is 500, default is 50.
#' @param lang limit the recent paste list to a particular language. Default is all pastes
#' @references [Scraping API](http://pastebin.com/api_scraping_faq)
#' @references [Scraping API](https://pastebin.com/api_scraping_faq)
#' @export
get_recent_pastes <- function(limit=50, lang=NULL) {

Expand All @@ -13,7 +13,7 @@ get_recent_pastes <- function(limit=50, lang=NULL) {
params <- list(limit=limit)
if (!is.null(lang)) params$lang <- lang

res <- httr::GET("http://pastebin.com/api_scraping.php",
res <- httr::GET("https://pastebin.com/api_scraping.php",
query=params)
httr::stop_for_status(res)

Expand Down
4 changes: 2 additions & 2 deletions R/get-trending-pastes.r
Expand Up @@ -2,11 +2,11 @@
#'
#' @md
#' @param pastebin_key pastebin API key
#' @references [http://pastebin.com/api#10](http://pastebin.com/api#10)
#' @references [https://pastebin.com/api#10](https://pastebin.com/api#10)
#' @export
get_trending_pastes <- function(pastebin_key=pastebin_api_key()) {

res <- httr::POST("http://pastebin.com/api/api_post.php",
res <- httr::POST("https://pastebin.com/api/api_post.php",
body=list(api_dev_key=pastebin_key,
api_option="trends"),
encode="form")
Expand Down
14 changes: 7 additions & 7 deletions R/new-paste.r
Expand Up @@ -4,20 +4,20 @@
#' @param text of paste
#' @param name name/title of paste
#' @param format hint for syntax highlighting. Defaults to `text`. See
#' [the detail page](http://pastebin.com/api#5) for more info.
#' [the detail page](https://pastebin.com/api#5) for more info.
#' @param impersonate if `TRUE` then `PASTEBIN_USER` and `PASTEBIN_PASSWORD` _must_ be set
#' in order to generate a user key to be applied with the API key. Don't blame me,
#' blame [pastebin](http://pastebin.com/api#8).
#' blame [pastebin](https://pastebin.com/api#8).
#' @param visibility one of `public`, `unlisted` or `private`. Defaults to `public`
#' @param expires either `n` for never or an abbreviated time expiration string in the form
#' of a digit (the "number of") and a units character `m` for minute(s),
#' `d` for day(s), `w` for week(s). Defaults to `n` (never). See
#' [the detail page](http://pastebin.com/api#6) for more info.
#' [the detail page](https://pastebin.com/api#6) for more info.
#' @param pastebin_key pastebin API key
#' @note The maximum size a paste can be is 512 kilobytes (0.5 megabytes). Pro members are
#' allowed to create pastes up to 10 megabytes.
#' @export
new_paste <- function(x, name=NULL, format="text", impersonate=FALSE,
new_paste <- function(text, name=NULL, format="text", impersonate=FALSE,
visibility=c("public", "unlisted", "private"),
expires="n", pastebin_key=pastebin_api_key()) {

Expand All @@ -28,7 +28,7 @@ new_paste <- function(x, name=NULL, format="text", impersonate=FALSE,

params <- list(api_dev_key=pastebin_key,
api_option="paste",
api_paste_code=x,
api_paste_code=text,
api_paste_name=name,
api_paste_format=format,
api_user_key="",
Expand All @@ -37,7 +37,7 @@ new_paste <- function(x, name=NULL, format="text", impersonate=FALSE,

if (impersonate) {

httr::POST("http://pastebin.com/api/api_login.php",
httr::POST("https://pastebin.com/api/api_login.php",
body=list(api_dev_key=pastebin_key,
api_user_name=Sys.getenv("PASTEBIN_USER"),
api_user_password=Sys.getenv("PASTEBIN_PASSWORD")),
Expand All @@ -49,7 +49,7 @@ new_paste <- function(x, name=NULL, format="text", impersonate=FALSE,

}

httr::POST("http://pastebin.com/api/api_post.php", body=params, encode="form") -> res
httr::POST("https://pastebin.com/api/api_post.php", body=params, encode="form") -> res

httr::stop_for_status(res)

Expand Down
2 changes: 2 additions & 0 deletions R/pastebin-package.R
Expand Up @@ -4,7 +4,9 @@
#' @docType package
#' @author Bob Rudis (bob@@rud.is)
#' @import purrr httr
#' @importFrom dplyr mutate
#' @importFrom xml2 read_html xml_find_all xml_name xml_text xml_children
#' @importFrom jsonlite fromJSON
#' @importFrom tibble as_tibble
#' @importFrom stats setNames
NULL
2 changes: 1 addition & 1 deletion README.Rmd
Expand Up @@ -2,7 +2,7 @@
output: rmarkdown::github_document
---

`pastebin` : Tools to work with the [pastebin](http://pastebin.com/) API
`pastebin` : Tools to work with the [pastebin](https://pastebin.com/) API

>Pastebin is a website where you can store any text online for easy sharing. The website is mainly used by programmers to store pieces of sources code or configuration information, but anyone is more than welcome to paste any type of text. The idea behind the site is to make it more convenient for people to share large amounts of text online.
Expand Down

0 comments on commit 274e578

Please sign in to comment.