Class: OpenMeteo::Client::UrlBuilder

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

Overview

The class that constructs the URLs for given endpoints.

Constant Summary collapse

API_PATHS =
{ forecast: "v1/forecast", forecast_dwd_icon: "v1/dwd-icon" }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_config: OpenMeteo::Client::Config.new) ⇒ UrlBuilder

Returns a new instance of UrlBuilder.



10
11
12
# File 'lib/open_meteo/client/url_builder.rb', line 10

def initialize(api_config: OpenMeteo::Client::Config.new)
  @api_config = api_config
end

Instance Attribute Details

#api_configObject (readonly)

Returns the value of attribute api_config.



8
9
10
# File 'lib/open_meteo/client/url_builder.rb', line 8

def api_config
  @api_config
end

Instance Method Details

#build_url(endpoint, *args) ⇒ Object



14
15
16
17
18
19
# File 'lib/open_meteo/client/url_builder.rb', line 14

def build_url(endpoint, *args)
  relative_path = API_PATHS.fetch(endpoint.to_sym)
  full_path = [api_config.url, relative_path].join("/")

  URI::DEFAULT_PARSER.escape(format(full_path, args))
end