Skip to content

Commit

Permalink
SRCH-2336 deprecate /api/search endpoint (#742)
Browse files Browse the repository at this point in the history
- add comments re. the deprecated Agencies API
  • Loading branch information
MothOnMars authored Jun 17, 2021
1 parent 9dac642 commit d21539b
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 220 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ AllCops:
- app/api/search_consumer/**/*
- app/controllers/sites/templated_font_and_colors_controller.rb
- app/controllers/sites/templates_controller.rb
# The Agencies API is deprecated and will be removed - SRCH-1574
- app/controllers/api/v1/agencies_controller.rb
- app/controllers/api/v2/agencies_controller.rb

Metrics/BlockLength:
Exclude:
Expand Down
1 change: 1 addition & 0 deletions app/controllers/api/v1/agencies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# deprecated: SRCH-1574
module Api
module V1
class AgenciesController < ApplicationController
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/api/v1/search_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Api
module V1
class SearchController < ApplicationController
DEPRECATION_MESSAGE = 'This API endpoint has been deprecated. Please refer to https://search.gov/developer/ for information on current Search.gov APIs.'

def search
render plain: DEPRECATION_MESSAGE, status: :not_found
end
end
end
end
1 change: 1 addition & 0 deletions app/controllers/api/v2/agencies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# deprecated: SRCH-1574
module Api
module V2
class AgenciesController < ApplicationController
Expand Down
43 changes: 0 additions & 43 deletions app/controllers/api_controller.rb

This file was deleted.

4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
concern :active_scaffold_association, ActiveScaffold::Routing::Association.new
concern :active_scaffold, ActiveScaffold::Routing::Basic.new(association: true)
get '/search' => 'searches#index', as: :search
get '/api/search' => 'api#search', as: :api_search
get '/search/advanced' => 'searches#advanced', as: :advanced_search
get '/search/images' => 'image_searches#index', as: :image_search
get '/search/docs' => 'searches#docs', as: :docs_search
get '/search/news' => 'searches#news', as: :news_search
get '/search/news/videos' => 'searches#video_news', as: :video_news_search
get '/auth/logindotgov/callback', to: 'omniauth_callbacks#login_dot_gov'

# Deprecated
get '/api/search' => 'api/v1/search#search', as: :api_search

namespace :api, defaults: { format: :json } do
namespace :v1 do
get '/agencies/search' => 'agencies#search'
Expand Down
8 changes: 5 additions & 3 deletions lib/middlewares/reject_invalid_request_uri.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class RejectInvalidRequestUri
def initialize(app)
@app = app
Expand All @@ -6,12 +8,12 @@ def initialize(app)
def call(env)
if env['REQUEST_URI']
uri = begin
CGI::unescape(env['REQUEST_URI'].force_encoding('UTF-8'))
CGI.unescape(env['REQUEST_URI'].dup.force_encoding('UTF-8'))
rescue ArgumentError
nil
end
return [400, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, []] if uri.nil? || (uri.is_a?(String) and !uri.valid_encoding?)
return [400, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, []] if uri.nil? || (uri.is_a?(String) && !uri.valid_encoding?)
end
@app.call(env)
end
end
end
173 changes: 0 additions & 173 deletions spec/controllers/api_controller_spec.rb

This file was deleted.

15 changes: 15 additions & 0 deletions spec/requests/api/v1/search_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

describe '/api/search' do
let(:endpoint) { '/api/search' }

before { get endpoint }

it 'returns a 404' do
expect(response.status).to eq 404
end

it 'provides a useful message' do
expect(response.body).to match(/This API endpoint has been deprecated/)
end
end

0 comments on commit d21539b

Please sign in to comment.