Sha256: 9da69d9f761d7d9e831c9d05ea987b71954ecd67448f7257569168f4e9136b08

Contents?: true

Size: 687 Bytes

Versions: 1

Compression:

Stored size: 687 Bytes

Contents

class Wettr::WeatherAPI
  include HTTParty

  base_uri "https://api.openweathermap.org"

  def self.call_with_lat_and_lon(lat:, lon:)
    @options = { query: { lat: lat, lon: lon } }
    call
  end

  def self.call_with_zip(zip)
    @options = { query: { zip: zip } }
    call
  end

  private
  
  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wettr-0.1.3 lib/wettr/weather_api.rb