Sha256: b1eb1172660d19da5a8aaf4051fcfc7c9b99249ff9f5f1e8675b2a854deb8aad

Contents?: true

Size: 626 Bytes

Versions: 23

Compression:

Stored size: 626 Bytes

Contents

require 'json'
require 'open-uri'

module EZ

  def self.weather(location = 'Evanston, IL')
    # Only cache up to 30 locations to avoid abuse
    @wx = {} unless @wx && @wx.keys.count < 30

    # Cache based on location
    @wx[location] ||= begin
      puts "Getting the current weather from openweathermap.org..."
      wx = from_api("http://api.openweathermap.org/data/2.5/weather?q=#{location}&units=imperial")
      @wx[location] = wx[:main]
    end

  end

  def self.from_api(uri_string)
    uri = URI.parse(URI.escape(uri_string))
    string = open(uri).read
    JSON.parse(string, symbolize_names: true)
  end

end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
ez-1.3.0 lib/ez/apis.rb
ez-1.2.0 lib/ez/apis.rb
ez-1.1.3 lib/ez/apis.rb
ez-1.1.2 lib/ez/apis.rb
ez-1.1.1 lib/ez/apis.rb
ez-1.1.0 lib/ez/apis.rb
ez-1.0.0 lib/ez/apis.rb
ez-0.9.9 lib/ez/apis.rb
ez-0.9.7 lib/ez/apis.rb
ez-0.9.6 lib/ez/apis.rb
ez-0.9.5 lib/ez/apis.rb
ez-0.9.1 lib/ez/apis.rb
ez-0.9.0 lib/ez/apis.rb
ez-0.8.7 lib/ez/apis.rb
ez-0.8.6 lib/ez/apis.rb
ez-0.7.0 lib/ez/apis.rb
ez-0.6.5 lib/ez/apis.rb
ez-0.6.4 lib/ez/apis.rb
ez-0.6.3 lib/ez/apis.rb
ez-0.6.2 lib/ez/apis.rb