class Wettr::Config

Public Class Methods

API_KEY() click to toggle source
# File lib/wettr/config.rb, line 10
def self.API_KEY
  @@API_KEY
end
start() click to toggle source
# File lib/wettr/config.rb, line 5
def self.start
  self.read_config_file
  self.set_api_key
end

Private Class Methods

read_config_file() click to toggle source
# File lib/wettr/config.rb, line 28
def self.read_config_file
  begin
    @@config_hash = YAML.load(File.read(ENV["HOME"] + "/.wettr.yml")) || {}
  rescue Errno::ENOENT => exception
    puts "Cannot find the wettr config file"
    puts "Please create a .wettr.yml config file in your home directory in order to use wettr"
    puts "See https://github.com/JWDonovan/wettr for more info"
    exit
  end
end
set_api_key() click to toggle source
# File lib/wettr/config.rb, line 16
def self.set_api_key
  if @@config_hash["API_KEY"]
    @@API_KEY = @@config_hash["API_KEY"]
  else
    puts "Cannot find API_KEY in .wettr.yml"
    puts "An OpenWeatherMap Current Weather API key is required to use wettr"
    puts "Create an account here to sign up for a key: https://home.openweathermap.org/users/sign_up"
    puts "See https://github.com/JWDonovan/wettr for more info"
    exit
  end
end