Browse Source

initial commit

batman
boB Rudis 3 years ago
parent
commit
22c6068245
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 6
      DESCRIPTION
  2. 2
      LICENSE
  3. 21
      LICENSE.md
  4. 3
      NAMESPACE
  5. 139
      R/core.R
  6. 2
      man/clearbit.Rd
  7. 17
      man/clearbit_api_key.Rd
  8. 23
      man/domain_to_org.Rd
  9. 22
      man/name_to_domain.Rd

6
DESCRIPTION

@ -1,6 +1,6 @@
Package: clearbit
Type: Package
Title: clearbit Title Goes Here Otherwise CRAN Checks Fail
Title: Tools to Query Clearbit
Version: 0.1.0
Date: 2021-07-09
Authors@R: c(
@ -8,11 +8,11 @@ Authors@R: c(
comment = c(ORCID = "0000-0001-5670-2640"))
)
Maintainer: Bob Rudis <bob@rud.is>
Description: A good description goes here otherwise CRAN checks fail.
Description: Clearbit provides an interface to perform queries on organizations and people.
URL: https://git.rud.is/hrbrmstr/clearbit
BugReports: https://git.rud.is/hrbrmstr/clearbit/issues
Encoding: UTF-8
License: AGPL
License: MIT + file LICENSE
Suggests:
covr, tinytest
Depends:

2
LICENSE

@ -0,0 +1,2 @@
YEAR: 2021
COPYRIGHT HOLDER: clearbit authors

21
LICENSE.md

@ -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.

3
NAMESPACE

@ -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)

139
R/core.R

@ -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
}
}

2
man/clearbit.Rd

@ -6,7 +6,7 @@
\alias{clearbit-package}
\title{...}
\description{
A good description goes here otherwise CRAN checks fail.
Clearbit provides an interface to perform queries on organizations and people.
}
\seealso{
Useful links:

17
man/clearbit_api_key.Rd

@ -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
}

23
man/domain_to_org.Rd

@ -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.
}

22
man/name_to_domain.Rd

@ -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…
Cancel
Save