Class: Glassfrog::Metric

Inherits:
Base
  • Object
show all
Defined in:
lib/glassfrog/metric.rb

Overview

Encapsulates GlassFrog Metrics.

Constant Summary collapse

PATH =
'/metrics'
TYPE =
:metrics

Instance Attribute Summary collapse

Attributes inherited from Base

#id

Class Method Summary collapse

Methods inherited from Base

#==, #hashify, #initialize

Methods included from Utils

#extract_id, #parameterize, #symbolize_keys

Constructor Details

This class inherits a constructor from Glassfrog::Base

Instance Attribute Details

#descriptionString

Returns:

  • (String)


13
14
15
# File 'lib/glassfrog/metric.rb', line 13

def description
  @description
end

#frequencyString

Returns:

  • (String)


13
14
15
# File 'lib/glassfrog/metric.rb', line 13

def frequency
  @frequency
end

#globalBoolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/glassfrog/metric.rb', line 15

def global
  @global
end

Returns:

  • (String)


13
14
15
# File 'lib/glassfrog/metric.rb', line 13

def link
  @link
end

Returns:

  • (Hash)


17
18
19
# File 'lib/glassfrog/metric.rb', line 17

def links
  @links
end

#role_nameString

Returns:

  • (String)


13
14
15
# File 'lib/glassfrog/metric.rb', line 13

def role_name
  @role_name
end

Class Method Details

.delete(client, options) ⇒ Boolean

Sends a DELETE request to delete a Metric on GlassFrog.

Parameters:

  • client (Glassforg::Client)

    The client that will send the request. Contains the API key.

  • options (Hash, Glassfrog::Base)

    The options containing the ID of the Metric to delete.

Returns:

  • (Boolean)

    Whether the request failed or not.



61
62
63
64
# File 'lib/glassfrog/metric.rb', line 61

def self.delete(client, options)
  path = PATH + '/' + options.delete(:id).to_s
  response = Glassfrog::REST::Delete.delete(client, path, options)
end

.get(client, options) ⇒ Array<Glassfrog::Metric>

Sends a GET request for Metric(s) to GlassFrog.

Parameters:

  • client (Glassfrog::Client)

    The client that will send the request. Contains the API key.

  • options (Hash, Glassfrog::Base)

    The options used to find the correct Metrics(s).

Returns:



27
28
29
30
# File 'lib/glassfrog/metric.rb', line 27

def self.get(client, options)
  response = Glassfrog::REST::Get.irregular_get(client, TYPE, PATH, options)
  response[TYPE] ? response[TYPE].map { |object| self.new(object) } : []
end

.patch(client, identifier, options) ⇒ Boolean

Sends a PATCH request to update a Metric on GlassFrog.

Parameters:

  • client (Glassforg::Client)

    The client that will send the request. Contains the API key.

  • identifier (Integer)

    The ID of the Metric to be updated.

  • options (Hash, Glassfrog::Base)

    The options used to update the Metric.

Returns:

  • (Boolean)

    Whether the request failed or not.



50
51
52
53
# File 'lib/glassfrog/metric.rb', line 50

def self.patch(client, identifier, options)
  options = Glassfrog::REST::Patch.formify(parse_options(options), self)
  response = Glassfrog::REST::Patch.patch(client, PATH + '/' + identifier.to_s, options)
end

.post(client, options) ⇒ Array<Glassfrog::Metric>

Sends a POST request to create a Metric on GlassFrog.

Parameters:

  • client (Glassforg::Client)

    The client that will send the request. Contains the API key.

  • options (Hash, Glassforg::Base)

    The options used to create the new Metrics.

Returns:



38
39
40
41
# File 'lib/glassfrog/metric.rb', line 38

def self.post(client, options)
  response = Glassfrog::REST::Post.post(client, PATH, { TYPE => [parse_options(options)] })
  response[TYPE] ? response[TYPE].map { |object| self.new(object) } : []
end