From a2f43e189b8b923c32d0546fc437efc696d3e8d0 Mon Sep 17 00:00:00 2001 From: coderhs Date: Sat, 6 Jul 2013 07:37:53 +0530 Subject: [PATCH] Function to fetch via city_id, and geographic location(lat,lon) --- lib/open_weather_api/base.rb | 2 ++ lib/open_weather_api/current_weather.rb | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/open_weather_api/base.rb b/lib/open_weather_api/base.rb index 61ca01e..13b401d 100644 --- a/lib/open_weather_api/base.rb +++ b/lib/open_weather_api/base.rb @@ -1,3 +1,5 @@ +#Base class with functions common to all other classes + require 'httparty' require 'addressable/uri' module OpenWeather diff --git a/lib/open_weather_api/current_weather.rb b/lib/open_weather_api/current_weather.rb index 02fb6de..0ea158b 100644 --- a/lib/open_weather_api/current_weather.rb +++ b/lib/open_weather_api/current_weather.rb @@ -3,12 +3,33 @@ class Current < Base @api_url = 'http://api.openweathermap.org/data/2.5/weather' - #format : Cochin,IN + #City format : Eg, Cochin,IN + #Useage: OpenWeather::Current.city('Cochin,In') def self.city(city, options = { }) query = Hash.new query[:q] = city send_request query.merge!(options), @api_url end + + #City Geographics Cordingates : Eg, lat 35 lon 139 + + def self.geographic_cordinate(lat, lon, options = {}) + query = Hash.new + query[:lat] = lat + query[:lon] = lon + send_request query.merge!(options), @api_url + end + + alias :geographic_cordinate :geocode + + #City Id, an integer value. Eg, 2172797 + #Useage: OpenWeather::Current.city_id(2172797) + + def self.city_id(city_id, options = {}) + query = Hash.new + query[:id] = city_id + send_request query.merge!(options), @api_url + end end end