require "remetric/version" require "base64" require "json" require "rest_client" class Remetric def initialize api_key, sandbox = false @rm_api_key = api_key @rm_sandbox = sandbox end def api_key @rm_api_key end def track data = {} begin RestClient.get "#{endpoint}/track/img/#{to_base64 data}" rescue { errors: "You are unauthorized." } end end def img data = {} src = "#{endpoint}/track/img/#{to_base64 data}" img = "<img src=\"#{src}\" style=\"display: none; \">" img end def redirect data = {} "#{endpoint}/track/redirect/#{to_base64 data}" end def to_base64 data = {} data["events_api_key"] = api_key URI.escape Base64.encode64(JSON.generate(data)) end def endpoint @rm_sandbox ? "http://localhost:3000" : "https://secure.remetric.com" end end