R/PlayerGameTypes.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


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

      PlayerGameTypesObject
    },
    fromJSON = function(PlayerGameTypesJson) {
      PlayerGameTypesObject <- jsonlite::fromJSON(PlayerGameTypesJson)
      if (!is.null(PlayerGameTypesObject$`name`)) {
        self$`name` <- PlayerGameTypesObject$`name`
      }
      if (!is.null(PlayerGameTypesObject$`athletes`)) {
        self$`athletes` <- lapply(PlayerGameTypesObject$`athletes`, function(x) {
          athletesObject <- PlayerGameAthletes$new()
          athletesObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))
          athletesObject
        })
      }
    },
    toJSONString = function() {
       sprintf(
        '{
           "name": %s,
           "athletes": [%s]
        }',
        self$`name`,
        lapply(self$`athletes`, function(x) paste(x$toJSON(), sep=","))
      )
    },
    fromJSONString = function(PlayerGameTypesJson) {
      PlayerGameTypesObject <- jsonlite::fromJSON(PlayerGameTypesJson)
      self$`name` <- PlayerGameTypesObject$`name`
      self$`athletes` <- lapply(PlayerGameTypesObject$`athletes`, function(x) PlayerGameAthletes$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
    }
  )
)
saiemgilani/cfbd-api-R documentation built on Feb. 16, 2021, 12:07 a.m.