Commit 41eef88b authored by John E. Vincent's avatar John E. Vincent

exposing watchers to API

parent 7fc0daa4
......@@ -62,7 +62,7 @@ module Noah
load File.join(File.dirname(__FILE__), 'service_routes.rb')
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.join(File.dirname(__FILE__), 'watcher_routes.rb')
#load File.joint(File.dirname(__FILE__), 'ephemeral_routes.rb')
end
......
......@@ -19,6 +19,14 @@ class Noah::App
end
end
put '/a/:appname/watch' do |appname|
required_params = ["endpoint"]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort) ? (a = Noah::Application.find(:name => appname).first) : (raise "Missing Parameters")
a.nil? ? (halt 404) : (w = a.watch!(:endpoint => data['endpoint']))
w.to_json
end
put '/a/:appname/?' do |appname|
required_params = ["name"]
data = JSON.parse(request.body.read)
......
......@@ -38,6 +38,14 @@ class Noah::App
end
end
put '/c/:configname/watch' do |configname|
required_params = ["endpoint"]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort) ? (c = Noah::Configuration.find(:name => configname).first) : (raise "Missing Parameters")
c.nil? ? (halt 404) : (w = c.watch!(:endpoint => data['endpoint']))
w.to_json
end
put '/c/:appname/:element?' do |appname, element|
app = Noah::Application.find_or_create(:name => appname)
config = Noah::Configuration.find_or_create(:name => element, :application_id => app.id)
......
......@@ -5,6 +5,10 @@ class Noah::App
# Eventually I'll move to root path
end
put '/e/*/watch' do
# Logic for adding watches to ephemerals
end
put '/e/*' do
# Some logic for creating ephemerals
end
......
......@@ -33,6 +33,14 @@ class Noah::App
end
end
put '/h/:hostname/watch' do |hostname|
required_params = ["endpoint"]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort) ? (h = Noah::Host.find(:name => hostname).first) : (raise "Missing Parameters")
h.nil? ? (halt 404) : (w = h.watch!(:endpoint => data['endpoint']))
w.to_json
end
put '/h/:hostname/?' do |hostname|
required_params = ["name", "status"]
data = JSON.parse(request.body.read)
......
......@@ -25,7 +25,7 @@ module Noah
end
def to_hash
h = {:pattern => pattern, :endpoint => endpoint, :created_at => created_at, :updated_at => updated_at}
h = {:pattern => pattern, :name => name, :endpoint => endpoint, :created_at => created_at, :updated_at => updated_at}
super.merge(h)
end
......
......@@ -30,6 +30,14 @@ class Noah::App
end
end
put '/s/:servicename/watch' do |servicename|
required_params = ["endpoint"]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort) ? (s = Noah::Service.find(:name => servicename).first) : (raise "Missing Parameters")
s.nil? ? (halt 404) : (w = s.watch!(:endpoint => data['endpoint']))
w.to_json
end
put '/s/:servicename/?' do |servicename|
required_params = ["status", "host", "name"]
data = JSON.parse(request.body.read)
......
module Noah
VERSION = "0.0.7"
VERSION = "0.0.9"
end
class Noah::App
get '/w/?' do
w = Noah::Watcher.all.sort_by(:pattern)
if w.size == 0
halt 404
else
w.to_json
end
end
end
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "Using the Watcher API", :reset_redis => true do
before(:each) do
endpoint = 'http://localhost:4567/webhook'
Ohm.redis.flushdb
a = Noah::Application.create :name => 'fooapp'
a.watch! :endpoint => endpoint
c = Noah::Configuration.create :name => 'fooconfig'
c.watch! :endpoint => endpoint
h = Noah::Host.create :name => 'localhost', :status => 'up'
h.watch! :endpoint => endpoint
s = Noah::Service.create :name => 'localhostservice', :status => 'up', :host => h
s.watch! :endpoint => endpoint
end
after(:all) do
Ohm.redis.flushdb
end
describe "calling" do
describe "GET" do
it "all watches should work" do
get '/w'
last_response.should be_ok
response = last_response.should return_json
response.is_a?(Array).should == true
response.size.should == 4
end
end
end
end
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