Module: Snitcher
Constant Summary collapse
- VERSION =
"0.3.1"
Instance Method Summary collapse
-
#snitch(token, opts = {}) ⇒ Object
Public: Check-in to Deadman’s Snitch.
Instance Method Details
#snitch(token, opts = {}) ⇒ Object
Public: Check-in to Deadman’s Snitch
token - The Snitch token given by Deadman’s Snitch (see the install page). opts - The hash of optional parameters that can be given during check-in:
:message - Text limited to ~250 characters.
:timeout - Number of seconds to set as connect and read timeout.
Examples
Snitch.snitch("c2354d53d2")
# => true
Returns true if the check-in succeeded or false if it failed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/snitcher.rb', line 21 def snitch(token, opts = {}) uri = URI.parse("https://nosnch.in/#{token}") timeout = opts.fetch(:timeout, 2) opts = { :open_timeout => timeout, :read_timeout => timeout, :ssl_timeout => timeout, :use_ssl => uri.port == 443 } Net::HTTP.start(uri.host, uri.port, opts) do |http| if = opts[:message] uri.query = URI.encode_www_form(:m => ) end request = Net::HTTP::Get.new(uri.request_uri) request["User-Agent"] = user_agent response = http.request(request) response.is_a?(Net::HTTPSuccess) end rescue ::Timeout::Error false end |