Class: Outbound::Client
Constant Summary
Constants included from Defaults
Instance Method Summary collapse
- #disable(platform, user_id, token) ⇒ Object
- #identify(user_id, info = {}, attributes = {}) ⇒ Object
-
#initialize(api_key, logger) ⇒ Client
constructor
A new instance of Client.
- #register(platform, user_id, token) ⇒ Object
- #track(user_id, event, properties = {}, user_info = {}, user_attributes = {}) ⇒ Object
Constructor Details
#initialize(api_key, logger) ⇒ Client
Returns a new instance of Client.
117 118 119 120 |
# File 'lib/outbound.rb', line 117 def initialize api_key, logger @api_key = api_key @logger = logger end |
Instance Method Details
#disable(platform, user_id, token) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/outbound.rb', line 175 def disable platform, user_id, token 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 token.is_a? String res = Result.new Outbound::ERROR_TOKEN, false @logger.error res.error return res end unless [Outbound::APNS, Outbound::GCM].include? platform res = Result.new Outbound::ERROR_PLATFORM, false @logger.error res.error return res end return post(@api_key, "/#{platform}/disable", {:token => token, :user_id => user_id}) end |
#identify(user_id, info = {}, attributes = {}) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/outbound.rb', line 122 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 |
#register(platform, user_id, token) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/outbound.rb', line 197 def register platform, user_id, token 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 token.is_a? String res = Result.new Outbound::ERROR_TOKEN, false @logger.error res.error return res end unless [Outbound::APNS, Outbound::GCM].include? platform res = Result.new Outbound::ERROR_PLATFORM, false @logger.error res.error return res end return post(@api_key, "/#{platform}/register", {:token => token, :user_id => user_id}) end |
#track(user_id, event, properties = {}, user_info = {}, user_attributes = {}) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/outbound.rb', line 140 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 |