diff options
| author | Marc Florisson | 2012-12-03 17:14:25 +0100 | 
|---|---|---|
| committer | Marc Florisson | 2012-12-03 17:14:25 +0100 | 
| commit | b07166f27d64a4847ab2a1c439cb94b522b876e4 (patch) | |
| tree | 888684a427895a5363e33ec4a4ad8bd8e2c984d4 /app | |
| parent | 966a9f62b3ffd8029c0104cee0d63d98582d95d9 (diff) | |
| download | chouette-core-b07166f27d64a4847ab2a1c439cb94b522b876e4.tar.bz2 | |
add some specs
Diffstat (limited to 'app')
| -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   | 
