R/message_object.R

# DaDaPush Public API
#
# DaDaPush: Real-time Notifications App Send real-time notifications through our API without coding and maintaining your own app for iOS or Android devices.
#
# The version of the OpenAPI document: v1
# Contact: contacts@dadapush.com
# Generated by: https://openapi-generator.tech


#' MessageObject Class
#'
#' @field actions 
#' @field channelName 
#' @field content 
#' @field createdAt 
#' @field id 
#' @field title 
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
MessageObject <- R6::R6Class(
  'MessageObject',
  public = list(
    `actions` = NULL,
    `channelName` = NULL,
    `content` = NULL,
    `createdAt` = NULL,
    `id` = NULL,
    `title` = NULL,
    initialize = function(`channelName`, `content`, `createdAt`, `id`, `title`, `actions`=NULL, ...){
      local.optional.var <- list(...)
      if (!missing(`channelName`)) {
        stopifnot(is.character(`channelName`), length(`channelName`) == 1)
        self$`channelName` <- `channelName`
      }
      if (!missing(`content`)) {
        stopifnot(is.character(`content`), length(`content`) == 1)
        self$`content` <- `content`
      }
      if (!missing(`createdAt`)) {
        stopifnot(is.character(`createdAt`), length(`createdAt`) == 1)
        self$`createdAt` <- `createdAt`
      }
      if (!missing(`id`)) {
        stopifnot(is.numeric(`id`), length(`id`) == 1)
        self$`id` <- `id`
      }
      if (!missing(`title`)) {
        stopifnot(is.character(`title`), length(`title`) == 1)
        self$`title` <- `title`
      }
      if (!is.null(`actions`)) {
        stopifnot(is.vector(`actions`), length(`actions`) != 0)
        sapply(`actions`, function(x) stopifnot(R6::is.R6(x)))
        self$`actions` <- `actions`
      }
    },
    toJSON = function() {
      MessageObjectObject <- list()
      if (!is.null(self$`actions`)) {
        MessageObjectObject[['actions']] <-
          sapply(self$`actions`, function(x) x$toJSON())
      }
      if (!is.null(self$`channelName`)) {
        MessageObjectObject[['channelName']] <-
          self$`channelName`
      }
      if (!is.null(self$`content`)) {
        MessageObjectObject[['content']] <-
          self$`content`
      }
      if (!is.null(self$`createdAt`)) {
        MessageObjectObject[['createdAt']] <-
          self$`createdAt`
      }
      if (!is.null(self$`id`)) {
        MessageObjectObject[['id']] <-
          self$`id`
      }
      if (!is.null(self$`title`)) {
        MessageObjectObject[['title']] <-
          self$`title`
      }

      MessageObjectObject
    },
    fromJSON = function(MessageObjectJson) {
      MessageObjectObject <- jsonlite::fromJSON(MessageObjectJson)
      if (!is.null(MessageObjectObject$`actions`)) {
        self$`actions` <- sapply(MessageObjectObject$`actions`, function(x) {
          actionsObject <- Action$new()
          actionsObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))
          actionsObject
        })
      }
      if (!is.null(MessageObjectObject$`channelName`)) {
        self$`channelName` <- MessageObjectObject$`channelName`
      }
      if (!is.null(MessageObjectObject$`content`)) {
        self$`content` <- MessageObjectObject$`content`
      }
      if (!is.null(MessageObjectObject$`createdAt`)) {
        self$`createdAt` <- MessageObjectObject$`createdAt`
      }
      if (!is.null(MessageObjectObject$`id`)) {
        self$`id` <- MessageObjectObject$`id`
      }
      if (!is.null(MessageObjectObject$`title`)) {
        self$`title` <- MessageObjectObject$`title`
      }
    },
    toJSONString = function() {
      sprintf(
        '{
           "actions":
             [%s],
           "channelName":
             "%s",
           "content":
             "%s",
           "createdAt":
             "%s",
           "id":
             %d,
           "title":
             "%s"
        }',
        paste(unlist(lapply(self$`actions`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox=TRUE))), collapse=","),
        self$`channelName`,
        self$`content`,
        self$`createdAt`,
        self$`id`,
        self$`title`
      )
    },
    fromJSONString = function(MessageObjectJson) {
      MessageObjectObject <- jsonlite::fromJSON(MessageObjectJson)
      data.frame <- MessageObjectObject$`actions`
      self$`actions` <- vector("list", length = nrow(data.frame))
      for (row in 1:nrow(data.frame)) {
          actions.node <- Action$new()
          actions.node$fromJSON(jsonlite::toJSON(data.frame[row,,drop = TRUE], auto_unbox = TRUE))
          self$`actions`[[row]] <- actions.node
      }
      self$`channelName` <- MessageObjectObject$`channelName`
      self$`content` <- MessageObjectObject$`content`
      self$`createdAt` <- MessageObjectObject$`createdAt`
      self$`id` <- MessageObjectObject$`id`
      self$`title` <- MessageObjectObject$`title`
      self
    }
  )
)
dadapush/dadapush-r-client documentation built on Nov. 4, 2019, 9:36 a.m.