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


#' PlayerGame Class
#'
#' @field id 
#' @field teams 
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
PlayerGame <- R6::R6Class(
  'PlayerGame',
  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() {
      PlayerGameObject <- list()
      if (!is.null(self$`id`)) {
        PlayerGameObject[['id']] <- self$`id`
      }
      if (!is.null(self$`teams`)) {
        PlayerGameObject[['teams']] <- lapply(self$`teams`, function(x) x$toJSON())
      }

      PlayerGameObject
    },
    fromJSON = function(PlayerGameJson) {
      PlayerGameObject <- jsonlite::fromJSON(PlayerGameJson)
      if (!is.null(PlayerGameObject$`id`)) {
        self$`id` <- PlayerGameObject$`id`
      }
      if (!is.null(PlayerGameObject$`teams`)) {
        self$`teams` <- lapply(PlayerGameObject$`teams`, function(x) {
          teamsObject <- PlayerGameTeams$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(PlayerGameJson) {
      PlayerGameObject <- jsonlite::fromJSON(PlayerGameJson)
      self$`id` <- PlayerGameObject$`id`
      self$`teams` <- lapply(PlayerGameObject$`teams`, function(x) PlayerGameTeams$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
    }
  )
)
saiemgilani/cfbd-api-R documentation built on Feb. 16, 2021, 12:07 a.m.