Class: SimpleKM::Client

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

Constant Summary collapse

DEFAULT_URI_PARAMS =
{
  scheme: "https",
  host: "trk.kissmetrics.com",
  path: "e"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
# File 'lib/simple_km/client.rb', line 10

def initialize options
  @api_key = options[:api_key]
  @user_identifier = options[:user_identifier]

  raise ArgumentError unless api_key && user_identifier
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



8
9
10
# File 'lib/simple_km/client.rb', line 8

def api_key
  @api_key
end

#user_identifierObject (readonly)

Returns the value of attribute user_identifier.



8
9
10
# File 'lib/simple_km/client.rb', line 8

def user_identifier
  @user_identifier
end

Instance Method Details

#record(action, data) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/simple_km/client.rb', line 17

def record action, data
  data ||= {}
  raise ArgumentError unless data.is_a?(Hash)

  query_values = {
    _k: api_key,
    _p: user_identifier,
    _n: action,
  }.merge(data)
  uri = Addressable::URI.new(DEFAULT_URI_PARAMS.merge(query_values: query_values))

  HTTParty.get(uri.to_s)
end