Sha256: 60f1a87830638180c06b25cf8a0347f7dfbc281a5a8b6259f184ecda104c50e2

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

class Hash
  alias_method :undecorated_get, :[]
  def [](key)
    undecorated_get(key) or undecorated_get(key.is_a?(String) ? key.to_sym : key.to_s)
  end
end

def load_settings(client_key, defaults, message)
  config_file_path = File.expand_path("~/.webstats_clients")

  $settings = {}

  if File.exists?(config_file_path)
    $settings = YAML.load(IO.read(config_file_path))[client_key]
  else
    $settings[client_key] = defaults

    File.open(config_file_path, "w") do |f|
      YAML.dump($settings, f)
    end

    puts message
    exit
  end
end

def make_request(url, password, failed_proc)
  while(true)
    begin
      Net::HTTP.start(url.host, url.port) { |http|
        http.read_timeout = http.open_timeout = 15
        puts url.request_uri
        req = Net::HTTP::Get.new(url.request_uri)
        req.basic_auth 'webstats', password unless password.nil?
        return JSON.parse(http.request(req).body)
      }
    rescue Exception => e
      return nil unless failed_proc.call(url, password, e)
    end
  end
end
  

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bloopletech-webstats-0.7.0 clients/common.rb
bloopletech-webstats-0.8.0 clients/common.rb
bloopletech-webstats-0.8.1 clients/common.rb
bloopletech-webstats-0.9.0 clients/common.rb