Skip to content

Instantly share code, notes, and snippets.

@marwahaha
Last active February 10, 2022 21:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marwahaha/fc07228f6e6f52572397edd9b0f17bd8 to your computer and use it in GitHub Desktop.
Save marwahaha/fc07228f6e6f52572397edd9b0f17bd8 to your computer and use it in GitHub Desktop.
library(digest)
library(httr)
library(jsonlite)
encryptionKey <- "test"
userLoginName <- "test"
uri <- "https://awqms.goldsystems.com/api/ContinuousResultsVer1?OrganizationIdentifiersCsv=BISHOP_PAIUTE_TRIBE_WQX&MonitoringLocationIdentifiersCsv=SW-1&MinDate=02-01-2021&MaxDate=02-02-2021"
getUTCTime <- function() {
time <- Sys.time()
as.numeric(time)
attr(time, "tzone") <- "UTC"
format(time, "%m/%d/%Y %I:%M:%S %p")
}
getSignature <- function(a, b, c, d, encryptionKey) {
str <- paste(a, b, c, d, sep="")
print(str)
base64_enc(hmac(base64_dec(encryptionKey), str, "sha256", raw=TRUE))
}
makeRequest <- function(userLoginName, uri, encryptionKey) {
time <- getUTCTime()
signature <- getSignature(userLoginName, time, uri, "GET", encryptionKey)
print(signature)
GET(uri,
add_headers(
"Content-Type"="application/json",
"X-UserID"=userLoginName,
"X-Stamp"=time,
"X-Signature"=signature
))
}
request <- makeRequest(userLoginName, uri, encryptionKey)
request$status_code
output <- content(request, "text", encoding = "UTF-8")
data <- fromJSON(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment