Module: ForecastIO
- Extended by:
- Configuration
- Defined in:
- lib/forecast_io.rb,
lib/forecast_io/version.rb,
lib/forecast_io/configuration.rb
Defined Under Namespace
Modules: Configuration
Constant Summary collapse
- VERSION =
'2.0.2'
Constants included from Configuration
Configuration::DEFAULT_FORECAST_IO_API_ENDPOINT
Instance Attribute Summary
Attributes included from Configuration
#api_endpoint, #api_key, #default_params, #timeout
Class Method Summary collapse
-
.connection ⇒ Object
Build or get an HTTP connection object.
-
.connection=(connection) ⇒ Object
Set an HTTP connection object.
-
.forecast(latitude, longitude, options = {}) ⇒ Object
Retrieve the forecast for a given latitude and longitude.
Methods included from Configuration
Class Method Details
.connection ⇒ Object
Build or get an HTTP connection object.
31 32 33 |
# File 'lib/forecast_io.rb', line 31 def connection @connection ||= Faraday.new(request: { timeout: ForecastIO.timeout }) end |
.connection=(connection) ⇒ Object
Set an HTTP connection object.
38 39 40 |
# File 'lib/forecast_io.rb', line 38 def connection=(connection) @connection = connection end |
.forecast(latitude, longitude, options = {}) ⇒ Object
Retrieve the forecast for a given latitude and longitude.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/forecast_io.rb', line 19 def forecast(latitude, longitude, = {}) forecast_url = "#{ForecastIO.api_endpoint}/forecast/#{ForecastIO.api_key}/#{latitude},#{longitude}" forecast_url += ",#{[:time]}" if [:time] forecast_response = get(forecast_url, [:params]) if forecast_response.success? return Hashie::Mash.new(MultiJson.load(forecast_response.body)) end end |