R/entity.R

# FireCloud
#
# FireCloud API 
#
# The version of the OpenAPI document: 0.1
# 
# Generated by: https://openapi-generator.tech

#' @docType class
#' @title Entity
#'
#' @description Entity Class
#'
#' @format An \code{R6Class} generator object
#'
#' @field name  character 
#'
#' @field entityType  character 
#'
#' @field attributes  named list( object ) 
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
Entity <- R6::R6Class(
  'Entity',
  public = list(
    `name` = NULL,
    `entityType` = NULL,
    `attributes` = NULL,
    initialize = function(
        `name`, `entityType`, `attributes`, ...
    ) {
      local.optional.var <- list(...)
      if (!missing(`name`)) {
        stopifnot(is.character(`name`), length(`name`) == 1)
        self$`name` <- `name`
      }
      if (!missing(`entityType`)) {
        stopifnot(is.character(`entityType`), length(`entityType`) == 1)
        self$`entityType` <- `entityType`
      }
      if (!missing(`attributes`)) {
        stopifnot(is.vector(`attributes`), length(`attributes`) != 0)
        sapply(`attributes`, function(x) stopifnot(is.character(x)))
        self$`attributes` <- `attributes`
      }
    },
    toJSON = function() {
      EntityObject <- list()
      if (!is.null(self$`name`)) {
        EntityObject[['name']] <-
          self$`name`
      }
      if (!is.null(self$`entityType`)) {
        EntityObject[['entityType']] <-
          self$`entityType`
      }
      if (!is.null(self$`attributes`)) {
        EntityObject[['attributes']] <-
          self$`attributes`
      }

      EntityObject
    },
    fromJSON = function(EntityJson) {
      EntityObject <- jsonlite::fromJSON(EntityJson)
      if (!is.null(EntityObject$`name`)) {
        self$`name` <- EntityObject$`name`
      }
      if (!is.null(EntityObject$`entityType`)) {
        self$`entityType` <- EntityObject$`entityType`
      }
      if (!is.null(EntityObject$`attributes`)) {
        self$`attributes` <- ApiClient$new()$deserializeObj(EntityObject$`attributes`, "map(object)", loadNamespace("openapi"))
      }
      self
    },
    toJSONString = function() {
      jsoncontent <- c(
        if (!is.null(self$`name`)) {
        sprintf(
        '"name":
          "%s"
                ',
        self$`name`
        )},
        if (!is.null(self$`entityType`)) {
        sprintf(
        '"entityType":
          "%s"
                ',
        self$`entityType`
        )},
        if (!is.null(self$`attributes`)) {
        sprintf(
        '"attributes":
          "%s"
        ',
        jsonlite::toJSON(lapply(self$`attributes`, function(x){ x }), auto_unbox = TRUE, digits=NA)
        )}
      )
      jsoncontent <- paste(jsoncontent, collapse = ",")
      paste('{', jsoncontent, '}', sep = "")
    },
    fromJSONString = function(EntityJson) {
      EntityObject <- jsonlite::fromJSON(EntityJson)
      self$`name` <- EntityObject$`name`
      self$`entityType` <- EntityObject$`entityType`
      self$`attributes` <- ApiClient$new()$deserializeObj(EntityObject$`attributes`, "map(object)", loadNamespace("openapi"))
      self
    }
  )
)
vjcitn/terraClientR documentation built on Dec. 23, 2021, 4:07 p.m.