Skip to content

Commit

Permalink
Add better handling & messaging when using the Scraping API (Fixes #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
hrbrmstr committed Jul 31, 2017
1 parent 274e578 commit 423aa6e
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 6 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: pastebin
Type: Package
Title: Tools to Work with the 'pastebin' API
Version: 0.1.1
Date: 2017-06-27
Version: 0.2.1
Date: 2017-07-31
Author: Bob Rudis (bob@@rud.is)
Maintainer: Bob Rudis <bob@rud.is>
Description: Tools to work with the 'pastebin' API.
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
0.2.1
* Add better handling & messaging when using the Scraping API (Fixes #1)

0.2.0
* Cleanup/CRAN checks
* Move to https API as required by pastebin
Expand Down
10 changes: 9 additions & 1 deletion R/get-paste-metadata.r
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#'
#' @md
#' @param paste_id paste id
#' @note This API call uses the Scraping API which requires a paid account and a white-listed IP address.
#' @references [Scraping API](https://pastebin.com/api_scraping_faq)
#' @export
get_paste_metadata <- function(paste_id) {
Expand All @@ -11,7 +12,14 @@ get_paste_metadata <- function(paste_id) {

httr::stop_for_status(res)

out <- jsonlite::fromJSON(httr::content(res, as="text", encoding="UTF-8"))
res <- httr::content(res, as="text", encoding="UTF-8")

if (grepl("THIS IP", res[1])) {
message(res)
return(invisible(NULL))
}

out <- jsonlite::fromJSON(res)

out$date <- as.POSIXct(as.numeric(out$date), origin="1970-01-01")
out$size <- as.numeric(out$size)
Expand Down
1 change: 1 addition & 0 deletions R/get-paste.r
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#' 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
#' @note This API call can use the Scraping API which requires a paid account and a white-listed IP address.
#' @references [Scraping API](https://pastebin.com/api_scraping_faq)
#' @export
get_paste <- function(x, use_scraping_api=FALSE, include_metadata=FALSE) {
Expand Down
12 changes: 9 additions & 3 deletions R/get-recent-pastes.r
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +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
#' @note This API call uses the Scraping API which requires a paid account and a white-listed IP address.
#' @references [Scraping API](https://pastebin.com/api_scraping_faq)
#' @export
get_recent_pastes <- function(limit=50, lang=NULL) {
Expand All @@ -17,9 +18,14 @@ get_recent_pastes <- function(limit=50, lang=NULL) {
query=params)
httr::stop_for_status(res)

httr::content(res, as="text", encoding="UTF-8") %>%
jsonlite::fromJSON() %>%
as_tibble() -> out
res <- httr::content(res, as="text", encoding="UTF-8")

if (grepl("THIS IP", res[1])) {
message(res)
return(invisible(NULL))
}

out <- as_tibble(jsonlite::fromJSON(res))

out$date <- as.POSIXct(as.numeric(out$date), origin="1970-01-01")
out$size <- as.numeric(out$size)
Expand Down
3 changes: 3 additions & 0 deletions man/get_paste.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/get_paste_metadata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/get_recent_pastes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 423aa6e

Please sign in to comment.