Class: WeatherApi
- Inherits:
-
Object
- Object
- WeatherApi
- Defined in:
- lib/weather_api.rb,
lib/weather_api/version.rb
Constant Summary collapse
- FORECAST_URL =
"http://www.myweather2.com/developer/forecast.ashx?output=json"- VERSION =
"1.2.1"
Instance Method Summary collapse
- #current ⇒ Object
- #day_max_temprature ⇒ Object
- #day_type ⇒ Object
- #forecast ⇒ Object
-
#initialize(key, lat, lng) ⇒ WeatherApi
constructor
A new instance of WeatherApi.
- #next_day ⇒ Object
- #response ⇒ Object
- #wind ⇒ Object
- #wind_degree ⇒ Object
- #wind_direction ⇒ Object
- #wind_speed ⇒ Object
Constructor Details
#initialize(key, lat, lng) ⇒ WeatherApi
Returns a new instance of WeatherApi.
8 9 10 11 12 13 14 15 16 |
# File 'lib/weather_api.rb', line 8 def initialize(key, lat, lng) uri = URI.parse(FORECAST_URL + "&uac=#{key}&query=#{lat},#{lng}") result = URI.open(uri).read unless result == "Unable to find any matching weather location to the query submitted!" @response = JSON.parse(result) else puts "Invalid Location" end end |
Instance Method Details
#current ⇒ Object
22 23 24 |
# File 'lib/weather_api.rb', line 22 def current response["weather"]["curren_weather"] end |
#day_max_temprature ⇒ Object
34 35 36 |
# File 'lib/weather_api.rb', line 34 def day_max_temprature "#{next_day['day_max_temp']} #{next_day['temp_unit']}" end |
#day_type ⇒ Object
38 39 40 |
# File 'lib/weather_api.rb', line 38 def day_type next_day["weather_text"] end |
#forecast ⇒ Object
26 27 28 |
# File 'lib/weather_api.rb', line 26 def forecast response["weather"]["forecast"] end |
#next_day ⇒ Object
30 31 32 |
# File 'lib/weather_api.rb', line 30 def next_day forecast.last end |
#response ⇒ Object
18 19 20 |
# File 'lib/weather_api.rb', line 18 def response @response end |
#wind ⇒ Object
42 43 44 |
# File 'lib/weather_api.rb', line 42 def wind next_day["day"][0]["wind"] end |
#wind_degree ⇒ Object
50 51 52 |
# File 'lib/weather_api.rb', line 50 def wind_degree wind["dir_degree"] end |
#wind_direction ⇒ Object
46 47 48 |
# File 'lib/weather_api.rb', line 46 def wind_direction wind["dir"] end |
#wind_speed ⇒ Object
54 55 56 |
# File 'lib/weather_api.rb', line 54 def wind_speed "#{wind['speed']} #{wind['wind_unit']}" end |