Class: Outbound::Client
Constant Summary
Constants included from Defaults
Instance Method Summary collapse
- #disable(platform, user_id, token) ⇒ Object
- #identify(user_id, info = {}) ⇒ 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 = {}, timestamp = Time.now.to_i) ⇒ Object
Constructor Details
#initialize(api_key, logger) ⇒ Client
Returns a new instance of Client.
116 117 118 119 |
# File 'lib/outbound.rb', line 116 def initialize(api_key, logger) @api_key = api_key @logger = logger end |
Instance Method Details
#disable(platform, user_id, token) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/outbound.rb', line 168 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 = {}) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/outbound.rb', line 121 def identify(user_id, info={}) 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) 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
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/outbound.rb', line 190 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 = {}, timestamp = Time.now.to_i) ⇒ Object
139 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 |
# File 'lib/outbound.rb', line 139 def track(user_id, event, properties={}, user_info={}, =Time.now.to_i) 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} 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 data[:timestamp] = puts return post(@api_key, '/track', data) end |