R/search_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 Search operations
#' @description locationiq.Search
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ Search } \emph{ Forward Geocoding }
#' The Search API allows converting addresses, such as a street address, into geographic coordinates (latitude and longitude). These coordinates can serve various use-cases, from placing markers on a map to helping algorithms determine nearby bus stops. This process is also known as Forward Geocoding.
#'
#' \itemize{
#' \item \emph{ @param } q character
#' \item \emph{ @param } format Enum < [json] > 
#' \item \emph{ @param } normalizecity Enum < [1] > 
#' \item \emph{ @param } addressdetails Enum < [0, 1] > 
#' \item \emph{ @param } viewbox character
#' \item \emph{ @param } bounded Enum < [0, 1] > 
#' \item \emph{ @param } limit integer
#' \item \emph{ @param } accept.language character
#' \item \emph{ @param } countrycodes character
#' \item \emph{ @param } namedetails Enum < [0, 1] > 
#' \item \emph{ @param } dedupe Enum < [0, 1] > 
#' \item \emph{ @param } extratags Enum < [0, 1] > 
#' \item \emph{ @param } statecode Enum < [0, 1] > 
#' \item \emph{ @param } matchquality integer
#' \item \emph{ @param } postaladdress integer
#' \item \emph{ @returnType } list( \link{location} ) \cr
#'
#'
#' \item status code : 200 | OK
#'
#' \item return type : array[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{
#' ####################  Search  ####################
#'
#' library(locationiq)
#' var.q <- 'Empire state building' # character | Address to geocode
#' var.format <- 'json' # character | Format to geocode. Only JSON supported for SDKs
#' var.normalizecity <- 1 # integer | For responses with no city value in the address section, the next available element in this order - city_district, locality, town, borough, municipality, village, hamlet, quarter, neighbourhood - from the address section will be normalized to city. Defaults to 1 for SDKs.
#' var.addressdetails <- 1 # integer | Include a breakdown of the address into elements. Defaults to 0.
#' var.viewbox <- '-132.84908,47.69382,-70.44674,30.82531' # character | The preferred area to find search results.  To restrict results to those within the viewbox, use along with the bounded option. Tuple of 4 floats. Any two corner points of the box - `max_lon,max_lat,min_lon,min_lat` or `min_lon,min_lat,max_lon,max_lat` - are accepted in any order as long as they span a real box. 
#' var.bounded <- 1 # integer | Restrict the results to only items contained with the viewbox
#' var.limit <- 10 # integer | Limit the number of returned results. Default is 10.
#' 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.countrycodes <- 'us' # character | Limit search to a list of countries.
#' var.namedetails <- 1 # integer | Include a list of alternative names in the results. These may include language variants, references, operator and brand.
#' var.dedupe <- 1 # integer | Sometimes you have several objects in OSM identifying the same place or object in reality. The simplest case is a street being split in many different OSM ways due to different characteristics. Nominatim will attempt to detect such duplicates and only return one match; this is controlled by the dedupe parameter which defaults to 1. Since the limit is, for reasons of efficiency, enforced before and not after de-duplicating, it is possible that de-duplicating leaves you with less results than requested.
#' 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.matchquality <- 0 # integer | Returns additional information about quality of the result in a matchquality object. Read more 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]
#'
#' #Forward Geocoding
#' api.instance <- SearchApi$new()
#'
#' #Configure API key authorization: key
#' api.instance$apiClient$apiKeys['key'] <- 'TODO_YOUR_API_KEY';
#'
#' result <- api.instance$Search(var.q, var.format, var.normalizecity, addressdetails=var.addressdetails, viewbox=var.viewbox, bounded=var.bounded, limit=var.limit, accept.language=var.accept.language, countrycodes=var.countrycodes, namedetails=var.namedetails, dedupe=var.dedupe, extratags=var.extratags, statecode=var.statecode, matchquality=var.matchquality, postaladdress=var.postaladdress)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom caTools base64encode
#' @export
SearchApi <- R6::R6Class(
  'SearchApi',
  public = list(
    apiClient = NULL,
    initialize = function(apiClient){
      if (!missing(apiClient)) {
        self$apiClient <- apiClient
      }
      else {
        self$apiClient <- ApiClient$new()
      }
    },
    Search = function(q, format, normalizecity, addressdetails=NULL, viewbox=NULL, bounded=NULL, limit=10, accept.language=NULL, countrycodes=NULL, namedetails=NULL, dedupe=NULL, extratags=NULL, statecode=NULL, matchquality=NULL, postaladdress=NULL, ...){
      apiResponse <- self$SearchWithHttpInfo(q, format, normalizecity, addressdetails, viewbox, bounded, limit, accept.language, countrycodes, namedetails, dedupe, extratags, statecode, matchquality, 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
      }
    },

    SearchWithHttpInfo = function(q, format, normalizecity, addressdetails=NULL, viewbox=NULL, bounded=NULL, limit=10, accept.language=NULL, countrycodes=NULL, namedetails=NULL, dedupe=NULL, extratags=NULL, statecode=NULL, matchquality=NULL, postaladdress=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

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

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

      queryParams['q'] <- q

      queryParams['format'] <- format

      queryParams['normalizecity'] <- normalizecity

      queryParams['addressdetails'] <- addressdetails

      queryParams['viewbox'] <- viewbox

      queryParams['bounded'] <- bounded

      queryParams['limit'] <- limit

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

      queryParams['countrycodes'] <- countrycodes

      queryParams['namedetails'] <- namedetails

      queryParams['dedupe'] <- dedupe

      queryParams['extratags'] <- extratags

      queryParams['statecode'] <- statecode

      queryParams['matchquality'] <- matchquality

      queryParams['postaladdress'] <- postaladdress

      urlPath <- "/search.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, "array[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.