Class: Bomtempo::OneCall
- Inherits:
-
Object
- Object
- Bomtempo::OneCall
- Defined in:
- lib/bomtempo/one_call.rb
Constant Summary collapse
- API_ONE_CALL =
"https://api.openweathermap.org/data/3.0/onecall"
Instance Method Summary collapse
-
#initialize(locate) ⇒ OneCall
constructor
A new instance of OneCall.
- #next_five_days ⇒ Object
Constructor Details
#initialize(locate) ⇒ OneCall
Returns a new instance of OneCall.
7 8 9 10 11 |
# File 'lib/bomtempo/one_call.rb', line 7 def initialize(locate) @lat = (locate[:coordenate] && locate[:coordenate][:lat])? locate[:coordenate][:lat] : nil @lon = (locate[:coordenate] && locate[:coordenate][:lon])? locate[:coordenate][:lon] : nil @city = locate[:city] end |
Instance Method Details
#next_five_days ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bomtempo/one_call.rb', line 13 def next_five_days return "City is required" unless !@city.nil? return "Coordenate is required" unless !@lat.nil? || !@lon.nil? url = "#{API_ONE_CALL}?lat=#{@lat}&lon=#{@lon}" + "&appid=#{Class.nesting[-1].get_token}" + "&units=metric&lang=pt_BR&exclude=hourly,minutely,alerts" response = JSON.parse(HTTParty.get(url).body) generate_body(response["daily"]) end |