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(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(config: OpenMeteo::Client::Config.new)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @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 = [config.url, relative_path].join("/")

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