Class: Files::FrontendMetric

Inherits:
Object
  • Object
show all
Defined in:
lib/files.com/models/frontend_metric.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}, options = {}) ⇒ FrontendMetric

Returns a new instance of FrontendMetric.



7
8
9
10
# File 'lib/files.com/models/frontend_metric.rb', line 7

def initialize(attributes = {}, options = {})
  @attributes = attributes || {}
  @options = options || {}
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/files.com/models/frontend_metric.rb', line 5

def attributes
  @attributes
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/files.com/models/frontend_metric.rb', line 5

def options
  @options
end

Class Method Details

.create(params = {}, options = {}) ⇒ Object

Parameters:

metric_type (required) - string - Statsd metric type.  Use `timing` to submit the amount of time something took, or `increment` to increment a counter
subkey (required) - string - Where in statsd to store the metric. The final key in statsd will be `files-react.[environment].[subkey]`
ms - int64 - For timing metrics, the number of milliseconds. Required if `metric_type` is `timing`.


54
55
56
57
58
59
60
61
62
63
# File 'lib/files.com/models/frontend_metric.rb', line 54

def self.create(params = {}, options = {})
  raise InvalidParameterError.new("Bad parameter: metric_type must be an String") if params[:metric_type] and !params[:metric_type].is_a?(String)
  raise InvalidParameterError.new("Bad parameter: subkey must be an String") if params[:subkey] and !params[:subkey].is_a?(String)
  raise InvalidParameterError.new("Bad parameter: ms must be an Integer") if params[:ms] and !params[:ms].is_a?(Integer)
  raise MissingParameterError.new("Parameter missing: metric_type") unless params[:metric_type]
  raise MissingParameterError.new("Parameter missing: subkey") unless params[:subkey]

  response, options = Api.send_request("/frontend_metrics", :post, params, options)
  FrontendMetric.new(response.data, options)
end

Instance Method Details

#metric_typeObject

string - Statsd metric type



13
14
15
# File 'lib/files.com/models/frontend_metric.rb', line 13

def metric_type
  @attributes[:metric_type]
end

#metric_type=(value) ⇒ Object



17
18
19
# File 'lib/files.com/models/frontend_metric.rb', line 17

def metric_type=(value)
  @attributes[:metric_type] = value
end

#msObject

int64 - For timing metrics, the number of milliseconds. Required if metric_type is timing.



31
32
33
# File 'lib/files.com/models/frontend_metric.rb', line 31

def ms
  @attributes[:ms]
end

#ms=(value) ⇒ Object



35
36
37
# File 'lib/files.com/models/frontend_metric.rb', line 35

def ms=(value)
  @attributes[:ms] = value
end

#saveObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/files.com/models/frontend_metric.rb', line 39

def save
  if @attributes[:id]
    raise NotImplementedError.new("The FrontendMetric object doesn't support updates.")
  else
    new_obj = FrontendMetric.create(@attributes, @options)
  end

  @attributes = new_obj.attributes
  true
end

#subkeyObject

string - Where in statsd to store the metric. The final key in statsd will be files-react.[environment].[subkey]



22
23
24
# File 'lib/files.com/models/frontend_metric.rb', line 22

def subkey
  @attributes[:subkey]
end

#subkey=(value) ⇒ Object



26
27
28
# File 'lib/files.com/models/frontend_metric.rb', line 26

def subkey=(value)
  @attributes[:subkey] = value
end