Class: KM

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

Class Method Summary collapse

Class Method Details

.alias(name, alias_to) ⇒ Object

Raises:

  • (ArgumentError)


46
47
48
49
50
51
52
53
54
55
56
# File 'lib/delayed_km.rb', line 46

def alias(name, alias_to)
  raise ArgumentError, "You must set an API key" if !@key
  raise ArgumentError, "You must identify a user first" if !@id
  p = {
      '_n' => alias_to,
      '_p' => name,
      '_k' => @key,
  }

  delay_query("a", p)
end

.api_keyObject



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

def api_key
  @key
end

.get(url) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/delayed_km.rb', line 74

def get(url)
  begin
    return HTTParty.get(url)
  rescue Exception => e
    raise e.exception(e.message)
  end
end

.hostObject



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

def host
  "trk.kissmetrics.com"
end

.identify(id) ⇒ Object



25
26
27
# File 'lib/delayed_km.rb', line 25

def identify(id)
  @id = id
end

.identityObject



9
10
11
# File 'lib/delayed_km.rb', line 9

def identity
  @id
end

.init(key) ⇒ Object



21
22
23
# File 'lib/delayed_km.rb', line 21

def init(key)
  @key = key
end

.record(action, props = {}) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/delayed_km.rb', line 29

def record(action, props = {})
  raise ArgumentError, "You must set an API key" if !@key
  raise ArgumentError, "You must identify a user first" if !@id
  props = hash_keys_to_str(props)
  props.update("_n" => action)
  props.update("_p" => @id)
  props.update("_k" => @key)

  if props["_t"]
    props['_d'] = "1"
  else
    props['_t'] = Time.now.to_i.to_s
  end

  delay_query("e", props)
end

.set(props = {}) ⇒ Object

Raises:

  • (ArgumentError)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/delayed_km.rb', line 58

def set(props = {})
  raise ArgumentError, "You must set an API key" if !@key
  raise ArgumentError, "You must identify a user first" if !@id
  props = hash_keys_to_str(props)

  props.update("_p" => @id)
  props.update("_k" => @key)

  if props["_t"]
    props['_d'] = "1"
  else
    props['_t'] = Time.now.to_i.to_s
  end
  delay_query("s", props)
end