diff options
Diffstat (limited to 'app/controllers/api')
| -rw-r--r-- | app/controllers/api/v1/chouette_controller.rb | 21 | ||||
| -rw-r--r-- | app/controllers/api/v1/networks_controller.rb | 2 |
2 files changed, 8 insertions, 15 deletions
diff --git a/app/controllers/api/v1/chouette_controller.rb b/app/controllers/api/v1/chouette_controller.rb index 401625da8..f307e6755 100644 --- a/app/controllers/api/v1/chouette_controller.rb +++ b/app/controllers/api/v1/chouette_controller.rb @@ -3,27 +3,20 @@ module Api class ChouetteController < ActionController::Base respond_to :json, :xml layout false - before_filter :restrict_access_and_switch + before_filter :authenticate def referential - @referential ||= organisation.referentials.find_by_id @referential_id - end - def organisation - @organisation ||= Organisation.find_by_id @organisation_id - end - + @referential ||= @api_key.referential + end private - def restrict_access_and_switch + def authenticate authenticate_or_request_with_http_token do |token, options| - switch_referential if key_exists?( token) + @api_key = ApiKey.new(token) + switch_referential if @api_key.exists? end end - def key_exists?( token) - @organisation_id, @referential_id = token.split('-') - organisation && referential - end def switch_referential - Apartment::Database.switch(referential.slug) + Apartment::Database.switch(@api_key.referential_slug) end end diff --git a/app/controllers/api/v1/networks_controller.rb b/app/controllers/api/v1/networks_controller.rb index c9cb6345e..c3d52348b 100644 --- a/app/controllers/api/v1/networks_controller.rb +++ b/app/controllers/api/v1/networks_controller.rb @@ -1,6 +1,6 @@ module Api module V1 - class NetworksController < ActionController::Base + class NetworksController < ChouetteController def networks @networks ||= referential.networks end |
