Commit 4386dac7 authored by John E. Vincent's avatar John E. Vincent

ephemeral nodes. no specs yet

parent 48a08b0e
......@@ -63,7 +63,7 @@ module Noah
load File.join(File.dirname(__FILE__), 'application_routes.rb')
load File.join(File.dirname(__FILE__), 'configuration_routes.rb')
load File.join(File.dirname(__FILE__), 'watcher_routes.rb')
#load File.joint(File.dirname(__FILE__), 'ephemeral_routes.rb')
load File.join(File.dirname(__FILE__), 'ephemeral_routes.rb')
end
end
require 'logger'
require 'base64'
class Noah::App
# Stubbing Ephemeral endpoints
get '/e/?' do
halt 404
end
get '/e/*' do
# Some logic to handle splats for ephemerals
# Eventually I'll move to root path
logger = Logger.new(STDOUT)
params["splat"].size == 0 ? (halt 404) : (e=Noah::Ephemeral.find(:path => "/#{params["splat"][0]}").first)
return e.to_json
end
put '/e/*/watch' do
# Logic for adding watches to ephemerals
required_params = ["endpoint"]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort) ? (e = Noah::Watcher.find(:path => params[:splat][0]).first) : (raise "Missing Parameters")
e.nil? ? (halt 404) : (w = e.watch!(:endpoint => data["endpoint"]))
w.to_json
end
put '/e/*' do
# Some logic for creating ephemerals
raise("Data too large") if request.body.size > 512
d = Base64.encode64(request.body.read) || nil
e = Noah::Ephemeral.new(:path => params[:splat][0], :data => d)
e.valid? ? (e.save; e.to_json) : (raise "#{e.errors}")
end
delete '/e/*' do
# See previous two entries
p = params[:splat][0]
e = Noah::Ephemeral.find(:path => p).first
if e
e.delete
r = {"result" => "success", "id" => "#{e.id}", "action" => "delete", "path" => e.name}
r.to_json
else
halt 404
end
end
end
require 'digest/sha1'
require 'base64'
module Noah
class Ephemeral < Model #NYI
attribute :path
attribute :data
attribute :lifetime
index :path
......@@ -17,6 +18,11 @@ module Noah
@name = path
end
def to_hash
data.nil? ? d=nil : d=Base64.decode64(data)
h = {:path => path, :data => d, :created_at => created_at, :updated_at => :updated_at}
super.merge(h)
end
protected
def save_hook
# called after any create,update,delete
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment