class WeatherGemKg::Clients::Apixu

Constants

API_KEY

Public Class Methods

new() click to toggle source
# File lib/weather_gem_kg/clients/apixu.rb, line 8
def initialize
  @base_url = "http://api.apixu.com/v1/forecast.json?key=#{API_KEY}"
end

Public Instance Methods

get_weather(city, days) click to toggle source
# File lib/weather_gem_kg/clients/apixu.rb, line 12
def get_weather(city, days)
  @data = get_weather_info(city, days)
  @data.dig('forecast', 'forecastday').map do |f|
    day = f.dig('day')
    {
      date: Time.at(f['date_epoch']).ctime.slice(0, 10),
      max_temp: day['maxtemp_c'],
      min_temp: day['mintemp_c'],
      condition: day.dig('condition', 'text')
    }
  end
end
get_weather_info(city, days) click to toggle source
# File lib/weather_gem_kg/clients/apixu.rb, line 25
def get_weather_info(city, days)
  HTTParty.get("#{@base_url}&q=#{city}&days=#{days}")
end