Mailinglist Archive: yast-commit (2114 mails)

< Previous Next >
[yast-commit] <rest-service> patch_refactor : small fixes to restfull resource
  • From: Martin Kudlvasr <mkudlvasr@xxxxxxx>
  • Date: Tue, 15 Sep 2009 16:15:15 +0200
  • Message-id: <E1MrI2g-0005ue-Sd@xxxxxxxxxxxxxxxx>
ref: refs/heads/patch_refactor
commit aa80f8228d1d0d9cd349a7b0d2f054b0138e67ed
Author: Martin Kudlvasr <mkudlvasr@xxxxxxx>
Date: Tue Sep 15 16:15:15 2009 +0200

small fixes to restfull resource
---
webservice/app/controllers/resources_controller.rb | 14 ++++++--------
webservice/app/models/resource.rb | 10 ++++++++--
webservice/app/views/resources/index.html.erb | 5 ++---
webservice/app/views/resources/show.html.erb | 4 ++--
webservice/config/routes.rb | 3 ++-
5 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/webservice/app/controllers/resources_controller.rb
b/webservice/app/controllers/resources_controller.rb
index 087010a..ae90e04 100644
--- a/webservice/app/controllers/resources_controller.rb
+++ b/webservice/app/controllers/resources_controller.rb
@@ -3,23 +3,21 @@ class ResourcesController < ApplicationController

def index
@resources = Resource.all
+ do_respond
+ end
+
+ def do_respond
@node = "Yast"

- logger.debug("Ahoj!")
- debugger
respond_to do |format|
format.html
format.xml { render :xml => @resources.to_xml }
+ format.json{ render :json=> @resources.to_json}
end
end

def show
@resources = Resource.find(params[:id])
- @node = "Yast"
-
- respond_to do |format|
- format.html
- format.xml { render :xml => @resources.to_xml }
- end
+ do_respond
end
end
diff --git a/webservice/app/models/resource.rb
b/webservice/app/models/resource.rb
index 8cd8b1e..417ec2b 100644
--- a/webservice/app/models/resource.rb
+++ b/webservice/app/models/resource.rb
@@ -7,6 +7,8 @@ class Resource
attr_accessor :implementations

class Implementation
+ attr_accessor :controller, :interface
+
def initialize(interface, impl_hash)
@interface = interface
@policy = impl_hash[:policy]
@@ -15,18 +17,22 @@ class Resource
end

def link_to
- "/#{@controller}/#{@singular ? "show" : "index"}"
+ "/#{@controller}/#{action}"
# url_for :only_path => :true,
# :controller => @controller,
# :action => (@singular ? :show : :index)
end

+ def action
+ @singular ? :show : :index
+ end
+
def to_xml(xml_builder = nil)
xml = xml_builder || Builder::XmlMarkup.new
xml.resource do
xml.interface(@interface)
xml.policy(@policy)
- xml.singular (:type => :boolean) @singular.to_s
+ xml.singular(@singular, :type => :boolean)
xml.href(link_to)
end
end
diff --git a/webservice/app/views/resources/index.html.erb
b/webservice/app/views/resources/index.html.erb
index 9bbe825..24ef6fa 100644
--- a/webservice/app/views/resources/index.html.erb
+++ b/webservice/app/views/resources/index.html.erb
@@ -1,5 +1,4 @@
<h1><%= @node -%> resources</h1>
-<%= @resources.inspect -%>
-<% @resources.implementations do |implementation| -%>
- <%= url_for :href => implementation.link_to -%><br/>
+<% @resources.implementations.each do |impl| -%>
+ <%= link_to impl.interface, :controller => impl.controller, :action =>
impl.action -%><br/>
<% end -%>
diff --git a/webservice/app/views/resources/show.html.erb
b/webservice/app/views/resources/show.html.erb
index 38e27f7..24ef6fa 100644
--- a/webservice/app/views/resources/show.html.erb
+++ b/webservice/app/views/resources/show.html.erb
@@ -1,4 +1,4 @@
<h1><%= @node -%> resources</h1>
-<% @resources.implementations do |implementation| -%>
- <%= url_for :href => implementation.link_to -%><br/>
+<% @resources.implementations.each do |impl| -%>
+ <%= link_to impl.interface, :controller => impl.controller, :action =>
impl.action -%><br/>
<% end -%>
diff --git a/webservice/config/routes.rb b/webservice/config/routes.rb
index d5c1414..03573e6 100644
--- a/webservice/config/routes.rb
+++ b/webservice/config/routes.rb
@@ -1,7 +1,8 @@
# route sessions statically, it is a singleton controller
ActionController::Routing::Routes.draw do |map|
map.resource :session
- map.resources :resources, :requirements => { :id => /[\w.]+/ }
+ map.resources :resources, :requirements => { :id => /[\w.]+/ },
+ :member => { :show => :get }
map.resources :permissions, :requirements => {:id => /.*/}
map.resources :vendor_settings

--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages