Module: ForecastIO

Extended by:
Configuration
Defined in:
lib/pirate_weather_forecast_ruby.rb,
lib/pirate_weather_forecast_ruby/version.rb,
lib/pirate_weather_forecast_ruby/configuration.rb

Defined Under Namespace

Modules: Configuration

Constant Summary collapse

VERSION =
"0.1.0"

Constants included from Configuration

Configuration::DEFAULT_FORECAST_IO_API_ENDPOINT

Class Attribute Summary collapse

Attributes included from Configuration

#api_endpoint, #api_key, #default_params, #timeout

Class Method Summary collapse

Methods included from Configuration

configure

Class Attribute Details

.connectionObject

Build or get an HTTP connection object.



33
34
35
# File 'lib/pirate_weather_forecast_ruby.rb', line 33

def connection
  @connection ||= Faraday.new(request: { timeout: ForecastIO.timeout })
end

Class Method Details

.forecast(latitude, longitude, options = {}) ⇒ Object

Retrieve the forecast for a given latitude and longitude.

Parameters:

  • latitude (String)

    Latitude.

  • longitude (String)

    Longitude.

  • options (String) (defaults to: {})

    Optional parameters. Valid options are ‘:time` and `:params`.



21
22
23
24
25
26
27
28
29
30
# File 'lib/pirate_weather_forecast_ruby.rb', line 21

def forecast(latitude, longitude, options = {})
  forecast_url = "#{ForecastIO.api_endpoint}/forecast/#{ForecastIO.api_key}/#{latitude},#{longitude}"
  forecast_url += ",#{options[:time]}" if options[:time]

  forecast_response = get(forecast_url, options[:params])

  return unless forecast_response.success?

  Hashie::Mash.new(MultiJson.load(forecast_response.body))
end