Class: Smyte::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/smyte/client.rb', line 9

def initialize(options=nil)
  options ||= {}
  [:api_key, :api_secret, :logger, :enabled].each do |key|
    if options.has_key?(key)
      value = options[key]
    else
      value = Smyte.send(key)
    end
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



7
8
9
# File 'lib/smyte/client.rb', line 7

def api_key
  @api_key
end

#api_secretObject (readonly)

Returns the value of attribute api_secret.



7
8
9
# File 'lib/smyte/client.rb', line 7

def api_secret
  @api_secret
end

#enabledObject (readonly)

Returns the value of attribute enabled.



7
8
9
# File 'lib/smyte/client.rb', line 7

def enabled
  @enabled
end

#loggerObject (readonly)

Returns the value of attribute logger.



7
8
9
# File 'lib/smyte/client.rb', line 7

def logger
  @logger
end

Instance Method Details

#action(event_name, payload) ⇒ Object



21
22
23
24
25
26
# File 'lib/smyte/client.rb', line 21

def action(event_name, payload)
  return true if !enabled

  process(event_name, payload, "/v2/action")
  true # any success is just true - nothing else to know
end

#classify(event_name, payload, options = {}) ⇒ Object



28
29
30
31
32
33
# File 'lib/smyte/client.rb', line 28

def classify(event_name, payload, options={})
  return Smyte::Classification.allowed if !enabled

  response = process(event_name, payload, "/v2/action/classify")
  Smyte::Classification.new(response, options)
end