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.3.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 17 18 19 |
# File 'lib/weather_api.rb', line 8 def initialize(key, lat, lng) warn "[DEPRECATION] google-map-weather-intregration: The MyWeather2 API (myweather2.com) " \ "has been shut down. This gem is no longer functional. " \ "Please migrate to the open-meteo gem (https://github.com/open-meteo/ruby-sdk) or openweathermap." 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
25 26 27 |
# File 'lib/weather_api.rb', line 25 def current response["weather"]["curren_weather"] end |
#day_max_temprature ⇒ Object
37 38 39 |
# File 'lib/weather_api.rb', line 37 def day_max_temprature "#{next_day['day_max_temp']} #{next_day['temp_unit']}" end |
#day_type ⇒ Object
41 42 43 |
# File 'lib/weather_api.rb', line 41 def day_type next_day["weather_text"] end |
#forecast ⇒ Object
29 30 31 |
# File 'lib/weather_api.rb', line 29 def forecast response["weather"]["forecast"] end |
#next_day ⇒ Object
33 34 35 |
# File 'lib/weather_api.rb', line 33 def next_day forecast.last end |
#response ⇒ Object
21 22 23 |
# File 'lib/weather_api.rb', line 21 def response @response end |
#wind ⇒ Object
45 46 47 |
# File 'lib/weather_api.rb', line 45 def wind next_day["day"][0]["wind"] end |
#wind_degree ⇒ Object
53 54 55 |
# File 'lib/weather_api.rb', line 53 def wind_degree wind["dir_degree"] end |
#wind_direction ⇒ Object
49 50 51 |
# File 'lib/weather_api.rb', line 49 def wind_direction wind["dir"] end |
#wind_speed ⇒ Object
57 58 59 |
# File 'lib/weather_api.rb', line 57 def wind_speed "#{wind['speed']} #{wind['wind_unit']}" end |