Sha256: 45ccfc37b7ba65011653cffc99f41e82b58a17da46330ff2e777ab36b7ff250c

Contents?: true

Size: 617 Bytes

Versions: 2

Compression:

Stored size: 617 Bytes

Contents

require "net/http"
require 'json'

module Forecastr
  class Radar
    API_URL = "http://api.openweathermap.org/data/2.5/weather?"

    class << self
      def find_by_city(city_name)
        radar = new
        radar.find_by_city(city_name)
      end
    end

    def find_by_city(city_name)
      uri = URI(API_URL + "q=" + city_name)
      @json = JSON.parse(Net::HTTP.get(uri))
      Forecastr::Forecast.new(@json)
    end

    def find_by_coordinates(lat, lon)
      uri = URI(API_URL + "lat=#{lat}&lon=#{lon}")
      @json = JSON.parse(Net::HTTP.get(uri))
      Forecastr::Forecast.new(@json)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
forecastr-0.1.1 lib/forecastr/radar.rb
forecastr-0.1.0 lib/forecastr/radar.rb