-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.qmd
More file actions
92 lines (67 loc) · 1.78 KB
/
Copy pathadmin.qmd
File metadata and controls
92 lines (67 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
title: "admin"
format: html
params:
pull_databraryr: false
verbose_login: true
switch_account: false
---
## About
This page tests administrative functions using an account on the staging server.
It makes use of credentials specific to that account.
The credentials are stored in `~/.Renviron`.
## Setup
```{r}
#| label: pull-new-databraryr
if (params$pull_databraryr) {
message("Pulling latest version of `databraryr` from GitHub.")
remotes::install_github(repo = "NYU-Databrary/databraryr", ref = "development")
} else {
message("Using installed version of `databraryr`.")
}
```
To switch between accounts, open '~/.Renviron`, uncomment the relevant environment variables
```{r}
#| label: "edit-renviron"
#| eval: false
if (params$switch_account) {
source("R/restart_r.R")
usethis::edit_r_environ(scope = "user")
}
```
Then restart R.
Now, we can confirm that the correct API endpoint and user account are selected.
```{r}
library(databraryr)
databraryr:::DATABRARY_BASE_URL
Sys.getenv("DATABRARY_LOGIN")
```
## Login
```{r}
#| label: "login to Databrary (staging)"
login_db(email = Sys.getenv("DATABRARY_LOGIN"),
password = Sys.getenv("DATABRARY_PASSWORD"),
client_id = Sys.getenv("DATABRARY_CLIENT_ID"),
client_secret = Sys.getenv("DATABRARY_CLIENT_SECRET"),
store = FALSE,
overwrite = FALSE)
```
### Check `whoami()`
```{r}
who <- whoami()
message(who$message, "\nGreat news, user: ", who$user)
```
## Test `get_*` functions
These functions retrieve usage statistics.
### Check `get_institution_statistics()`
```{r}
databraryr::get_institution_statistics(institution_id = 8) # NYU
```
### Check `get_user_statistics()`
```{r}
databraryr::get_user_statistics(user_id = 5) # Karen Adolph
```
## Clean-up
```{r}
logout_db()
```