lib/eotb.rb in eotb-0.0.2 vs lib/eotb.rb in eotb-0.1.0
- old
+ new
@@ -1,22 +1,22 @@
-require 'json'
require 'net/http'
+require 'rubygems'
+require 'json'
class Eotb
- def initialize(api_key, host = '127.0.0.1:3000')
- @api_key = api_key
- @host = host
- @array = []
+ attr_reader :http
+
+ def initialize(api_key, host = '127.0.0.1', port = '3000')
+ @path = '/apps/' + api_key.to_s + '/events'
+ @http = Net::HTTP.new(host, port)
end
- def to_json(array = @array)
+ def to_json(array)
JSON.generate(array)
end
- def register_event(actor, action, subject)
- @array << actor << action << subject
- @array.to_json
- # @array.clear
+ def register_event(actor, action, subject = nil)
+ @http.post(@path, [actor, action, subject].compact.to_json)
end
end
\ No newline at end of file