Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
Conflicts:
	DESCRIPTION
  • Loading branch information
dmpe committed Jul 23, 2015
2 parents 34b6a64 + c8d7ac0 commit 9e4363a
Show file tree
Hide file tree
Showing 19 changed files with 574 additions and 396 deletions.
9 changes: 4 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ Description: Provides easier interaction with
or a 'Socrata' "human-friendly" URL,
returns an R data frame.
Converts dates to 'POSIX' format.
Manages throttling by 'Socrata'. Supports geojson format
Version: 1.7.0
Date: 2015-8-31
Manages throttling by 'Socrata'.
Version: 1.6.3
Date: 2015-07-23
Author: Hugh Devlin, Ph. D., Tom Schenk, Jr., and John Malc
Maintainer: "Tom Schenk Jr." <developers@cityofchicago.org>
Depends:
R (>= 3.0.0)
Imports:
httr (>= 1.0.0),
jsonlite (>= 0.9.16),
mime (>= 0.3),
geojsonio (>= 0.1.0)
mime (>= 0.3)
Suggests:
testthat (>= 0.10.0),
roxygen2 (>= 4.1.0)
Expand Down
269 changes: 0 additions & 269 deletions R/RSocrata.R

This file was deleted.

44 changes: 44 additions & 0 deletions R/errorHandling.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#' Provides error handling functionality
#'
#' @description Based on \url{http://dev.socrata.com/docs/response-codes.html}
#'
#' @section TODO: Add messages that alert the user on the URL being valid,
#' but one that is not compatible with RSocrata.
#' See \url{https://github.com/Chicago/RSocrata/issues/16}
#'
#' @param rsp - \code{\link{httr::response}} response
#' @importFrom httr stop_for_status
#'
#' @noRd
errorHandling <- function(rsp = NULL) {

if (rsp$status_code == 200) {
invisible("OK. Your request was successful.")

} else if(rsp$status_code == 202) {
warning("202 Request processing. You can retry your request, and when it's complete, you'll get a 200 instead.")

} else if(rsp$status_code == 400) {
stop("400 Bad request. Most probably was your request malformed.")

} else if(rsp$status_code == 401) {
# only necessary when accessing datasets that have been marked as private or when making write requests (PUT, POST, and DELETE)
stop("Unauthorized. You attempted to authenticate but something went wrong.")

} else if(rsp$status_code == 403) {
stop("Forbidden. You're not authorized to access this resource. Make sure you authenticate to access private datasets.")

} else if(rsp$status_code == 404) {
stop("Not found. The resource requested doesn't exist.")

} else if(rsp$status_code == 429) {
stop("Too Many Requests. Your client is currently being rate limited. Make sure you're using an app token.")

} else if(rsp$status_code == 500) {
stop("Server error.")

} else {
httr::stop_for_status(rsp)
}

}
29 changes: 29 additions & 0 deletions R/fourByFour.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#' Checks the validity of the syntax for a potential Socrata dataset Unique Identifier, also known as a 4x4.
#'
#' @description Will check the validity of a potential dataset unique identifier
#' supported by Socrata. It will provide an exception if the syntax
#' does not align to Socrata unique identifiers. It only checks for
#' the validity of the syntax, but does not check if it actually exists.
#'
#' @param fourByFour - a string; character vector of length one
#' @return TRUE if is valid Socrata unique identifier, FALSE otherwise
#' @author Tom Schenk Jr \email{tom.schenk@@cityofchicago.org}
#' @examples
#' isFourByFour(fourByFour = "4334-bgaj")
#' isFourByFour("433-bgaj")
#' isFourByFour(fourByFour = "4334-!gaj")
#'
#' @export
isFourByFour <- function(fourByFour = "") {

if (nchar(fourByFour) == 9) {
if(identical(grepl("[[:alnum:]]{4}-[[:alnum:]]{4}", fourByFour), TRUE)) {
return(TRUE)
} else {
return(FALSE)
}
} else {
return(FALSE)
}

}
Loading

0 comments on commit 9e4363a

Please sign in to comment.