module OpenWeather::Utilities

Utility functions.

@author Mostly github.com/paradox460/snoo

Public Instance Methods

city_name_from_file() click to toggle source
# File lib/OpenWeather/utilities.rb, line 17
def city_name_from_file
  @city_file.nil? ? "" : JSON.parse(File.read @city_file)['city']['name']
end
city_name_from_id(id) click to toggle source
# File lib/OpenWeather/utilities.rb, line 21
def city_name_from_id(id)
  weather = weather_raw id
  weather['name']
end
today() click to toggle source
# File lib/OpenWeather/utilities.rb, line 7
def today
  time = Time.new
  time.strftime("%Y-%m-%d")
end
tomorrow() click to toggle source
# File lib/OpenWeather/utilities.rb, line 12
def tomorrow
  time = Time.now + (60 * 60 * 24)
  time.strftime("%Y-%m-%d")
end

Private Instance Methods

get(*args, &block) click to toggle source

HTTParty get wrapper. This serves to clean up code, as well as throw webserver errors wherever needed

# File lib/OpenWeather/utilities.rb, line 29
def get *args, &block
  response = self.class.get *args, &block
  raise WebserverError, response.code unless response.code == 200
  response
end
post(*args, &block) click to toggle source

HTTParty POST wrapper. This serves to clean up code, as well as throw webserver errors wherever needed

# File lib/OpenWeather/utilities.rb, line 37
def post *args, &block
  response = self.class.post *args, &block
  raise WebserverError, response.code unless response.code == 200
  response
end