diff --git a/app/constraints/api_constraint.rb b/app/constraints/api_constraint.rb deleted file mode 100644 index 1a3dacd04..000000000 --- a/app/constraints/api_constraint.rb +++ /dev/null @@ -1,12 +0,0 @@ -class ApiConstraint - attr_reader :version - - def initialize(options) - @version = options.fetch(:version) - @default = options.fetch(:default) - end - - def matches?(request) - @default || request.headers.fetch(:accept, "").include?("version=#{version}") - end -end diff --git a/config/routes.rb b/config/routes.rb index b9a8f857e..34d2ef81c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -71,16 +71,12 @@ # resources :events # end - resources :events, constraints: ApiConstraint.new(version: 2, default: :false) - resources :old_events, path: "events", constraints: ApiConstraint.new(version: 1, default: :true) - - # scope module: :v2, constraints: ApiConstraint.new(version: 2, default: :false) do - # resources :events - # end - - # scope module: :v1, constraints: ApiConstraint.new(version: 1, default: :true) do - # resources :events - # end + constraints(-> (req) { req.env["HTTP_ACCEPT"].to_s.include?("version=2") }) do + resources :events + end + constraints(-> (req) { req.env["HTTP_ACCEPT"].to_s.exclude?("version=2") }) do + resources :old_events, path: "events" + end resources :prefixes, constraints: { :id => /.+/ } resources :provider_prefixes, path: 'provider-prefixes'