## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")

## -----------------------------------------------------------------------------
library(data.table)
library(zot)

Config <- zotConfig(userID = "42", key = "example-key")
Config

## -----------------------------------------------------------------------------
zotLibraryPath(Config, library = "user")
zotLibraryPath(Config, library = "5107760")

## -----------------------------------------------------------------------------
Performer <- function(config, method, path, query, body, version) {
  Page <- if (query$start == 0L) {
    list(list(key = "A", title = "One"), list(key = "B", title = "Two"))
  } else {
    list(list(key = "C", title = "Three"))
  }
  list(status = 200L, headers = list(`total-results` = "3"), body = Page)
}

Config$performer <- Performer
Items <- zotGetAll(
  Config,
  path = paste0(zotLibraryPath(Config), "/items/top"),
  limit = 2L
)
vapply(Items, function(Item) Item$key, character(1L))

## -----------------------------------------------------------------------------
Candidates <- data.table(
  itemKey = c("A", "B"),
  library = "user",
  title = c("Reviewed book (1).pdf", "Existing title")
)

Plan <- ztRetitle(Candidates, transform = ztCleanTitle)
Plan

## -----------------------------------------------------------------------------
Preview <- zotPreview(Plan, describe = "Normalize one reviewed title")
Preview

