clients/common.rb in bloopletech-webstats-0.6.0 vs clients/common.rb in bloopletech-webstats-0.7.0
- old
+ new
@@ -3,24 +3,40 @@
def [](key)
undecorated_get(key) or undecorated_get(key.is_a?(String) ? key.to_sym : key.to_s)
end
end
-def load_settings(defaults_key, defaults)
+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))
+ $settings = YAML.load(IO.read(config_file_path))[client_key]
else
- $settings[defaults_key] = defaults
+ $settings[client_key] = defaults
File.open(config_file_path, "w") do |f|
YAML.dump($settings, f)
end
- puts "Please edit ~/.webstats_clients and add some URLs to monitor"
+ 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
\ No newline at end of file