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


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

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