R/reverse_api.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 Reverse operations
#' @description locationiq.Reverse
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ Reverse } \emph{ Reverse Geocoding }
#' Reverse geocoding is the process of converting a coordinate or location (latitude, longitude) to a readable address or place name. This permits the identification of nearby street addresses, places, and/or area subdivisions such as a neighborhood, county, state, or country.
#'
#' \itemize{
#' \item \emph{ @param } lat numeric
#' \item \emph{ @param } lon numeric
#' \item \emph{ @param } format Enum < [json] > 
#' \item \emph{ @param } normalizecity Enum < [1] > 
#' \item \emph{ @param } addressdetails Enum < [0, 1] > 
#' \item \emph{ @param } accept.language character
#' \item \emph{ @param } namedetails Enum < [0, 1] > 
#' \item \emph{ @param } extratags Enum < [0, 1] > 
#' \item \emph{ @param } statecode Enum < [0, 1] > 
#' \item \emph{ @param } showdistance integer
#' \item \emph{ @param } postaladdress integer
#' \item \emph{ @returnType } \link{Location} \cr
#'
#'
#' \item status code : 200 | OK
#'
#' \item return type : Location 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Bad Request
#'
#' \item return type : Error 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 401 | Unauthorized
#'
#' \item return type : Error 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 403 | The request has been made from an unauthorized domain.
#'
#' \item return type : Error 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 404 | No location or places were found for the given input
#'
#' \item return type : Error 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 429 | Request exceeded the rate-limits set on your account
#'
#' \item return type : Error 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 500 | Internal Server Error
#'
#' \item return type : Error 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' }
#'
#'
#' @examples
#' \donttest{
#' ####################  Reverse  ####################
#'
#' library(locationiq)
#' var.lat <- 40.7487727 # numeric | Latitude of the location to generate an address for.
#' var.lon <- -73.9849336 # numeric | Longitude of the location to generate an address for.
#' var.format <- 'json' # character | Format to geocode. Only JSON supported for SDKs
#' var.normalizecity <- 1 # integer | Normalizes village to city level data to city
#' var.addressdetails <- 1 # integer | Include a breakdown of the address into elements. Defaults to 1.
#' var.accept.language <- 'en' # character | Preferred language order for showing search results, overrides the value specified in the Accept-Language HTTP header. Defaults to en. To use native language for the response when available, use accept-language=native
#' var.namedetails <- 0 # integer | Include a list of alternative names in the results. These may include language variants, references, operator and brand.
#' var.extratags <- 0 # integer | Include additional information in the result if available, e.g. wikipedia link, opening hours.
#' var.statecode <- 0 # integer | Adds state or province code when available to the statecode key inside the address element. Currently supported for addresses in the USA, Canada and Australia. Defaults to 0
#' var.showdistance <- 0 # integer | Returns the straight line distance (meters) between the input location and the result's location. Value is set in the distance key of the response. Defaults to 0 [0,1]
#' var.postaladdress <- 0 # integer | Returns address inside the postaladdress key, that is specifically formatted for each country. Currently supported for addresses in Germany. Defaults to 0 [0,1]
#'
#' #Reverse Geocoding
#' api.instance <- ReverseApi$new()
#'
#' #Configure API key authorization: key
#' api.instance$apiClient$apiKeys['key'] <- 'TODO_YOUR_API_KEY';
#'
#' result <- api.instance$Reverse(var.lat, var.lon, var.format, var.normalizecity, addressdetails=var.addressdetails, accept.language=var.accept.language, namedetails=var.namedetails, extratags=var.extratags, statecode=var.statecode, showdistance=var.showdistance, postaladdress=var.postaladdress)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom caTools base64encode
#' @export
ReverseApi <- R6::R6Class(
  'ReverseApi',
  public = list(
    apiClient = NULL,
    initialize = function(apiClient){
      if (!missing(apiClient)) {
        self$apiClient <- apiClient
      }
      else {
        self$apiClient <- ApiClient$new()
      }
    },
    Reverse = function(lat, lon, format, normalizecity, addressdetails=1, accept.language=NULL, namedetails=NULL, extratags=NULL, statecode=NULL, showdistance=NULL, postaladdress=NULL, ...){
      apiResponse <- self$ReverseWithHttpInfo(lat, lon, format, normalizecity, addressdetails, accept.language, namedetails, extratags, statecode, showdistance, postaladdress, ...)
      resp <- apiResponse$response
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        apiResponse$content
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        apiResponse
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        apiResponse
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        apiResponse
      }
    },

    ReverseWithHttpInfo = function(lat, lon, format, normalizecity, addressdetails=1, accept.language=NULL, namedetails=NULL, extratags=NULL, statecode=NULL, showdistance=NULL, postaladdress=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

      if (missing(`lat`)) {
        stop("Missing required parameter `lat`.")
      }

      if (missing(`lon`)) {
        stop("Missing required parameter `lon`.")
      }

      if (missing(`format`)) {
        stop("Missing required parameter `format`.")
      }

      if (missing(`normalizecity`)) {
        stop("Missing required parameter `normalizecity`.")
      }

      queryParams['lat'] <- lat

      queryParams['lon'] <- lon

      queryParams['format'] <- format

      queryParams['normalizecity'] <- normalizecity

      queryParams['addressdetails'] <- addressdetails

      queryParams['accept-language'] <- accept.language

      queryParams['namedetails'] <- namedetails

      queryParams['extratags'] <- extratags

      queryParams['statecode'] <- statecode

      queryParams['showdistance'] <- showdistance

      queryParams['postaladdress'] <- postaladdress

      urlPath <- "/reverse.php"
      # API key authentication
      if ("key" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["key"]) > 0) {
        queryParams['key'] <- paste(unlist(self$apiClient$apiKeys["key"]), collapse='')
      }

      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) {
        deserializedRespObj <- tryCatch(
          self$apiClient$deserialize(resp, "Location", loadNamespace("locationiq")),
          error = function(e){
             stop("Failed to deserialize response")
          }
        )
        ApiResponse$new(deserializedRespObj, resp)
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        ApiResponse$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        ApiResponse$new("API server error", resp)
      }
    }
  )
)
location-iq/locationiq-r-client documentation built on Feb. 28, 2020, 9:42 p.m.