Class: Outbound::Client
Constant Summary
Constants included from Defaults
Instance Method Summary collapse
- #identify(user_id, info = {}, attributes = {}) ⇒ Object
-
#initialize(api_key, logger) ⇒ Client
constructor
A new instance of Client.
- #track(user_id, event, properties = {}, user_info = {}, user_attributes = {}) ⇒ Object
Constructor Details
#initialize(api_key, logger) ⇒ Client
Returns a new instance of Client.
84 85 86 87 |
# File 'lib/outbound.rb', line 84 def initialize api_key, logger @api_key = api_key @logger = logger end |
Instance Method Details
#identify(user_id, info = {}, attributes = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/outbound.rb', line 89 def identify user_id, info={}, attributes={} unless user_id.is_a? String or user_id.is_a? Numeric res = Result.new Outbound::ERROR_USER_ID, false @logger.error res.error return res end user_data = {:user_id => user_id} begin user = user(info, attributes) user_data = user_data.merge user rescue @logger.error "Could not use user info (#{info}) and/or user attributes #{attributes} given to identify call." end return post(@api_key, '/identify', user_data) end |
#track(user_id, event, properties = {}, user_info = {}, user_attributes = {}) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/outbound.rb', line 107 def track user_id, event, properties={}, user_info={}, user_attributes={} unless user_id.is_a? String or user_id.is_a? Numeric res = Result.new Outbound::ERROR_USER_ID, false @logger.error res.error return res end unless event.is_a? String res = Result.new Outbound::ERROR_EVENT_NAME, false @logger.error res.error return res end data = {:user_id => user_id, :event => event} begin user = user(user_info, user_attributes) if user.length > 0 data[:user] = user end rescue @logger.error "Could not use user info (#{user_info}) and/or user attributes #{user_attributes} given to track call." end if properties.is_a? Hash if properties.length > 0 data[:properties] = properties end else @logger.error "Could not use event properties (#{properties}) given to track call." end return post(@api_key, '/track', data) end |