class Forecast::Adapters::ForecastIoAdapter

Public Instance Methods

current(latitude, longitude) click to toggle source
# File lib/forecast/adapters/forecast_io_adapter.rb, line 7
def current(latitude, longitude)
  result = get_json(get_action(latitude, longitude))
  get_forecast({latitude: latitude, longitude: longitude}.merge(result['currently'])) unless nil
end
daily(latitude, longitude) click to toggle source
# File lib/forecast/adapters/forecast_io_adapter.rb, line 21
def daily(latitude, longitude)
  result = get_json(get_action(latitude, longitude))
  forecasts = Forecast::Collection.new
  result['daily']['data'].each do |hash|
    forecasts << get_forecast({latitude: latitude, longitude: longitude}.merge(hash))
  end
  return forecasts
end
hourly(latitude, longitude) click to toggle source
# File lib/forecast/adapters/forecast_io_adapter.rb, line 12
def hourly(latitude, longitude)
  result = get_json(get_action(latitude, longitude))
  forecasts = Forecast::Collection.new
  result['hourly']['data'].each do |hash|
    forecasts << get_forecast({latitude: latitude, longitude: longitude}.merge(hash))
  end
  return forecasts
end

Private Instance Methods

get_action(latitude, longitude) click to toggle source
# File lib/forecast/adapters/forecast_io_adapter.rb, line 32
def get_action(latitude, longitude)
  api_key = options[:api_key]
  return "https://api.forecast.io/forecast/#{api_key}/#{latitude},#{longitude}"
end
get_forecast(hash) click to toggle source
# File lib/forecast/adapters/forecast_io_adapter.rb, line 37
def get_forecast(hash)
  forecast = Forecast.new(hash)
  forecast.latitude = hash[:latitude]
  forecast.longitude = hash[:longitude]
  forecast.time = get_time(hash['time'])
  forecast.condition = get_condition(hash['summary'])
  forecast.text = get_text(hash['summary'])
  forecast.temperature_min = get_temperature(hash['temperatureMin'], :fahrenheit)
  forecast.temperature_max = get_temperature(hash['temperatureMax'], :fahrenheit)
  forecast.temperature = get_temperature(hash.has_key?('temperature') ? hash['temperature'] : [hash['temperatureMin'], hash['temperatureMax']], :fahrenheit)
  return forecast
end