This repository has been archived by the owner on Oct 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Steph Locke
committed
Mar 24, 2016
1 parent
017b12f
commit f1763f5
Showing
5 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#' Search for cases where an email address has been included in | ||
#' a paste | ||
#' | ||
#' @param emails A character vector of email addresses | ||
#' @param ... Optional passthrough to HIBP_headers() | ||
#' | ||
#' @return List of data.frames containing results | ||
#' @export | ||
#' | ||
#' @examples | ||
#' pastes(c("steff.sullivan@gmail.com","stephanie.g.locke@gmail.com")) | ||
pastes<-function( | ||
emails | ||
,...){ | ||
|
||
if(length(emails)==0|!inherits(emails,"character")) stop("Problematic emails") | ||
|
||
encoded<-urltools::url_encode(emails) | ||
URLS<-paste0("https://haveibeenpwned.com/api/pasteaccount/" | ||
,encoded) | ||
|
||
res<-lapply(URLS, GETcontent, HIBP_headers(...)) | ||
names(res)<-emails | ||
|
||
return(res) | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
context("pastes") | ||
|
||
test_that("pastes works for a single account",{ | ||
|
||
acct<-"steff.sullivan@gmail.com" | ||
|
||
# Simplest usage scenario | ||
res<-pastes(acct) | ||
|
||
expect_is(res, "list") | ||
expect_named(res, acct) | ||
expect_equal(length(res),1) | ||
expect_is(res[[acct]],"data.frame") | ||
expect_gte(ncol(res[[acct]]),1) | ||
expect_gte(nrow(res[[acct]]),1) | ||
|
||
# With header passthrough | ||
expect_error(pastes(acct,agent="blah"),NA) | ||
}) | ||
|
||
test_that("pastes works for multiple accounts",{ | ||
|
||
acct<-c("steff.sullivan@gmail.com","stephanie.g.locke@gmail.com") | ||
|
||
# Simplest usage scenario | ||
res<-pastes(acct) | ||
|
||
expect_is(res, "list") | ||
expect_named(res, acct) | ||
expect_equal(length(res),length(acct)) | ||
for(i in 1:length(acct)){ | ||
a<-acct[i] | ||
expect_is(res[[a]],"data.frame") | ||
expect_gte(ncol(res[[a]]),1) | ||
expect_gte(nrow(res[[a]]),1) | ||
} | ||
|
||
# With header passthrough | ||
expect_error(pastes(acct,agent="blah"),NA) | ||
}) | ||
|
||
test_that("handles incorrect values",{ | ||
errors<-"Problematic emails" | ||
|
||
expect_error(pastes(TRUE),errors) | ||
expect_error(pastes(as.character(c())),errors) | ||
|
||
}) |