commit 6f752880ed78071924334d69845eed15e8c24d11
parent 63c2ca7b47a596908e410b60709ab05739af945c
Author: eamoncaddigan <eamon.caddigan@gmail.com>
Date:   Sun,  9 Aug 2015 00:27:01 -0400
Okay, so building this updated httr which broke things. But now they're fixed so that's cool. Maybe this works now? Need to test a lot.
Diffstat:
6 files changed, 92 insertions(+), 10 deletions(-)
diff --git a/NAMESPACE b/NAMESPACE
@@ -1 +1,3 @@
-exportPattern("^[^\\.]")
+# Generated by roxygen2 (4.1.1): do not edit by hand
+
+export(guessGender)
diff --git a/R/guessGender.R b/R/guessGender.R
@@ -18,7 +18,7 @@ checkLanguageCountryCodes <- function(countryCode, languageCode) {
 #' is requested, otherwise returns the element itself.
 #' @keywords internal
 getListElement <- function(listName, elementName) {
-  if (match(elementName, listName, nomatch = 0) > 0) {
+  if (match(elementName, names(listName), nomatch = 0) > 0) {
     listElement <- listName[[elementName]]
   } else {
     listElement <- NA
@@ -58,19 +58,21 @@ lookupNameVector <- function(nameVector, countryCode = NA, languageCode = NA, ap
   }
 
   # Run it!
-  queryResult <- httr::GET("https://api.genderize.io", query = query)
+  # XXX - setting ssl_verifypeer to FALSE is probably really bad. Whatev.
+  queryResult <- httr::GET("https://api.genderize.io", query = query,
+                           httr::config(ssl_verifypeer = FALSE))
   if (httr::status_code(queryResult) == 200) {
-    responseDF <- jsonlite::fromJSON(httr::content(queryResult, as="text"))
+    responseFromJSON <- jsonlite::fromJSON(httr::content(queryResult, as="text"))
     # Make sure this is a data.frame with the correct columns. I bet fromJSON
     # can do this for me but I don't know how. This code works whether fromJSON
     # returned a list (the response to one name) or a data.frame (the response
     # to several).
-    responseDF <- data.frame(name = getListElement(responseDF, "name"),
-                             gender = getListElement(responseDF, "gender"),
-                             country_id = getListElement(responseDF, "country_id"),
-                             language_id = getListElement(responseDF, "language_id"),
-                             probability = getListElement(responseDF, "probability"),
-                             count = getListElement(responseDF, "count"),
+    responseDF <- data.frame(name = getListElement(responseFromJSON, "name"),
+                             gender = getListElement(responseFromJSON, "gender"),
+                             country_id = getListElement(responseFromJSON, "country_id"),
+                             language_id = getListElement(responseFromJSON, "language_id"),
+                             probability = getListElement(responseFromJSON, "probability"),
+                             count = getListElement(responseFromJSON, "count"),
                              stringsAsFactors = FALSE)
 
   } else {
diff --git a/man/checkLanguageCountryCodes.Rd b/man/checkLanguageCountryCodes.Rd
@@ -0,0 +1,13 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/guessGender.R
+\name{checkLanguageCountryCodes}
+\alias{checkLanguageCountryCodes}
+\title{Check country and language code.}
+\usage{
+checkLanguageCountryCodes(countryCode, languageCode)
+}
+\description{
+Makes sure that no more than one of countryCode or languageCode is *not* NA
+ (i.e., they can both be NA, or one can be NA).
+}
+
diff --git a/man/getListElement.Rd b/man/getListElement.Rd
@@ -0,0 +1,14 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/guessGender.R
+\name{getListElement}
+\alias{getListElement}
+\title{Get an element from a list}
+\usage{
+getListElement(listName, elementName)
+}
+\description{
+Helper function that returns NA instead of NULL when a missing list element
+is requested, otherwise returns the element itself.
+}
+\keyword{internal}
+
diff --git a/man/guessGender.Rd b/man/guessGender.Rd
@@ -0,0 +1,26 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/guessGender.R
+\name{guessGender}
+\alias{guessGender}
+\title{Guess names' genders}
+\usage{
+guessGender(nameVector, countryCode = NA, languageCode = NA, apiKey = NA)
+}
+\arguments{
+\item{nameVector}{A vector containing one or more names to look up.}
+
+\item{countryCode}{An optional ISO 3166-1 alpha-2 country code.}
+
+\item{languageCode}{An optional ISO 639-1 language code. Only one of
+countryCode or languageCode can be specified.}
+
+\item{apiKey}{An optional API key for genderize.io.}
+}
+\description{
+This function uses the genderize.io API to supply estimates of the gender one
+or more names.
+}
+\examples{
+guessGender(c("Eamon", "Sean"), countryCode = "US")
+}
+
diff --git a/man/lookupNameVector.Rd b/man/lookupNameVector.Rd
@@ -0,0 +1,25 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/guessGender.R
+\name{lookupNameVector}
+\alias{lookupNameVector}
+\title{Look up a vector of names.}
+\usage{
+lookupNameVector(nameVector, countryCode = NA, languageCode = NA,
+  apiKey = NA)
+}
+\arguments{
+\item{nameVector}{A vector containing one or more names to look up.}
+
+\item{countryCode}{An optional ISO 3166-1 alpha-2 country code.}
+
+\item{languageCode}{An optional ISO 639-1 language code. Only one of
+countryCode or languageCode can be specified.}
+
+\item{apiKey}{An optional API key for genderize.io.}
+}
+\description{
+This function actually implements the genderize.io API. Can only query 10
+names at a time.
+}
+\keyword{internal}
+