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


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

      RankingWeekObject
    },
    fromJSON = function(RankingWeekJson) {
      RankingWeekObject <- jsonlite::fromJSON(RankingWeekJson)
      if (!is.null(RankingWeekObject$`season`)) {
        self$`season` <- RankingWeekObject$`season`
      }
      if (!is.null(RankingWeekObject$`seasonType`)) {
        self$`seasonType` <- RankingWeekObject$`seasonType`
      }
      if (!is.null(RankingWeekObject$`week`)) {
        self$`week` <- RankingWeekObject$`week`
      }
      if (!is.null(RankingWeekObject$`polls`)) {
        self$`polls` <- lapply(RankingWeekObject$`polls`, function(x) {
          pollsObject <- RankingWeekPolls$new()
          pollsObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))
          pollsObject
        })
      }
    },
    toJSONString = function() {
       sprintf(
        '{
           "season": %d,
           "seasonType": %s,
           "week": %d,
           "polls": [%s]
        }',
        self$`season`,
        self$`seasonType`,
        self$`week`,
        lapply(self$`polls`, function(x) paste(x$toJSON(), sep=","))
      )
    },
    fromJSONString = function(RankingWeekJson) {
      RankingWeekObject <- jsonlite::fromJSON(RankingWeekJson)
      self$`season` <- RankingWeekObject$`season`
      self$`seasonType` <- RankingWeekObject$`seasonType`
      self$`week` <- RankingWeekObject$`week`
      self$`polls` <- lapply(RankingWeekObject$`polls`, function(x) RankingWeekPolls$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
    }
  )
)
saiemgilani/cfbd-api-R documentation built on Feb. 16, 2021, 12:07 a.m.