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


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

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