R/api_usage_aggregated_out.R

# NamSor API v2
#
# NamSor API v2 : enpoints to process personal names (gender, cultural origin or ethnicity) in all alphabets or languages. Use GET methods for small tests, but prefer POST methods for higher throughput (batch processing of up to 1000 names at a time). Need something you can't find here? We have many more features coming soon. Let us know, we'll do our best to add it! 
#
# OpenAPI spec version: 2.0.2-beta
# Contact: contact@namsor.com
# Generated by: https://openapi-generator.tech


#' APIUsageAggregatedOut Class
#'
#' @field timeUnit 
#' @field periodStart 
#' @field periodEnd 
#' @field totalUsage 
#' @field historyTruncated 
#' @field data 
#' @field colHeaders 
#' @field rowHeaders 
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
APIUsageAggregatedOut <- R6::R6Class(
  'APIUsageAggregatedOut',
  public = list(
    `timeUnit` = NULL,
    `periodStart` = NULL,
    `periodEnd` = NULL,
    `totalUsage` = NULL,
    `historyTruncated` = NULL,
    `data` = NULL,
    `colHeaders` = NULL,
    `rowHeaders` = NULL,
    initialize = function(`timeUnit`, `periodStart`, `periodEnd`, `totalUsage`, `historyTruncated`, `data`, `colHeaders`, `rowHeaders`){
      if (!missing(`timeUnit`)) {
        stopifnot(is.character(`timeUnit`), length(`timeUnit`) == 1)
        self$`timeUnit` <- `timeUnit`
      }
      if (!missing(`periodStart`)) {
        stopifnot(is.numeric(`periodStart`), length(`periodStart`) == 1)
        self$`periodStart` <- `periodStart`
      }
      if (!missing(`periodEnd`)) {
        stopifnot(is.numeric(`periodEnd`), length(`periodEnd`) == 1)
        self$`periodEnd` <- `periodEnd`
      }
      if (!missing(`totalUsage`)) {
        stopifnot(is.numeric(`totalUsage`), length(`totalUsage`) == 1)
        self$`totalUsage` <- `totalUsage`
      }
      if (!missing(`historyTruncated`)) {
        self$`historyTruncated` <- `historyTruncated`
      }
      if (!missing(`data`)) {
        stopifnot(is.vector(`data`), length(`data`) != 0)
        sapply(`data`, function(x) stopifnot(R6::is.R6(x)))
        self$`data` <- `data`
      }
      if (!missing(`colHeaders`)) {
        stopifnot(is.vector(`colHeaders`), length(`colHeaders`) != 0)
        sapply(`colHeaders`, function(x) stopifnot(is.character(x)))
        self$`colHeaders` <- `colHeaders`
      }
      if (!missing(`rowHeaders`)) {
        stopifnot(is.vector(`rowHeaders`), length(`rowHeaders`) != 0)
        sapply(`rowHeaders`, function(x) stopifnot(is.character(x)))
        self$`rowHeaders` <- `rowHeaders`
      }
    },
    toJSON = function() {
      APIUsageAggregatedOutObject <- list()
      if (!is.null(self$`timeUnit`)) {
        APIUsageAggregatedOutObject[['timeUnit']] <-
          self$`timeUnit`
      }
      if (!is.null(self$`periodStart`)) {
        APIUsageAggregatedOutObject[['periodStart']] <-
          self$`periodStart`
      }
      if (!is.null(self$`periodEnd`)) {
        APIUsageAggregatedOutObject[['periodEnd']] <-
          self$`periodEnd`
      }
      if (!is.null(self$`totalUsage`)) {
        APIUsageAggregatedOutObject[['totalUsage']] <-
          self$`totalUsage`
      }
      if (!is.null(self$`historyTruncated`)) {
        APIUsageAggregatedOutObject[['historyTruncated']] <-
          self$`historyTruncated`
      }
      if (!is.null(self$`data`)) {
        APIUsageAggregatedOutObject[['data']] <-
          sapply(self$`data`, function(x) x$toJSON())
      }
      if (!is.null(self$`colHeaders`)) {
        APIUsageAggregatedOutObject[['colHeaders']] <-
          self$`colHeaders`
      }
      if (!is.null(self$`rowHeaders`)) {
        APIUsageAggregatedOutObject[['rowHeaders']] <-
          self$`rowHeaders`
      }

      APIUsageAggregatedOutObject
    },
    fromJSON = function(APIUsageAggregatedOutJson) {
      APIUsageAggregatedOutObject <- jsonlite::fromJSON(APIUsageAggregatedOutJson)
      if (!is.null(APIUsageAggregatedOutObject$`timeUnit`)) {
        self$`timeUnit` <- APIUsageAggregatedOutObject$`timeUnit`
      }
      if (!is.null(APIUsageAggregatedOutObject$`periodStart`)) {
        self$`periodStart` <- APIUsageAggregatedOutObject$`periodStart`
      }
      if (!is.null(APIUsageAggregatedOutObject$`periodEnd`)) {
        self$`periodEnd` <- APIUsageAggregatedOutObject$`periodEnd`
      }
      if (!is.null(APIUsageAggregatedOutObject$`totalUsage`)) {
        self$`totalUsage` <- APIUsageAggregatedOutObject$`totalUsage`
      }
      if (!is.null(APIUsageAggregatedOutObject$`historyTruncated`)) {
        self$`historyTruncated` <- APIUsageAggregatedOutObject$`historyTruncated`
      }
      if (!is.null(APIUsageAggregatedOutObject$`data`)) {
        self$`data` <- sapply(APIUsageAggregatedOutObject$`data`, function(x) {
          dataObject <- integer$new()
          dataObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))
          dataObject
        })
      }
      if (!is.null(APIUsageAggregatedOutObject$`colHeaders`)) {
        self$`colHeaders` <- APIUsageAggregatedOutObject$`colHeaders`
      }
      if (!is.null(APIUsageAggregatedOutObject$`rowHeaders`)) {
        self$`rowHeaders` <- APIUsageAggregatedOutObject$`rowHeaders`
      }
    },
    toJSONString = function() {
      sprintf(
        '{
           "timeUnit":
             "%s",
           "periodStart":
             %d,
           "periodEnd":
             %d,
           "totalUsage":
             %d,
           "historyTruncated":
             "%s",
           "data":
             [%s],
           "colHeaders":
             [%s],
           "rowHeaders":
             [%s]
        }',
        self$`timeUnit`,
        self$`periodStart`,
        self$`periodEnd`,
        self$`totalUsage`,
        self$`historyTruncated`,
        paste(unlist(lapply(self$`data`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox=TRUE))), collapse=","),
        paste(unlist(lapply(self$`colHeaders`, function(x) paste0('"', x, '"'))), collapse=","),
        paste(unlist(lapply(self$`rowHeaders`, function(x) paste0('"', x, '"'))), collapse=",")
      )
    },
    fromJSONString = function(APIUsageAggregatedOutJson) {
      APIUsageAggregatedOutObject <- jsonlite::fromJSON(APIUsageAggregatedOutJson)
      self$`timeUnit` <- APIUsageAggregatedOutObject$`timeUnit`
      self$`periodStart` <- APIUsageAggregatedOutObject$`periodStart`
      self$`periodEnd` <- APIUsageAggregatedOutObject$`periodEnd`
      self$`totalUsage` <- APIUsageAggregatedOutObject$`totalUsage`
      self$`historyTruncated` <- APIUsageAggregatedOutObject$`historyTruncated`
      data.frame <- APIUsageAggregatedOutObject$`data`
      self$`data` <- vector("list", length = nrow(data.frame))
      for (row in 1:nrow(data.frame)) {
          data.node <- integer$new()
          data.node$fromJSON(jsonlite::toJSON(data.frame[row,,drop = TRUE], auto_unbox = TRUE))
          self$`data`[[row]] <- data.node
      }
      self$`colHeaders` <- lapply(APIUsageAggregatedOutObject$`colHeaders`, function (x) x)
      self$`rowHeaders` <- lapply(APIUsageAggregatedOutObject$`rowHeaders`, function (x) x)
      self
    }
  )
)
wing328/namsor-r-client documentation built on May 26, 2019, 7:01 p.m.