Module: Snitcher

Extended by:
Snitcher
Included in:
Snitcher
Defined in:
lib/snitcher.rb,
lib/snitcher/api.rb,
lib/snitcher/version.rb

Defined Under Namespace

Modules: API

Constant Summary collapse

VERSION =
"0.4.0"

Instance Method Summary collapse

Instance Method Details

#snitch(*args) ⇒ Boolean

Check-in to Dead Man’s Snitch.

Examples:

Snitch.snitch("c2354d53d2")
# => true

Parameters:

  • token (String)

    The unique Snitch token to check-in with. This can be found on the Setup page as the last part of the HTTP check-in url. For example, c2354d53d2 is the token in nosnch.in/c2354d53d2.

  • opts (Hash)

Returns:

  • (Boolean)

    if the check-in succeeded.



62
63
64
65
66
# File 'lib/snitcher.rb', line 62

def snitch(*args)
  snitch!(*args)
rescue StandardError
  false
end

#snitch!(token, opts = {}) ⇒ Boolean

Check-in to Dead Man’s Snitch, exceptions are raised on failures.

Examples:

Snitch.snitch("c2354d53d2")
# => true

Parameters:

  • token (String)

    The unique Snitch token to check-in with. This can be found on the Setup page as the last part of the HTTP check-in url. For example, c2354d53d2 is the token in nosnch.in/c2354d53d2.

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :message (String)

    Text message to include with the check-in. The message is limited to 256 characters.

  • :timeout (Float, Fixnum)

    Number of seconds to wait for a response from the server. Default is 5 seconds.

Returns:

  • (Boolean)

    if the check-in succeeded.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/snitcher.rb', line 28

def snitch!(token, opts = {})
  uri       = URI.parse(checkin_url(opts, token))
  uri.query = URI.encode_www_form(m: opts[:message]) if opts[:message]

  opts = initialize_opts(opts, uri)

  Net::HTTP.start(uri.host, uri.port, opts) do |http|
    request = Net::HTTP::Get.new(uri.request_uri)
    request["User-Agent"] = user_agent

    response = http.request(request)
    response.is_a?(Net::HTTPSuccess)
  end
end