---
server/server.rb | 29 +++++++++++++++++++++++++++--
server/views/api/capabilities.html.haml | 14 ++++++++++++++
server/views/api/capabilities.xml.haml | 6 ++++++
server/views/api/show.html.haml | 4 ++--
server/views/api/show.xml.haml | 2 +-
5 files changed, 50 insertions(+), 5 deletions(-)
create mode 100644 server/views/api/capabilities.html.haml
create mode 100644 server/views/api/capabilities.xml.haml
diff --git a/server/server.rb b/server/server.rb
index b8720a9..9a4dcda 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -28,6 +28,8 @@ end
# whatever you want (eg. if you running API behind NAT)
HOSTNAME=ENV['API_HOST'] ? ENV['API_HOST'] : nil
+API_VERSION = 0.1
+
error Deltacloud::Validation::Failure do
report_error(400, "validation_failure")
end
@@ -49,7 +51,6 @@ Sinatra::Application.register Sinatra::RespondTo
get '/' do redirect url_for('/api'); end
get '/api\/?' do
- @version = 0.1
if params[:force_auth]
return [401, 'Authentication failed'] unless
driver.valid_credentials?(credentials)
end
@@ -57,7 +58,7 @@ get '/api\/?' do
format.xml { haml :"api/show" }
format.json do
{ :api => {
- :version => @version,
+ :version => API_VERSION,
:driver => DRIVER,
:links => entry_points.collect { |l| { :rel => l[0], :href =>
l[1]} }
}
@@ -67,6 +68,30 @@ get '/api\/?' do
end
end
+get '/api/capabilities' do
+ @capabilities = { }
+ collections.values.each do |collection|
+ collection_capabilities = []
+ collection.operations.each do |name, operation|
+ collection_capabilities << name if operation.has_capability?(driver)
+ end
+ @capabilities[collection.name] = collection_capabilities
+ end
+
+ respond_to do |format|
+ format.xml { haml :"api/capabilities" }
+ format.json do
+ { :api => {
+ :version => API_VERSION,
+ :driver => DRIVER,
+ :capabilities => @capabilities
+ }
+ }.to_json
+ end
+ format.html { haml :"api/capabilities" }
+ end
+end
+
# Rabbit DSL
collection :realms do
diff --git a/server/views/api/capabilities.html.haml
b/server/views/api/capabilities.html.haml
new file mode 100644
index 0000000..77f2291
--- /dev/null
+++ b/server/views/api/capabilities.html.haml
@@ -0,0 +1,14 @@
+%h1
+ API v#{API_VERSION} Capabilities for #{DRIVER}
+
+%ul
+ - @capabilities.keys.sort_by { |k| k.to_s }.each do |key|
+ %li
+ = link_to key.to_s.gsub('_', ' ').titlecase, url_for("/api/#{key}")
+ %dl
+ - @capabilities[key].each do |capability|
+ %dt
+ = capability
+ %li
+ %strong
+ %a{:href => url_for("/api/docs")} Documentation (v#{API_VERSION})
diff --git a/server/views/api/capabilities.xml.haml
b/server/views/api/capabilities.xml.haml
new file mode 100644
index 0000000..01dea85
--- /dev/null
+++ b/server/views/api/capabilities.xml.haml
@@ -0,0 +1,6 @@
+%api_capabilities{ :version=>API_VERSION, :driver=>DRIVER }
+ - @capabilities.keys.each do |key|
+ %link{ :rel => key, :href => url_for("/api/#{key}") }
+ - @capabilities[key].each do |capability|
+ %capability{ :name => capability }
+
diff --git a/server/views/api/show.html.haml b/server/views/api/show.html.haml
index 0077972..fb0af93 100644
--- a/server/views/api/show.html.haml
+++ b/server/views/api/show.html.haml
@@ -1,5 +1,5 @@
%h1
- API v...@version}
+ API v#{API_VERSION}
%ul
- collections.keys.sort_by { |k| k.to_s }.each do |key|
@@ -12,4 +12,4 @@
= op
%li
%strong
- %a{:href => url_for("/api/docs")} Documentation (v...@version})
+ %a{:href => url_for("/api/docs")} Documentation (v#{API_VERSION})
diff --git a/server/views/api/show.xml.haml b/server/views/api/show.xml.haml
index 70c26c9..d01d80b 100644
--- a/server/views/api/show.xml.haml
+++ b/server/views/api/show.xml.haml
@@ -1,4 +1,4 @@
-%api{ :version=>@version, :driver=>DRIVER }
+%api{ :version=>API_VERSION, :driver=>DRIVER }
- for entry_point in entry_points
%link{ :rel=>entry_point[0], :href=>entry_point[1] }
- for feature in driver.features(entry_point[0])
--
1.7.2.3