Class: RevRise::Base
- Inherits:
-
Object
- Object
- RevRise::Base
- Defined in:
- lib/revrise.rb
Instance Method Summary collapse
-
#initialize(token) ⇒ Base
constructor
A new instance of Base.
- #track(event_name, properties) ⇒ Object
Constructor Details
#initialize(token) ⇒ Base
Returns a new instance of Base.
13 14 15 |
# File 'lib/revrise.rb', line 13 def initialize( token ) @endpoint = "http://api.revrise.com/events/track?token=" + token end |
Instance Method Details
#track(event_name, properties) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/revrise.rb', line 17 def track( event_name, properties ) event = { :name => event_name, :properties => properties }.to_json data = Base64.encode64(event).gsub(/\n/, '') url = "#{@endpoint}&data=#{data}" uri = URI(url) http = Net::HTTP.new(uri.host, uri.port) size = 1000 headers = { 'Range' => "bytes=#{size}-" } response = begin http.get(uri.to_s, headers) rescue *HTTP_ERRORS => e #log :error, "Unable to contact the RevRise server. HTTP Error=#{e}" nil end case response when Net::HTTPSuccess then #log :info, "Success: #{response.class}", response else #log :error, "Failure: #{response.class}", response puts "Unable to reach RevRise API. Check status" end end |