diff options
| author | Marc Florisson | 2012-11-30 10:04:01 +0100 |
|---|---|---|
| committer | Marc Florisson | 2012-11-30 10:04:01 +0100 |
| commit | a0bd6fc318e7ebe75e8c03949b9fc61e581de943 (patch) | |
| tree | 1c465d9653b9abe4e1dba0378f468357f63f49f2 /app | |
| parent | a018c33f2792033e5c0829252775f9831950b3ae (diff) | |
| download | chouette-core-a0bd6fc318e7ebe75e8c03949b9fc61e581de943.tar.bz2 | |
add gem rabl
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/api/v1/chouette_controller.rb | 31 | ||||
| -rw-r--r-- | app/controllers/api/v1/lines_controller.rb | 17 | ||||
| -rw-r--r-- | app/controllers/api/v1/networks_controller.rb | 26 | ||||
| -rw-r--r-- | app/views/api/v1/lines/show.json.rabl | 11 | ||||
| -rw-r--r-- | app/views/api/v1/lines/show.xml.rabl | 10 |
5 files changed, 69 insertions, 26 deletions
diff --git a/app/controllers/api/v1/chouette_controller.rb b/app/controllers/api/v1/chouette_controller.rb new file mode 100644 index 000000000..401625da8 --- /dev/null +++ b/app/controllers/api/v1/chouette_controller.rb @@ -0,0 +1,31 @@ +module Api + module V1 + class ChouetteController < ActionController::Base + respond_to :json, :xml + layout false + before_filter :restrict_access_and_switch + + def referential + @referential ||= organisation.referentials.find_by_id @referential_id + end + def organisation + @organisation ||= Organisation.find_by_id @organisation_id + end + +private + def restrict_access_and_switch + authenticate_or_request_with_http_token do |token, options| + switch_referential if key_exists?( token) + end + end + def key_exists?( token) + @organisation_id, @referential_id = token.split('-') + organisation && referential + end + def switch_referential + Apartment::Database.switch(referential.slug) + end + + end + end +end diff --git a/app/controllers/api/v1/lines_controller.rb b/app/controllers/api/v1/lines_controller.rb new file mode 100644 index 000000000..2e22161d0 --- /dev/null +++ b/app/controllers/api/v1/lines_controller.rb @@ -0,0 +1,17 @@ +module Api + module V1 + class LinesController < ChouetteController + inherit_resources + + defaults :resource_class => Chouette::Line, :finder => :find_by_objectid! + + protected + + def collection + @lines ||= referential.lines + end + end + end +end + + diff --git a/app/controllers/api/v1/networks_controller.rb b/app/controllers/api/v1/networks_controller.rb index 2ecc23ed0..c9cb6345e 100644 --- a/app/controllers/api/v1/networks_controller.rb +++ b/app/controllers/api/v1/networks_controller.rb @@ -1,23 +1,12 @@ module Api module V1 class NetworksController < ActionController::Base - respond_to :json, :xml - layout false - before_filter :restrict_access_and_switch - - def referential - @referential ||= organisation.referentials.find_by_id @referential_id - end - def organisation - @organisation ||= Organisation.find_by_id @organisation_id - end def networks @networks ||= referential.networks end def network @network ||= networks.where( :objectid => params[:id]) end - def index respond_to do |format| @@ -31,21 +20,6 @@ module Api format.xml { render :xml => network } end end - -private - def restrict_access_and_switch - authenticate_or_request_with_http_token do |token, options| - switch_referential if key_exists?( token) - end - end - def key_exists?( token) - @organisation_id, @referential_id = token.split('-') - organisation && referential - end - def switch_referential - Apartment::Database.switch(referential.slug) - end - end end end diff --git a/app/views/api/v1/lines/show.json.rabl b/app/views/api/v1/lines/show.json.rabl new file mode 100644 index 000000000..f9bf85dbd --- /dev/null +++ b/app/views/api/v1/lines/show.json.rabl @@ -0,0 +1,11 @@ +object @line +attributes :objectid, :creation_time, :creator_id, :name, :number, :published_name, :transport_mode_name +attributes :registration_number, :comment, :mobility_restricted_suitability, :int_user_needs + +child :network do + attributes :id, :name + node(:aa) { |network| titi } + node(:url) { |network| api_v1_network_url(:id => network.objectid) } +end + + # attr_accessible :transport_mode, :network_id, :company_id, :objectid, :object_version diff --git a/app/views/api/v1/lines/show.xml.rabl b/app/views/api/v1/lines/show.xml.rabl new file mode 100644 index 000000000..e1e165d30 --- /dev/null +++ b/app/views/api/v1/lines/show.xml.rabl @@ -0,0 +1,10 @@ +object @line +attributes :objectid, :creation_time, :creator_id, :name, :number, :published_name, :transport_mode_name +attributes :registration_number, :comment, :mobility_restricted_suitability, :int_user_needs + +child :network do + attributes :id, :name + node(:aa) { |network| titi } + node(:url) { |network| api_v1_network_url(:id => network.objectid) } +end + |
