## ----options, include=FALSE---------------------------------------------------
library(knitr)
opts_chunk$set(
    echo = TRUE,
    eval = TRUE,
    message = FALSE,
    warning = FALSE,
    collapse = FALSE,
    comment = NA,
    prompt = FALSE,
    tidy = FALSE,
    dev = "png",
    out.width = "100%"
)

## check the output type
out_type <- opts_knit$get("rmarkdown.pandoc.to")
if (is.null(out_type)) {
    out_type <- "html"
}

## add styling
if (out_type == "html") {
    BiocStyle::markdown()
} else if (out_type == "latex") {
    BiocStyle::latex()
}

## ----load-package-------------------------------------------------------------
library(Rega)

## ----add-credential, eval=FALSE-----------------------------------------------
# # You will be prompted for password
# keyring::key_set(
#     service = "REGA_EGA",
#     username = "<your-ega-username>"
# )

## ----generate-secret----------------------------------------------------------
# Run this in your R console to generate a key
httr2::secret_make_key()

## ----parse-metadata-----------------------------------------------------------
metadata_file <- system.file(
    "extdata/submission_example.xlsx",
    package = "Rega"
)

parsed_metadata <- default_parser(metadata_file)
head(parsed_metadata)

## ----validate-metadata--------------------------------------------------------
validation_summary <- default_validator(parsed_metadata)
validation_summary

## ----run-workflow, eval=FALSE-------------------------------------------------
# responses <- new_submission(parsed_metadata, logfile = "log.yaml")

## ----client-with-oauth--------------------------------------------------------
api <- extract_api()
ega <- create_client(api, verbosity = 3)

## ----run-workflow-verbose, eval=FALSE-----------------------------------------
# responses <- new_submission(parsed_metadata, client = ega)

## ----get-entry-by-title, eval=FALSE-------------------------------------------
# # checks all tables
# resp <- get_entry_by_title("RNASeq")
# # checks only samples and studies, logs responses
# resp <- get_entry_by_title(
#     "RNASeq", type = c("samples", "studies"), logfile = "log.yaml"
# )

## ----delete-submission-contents, eval=FALSE-----------------------------------
# resp <- delete_submission_contents(00001, ega)
# resp <- delete_submission(00001, ega)

## ----client-with-token, eval=FALSE--------------------------------------------
# bt <- ega_token()
# ega <- create_client(api, bt$access_token)
# 
# ega$get__enums()

## ----session-info-------------------------------------------------------------
sessionInfo()

