boB Rudis
3 years ago
9 changed files with 231 additions and 4 deletions
@ -0,0 +1,2 @@ |
|||
YEAR: 2021 |
|||
COPYRIGHT HOLDER: clearbit authors |
@ -0,0 +1,21 @@ |
|||
# MIT License |
|||
|
|||
Copyright (c) 2021 clearbit authors |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|||
SOFTWARE. |
@ -1,4 +1,7 @@ |
|||
# Generated by roxygen2: do not edit by hand |
|||
|
|||
export(clearbit_api_key) |
|||
export(domain_to_org) |
|||
export(name_to_domain) |
|||
import(httr) |
|||
importFrom(jsonlite,fromJSON) |
|||
|
@ -0,0 +1,139 @@ |
|||
httr::user_agent( |
|||
sprintf( |
|||
"clearbit R package v%s: (<%s>)", |
|||
utils::packageVersion("clearbit"), |
|||
utils::packageDescription("clearbit")$URL |
|||
) |
|||
) -> .CLEARBIT_UA |
|||
|
|||
#' Get or set CLEARBIT_API_KEY value |
|||
#' |
|||
#' @param force Force setting a new Rapid7 Open Data API key for the current environment? |
|||
#' @return atomic character vector containing the Clearbit API key |
|||
#' @export |
|||
clearbit_api_key <- function(force = FALSE) { |
|||
|
|||
env <- Sys.getenv('CLEARBIT_API_KEY') |
|||
if (!identical(env, "") && !force) return(env) |
|||
|
|||
if (!interactive()) { |
|||
stop("Please set env var CLEARBIT_API_KEY to your Clearbit API key", |
|||
call. = FALSE) |
|||
} |
|||
|
|||
message("Couldn't find env var CLEARBIT_API_KEY See ?clearbit_api_key for more details.") |
|||
message("Please enter your Clearbit API key and press enter:") |
|||
pat <- readline(": ") |
|||
|
|||
if (identical(pat, "")) { |
|||
stop("Clearbit API key entry failed", call. = FALSE) |
|||
} |
|||
|
|||
message("Updating CLEARBIT_API_KEY env var...") |
|||
Sys.setenv(CLEARBIT_API_KEY = pat) |
|||
|
|||
pat |
|||
|
|||
} |
|||
|
|||
#' The Company Name to Domain API lets you convert the exact name of a company |
|||
#' to a website domain, and a logo. |
|||
#' |
|||
#' Clearbit matches based on exact company name, and returns the company with the most |
|||
#' website traffic. It’s worth noting, that since a company name is not a unique |
|||
#' identifier, you should be prepared for some inherent inaccuracy in the results. |
|||
#' |
|||
#' @param name name of the company to look for |
|||
#' @param api_key Clearbit API key. See [clearbit_api_key()] |
|||
#' @return data frame containing `domain`, `logo`, and `name` if found. `NULL` if not |
|||
#' @export |
|||
name_to_domain <- function(name, api_key = clearbit_api_key()) { |
|||
|
|||
httr::GET( |
|||
url = "https://company.clearbit.com/v1/domains/find", |
|||
httr::authenticate( |
|||
user = api_key, |
|||
password = "" |
|||
), |
|||
query = list( |
|||
name = name[1] |
|||
), |
|||
.CLEARBIT_UA |
|||
) -> res |
|||
|
|||
status <- httr::status_code(res) |
|||
|
|||
if (status == 200) { |
|||
|
|||
out <- httr::content(res, as = "text", encoding = "UTF-8") |
|||
out <- jsonlite::fromJSON(out) |
|||
as.data.frame(out) |
|||
|
|||
} else if (status == 404) { |
|||
|
|||
warning("Company not found.") |
|||
NULL |
|||
|
|||
} else if (status == 422) { |
|||
|
|||
warning("Company name is invalid.") |
|||
NULL |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
#' The Company Name to Domain API lets you convert the exact name of a company |
|||
#' to a website domain, and a logo. |
|||
#' |
|||
#' The Company API allows you to look up a company by their domain. Alongside |
|||
#' the domain you may also provide any additional attributes you have about the |
|||
#' company, such as their company name or twitter handle. Including more detail |
|||
#' will help us be more accurate when searching. |
|||
#' |
|||
#' @param domain name of the company to look for |
|||
#' @param api_key Clearbit API key. See [clearbit_api_key()] |
|||
#' @return data frame if found. `NULL` if not |
|||
#' @export |
|||
domain_to_org <- function(domain, api_key = clearbit_api_key()) { |
|||
|
|||
httr::GET( |
|||
url = "https://company.clearbit.com/v2/companies/find", |
|||
httr::authenticate( |
|||
user = api_key, |
|||
password = "" |
|||
), |
|||
query = list( |
|||
domain = domain[1] |
|||
), |
|||
.CLEARBIT_UA |
|||
) -> res |
|||
|
|||
status <- httr::status_code(res) |
|||
|
|||
if (status == 200) { |
|||
|
|||
out <- httr::content(res, as = "text", encoding = "UTF-8") |
|||
out <- jsonlite::fromJSON(out) |
|||
out |
|||
|
|||
} else if (status == 202) { |
|||
|
|||
out <- httr::content(res, as = "text", encoding = "UTF-8") |
|||
out <- jsonlite::fromJSON(out) |
|||
out |
|||
|
|||
} else if (status == 404) { |
|||
|
|||
warning("Company not found.") |
|||
NULL |
|||
|
|||
} else if (status == 422) { |
|||
|
|||
warning("Domain name is invalid.") |
|||
NULL |
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,17 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/core.R |
|||
\name{clearbit_api_key} |
|||
\alias{clearbit_api_key} |
|||
\title{Get or set CLEARBIT_API_KEY value} |
|||
\usage{ |
|||
clearbit_api_key(force = FALSE) |
|||
} |
|||
\arguments{ |
|||
\item{force}{Force setting a new Rapid7 Open Data API key for the current environment?} |
|||
} |
|||
\value{ |
|||
atomic character vector containing the Clearbit API key |
|||
} |
|||
\description{ |
|||
Get or set CLEARBIT_API_KEY value |
|||
} |
@ -0,0 +1,23 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/core.R |
|||
\name{domain_to_org} |
|||
\alias{domain_to_org} |
|||
\title{The Company Name to Domain API lets you convert the exact name of a company |
|||
to a website domain, and a logo.} |
|||
\usage{ |
|||
domain_to_org(domain, api_key = clearbit_api_key()) |
|||
} |
|||
\arguments{ |
|||
\item{domain}{name of the company to look for} |
|||
|
|||
\item{api_key}{Clearbit API key. See \code{\link[=clearbit_api_key]{clearbit_api_key()}}} |
|||
} |
|||
\value{ |
|||
data frame if found. \code{NULL} if not |
|||
} |
|||
\description{ |
|||
The Company API allows you to look up a company by their domain. Alongside |
|||
the domain you may also provide any additional attributes you have about the |
|||
company, such as their company name or twitter handle. Including more detail |
|||
will help us be more accurate when searching. |
|||
} |
@ -0,0 +1,22 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/core.R |
|||
\name{name_to_domain} |
|||
\alias{name_to_domain} |
|||
\title{The Company Name to Domain API lets you convert the exact name of a company |
|||
to a website domain, and a logo.} |
|||
\usage{ |
|||
name_to_domain(name, api_key = clearbit_api_key()) |
|||
} |
|||
\arguments{ |
|||
\item{name}{name of the company to look for} |
|||
|
|||
\item{api_key}{Clearbit API key. See \code{\link[=clearbit_api_key]{clearbit_api_key()}}} |
|||
} |
|||
\value{ |
|||
data frame containing \code{domain}, \code{logo}, and \code{name} if found. \code{NULL} if not |
|||
} |
|||
\description{ |
|||
Clearbit matches based on exact company name, and returns the company with the most |
|||
website traffic. It’s worth noting, that since a company name is not a unique |
|||
identifier, you should be prepared for some inherent inaccuracy in the results. |
|||
} |
Loading…
Reference in new issue