Sha256: 09565e7116181dfc6032ced78ecdbdbfbd09cef10832078469ab0738e55c8d08

Contents?: true

Size: 855 Bytes

Versions: 1

Compression:

Stored size: 855 Bytes

Contents

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["publishable_key"] = api_key
    URI.escape Base64.encode64(JSON.generate(data))
  end

  def endpoint
    @rm_sandbox ? "http://localhost:3000" : "https://secure.remetric.com"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
remetric-0.0.13 lib/remetric.rb