Class: FnordMetric::API

Inherits:
Object
  • Object
show all
Defined in:
lib/fnordmetric/api.rb

Constant Summary collapse

@@opts =
nil

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ API

Returns a new instance of API.



5
6
7
8
# File 'lib/fnordmetric/api.rb', line 5

def initialize(opts={})
  @@opts = FnordMetric.default_options(opts)
  connect
end

Instance Method Details

#connectObject



10
11
12
# File 'lib/fnordmetric/api.rb', line 10

def connect
  @redis = Redis.connect(:url => @@opts[:redis_url])
end

#disconnectObject



28
29
30
# File 'lib/fnordmetric/api.rb', line 28

def disconnect
  @redis.quit
end

#event(event_data) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fnordmetric/api.rb', line 14

def event(event_data)
  begin
    if event_data.is_a?(Hash)
      event_data = event_data.to_json
    else
      JSON.parse(event_data) # void ;)
    end
  rescue JSON::ParserError
    FnordMetric.log("event_lost: can't parse json")
  else
    push_event(get_next_uuid, event_data)
  end
end