aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Florisson2012-11-06 22:00:17 +0100
committerMarc Florisson2012-11-06 22:00:17 +0100
commit1ee37c6b375e52daf3dd2f65d138594b3647a86b (patch)
treeccda8f61cc78099e7e286cd0b752060111506388
parentc1c4d3fbc9231fe6b1bdd325faced49f33cdf1b2 (diff)
downloadchouette-core-1ee37c6b375e52daf3dd2f65d138594b3647a86b.tar.bz2
add api/v1
-rw-r--r--app/controllers/api/v1/networks_controller.rb50
-rw-r--r--app/views/api/v1/networks/index.html.erb3
-rw-r--r--config/routes.rb7
3 files changed, 60 insertions, 0 deletions
diff --git a/app/controllers/api/v1/networks_controller.rb b/app/controllers/api/v1/networks_controller.rb
new file mode 100644
index 000000000..4404f1496
--- /dev/null
+++ b/app/controllers/api/v1/networks_controller.rb
@@ -0,0 +1,50 @@
+module Api
+ module V1
+ class NetworksController < ActionController::Base
+ respond_to :json, :xml
+ layout false
+ before_filter :restrict_access
+
+ def referential
+ @referential ||= organisation.referentials.find @referential_id
+ end
+ def organisation
+ @organisation ||= Organisation.find @organisation_id
+ end
+ def networks
+ @networks ||= referential.networks
+ end
+ def network
+ @network ||= networks.where( :objectid => params[:id])
+ end
+
+ def index
+ respond_to do |format|
+ format.json { render :json => networks }
+ format.xml { render :xml => networks }
+ end
+ end
+ def show
+ respond_to do |format|
+ format.json { render :json => network }
+ format.xml { render :xml => network }
+ end
+ end
+
+private
+ def restrict_access
+ parse_key
+ head :unauthorized unless organisation && referential
+ end
+ def parse_key
+ @organisation_id, @referential_id = params[:access_token].split('-')
+ switch_referential
+ end
+ def switch_referential
+ Apartment::Database.switch(referential.slug)
+ end
+
+ end
+ end
+end
+
diff --git a/app/views/api/v1/networks/index.html.erb b/app/views/api/v1/networks/index.html.erb
new file mode 100644
index 000000000..93a634270
--- /dev/null
+++ b/app/views/api/v1/networks/index.html.erb
@@ -0,0 +1,3 @@
+<p>
+ <%= @networks.map(&:name).join(',') %>
+</p>
diff --git a/config/routes.rb b/config/routes.rb
index 6d16a187b..f711394b6 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -4,6 +4,13 @@ ChouetteIhm::Application.routes.draw do
match "/users/sign_up" => "subscriptions#new"
end
+ namespace :api do
+ namespace :v1 do
+ resources :networks
+ end
+ end
+
+
resource :subscription
resource :organisation do