class Wettr::WeatherAPI

Public Class Methods

call_with_lat_and_lon(lat:, lon:) click to toggle source
# File lib/wettr/weather_api.rb, line 6
def self.call_with_lat_and_lon(lat:, lon:)
  @options = { query: { lat: lat, lon: lon } }
  call
end
call_with_zip(zip) click to toggle source
# File lib/wettr/weather_api.rb, line 11
def self.call_with_zip(zip)
  @options = { query: { zip: zip } }
  call
end

Private Class Methods

call() click to toggle source
# File lib/wettr/weather_api.rb, line 18
def self.call
  default_params appid: Wettr::Config.API_KEY, units: "imperial"
  
  response = self.get("/data/2.5/weather", @options)

  if response["cod"] != 200
    puts "Encountered an error contacting OpenWeatherMap"
    puts "Returned the following response: #{ response['cod'] }"
    puts "Message: #{ response['message'] }"
    exit
  end

  response
end