Last active
December 18, 2015 10:19
-
-
Save r38y/5767280 to your computer and use it in GitHub Desktop.
A class for wrapping DMS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/https' | |
require 'uri' | |
class RunDMS | |
def self.snitch(id, options={}, &block) | |
dead_man = new(id, options) | |
block.call | |
dead_man.snitch | |
end | |
def initialize(id, options={}) | |
raise ArgumentError unless id | |
@id = id | |
@start_time = Time.now | |
@actually_snitch = !!options.delete(:if) | |
end | |
def elapsed_time | |
(Time.now - @start_time) | |
end | |
def uri | |
@uri ||= URI.parse("https://nosnch.in/#{@id}?m=#{elapsed_time}+seconds") | |
end | |
def http | |
Net::HTTP.new(uri.host, uri.port).tap do |http| | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
end | |
end | |
def snitch | |
if @actually_snitch | |
Rails.logger.info "***** Actually snitching! #{@id}" | |
http.get(uri.request_uri) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment