Skip to content

Commit

Permalink
Merge pull request #91 from data-mermaid/me-endpoint
Browse files Browse the repository at this point in the history
Add mermaid_get_me() function
  • Loading branch information
sharlagelfand authored Jul 3, 2024
2 parents 6c1ecec + 27a5e90 commit 9950217
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: mermaidr
Title: Interface to the 'MERMAID' API
Version: 1.0.0
Version: 1.0.1
Authors@R:
c(person(given = "Sharla",
family = "Gelfand",
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export(mermaid_countries)
export(mermaid_get_default_project)
export(mermaid_get_endpoint)
export(mermaid_get_managements)
export(mermaid_get_me)
export(mermaid_get_my_projects)
export(mermaid_get_project_data)
export(mermaid_get_project_endpoint)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# mermaidr 1.0.1

* Added `mermaid_get_me()` endpoint to get profile information for the user.

# mermaidr 1.0.0

* `mermaid_get_project_data()` now uses CSV endpoints, which significantly speeds up getting data from projects with a large number of observations
Expand Down
9 changes: 9 additions & 0 deletions R/mermaid_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ get_response <- function(path, endpoint, ua, token, limit) {
get_csv_response(path, ua, limit, token)
} else if (stringr::str_detect(path, "ingest_schema")) {
get_ingest_schema_response(path, ua, token)
} else if (stringr::str_detect(path, "/me/")) {
get_me_response(path, ua, limit, token)
} else {
get_paginated_response(path, ua, token, limit)
}
Expand All @@ -83,6 +85,13 @@ get_csv_response <- function(path, ua, limit, token) {
get_and_parse(path, ua, limit, token)
}

get_me_response <- function(path, ua, limit, token) {
res <- get_and_parse(path, ua, limit, token)

res[c("id", "first_name", "last_name", "email")] %>%
dplyr::as_tibble()
}

get_paginated_response <- function(path, ua, token, limit) {
all_res <- list()
i <- 1
Expand Down
18 changes: 18 additions & 0 deletions R/mermaid_get_me.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#' Get your MERMAID Profile
#'
#' Get your MERMAID profile. Returns ID, first/last name, and email address. Requires authorization.
#'
#' @inheritParams mermaid_GET
#'
#' @return A tibble of MERMAID profile information, including first and last name, full name, and email address.
#' @export
#'
#' @examples
#' \dontrun{
#' mermaid_get_me()
#' }
mermaid_get_me <- function(token = mermaid_token()) {
res <- mermaid_GET("me", token = token)

res[["me"]]
}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ reference:
- mermaid_get_endpoint
- mermaid_get_summary_sampleevents
- mermaid_countries
- mermaid_get_me

- title: Accessing Project-Specific Data
contents:
Expand Down
22 changes: 22 additions & 0 deletions man/mermaid_get_me.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9950217

Please sign in to comment.