From: Maros Zatko <mzatko(a)redhat.com>
Includes routes, controller + view, test
---
src/app/controllers/api/entrypoint_controller.rb | 32 ++++++++++++
src/app/views/api/entrypoint/index.xml.haml | 6 ++
src/config/routes.rb | 1 +
.../controllers/api/entrypoint_controller_spec.rb | 52 ++++++++++++++++++++
4 files changed, 91 insertions(+), 0 deletions(-)
create mode 100644 src/app/controllers/api/entrypoint_controller.rb
create mode 100644 src/app/views/api/entrypoint/index.xml.haml
create mode 100644 src/spec/controllers/api/entrypoint_controller_spec.rb
diff --git a/src/app/controllers/api/entrypoint_controller.rb
b/src/app/controllers/api/entrypoint_controller.rb
new file mode 100644
index 0000000..9d415de
--- /dev/null
+++ b/src/app/controllers/api/entrypoint_controller.rb
@@ -0,0 +1,32 @@
+#
+# Copyright (C) 2011 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at
http://www.gnu.org/copyleft/gpl.html.
+
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+module Api
+ class EntrypointController < ApplicationController
+ before_filter :require_user
+
+ respond_to :xml
+ layout :false
+
+ def index
+ end
+ end
+end
diff --git a/src/app/views/api/entrypoint/index.xml.haml
b/src/app/views/api/entrypoint/index.xml.haml
new file mode 100644
index 0000000..f3a1d92
--- /dev/null
+++ b/src/app/views/api/entrypoint/index.xml.haml
@@ -0,0 +1,6 @@
+!!! XML
+%api{:href => api_url}
+ %images{:href => api_images_url}
+ %builds{:href => api_builds_url}
+ %provider_images{:href => api_provider_images_url}
+ %target_images{:href => api_target_images_url}
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 45c8223..1fc3d47 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -182,6 +182,7 @@ Conductor::Application.routes.draw do
post 'create'
end
+ get 'api', :controller => 'api/entrypoint', :action =>
'index'
namespace :api do
resources :images do
resources :builds
diff --git a/src/spec/controllers/api/entrypoint_controller_spec.rb
b/src/spec/controllers/api/entrypoint_controller_spec.rb
new file mode 100644
index 0000000..36a8c86
--- /dev/null
+++ b/src/spec/controllers/api/entrypoint_controller_spec.rb
@@ -0,0 +1,52 @@
+#
+# Copyright (C) 2011 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at
http://www.gnu.org/copyleft/gpl.html.
+
+require 'spec_helper'
+
+describe Api::EntrypointController do
+ render_views
+
+ before(:each) do
+ @admin_permission = FactoryGirl.create :admin_permission
+ @admin = @admin_permission.user
+ mock_warden(@admin)
+ end
+
+ context "XML format response for " do
+ before do
+ send_and_accept_xml
+ end
+
+ describe "#index" do
+ before do
+ get :index
+ end
+
+ it { response.should be_success }
+ it { response.headers['Content-Type'].should
include("application/xml") }
+ it {
+ resp = Hash.from_xml(response.body)
+ api = resp['api']
+ api['images']['href'].should == api_images_url
+ api['builds']['href'].should == api_builds_url
+ api['target_images']['href'].should == api_target_images_url
+ api['provider_images']['href'].should == api_provider_images_url
+ }
+ end
+ end
+end
--
1.7.6.2