R/autocomplete_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 Autocomplete operations
#' @description locationiq.Autocomplete
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ Autocomplete } \emph{  }
#' The Autocomplete API is a variant of the Search API that returns place predictions in response to an HTTP request.  The request specifies a textual search string and optional geographic bounds.  The service can be used to provide autocomplete functionality for text-based geographic searches, by returning places such as businesses, addresses and points of interest as a user types. The Autocomplete API can match on full words as well as substrings. Applications can therefore send queries as the user types, to provide on-the-fly place predictions.
#'
#' \itemize{
#' \item \emph{ @param } q character
#' \item \emph{ @param } normalizecity Enum < [1] > 
#' \item \emph{ @param } limit integer
#' \item \emph{ @param } viewbox character
#' \item \emph{ @param } bounded Enum < [0, 1] > 
#' \item \emph{ @param } countrycodes character
#' \item \emph{ @param } accept.language character
#' \item \emph{ @param } tag character
#'
#'
#' \item status code : 200 | OK
#'
#' \item return type : array[object] 
#' \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{
#' ####################  Autocomplete  ####################
#'
#' library(locationiq)
#' var.q <- 'Empire state' # character | Address to geocode
#' 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.limit <- 10 # integer | Limit the number of returned results. Default is 10.
#' 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.countrycodes <- 'us' # character | Limit search to a list of countries.
#' 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.tag <- 'place' # character | Restricts the autocomplete search results to elements of specific OSM class and type.  Example - To restrict results to only class place and type city: tag=place:city, To restrict the results to all of OSM class place: tag=place
#'
#' api.instance <- AutocompleteApi$new()
#'
#' #Configure API key authorization: key
#' api.instance$apiClient$apiKeys['key'] <- 'TODO_YOUR_API_KEY';
#'
#' result <- api.instance$Autocomplete(var.q, var.normalizecity, limit=var.limit, viewbox=var.viewbox, bounded=var.bounded, countrycodes=var.countrycodes, accept.language=var.accept.language, tag=var.tag)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom caTools base64encode
#' @export
AutocompleteApi <- R6::R6Class(
  'AutocompleteApi',
  public = list(
    apiClient = NULL,
    initialize = function(apiClient){
      if (!missing(apiClient)) {
        self$apiClient <- apiClient
      }
      else {
        self$apiClient <- ApiClient$new()
      }
    },
    Autocomplete = function(q, normalizecity, limit=10, viewbox=NULL, bounded=NULL, countrycodes=NULL, accept.language=NULL, tag=NULL, ...){
      apiResponse <- self$AutocompleteWithHttpInfo(q, normalizecity, limit, viewbox, bounded, countrycodes, accept.language, tag, ...)
      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
      }
    },

    AutocompleteWithHttpInfo = function(q, normalizecity, limit=10, viewbox=NULL, bounded=NULL, countrycodes=NULL, accept.language=NULL, tag=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

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

      queryParams['q'] <- q

      queryParams['limit'] <- limit

      queryParams['viewbox'] <- viewbox

      queryParams['bounded'] <- bounded

      queryParams['countrycodes'] <- countrycodes

      queryParams['normalizecity'] <- normalizecity

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

      queryParams['tag'] <- tag

      urlPath <- "/autocomplete.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[object]", 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.