diff options
| author | Marc Florisson | 2012-12-13 16:03:53 +0100 | 
|---|---|---|
| committer | Marc Florisson | 2012-12-13 16:03:53 +0100 | 
| commit | 3a4ee94cd91de749521ac190656c65266861270f (patch) | |
| tree | 33cbf422cd46bc5c7095d9a466f940f62f83e90b /app/controllers/api | |
| parent | 845a400042115db5c3f7c1b77a685c5ece177d83 (diff) | |
| download | chouette-core-3a4ee94cd91de749521ac190656c65266861270f.tar.bz2 | |
make api_key persistent
Diffstat (limited to 'app/controllers/api')
| -rw-r--r-- | app/controllers/api/v1/chouette_controller.rb | 12 | ||||
| -rw-r--r-- | app/controllers/api/v1/lines_controller.rb | 1 | ||||
| -rw-r--r-- | app/controllers/api/v1/networks_controller.rb | 4 | 
3 files changed, 11 insertions, 6 deletions
diff --git a/app/controllers/api/v1/chouette_controller.rb b/app/controllers/api/v1/chouette_controller.rb index 1264e3484..98f15414b 100644 --- a/app/controllers/api/v1/chouette_controller.rb +++ b/app/controllers/api/v1/chouette_controller.rb @@ -1,18 +1,20 @@  module Api    module V1      class ChouetteController < ActionController::Base +      inherit_resources        respond_to :json, :xml        layout false        before_filter :authenticate -      def referential -        @referential ||= @api_key.referential -      end +      belongs_to :referential +  private +      alias_method :referential, :parent +        def authenticate          authenticate_or_request_with_http_token do |token, options| -          @api_key = ApiKey.new(token) -          switch_referential if @api_key.exists? +          @api_key = referential.api_keys.find_by_token(token) +          switch_referential if @api_key          end        end        def switch_referential diff --git a/app/controllers/api/v1/lines_controller.rb b/app/controllers/api/v1/lines_controller.rb index 1df8a6618..9e58ea46b 100644 --- a/app/controllers/api/v1/lines_controller.rb +++ b/app/controllers/api/v1/lines_controller.rb @@ -1,7 +1,6 @@  module Api    module V1      class LinesController < ChouetteController -      inherit_resources        defaults :resource_class => Chouette::Line, :finder => :find_by_objectid! diff --git a/app/controllers/api/v1/networks_controller.rb b/app/controllers/api/v1/networks_controller.rb index 0b014e27b..c69c46433 100644 --- a/app/controllers/api/v1/networks_controller.rb +++ b/app/controllers/api/v1/networks_controller.rb @@ -4,9 +4,13 @@ module Api        inherit_resources        defaults :resource_class => Chouette::Network, :finder => :find_by_objectid! +      belongs_to :referential, :parent_class => ::Referential    protected +      def parent +        @referential ||= Referential.find(params[:referential_id]) +      end        def collection          @networks ||= referential.networks.search(params[:q]).result(:distinct => true)        end   | 
