## ----include=FALSE------------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----eval=FALSE---------------------------------------------------------------
# install.packages("distilleR")

## ----eval=FALSE---------------------------------------------------------------
# # install.packages("devtools")
# devtools::install_github("openefsa/distilleR")

## ----apiKeyExample, eval=FALSE------------------------------------------------
# token <- getAuthenticationToken(distillerKey = "<your_distiller_api_key>")

## ----instanceUrlExample1, eval=FALSE------------------------------------------
# token <- getAuthenticationToken(
#   distillerKey = "<your_distiller_api_key>",
#   distillerInstanceUrl = "<your_distiller_instance_url>"
# )

## ----instanceUrlExample2, eval=FALSE------------------------------------------
# projects <- getProjects(
#   distillerToken = distillerToken,
#   distillerInstanceUrl = "<your_distiller_instance_url>"
# )

## ----loadLibrary, eval=FALSE--------------------------------------------------
# library(distilleR)

## ----eval=FALSE---------------------------------------------------------------
# help("<function_name>")

## ----eval=FALSE---------------------------------------------------------------
# help("getReport")

## ----tokenSetup, eval=FALSE---------------------------------------------------
# token <- getAuthenticationToken()

## ----projectsList, eval=FALSE-------------------------------------------------
# projects <- getProjects(distillerToken = token)
# 
# print(projects)

## ----reportsList, eval=FALSE--------------------------------------------------
# reports <- getReports(projectId = 1234, distillerToken = token)
# 
# print(reports)

## ----getReport, eval=FALSE----------------------------------------------------
# projectId_ <- 1234
# reportId_ <- 567
# 
# report <- getReport(
#   projectId = projectId_,
#   reportId = reportId_,
#   format = "excel",
#   distillerToken = token)
# 
# print(head(report))

## ----getReportAsync, eval=FALSE-----------------------------------------------
# projectId_ <- 1234
# reportId_ <- 567
# 
# job <- getReportAsync(
#   projectId = projectId_,
#   reportId = reportId_,
#   format = "csv",
#   distillerToken = token)
# 
# print(job)

## ----getReportAsyncOutput, eval=FALSE-----------------------------------------
# # A tibble: 1 × 3
#   token                                status  duplicate
#   <chr>                                <chr>   <lgl>
# 1 e515528e-ce65-44a3-88c3-29207a39e732 pending FALSE

## ----getAsyncReportStatus, eval=FALSE-----------------------------------------
# jobToken <- job$token
# 
# jobStatus <- getAsyncReportStatus(jobToken = jobToken)
# 
# print(jobStatus)

## ----getAsyncReportStatusOutput, eval=FALSE-----------------------------------
# # A tibble: 1 × 7
#   token                                status    created_at      finished_at downstream_status error result_url
#   <chr>                                <chr>     <chr>           <chr>                   <int> <chr> <chr>
# 1 e515538e-cc65-44e3-88b3-29207a99e735 succeeded 2026-07-02T14:… 2026-07-02…               200 NA    /jobs/e51…

## ----getAsyncReportResult, eval=FALSE-----------------------------------------
# jobResult <- getAsyncReportResult(jobToken = jobToken, format = "csv")

