Skip to content

Commit a2f43e1

Browse files
committed
Function to fetch via city_id, and geographic ___location(lat,lon)
1 parent 60bca9f commit a2f43e1

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/open_weather_api/base.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#Base class with functions common to all other classes
2+
13
require 'httparty'
24
require 'addressable/uri'
35
module OpenWeather

lib/open_weather_api/current_weather.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,33 @@ class Current < Base
33

44
@api_url = 'http://api.openweathermap.org/data/2.5/weather'
55

6-
#format : Cochin,IN
6+
#City format : Eg, Cochin,IN
7+
#Useage: OpenWeather::Current.city('Cochin,In')
78
def self.city(city, options = { })
89
query = Hash.new
910
query[:q] = city
1011
send_request query.merge!(options), @api_url
1112
end
13+
14+
#City Geographics Cordingates : Eg, lat 35 lon 139
15+
16+
def self.geographic_cordinate(lat, lon, options = {})
17+
query = Hash.new
18+
query[:lat] = lat
19+
query[:lon] = lon
20+
send_request query.merge!(options), @api_url
21+
end
22+
23+
alias :geographic_cordinate :geocode
24+
25+
#City Id, an integer value. Eg, 2172797
26+
#Useage: OpenWeather::Current.city_id(2172797)
27+
28+
def self.city_id(city_id, options = {})
29+
query = Hash.new
30+
query[:id] = city_id
31+
send_request query.merge!(options), @api_url
32+
end
1233
end
1334
end
1435

0 commit comments

Comments
 (0)