Class: WeatherApi

Inherits:
Object
  • Object
show all
Defined in:
lib/weather_api.rb

Instance Method Summary collapse

Constructor Details

#initialize(key, lat, lng) ⇒ WeatherApi

Returns a new instance of WeatherApi.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/weather_api.rb', line 6

def initialize(key, lat, lng)

  url          =       'http://www.myweather2.com/developer/forecast.ashx?output=json'
  uri          =       URI.parse(url+"&uac=#{key}&query=#{lat},#{lng}")
  result       =       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

#currentObject



22
23
24
# File 'lib/weather_api.rb', line 22

def current
  response['weather']['curren_weather']
end

#day_max_tempratureObject



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_typeObject



38
39
40
# File 'lib/weather_api.rb', line 38

def day_type
  next_day['weather_text']
end

#forecastObject



26
27
28
# File 'lib/weather_api.rb', line 26

def forecast
  response['weather']['forecast']
end

#next_dayObject



30
31
32
# File 'lib/weather_api.rb', line 30

def next_day
  forecast.last
end

#responseObject



18
19
20
# File 'lib/weather_api.rb', line 18

def response
  @response
end

#windObject



42
43
44
# File 'lib/weather_api.rb', line 42

def wind
  next_day['day'][0]['wind']
end

#wind_degreeObject



50
51
52
# File 'lib/weather_api.rb', line 50

def wind_degree
  wind['dir_degree']
end

#wind_directionObject



46
47
48
# File 'lib/weather_api.rb', line 46

def wind_direction
  wind['dir']
end

#wind_speedObject



54
55
56
# File 'lib/weather_api.rb', line 54

def wind_speed
  "#{wind['speed']} #{wind['wind_unit']}"
end