Method: Snitcher::API::Client#snitches

Defined in:
lib/snitcher/api/client.rb

#snitches(filters = {}) ⇒ Array<Snitcher::API::Snitch>

Get the list snitches on the account

Examples:

List the Snitches on an account

client.snitches
# => [ #<Snitcher::API::Snitch:...>, #<Snitcher::API::Snitch:...> ]

List Snitches with a specific tag

client.snitches(tags: "production")
# => [ #<Snitcher::API::Snitch:...>, #<Snitcher::API::Snitch:...> ]

List Snitches with multiple tags

client.snitches(tags: ["production", "critical"])
# => [ #<Snitcher::API::Snitch:...>, #<Snitcher::API::Snitch:...> ]

Parameters:

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

Options Hash (filters):

  • tags (String, Array<String>)

    only return Snitches that are tagged with all of the given tags. For example, if a Snitch is tagged with “production” and “critical” it will be returned when filtering by “production”, “critical”, or [“production”, “critical”] but not [“production”, “backups”].

Returns:

Raises:

  • (Timeout::Error)

    if the API request took too long to execute.

  • (Snitcher::API::Error)

    if any API errors occur.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/snitcher/api/client.rb', line 64

def snitches(filters = {})
  query = {}

  # Tags allow for labeling Snitches for better categorization. This allows
  # filtering by a set of tags.
  if tags = filters[:tags]
    tags = Array(tags).flatten
    query[:tags] = tags.map(&:strip).compact.uniq.join(",")
  end

  # JSON array of Snitch attributes
  response = get("/v1/snitches", query)

  # Convert the attributes hashes into Objects
  response.map! do |snitch|
    Snitcher::API::Snitch.new(snitch)
  end
end