R/BoxScorePlayers.r

# College Football Data API
#
# This is an API for accessing all sorts of college football data.  It currently has a wide array of data ranging from play by play to player statistics to game scores and more.
#
# OpenAPI spec version: 2.3.5
# Contact: admin@collegefootballdata.com
# Generated by: https://github.com/swagger-api/swagger-codegen.git


#' BoxScorePlayers Class
#'
#' @field usage 
#' @field ppa 
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
BoxScorePlayers <- R6::R6Class(
  'BoxScorePlayers',
  public = list(
    `usage` = NULL,
    `ppa` = NULL,
    initialize = function(`usage`, `ppa`){
      if (!missing(`usage`)) {
        stopifnot(is.list(`usage`), length(`usage`) != 0)
        lapply(`usage`, function(x) stopifnot(R6::is.R6(x)))
        self$`usage` <- `usage`
      }
      if (!missing(`ppa`)) {
        stopifnot(is.list(`ppa`), length(`ppa`) != 0)
        lapply(`ppa`, function(x) stopifnot(R6::is.R6(x)))
        self$`ppa` <- `ppa`
      }
    },
    toJSON = function() {
      BoxScorePlayersObject <- list()
      if (!is.null(self$`usage`)) {
        BoxScorePlayersObject[['usage']] <- lapply(self$`usage`, function(x) x$toJSON())
      }
      if (!is.null(self$`ppa`)) {
        BoxScorePlayersObject[['ppa']] <- lapply(self$`ppa`, function(x) x$toJSON())
      }

      BoxScorePlayersObject
    },
    fromJSON = function(BoxScorePlayersJson) {
      BoxScorePlayersObject <- jsonlite::fromJSON(BoxScorePlayersJson)
      if (!is.null(BoxScorePlayersObject$`usage`)) {
        self$`usage` <- lapply(BoxScorePlayersObject$`usage`, function(x) {
          usageObject <- BoxScorePlayersUsage$new()
          usageObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))
          usageObject
        })
      }
      if (!is.null(BoxScorePlayersObject$`ppa`)) {
        self$`ppa` <- lapply(BoxScorePlayersObject$`ppa`, function(x) {
          ppaObject <- BoxScorePlayersPpa$new()
          ppaObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))
          ppaObject
        })
      }
    },
    toJSONString = function() {
       sprintf(
        '{
           "usage": [%s],
           "ppa": [%s]
        }',
        lapply(self$`usage`, function(x) paste(x$toJSON(), sep=",")),
        lapply(self$`ppa`, function(x) paste(x$toJSON(), sep=","))
      )
    },
    fromJSONString = function(BoxScorePlayersJson) {
      BoxScorePlayersObject <- jsonlite::fromJSON(BoxScorePlayersJson)
      self$`usage` <- lapply(BoxScorePlayersObject$`usage`, function(x) BoxScorePlayersUsage$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
      self$`ppa` <- lapply(BoxScorePlayersObject$`ppa`, function(x) BoxScorePlayersPpa$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
    }
  )
)
saiemgilani/cfbd-api-R documentation built on Feb. 16, 2021, 12:07 a.m.