Class: Bothan::Metrics

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/bothan/metrics.rb

Instance Method Summary collapse

Constructor Details

#initialize(username, password, endpoint) ⇒ Metrics

Returns a new instance of Metrics.



6
7
8
9
# File 'lib/bothan/metrics.rb', line 6

def initialize(username, password, endpoint)
  self.class.base_uri endpoint
  self.class.basic_auth username, password
end

Instance Method Details

#allObject



11
12
13
# File 'lib/bothan/metrics.rb', line 11

def all
  (self.class.get('/metrics').parsed_response || {})['metrics']
end

#create_geo(name, features, time = DateTime.now) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/bothan/metrics.rb', line 51

def create_geo(name, features, time = DateTime.now)
  value = {
    type: "FeatureCollection",
    features: features
  }

  create_metric(name, value, time)
end

#create_multiple(name, values, time = DateTime.now) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/bothan/metrics.rb', line 43

def create_multiple(name, values, time = DateTime.now)
  value = {
    total: values
  }

  create_metric(name, value, time)
end

#create_single(name, value, time = DateTime.now) ⇒ Object Also known as: create



27
28
29
# File 'lib/bothan/metrics.rb', line 27

def create_single(name, value, time = DateTime.now)
  create_metric(name, value, time)
end

#create_target(name, actual, annual_target, ytd_target = nil, time = DateTime.now) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/bothan/metrics.rb', line 33

def create_target(name, actual, annual_target, ytd_target = nil, time = DateTime.now)
  value = {
    actual: actual,
    annual_target: annual_target,
    ytd_target: ytd_target
  }.delete_if { |k, v| v.nil? }

  create_metric(name, value, time)
end

#find(metric, from = nil, to = nil) ⇒ Object

Raises:



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bothan/metrics.rb', line 15

def find(metric, from = nil, to = nil)
  if from.nil? && to.nil?
    metric = self.class.get("/metrics/#{metric}").parsed_response
  elsif !from.nil? && to.nil?
    metric = self.class.get("/metrics/#{metric}/#{from}").parsed_response
  elsif !from.nil? && !to.nil?
    metric = self.class.get("/metrics/#{metric}/#{from}/#{to}").parsed_response
  end
  raise MetricNotFound if metric.nil?
  metric['count'] ? metric['values'] : metric
end