Class: Underpass::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/underpass/client.rb

Overview

Runs the Overpass API query with retry logic for transient errors.

Handles caching of responses and automatic retries with exponential backoff for rate limiting (429) and timeout (504) responses.

Constant Summary collapse

MAX_RETRIES =

Returns default maximum number of retries.

Returns:

  • (Integer)

    default maximum number of retries

3

Class Method Summary collapse

Class Method Details

.perform(request, max_retries: MAX_RETRIES) ⇒ Net::HTTPResponse

Performs the API request with automatic retries for rate limiting and timeouts.

Results are cached when a Underpass::Cache instance is configured via Underpass.cache.

Parameters:

  • request (QL::Request)

    the prepared Overpass query request

  • max_retries (Integer) (defaults to: MAX_RETRIES)

    maximum number of retry attempts

Returns:

  • (Net::HTTPResponse)

    the API response

Raises:

  • (RateLimitError)

    when rate limited after exhausting retries

  • (TimeoutError)

    when the API times out after exhausting retries

  • (ApiError)

    when the API returns an unexpected error



26
27
28
29
30
31
32
33
34
# File 'lib/underpass/client.rb', line 26

def self.perform(request, max_retries: MAX_RETRIES)
  cache_key = Digest::SHA256.hexdigest(request.to_query)
  cached = Underpass.cache&.fetch(cache_key)
  return cached if cached

  response = perform_with_retries(request, max_retries)
  Underpass.cache&.store(cache_key, response)
  response
end