aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/api
diff options
context:
space:
mode:
authorMarc Florisson2012-11-06 22:00:17 +0100
committerMarc Florisson2012-11-06 22:00:17 +0100
commit1ee37c6b375e52daf3dd2f65d138594b3647a86b (patch)
treeccda8f61cc78099e7e286cd0b752060111506388 /app/controllers/api
parentc1c4d3fbc9231fe6b1bdd325faced49f33cdf1b2 (diff)
downloadchouette-core-1ee37c6b375e52daf3dd2f65d138594b3647a86b.tar.bz2
add api/v1
Diffstat (limited to 'app/controllers/api')
-rw-r--r--app/controllers/api/v1/networks_controller.rb50
1 files changed, 50 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
+