R/directions_directions.R

# LocationIQ
#
# LocationIQ provides flexible enterprise-grade location based solutions. We work with developers, startups and enterprises worldwide serving billions of requests everyday. This page provides an overview of the technical aspects of our API and will help you get started.
#
# The version of the OpenAPI document: 1.1.0
# 
# Generated by: https://openapi-generator.tech

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

      DirectionsDirectionsObject
    },
    fromJSON = function(DirectionsDirectionsJson) {
      DirectionsDirectionsObject <- jsonlite::fromJSON(DirectionsDirectionsJson)
      if (!is.null(DirectionsDirectionsObject$`code`)) {
        self$`code` <- DirectionsDirectionsObject$`code`
      }
      if (!is.null(DirectionsDirectionsObject$`waypoints`)) {
        self$`waypoints` <- ApiClient$new()$deserializeObj(DirectionsDirectionsObject$`waypoints`, "array[object]", loadNamespace("locationiq"))
      }
      if (!is.null(DirectionsDirectionsObject$`routes`)) {
        self$`routes` <- ApiClient$new()$deserializeObj(DirectionsDirectionsObject$`routes`, "array[DirectionsDirectionsRoutes]", loadNamespace("locationiq"))
      }
    },
    toJSONString = function() {
      jsoncontent <- c(
        if (!is.null(self$`code`)) {
        sprintf(
        '"code":
          "%s"
                ',
        self$`code`
        )},
        if (!is.null(self$`waypoints`)) {
        sprintf(
        '"waypoints":
           [%s]
        ',
        paste(unlist(lapply(self$`waypoints`, function(x) paste0('"', x, '"'))), collapse=",")
        )},
        if (!is.null(self$`routes`)) {
        sprintf(
        '"routes":
        [%s]
',
        paste(sapply(self$`routes`, function(x) jsonlite::toJSON(x$toJSON(), auto_unbox=TRUE, digits = NA)), collapse=",")
        )}
      )
      jsoncontent <- paste(jsoncontent, collapse = ",")
      paste('{', jsoncontent, '}', sep = "")
    },
    fromJSONString = function(DirectionsDirectionsJson) {
      DirectionsDirectionsObject <- jsonlite::fromJSON(DirectionsDirectionsJson)
      self$`code` <- DirectionsDirectionsObject$`code`
      self$`waypoints` <- ApiClient$new()$deserializeObj(DirectionsDirectionsObject$`waypoints`, "array[object]", loadNamespace("locationiq"))
      self$`routes` <- ApiClient$new()$deserializeObj(DirectionsDirectionsObject$`routes`, "array[DirectionsDirectionsRoutes]", loadNamespace("locationiq"))
      self
    }
  )
)
location-iq/locationiq-r-client documentation built on Feb. 28, 2020, 9:42 p.m.