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


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

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