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",
  "alert_email" => [],
  "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...>


69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/snitcher/api/snitch.rb', line 69

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"]
  @alert_email   = payload["alert_email"] || []
  @check_in_url  = payload["check_in_url"]
  @checked_in_at = payload["checked_in_at"]
end

Instance Attribute Details

#alert_emailArray<String>

alert_email is a list of email addresses that will be notified when this Snitch goes missing, errors, or becomes healthy again. When this is set, only the email addresses in the list will be notified. When the list is empty then all team members will be alerted by default.

Returns:

  • (Array<String>)

    override list of email addresses



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

def alert_email
  @alert_email
end

#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.



34
35
36
# File 'lib/snitcher/api/snitch.rb', line 34

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



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

def checked_in_at
  @checked_in_at
end

#created_atString

Returns when the Snitch was created.

Returns:

  • (String)

    when the Snitch was created.



37
38
39
# File 'lib/snitcher/api/snitch.rb', line 37

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”.



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

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.



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

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.



41
42
43
# File 'lib/snitcher/api/snitch.rb', line 41

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”.



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

def status
  @status
end

#tagsArray<String>

Returns list of tags on the Snitch.

Returns:

  • (Array<String>)

    list of tags on the Snitch.



11
12
13
# File 'lib/snitcher/api/snitch.rb', line 11

def tags
  @tags
end

#tokenString

Returns unique token used to identify a Snitch.

Returns:

  • (String)

    unique token used to identify a Snitch.



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

def token
  @token
end