Skip to content

Commit 0a839fd

Browse files
committed
Added base Lib function + Started Current weather Class
1 parent 8bb0093 commit 0a839fd

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

lib/open_weather_api.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module OpenWeather
2+
autoload :Current, "./open_weather_api/current_weather"
3+
autoload :Base, "./open_weather_api/base"
4+
5+
end

lib/open_weather_api/base.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'httparty'
2+
require 'addressable/uri'
3+
module OpenWeather
4+
class Base
5+
def self.send_request hash, url
6+
uri = Addressable::URI.parse(url)
7+
uri.query_values = hash
8+
HTTParty.get(uri.to_s)
9+
end
10+
end
11+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module OpenWeather
2+
class Current < Base
3+
4+
@api_url = 'http://api.openweathermap.org/data/2.5/weather'
5+
6+
#format : Cochin,IN
7+
def self.city(city, options = { })
8+
query = Hash.new
9+
query[:q] = city
10+
run_call query.merge!(options), @api_url
11+
end
12+
end
13+
end

lib/open_weather_api/dump.rdb

76 Bytes
Binary file not shown.

lib/open_weather_api/test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require '/home/hsps/sandbox/open_weather_map/lib/open_weather_api'
2+
3+
puts OpenWeather::Current.city('Cochin,IN')

0 commit comments

Comments
 (0)