#' Assign an Activity to Device Side
#'
#' With this endpoint you can assign an Activity to any Side of your active Device.
#'
#' @param activityId ID of an Activity, eg. 123.
#' @param deviceSide Side of an active Device.
#' @param token Token obtained with \code{\link{signIn}}.
#' @param as_df If TRUE a data frame is returned, if FALSE a list is returned.
#'
#' @return A data frame or list with id, name, color, integration and deviceSide.
#' @export
#'
#' @examples token <- "123456789"
#' assignActivity(activityId = "57302", deviceSide = 8, token, as_df = TRUE)
assignActivity <- function(activityId = NULL, deviceSide = NULL, token, as_df = TRUE) {
if (is.null(activityId)) stop("You haven't provided an activityId")
if (is.null(deviceSide)) stop("You haven't provided a deviceSide")
# Base url and bearer token
base_url <- "https://api.timeular.com/api/v1/"
bearer_token <- paste("Bearer", token)
# Request
resp <- httr::POST(
url = paste0(base_url, "activities/", activityId, "/device-side/", deviceSide),
encode = "json",
httr::add_headers(Authorization = bearer_token)
)
# Status and stop execution if status different from 200
status <- httr::status_code(resp)
if (status != 200) stop("Something went wrong! Error code ", status)
# Parse response
parsed <- httr::content(resp, type = "application/json")
# If as_df is TRUE
if (as_df) {
parsed <- data.frame(
id = ifelse(is.null(parsed$id), NA, parsed$id),
name = ifelse(is.null(parsed$name), NA, parsed$name),
color = ifelse(is.null(parsed$color), NA, parsed$color),
integration = ifelse(is.null(parsed$integration), NA, parsed$integration),
deviceSide = ifelse(is.null(parsed$deviceSide), NA, parsed$deviceSide),
stringsAsFactors = FALSE
)
}
return(parsed)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.