boB Rudis
5 years ago
6 changed files with 149 additions and 25 deletions
@ -0,0 +1,73 @@ |
|||||
|
#' Create a new deep search task. Search for a term or with a Lucene query. |
||||
|
#' |
||||
|
#' Unlike the more lighweight [pt_search()] results from this endpoint |
||||
|
#' will be available at the returned URL. |
||||
|
#' |
||||
|
#' @param query search term (e.g. an IP address, domain, or file hash) or valid Lucene query |
||||
|
#' @param api_key your [packettotal_api_key()]. |
||||
|
#' @export |
||||
|
#' @references <https://packettotal.com/api-docs/#/search |
||||
|
#' @examples |
||||
|
#' str(try(pt_deep_search("botnet OR malware"), silent=TRUE), 1) |
||||
|
pt_deep_search <- function(query, api_key = packettotal_api_key()) { |
||||
|
|
||||
|
httr::POST( |
||||
|
url = "https://api.packettotal.com/v1/search/deep", |
||||
|
body = list( |
||||
|
query = query |
||||
|
), |
||||
|
encode = "json", |
||||
|
httr::add_headers( |
||||
|
`x-api-key` = api_key |
||||
|
), |
||||
|
.PACKETTOTAL_UA |
||||
|
) -> res |
||||
|
|
||||
|
httr::stop_for_status(res) |
||||
|
|
||||
|
out <- httr::content(res, as = "text", encoding = "UTF-8") |
||||
|
|
||||
|
out <- jsonlite::fromJSON(out) |
||||
|
|
||||
|
class(out) <- "pt_search_result" |
||||
|
|
||||
|
out |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#' @rdname pt_deep_search |
||||
|
#' @param search_result output from [pt_deep_search()] or a plain search results id |
||||
|
#' @export |
||||
|
pt_get_search_results <- function(search_result, api_key = packettotal_api_key()) { |
||||
|
|
||||
|
res_url <- NULL |
||||
|
if (inherits(search_result, "pt_search_result")) { |
||||
|
res_url <- sprintf("https://api.packettotal.com%s", search_result$results_uri) |
||||
|
} else if (is.character(search_result)) { |
||||
|
search_result <- search_result[1] |
||||
|
if (grepl("v1/", search_result)) { |
||||
|
res_url <- sprintf("https://api.packettotal.com%s", search_result) |
||||
|
} else { |
||||
|
res_url <- sprintf("https://api.packettotal.com/v1/search/deep/results/%s", search_result) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (is.null(res_url)) stop("Unrecognized search result.", call.=FALSE) |
||||
|
|
||||
|
httr::GET( |
||||
|
url = res_url, |
||||
|
httr::add_headers( |
||||
|
`x-api-key` = api_key |
||||
|
), |
||||
|
.PACKETTOTAL_UA |
||||
|
) -> res |
||||
|
|
||||
|
httr::stop_for_status(res) |
||||
|
|
||||
|
out <- httr::content(res, as = "text", encoding = "UTF-8") |
||||
|
|
||||
|
out <- jsonlite::fromJSON(out) |
||||
|
|
||||
|
out |
||||
|
|
||||
|
} |
@ -0,0 +1,28 @@ |
|||||
|
% Generated by roxygen2: do not edit by hand |
||||
|
% Please edit documentation in R/deep-search.R |
||||
|
\name{pt_deep_search} |
||||
|
\alias{pt_deep_search} |
||||
|
\alias{pt_get_search_results} |
||||
|
\title{Create a new deep search task. Search for a term or with a Lucene query.} |
||||
|
\usage{ |
||||
|
pt_deep_search(query, api_key = packettotal_api_key()) |
||||
|
|
||||
|
pt_get_search_results(search_result, api_key = packettotal_api_key()) |
||||
|
} |
||||
|
\arguments{ |
||||
|
\item{query}{search term (e.g. an IP address, domain, or file hash) or valid Lucene query} |
||||
|
|
||||
|
\item{api_key}{your \code{\link[=packettotal_api_key]{packettotal_api_key()}}.} |
||||
|
|
||||
|
\item{search_result}{output from \code{\link[=pt_deep_search]{pt_deep_search()}} or a plain search results id} |
||||
|
} |
||||
|
\description{ |
||||
|
Unlike the more lighweight \code{\link[=pt_search]{pt_search()}} results from this endpoint |
||||
|
will be available at the returned URL. |
||||
|
} |
||||
|
\examples{ |
||||
|
str(try(pt_deep_search("botnet OR malware"), silent=TRUE), 1) |
||||
|
} |
||||
|
\references{ |
||||
|
<https://packettotal.com/api-docs/#/search |
||||
|
} |
Loading…
Reference in new issue