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

library(tRakt)
library(kableExtra)
library(purrr)
library(dplyr)
library(stringr)
api <- system.file("api-methods.yml", package = "tRakt") %>%
  yaml::read_yaml() 

api <- api %>%
  map_dfr(~ {
    map_dfr(.x, as_tibble, .id = "Method")
  }, .id = "Section")

pkg_funs <- getNamespaceExports("tRakt") %>%
  str_subset("%>%|trakt_get|build_trakt_url|trakt_credentials", negate = TRUE)

unmentioned <- pkg_funs[!(pkg_funs %in% str_remove_all(api$implementation, pattern = "\\(\\)"))]

format_api_table <- function(xdf) {
  xdf %>%
    mutate(
      endpoint = cell_spec(endpoint, link = url),
      # Section = stringr::str_to_title(Section),
      # Section = cell_spec(Section, bold = TRUE),
      Method = str_to_title(Method),
      Method = str_replace_all(Method, "^Id\\s", "ID "),
      #implementation = if_else(is.na(implementation), "N/A", implementation),
      implementation = if_else(
        implementation == "none",
        "",
        paste0("<code>", implementation, "</code>")
      ),
      authentication = if_else(
        !is.na(authentication),
        cell_spec("Required", bold = TRUE, color = "white", background = "red"),
        cell_spec("Optional", bold = FALSE, color = "white", background = "green")
      ),
    ) %>%
    select(
      -url,
      Endpoint = endpoint,
      Auth = authentication,
      Implementation = implementation
    )
}

print_api_table <- function(xdf) {
  xdf %>%
    kable(escape = FALSE) %>%
    kable_styling(
      position = "center",
      bootstrap_options = c("striped", "hover"),
      full_width = TRUE
    )
}

This is a reference list of API methods available, their endpoint URLs (with user-specified parameters indiciated by a : prefix) and a link to their respective implementation in this package, if applicable.
Authenticated methods (there's only a few) are indicated as such.

Note that not all available methods are listed here, especially those geared towards interactive apps – I highly doubt that people will want to post (or update) comments through this package.

Search

api %>%
  filter(Section == "search") %>%
  select(-Section) %>%
  format_api_table() %>%
  print_api_table()

Movies

api %>%
  filter(Section == "movies") %>%
  select(-Section) %>%
  format_api_table() %>%
  print_api_table()

Shows

api %>%
  filter(Section == "shows") %>%
  select(-Section) %>%
  format_api_table() %>%
  print_api_table()

Seasons

api %>%
  filter(Section == "seasons") %>%
  select(-Section) %>%
  format_api_table() %>%
  print_api_table()

Episodes

api %>%
  filter(Section == "episodes") %>%
  select(-Section) %>%
  format_api_table() %>%
  print_api_table()

People

api %>%
  filter(Section == "people") %>%
  select(-Section) %>%
  format_api_table() %>%
  print_api_table()

Users

api %>%
  filter(Section == "users") %>%
  select(-Section) %>%
  format_api_table() %>%
  print_api_table()

Comments

api %>%
  filter(Section == "comments") %>%
  select(-Section) %>%
  format_api_table() %>%
  print_api_table()

Lists

api %>%
  filter(Section == "lists") %>%
  select(-Section) %>%
  format_api_table() %>%
  print_api_table()

Misc

These endpoints are used to check filter arguments. The output is cached in tidied up format as package datasets.

api %>%
  filter(Section %in% c(
    "certifications", "countries",
    "genres", "languages", "networks"
  )) %>%
  format_api_table() %>%
  select(-Auth) %>%
  print_api_table()


jemus42/tRakt documentation built on May 4, 2024, 9:21 a.m.