-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev' into dev
Conflicts: DESCRIPTION
- Loading branch information
Showing
19 changed files
with
574 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |
Oops, something went wrong.