Sha256: 4cff17904ab027a784ae3d78d2ca93dddb09f72c1f8ecc1a430347a4a31e7bc3
Contents?: true
Size: 895 Bytes
Versions: 1
Compression:
Stored size: 895 Bytes
Contents
require 'rubygems' require 'net/http' require 'uri' require 'json' class Eotb def self.configure(api_key, host = '127.0.0.1', port = '3000') @@uri = URI.parse('http://' + host + ':' + port + '/apps/' + api_key + '/events') @@post = Net::HTTP::Post.new(@@uri.path) @@api_key = { "event[app_id]" => api_key } end def self.register_event(actor, action, subject = {}) actor = { "event[actor]" => format(actor) } action = { "event[action]" => action.to_s } data = {} subject.each { |key, value| data["event[subject][#{key.to_s}]"] = format(value) } event = @@api_key.merge(actor).merge(action).merge(data) @@post.set_form_data(event) Net::HTTP.new(@@uri.host, @@uri.port).start.request(@@post) end def self.format(object) if object.respond_to? :to_json object.to_json else object.inspect end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
eotb-0.4.0 | lib/eotb.rb |