-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from coderaanalytics/frg
Switch from session to token access to backend
- Loading branch information
Showing
16 changed files
with
327 additions
and
454 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
Package: econdatar | ||
Title: Automation of Data Tasks to and from Codera Analytics' Econometric Data Services | ||
Version: 3.0.2 | ||
Version: 3.1.0 | ||
Date: 2024-04-24 | ||
Authors@R: c(person("Byron", "Botha", role = c("aut", "cre"), email = "[email protected]"), | ||
person("Sebastian", "Krantz", role = "ctb")) | ||
Description: Automation of data tasks to and from <https://codera.co.za> econometric data services. Using this package users can download data from <https://www.econdata.co.za> directly into R (in tidy format) after signing up for a free account. <https://www.econdata.co.za> hosts a comprehensive database of South African macroeconomic data. | ||
Depends: R (>= 4.2.0) | ||
Imports: httr, jsonlite, readODS, collapse, data.table | ||
Imports: httr, jose, jsonlite, readODS, collapse, data.table | ||
Suggests: tcltk | ||
URL: https://www.econdata.co.za/ | ||
BugReports: https://github.com/coderaanalytics/econdatar/issues | ||
|
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 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 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 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 |
---|---|---|
@@ -1,27 +1,20 @@ | ||
.pkgenv <- new.env(parent = emptyenv()) | ||
|
||
login_helper <- function(credentials, login_url) { | ||
if (!is.null(credentials)) { | ||
creds <- unlist(strsplit(credentials, ";")) | ||
} else if (Sys.getenv("ECONDATA_CREDENTIALS") != "") { | ||
login_helper <- function(auth) { | ||
if (Sys.getenv("ECONDATA_CREDENTIALS") != "") { | ||
creds <- unlist(strsplit(Sys.getenv("ECONDATA_CREDENTIALS"), ";")) | ||
response <- POST(auth$url, | ||
path = auth$path, | ||
body = list(grant_type = "client_credentials", | ||
client_id = creds[1], | ||
client_secret = creds[2]), | ||
encode = "form", | ||
accept_json()) | ||
if (response$status_code != 200) | ||
stop(content(response)) | ||
token <- content(response)$access_token | ||
} else { | ||
creds <- econdata_credentials() | ||
token <- econdata_credentials() | ||
} | ||
|
||
response <- POST(login_url, | ||
path = "/signin", | ||
body = list(username = creds[1], | ||
password = creds[2]), | ||
encode = "form") | ||
|
||
if (response$status_code != 200) | ||
stop(content(response, encoding = "UTF-8")) | ||
|
||
cookie_jar <- cookies(response) | ||
domain <- substr(login_url, 9, nchar(login_url)) | ||
session <- cookie_jar[which(cookie_jar[, 1] == paste0("#HttpOnly_", domain) & | ||
cookie_jar[, 6] == "ring-session"), ] | ||
assign("econdata_session", as.character(session), envir = .pkgenv) | ||
lockBinding("econdata_session", .pkgenv) | ||
assign("econdata_token", paste("Bearer", token), envir = .pkgenv) | ||
} |
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
Oops, something went wrong.