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

#' @title Games operations
#' @description swagger.Games
#'
#' @field path Stores url path of the request.
#' @field apiClient Handles the client-server communication.
#' @field userAgent Set the user agent of the request.
#'
#' @importFrom R6 R6Class
#'
#' @section Methods:
#' \describe{
#'
#' get_advanced_box_score Advanced box scores
#'
#'
#' get_calendar Season calendar
#'
#'
#' get_game_media Game media information and schedules
#'
#'
#' get_games Games and results
#'
#'
#' get_player_game_stats Player game stats
#'
#'
#' get_team_game_stats Team game stats
#'
#'
#' get_team_records Team records
#'
#' }
#'
#' @export
GamesApi <- R6::R6Class(
  'GamesApi',
  public = list(
    userAgent = "Swagger-Codegen/1.0.0/r",
    apiClient = NULL,
    initialize = function(apiClient){
      if (!missing(apiClient)) {
        self$apiClient <- apiClient
      }
      else {
        self$apiClient <- ApiClient$new()
      }
    },
    get_advanced_box_score = function(game_id, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- character()

      if (!missing(`game_id`)) {
        queryParams['gameId'] <- game_id
      }

      urlPath <- "/game/box/advanced"
      resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
                                 method = "GET",
                                 queryParams = queryParams,
                                 headerParams = headerParams,
                                 body = body,
                                 ...)
      
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        returnObject <- BoxScore$new()
        result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
        Response$new(returnObject, resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        Response$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        Response$new("API server error", resp)
      }

    },
    get_calendar = function(year, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- character()

      if (!missing(`year`)) {
        queryParams['year'] <- year
      }

      urlPath <- "/calendar"
      resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
                                 method = "GET",
                                 queryParams = queryParams,
                                 headerParams = headerParams,
                                 body = body,
                                 ...)
      
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        returnObject <- Week$new()
        result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
        Response$new(returnObject, resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        Response$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        Response$new("API server error", resp)
      }

    },
    get_game_media = function(year, week, season_type, team, conference, media_type, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- character()

      if (!missing(`year`)) {
        queryParams['year'] <- year
      }

      if (!missing(`week`)) {
        queryParams['week'] <- week
      }

      if (!missing(`season_type`)) {
        queryParams['seasonType'] <- season_type
      }

      if (!missing(`team`)) {
        queryParams['team'] <- team
      }

      if (!missing(`conference`)) {
        queryParams['conference'] <- conference
      }

      if (!missing(`media_type`)) {
        queryParams['mediaType'] <- media_type
      }

      urlPath <- "/games/media"
      resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
                                 method = "GET",
                                 queryParams = queryParams,
                                 headerParams = headerParams,
                                 body = body,
                                 ...)
      
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        returnObject <- GameMedia$new()
        result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
        Response$new(returnObject, resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        Response$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        Response$new("API server error", resp)
      }

    },
    get_games = function(year, week, season_type, team, home, away, conference, id, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- character()

      if (!missing(`year`)) {
        queryParams['year'] <- year
      }

      if (!missing(`week`)) {
        queryParams['week'] <- week
      }

      if (!missing(`season_type`)) {
        queryParams['seasonType'] <- season_type
      }

      if (!missing(`team`)) {
        queryParams['team'] <- team
      }

      if (!missing(`home`)) {
        queryParams['home'] <- home
      }

      if (!missing(`away`)) {
        queryParams['away'] <- away
      }

      if (!missing(`conference`)) {
        queryParams['conference'] <- conference
      }

      if (!missing(`id`)) {
        queryParams['id'] <- id
      }

      urlPath <- "/games"
      resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
                                 method = "GET",
                                 queryParams = queryParams,
                                 headerParams = headerParams,
                                 body = body,
                                 ...)
      
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        returnObject <- Game$new()
        result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
        Response$new(returnObject, resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        Response$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        Response$new("API server error", resp)
      }

    },
    get_player_game_stats = function(year, week, season_type, team, conference, category, game_id, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- character()

      if (!missing(`year`)) {
        queryParams['year'] <- year
      }

      if (!missing(`week`)) {
        queryParams['week'] <- week
      }

      if (!missing(`season_type`)) {
        queryParams['seasonType'] <- season_type
      }

      if (!missing(`team`)) {
        queryParams['team'] <- team
      }

      if (!missing(`conference`)) {
        queryParams['conference'] <- conference
      }

      if (!missing(`category`)) {
        queryParams['category'] <- category
      }

      if (!missing(`game_id`)) {
        queryParams['gameId'] <- game_id
      }

      urlPath <- "/games/players"
      resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
                                 method = "GET",
                                 queryParams = queryParams,
                                 headerParams = headerParams,
                                 body = body,
                                 ...)
      
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        returnObject <- PlayerGame$new()
        result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
        Response$new(returnObject, resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        Response$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        Response$new("API server error", resp)
      }

    },
    get_team_game_stats = function(year, week, season_type, team, conference, game_id, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- character()

      if (!missing(`year`)) {
        queryParams['year'] <- year
      }

      if (!missing(`week`)) {
        queryParams['week'] <- week
      }

      if (!missing(`season_type`)) {
        queryParams['seasonType'] <- season_type
      }

      if (!missing(`team`)) {
        queryParams['team'] <- team
      }

      if (!missing(`conference`)) {
        queryParams['conference'] <- conference
      }

      if (!missing(`game_id`)) {
        queryParams['gameId'] <- game_id
      }

      urlPath <- "/games/teams"
      resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
                                 method = "GET",
                                 queryParams = queryParams,
                                 headerParams = headerParams,
                                 body = body,
                                 ...)
      
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        returnObject <- TeamGame$new()
        result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
        Response$new(returnObject, resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        Response$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        Response$new("API server error", resp)
      }

    },
    get_team_records = function(year, team, conference, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- character()

      if (!missing(`year`)) {
        queryParams['year'] <- year
      }

      if (!missing(`team`)) {
        queryParams['team'] <- team
      }

      if (!missing(`conference`)) {
        queryParams['conference'] <- conference
      }

      urlPath <- "/records"
      resp <- self$apiClient$callApi(url = paste0(self$apiClient$basePath, urlPath),
                                 method = "GET",
                                 queryParams = queryParams,
                                 headerParams = headerParams,
                                 body = body,
                                 ...)
      
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        returnObject <- TeamRecord$new()
        result <- returnObject$fromJSON(httr::content(resp, "text", encoding = "UTF-8"))
        Response$new(returnObject, resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        Response$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        Response$new("API server error", resp)
      }

    }
  )
)
saiemgilani/cfbd-api-R documentation built on Feb. 16, 2021, 12:07 a.m.