Class: Snitcher::API::Snitch

Inherits:
Object
  • Object
show all
Defined in:
lib/snitcher/api/snitch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ Object

Create a new Snitch from an API response.

Examples:

payload = {
  "token" => "c2354d53d3",
  "href" => "/v1/snitches/c2354d53d3",
  "name" => "Daily Backups",
  "tags" => [
    "production",
    "critical"
  ],
  "status" => "pending",
  "checked_in_at" => "",
  "type": {
    "interval" => "daily"
  },
  "check_in_url" => "https://nosnch.in/c2354d53d3",
  "created_at" => "2015-08-15T12:15:00.234Z",
  "notes" => "Important user data.",
}

Snitcher::API::Snitch.new(payload)
# => #<Snitcher::API::Snitch...>


58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/snitcher/api/snitch.rb', line 58

def initialize(payload)
  @token     = payload["token"]
  @name      = payload["name"]
  @tags      = payload["tags"]
  @status    = payload["status"]
  @interval  = payload["type"]["interval"]
  @notes     = payload["notes"]

  @created_at    = payload["created_at"]
  @check_in_url  = payload["check_in_url"]
  @checked_in_at = payload["checked_in_at"]
end

Instance Attribute Details

#check_in_urlString

Returns url used to check-in in the Snitch as healthy.

Returns:

  • (String)

    url used to check-in in the Snitch as healthy.



24
25
26
# File 'lib/snitcher/api/snitch.rb', line 24

def check_in_url
  @check_in_url
end

#checked_in_atString

Returns when the Snitch last checked_in.

Returns:

  • (String)

    when the Snitch last checked_in



16
17
18
# File 'lib/snitcher/api/snitch.rb', line 16

def checked_in_at
  @checked_in_at
end

#created_atString

Returns when the Snitch was created.

Returns:

  • (String)

    when the Snitch was created.



27
28
29
# File 'lib/snitcher/api/snitch.rb', line 27

def created_at
  @created_at
end

#intervalString

Returns how often Dead Man’s Snitch expects to hear from the Snitch. One of “15_minute”, “30_minute”, “hourly”, “daily”, “weekly”, or “monthly”.

Returns:

  • (String)

    how often Dead Man’s Snitch expects to hear from the Snitch. One of “15_minute”, “30_minute”, “hourly”, “daily”, “weekly”, or “monthly”.



21
22
23
# File 'lib/snitcher/api/snitch.rb', line 21

def interval
  @interval
end

#nameString

Returns useful name for the Snitch to help identify it.

Returns:

  • (String)

    useful name for the Snitch to help identify it.



6
7
8
# File 'lib/snitcher/api/snitch.rb', line 6

def name
  @name
end

#notesString

Returns generic notes for the Snitch. Useful for specifying actions to take when a Snitch stops reporting.

Returns:

  • (String)

    generic notes for the Snitch. Useful for specifying actions to take when a Snitch stops reporting.



31
32
33
# File 'lib/snitcher/api/snitch.rb', line 31

def notes
  @notes
end

#statusString

Returns the current reporting status of the Snitch. One of “pending”, “healthy”, “paused”, “failed”, or “errored”.

Returns:

  • (String)

    the current reporting status of the Snitch. One of “pending”, “healthy”, “paused”, “failed”, or “errored”.



13
14
15
# File 'lib/snitcher/api/snitch.rb', line 13

def status
  @status
end

#tagsArray<String>

Returns list of tags on the Snitch.

Returns:

  • (Array<String>)

    list of tags on the Snitch.



9
10
11
# File 'lib/snitcher/api/snitch.rb', line 9

def tags
  @tags
end

#tokenString

Returns unique token used to identify a Snitch.

Returns:

  • (String)

    unique token used to identify a Snitch.



3
4
5
# File 'lib/snitcher/api/snitch.rb', line 3

def token
  @token
end