Class: WeatherApi

Inherits:
Object
  • Object
show all
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

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

#currentObject



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

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

#day_max_tempratureObject



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_typeObject



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

def day_type
  next_day["weather_text"]
end

#forecastObject



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

def forecast
  response["weather"]["forecast"]
end

#next_dayObject



33
34
35
# File 'lib/weather_api.rb', line 33

def next_day
  forecast.last
end

#responseObject



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

def response
  @response
end

#windObject



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

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

#wind_degreeObject



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

def wind_degree
  wind["dir_degree"]
end

#wind_directionObject



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

def wind_direction
  wind["dir"]
end

#wind_speedObject



57
58
59
# File 'lib/weather_api.rb', line 57

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