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


#' TeamGameTeams Class
#'
#' @field school 
#' @field conference 
#' @field homeAway 
#' @field points 
#' @field stats 
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
TeamGameTeams <- R6::R6Class(
  'TeamGameTeams',
  public = list(
    `school` = NULL,
    `conference` = NULL,
    `homeAway` = NULL,
    `points` = NULL,
    `stats` = NULL,
    initialize = function(`school`, `conference`, `homeAway`, `points`, `stats`){
      if (!missing(`school`)) {
        stopifnot(is.character(`school`), length(`school`) == 1)
        self$`school` <- `school`
      }
      if (!missing(`conference`)) {
        stopifnot(is.character(`conference`), length(`conference`) == 1)
        self$`conference` <- `conference`
      }
      if (!missing(`homeAway`)) {
        self$`homeAway` <- `homeAway`
      }
      if (!missing(`points`)) {
        stopifnot(is.numeric(`points`), length(`points`) == 1)
        self$`points` <- `points`
      }
      if (!missing(`stats`)) {
        stopifnot(is.list(`stats`), length(`stats`) != 0)
        lapply(`stats`, function(x) stopifnot(R6::is.R6(x)))
        self$`stats` <- `stats`
      }
    },
    toJSON = function() {
      TeamGameTeamsObject <- list()
      if (!is.null(self$`school`)) {
        TeamGameTeamsObject[['school']] <- self$`school`
      }
      if (!is.null(self$`conference`)) {
        TeamGameTeamsObject[['conference']] <- self$`conference`
      }
      if (!is.null(self$`homeAway`)) {
        TeamGameTeamsObject[['homeAway']] <- self$`homeAway`
      }
      if (!is.null(self$`points`)) {
        TeamGameTeamsObject[['points']] <- self$`points`
      }
      if (!is.null(self$`stats`)) {
        TeamGameTeamsObject[['stats']] <- lapply(self$`stats`, function(x) x$toJSON())
      }

      TeamGameTeamsObject
    },
    fromJSON = function(TeamGameTeamsJson) {
      TeamGameTeamsObject <- jsonlite::fromJSON(TeamGameTeamsJson)
      if (!is.null(TeamGameTeamsObject$`school`)) {
        self$`school` <- TeamGameTeamsObject$`school`
      }
      if (!is.null(TeamGameTeamsObject$`conference`)) {
        self$`conference` <- TeamGameTeamsObject$`conference`
      }
      if (!is.null(TeamGameTeamsObject$`homeAway`)) {
        self$`homeAway` <- TeamGameTeamsObject$`homeAway`
      }
      if (!is.null(TeamGameTeamsObject$`points`)) {
        self$`points` <- TeamGameTeamsObject$`points`
      }
      if (!is.null(TeamGameTeamsObject$`stats`)) {
        self$`stats` <- lapply(TeamGameTeamsObject$`stats`, function(x) {
          statsObject <- TeamGameStats$new()
          statsObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))
          statsObject
        })
      }
    },
    toJSONString = function() {
       sprintf(
        '{
           "school": %s,
           "conference": %s,
           "homeAway": %s,
           "points": %d,
           "stats": [%s]
        }',
        self$`school`,
        self$`conference`,
        self$`homeAway`,
        self$`points`,
        lapply(self$`stats`, function(x) paste(x$toJSON(), sep=","))
      )
    },
    fromJSONString = function(TeamGameTeamsJson) {
      TeamGameTeamsObject <- jsonlite::fromJSON(TeamGameTeamsJson)
      self$`school` <- TeamGameTeamsObject$`school`
      self$`conference` <- TeamGameTeamsObject$`conference`
      self$`homeAway` <- TeamGameTeamsObject$`homeAway`
      self$`points` <- TeamGameTeamsObject$`points`
      self$`stats` <- lapply(TeamGameTeamsObject$`stats`, function(x) TeamGameStats$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
    }
  )
)
saiemgilani/cfbd-api-R documentation built on Feb. 16, 2021, 12:07 a.m.