Skip to content

Commit

Permalink
added linkpreview
Browse files Browse the repository at this point in the history
  • Loading branch information
schochastics committed Oct 2, 2023
1 parent 9e24149 commit 018a3f0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion R/auth.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ get_token <- function(service = "shrinker") {
token <- switch(service,
shrinker = .key_to_base64(),
klazify = Sys.getenv("KLAZIFY_TOKEN"),
whoisxml = Sys.getenv("WHOISXML_TOKEN")
whoisxml = Sys.getenv("WHOISXML_TOKEN"),
linkpreview = Sys.getenv("LINKPREVIEW_TOKEN")
)
if (token == "") {
rlang::abort("token not found in .Renviron")
Expand Down
29 changes: 29 additions & 0 deletions R/linkpreview.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.make_request_linkpreview <- function(path = "", params = list()) {
token <- get_token(service = "linkpreview")
req <- httr2::request("https://api.linkpreview.net")
req <- httr2::req_url_path_append(req, path)
req <- httr2::req_headers(req, "X-Linkpreview-Api-Key" = token)
req <- httr2::req_user_agent(req, "domainator R package (http://github.com/schochastics/domainator)")
if (length(params) != 0) {
req <- httr2::req_url_query(req, !!!params)
}
# resp <- httr2::req_dry_run(req)
resp <- httr2::req_perform(req)
resp
}

#' linkpreviewer
#' @description use linkpreview to get the description of a URL.
#' @param url character. URL to be categorized
#' @return data.frame with the title and description of a website
#' @examples
#' \dontrun{
#' get_url_category_linkpreview("https://www.google.com")
#' }
#' @export
get_url_category_linkpreview <- function(url) {
params <- list("q" = URLencode(url))
resp <- .make_request_linkpreview(path = "", params)
dat <- httr2::resp_body_json(resp)
data.frame(dat)
}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ domainator wraps various APIs and provides lists to classify domains. This inclu
- [webshrinker](https://webshrinker.com) (commercial)
- [klazify](https://www.klazify.com/) (commercial)
- [whoisxmlapi](https://whoisxmlapi.com) (commercial)
- [linkpreview](https://my.linkpreview.net/) (commercial)

**Lists**

Expand Down Expand Up @@ -47,5 +48,11 @@ Get the API key from
[here](https://website-categorization.whoisxmlapi.com/api/documentation/v2/making-requests).
Add WHOISXML_TOKEN="your-token" to `.Renviron`


### linkpreview

Get the API key from [here](https://my.linkpreview.net/).
Add LINKPREVIEW_TOKEN="your-token" to `.Renviron`

## Example

0 comments on commit 018a3f0

Please sign in to comment.