lib/eotb.rb in eotb-0.4.3 vs lib/eotb.rb in eotb-0.4.4
- old
+ new
@@ -3,10 +3,12 @@
require 'uri'
require 'json'
class Eotb
+ METHODS = [:to_actor, :to_subject, :to_json, :to_hash, :inspect]
+
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
@@ -17,20 +19,10 @@
@@post.set_form_data(event)
Net::HTTP.new(@@uri.host, @@uri.port).start.request(@@post)
end
def self.value_format(value)
- if value.respond_to? :to_actor
- value.to_actor
- elsif value.respond_to? :to_subject
- value.to_subject
- elsif value.respond_to? :to_json
- value.to_json
- elsif value.respond_to? :to_hash
- value.to_hash
- else
- value.inspect
- end
+ value.send METHODS.find { |m| m if value.respond_to? m }
end
def self.hash_flatten(hash)
hash.inject({}) do |h, (k, v)|
if v.is_a?(Hash)
\ No newline at end of file