diff options
-rw-r--r-- | app/controllers/configs_controller.rb | 64 | ||||
-rw-r--r-- | app/helpers/configs_helper.rb | 2 | ||||
-rw-r--r-- | app/views/configs/create.html.erb | 2 | ||||
-rw-r--r-- | app/views/configs/index.html.erb | 2 | ||||
-rw-r--r-- | config/routes.rb | 2 | ||||
-rw-r--r-- | test/functional/configs_controller_test.rb | 8 | ||||
-rw-r--r-- | test/unit/helpers/configs_helper_test.rb | 4 |
7 files changed, 84 insertions, 0 deletions
diff --git a/app/controllers/configs_controller.rb b/app/controllers/configs_controller.rb new file mode 100644 index 0000000..a6a12cb --- /dev/null +++ b/app/controllers/configs_controller.rb @@ -0,0 +1,64 @@ +class ConfigsController < ApplicationController + + require 'json/add/rails' + + before_filter :authentication + before_filter :add_cookie_header # only for anonymous participants + + def initialize + super + end + + def index + config_render + end + + def create + unless Mime::Type.lookup(request.headers["CONTENT_TYPE"]).to_sym == :json + raise Ecs::InvalidMimetypeException, "Please provide \"Content-Type:\" header. Data format has to be in JSON (application/json)" + end + + config= ActiveSupport::JSON.decode request.raw_post + + if config["participant_events"] == true + @participant.events_= true + else + @participant.events_= false + end unless config["participant_events"].nil? + + if config["selfrouting"] == true + @participant.community_selfrouting= true + else + @participant.community_selfrouting= false + end unless config["selfrouting"].nil? + + @participant.save! + config_render + #rescue ActiveSupport::OkJson::Error + rescue Ecs::InvalidMimetypeException + raise + rescue ActiveRecord::RecordInvalid + raise Ecs::InvalidMessageException, "Data could not be saved (ConfigsController#create)." + rescue StandardError + raise Ecs::InvalidMessageException, "You have provided invalid JSON data (ConfigsController#create)." + end + +private + + def config_render + config = nil + config_txt = "" + res_ev={};Ressource.all.each {|r| res_ev["/#{r.namespace}/#{r.ressource}"] = r.events} + config= \ + { + :participant_events => @participant.events?.to_s, + :resource_events => res_ev, + :selfrouting => @participant.community_selfrouting.to_s + } + respond_to do |format| + format.json { render :json => JSON.pretty_generate(config) + "\r\n" } + format.xml { render :xml => config } + end + end + +end diff --git a/app/helpers/configs_helper.rb b/app/helpers/configs_helper.rb new file mode 100644 index 0000000..5cac46f --- /dev/null +++ b/app/helpers/configs_helper.rb @@ -0,0 +1,2 @@ +module ConfigsHelper +end diff --git a/app/views/configs/create.html.erb b/app/views/configs/create.html.erb new file mode 100644 index 0000000..52a9380 --- /dev/null +++ b/app/views/configs/create.html.erb @@ -0,0 +1,2 @@ +<h1>Configs#create</h1> +<p>Find me in app/views/configs/create.html.erb</p> diff --git a/app/views/configs/index.html.erb b/app/views/configs/index.html.erb new file mode 100644 index 0000000..df50741 --- /dev/null +++ b/app/views/configs/index.html.erb @@ -0,0 +1,2 @@ +<h1>Configs#index</h1> +<p>Find me in app/views/configs/index.html.erb</p> diff --git a/config/routes.rb b/config/routes.rb index ff8114c..eeae969 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -32,6 +32,8 @@ ActionController::Routing::Routes.draw do |map| :only => [:index] map.resources :events, :path_prefix => '/sys', :name_prefix => 'sys_', :only => [:index], :collection => { :fifo => [:get, :post] } + map.resources :configs, :path_prefix => '/sys', :name_prefix => 'sys_', + :only => [:index, :create] begin Ressource.all.each do |r| diff --git a/test/functional/configs_controller_test.rb b/test/functional/configs_controller_test.rb new file mode 100644 index 0000000..049e561 --- /dev/null +++ b/test/functional/configs_controller_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class ConfigsControllerTest < ActionController::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/test/unit/helpers/configs_helper_test.rb b/test/unit/helpers/configs_helper_test.rb new file mode 100644 index 0000000..4a0c42a --- /dev/null +++ b/test/unit/helpers/configs_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class ConfigsHelperTest < ActionView::TestCase +end |