Class: OpenMeteo::Client::UrlBuilder
- Inherits:
-
Object
- Object
- OpenMeteo::Client::UrlBuilder
- 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
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #build_url(endpoint, *args) ⇒ Object
-
#initialize(config: OpenMeteo::Client::Config.new) ⇒ UrlBuilder
constructor
A new instance of UrlBuilder.
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
#config ⇒ Object (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 |