Skip to content

Commit

Permalink
Remove unused endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Sep 17, 2019
1 parent 1b29eaa commit f446bc6
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 167 deletions.
29 changes: 4 additions & 25 deletions app/controllers/marcxml_controller.rb
@@ -1,31 +1,10 @@
# frozen_string_literal: true

class MarcxmlController < ApplicationController #:nodoc:
before_action :set_marcxml_resource

rescue_from(SymphonyReader::ResponseError) do |e|
render status: :internal_server_error, plain: e.message
end

# Given a barcode, returns a catkey by looking in searchworks
class MarcxmlController < ApplicationController
def catkey
render plain: @marcxml.catkey
end

def marcxml
render xml: @marcxml.marcxml
end

def mods
render xml: @marcxml.mods
end

private

def set_marcxml_resource
@marcxml = MarcxmlResource.find_by(**marcxml_resource_params)
end
marcxml = MarcxmlResource.find_by(barcode: params[:barcode])

def marcxml_resource_params
params.slice(:barcode, :catkey).to_unsafe_h.symbolize_keys
render plain: marcxml.catkey
end
end
2 changes: 0 additions & 2 deletions config/routes.rb
Expand Up @@ -19,8 +19,6 @@
end

scope :catalog do
get 'marcxml', to: 'marcxml#marcxml'
get 'mods', to: 'marcxml#mods'
get 'catkey', to: 'marcxml#catkey'
end

Expand Down
70 changes: 0 additions & 70 deletions openapi.json
Expand Up @@ -223,76 +223,6 @@
]
}
},
"/catalog/marcxml": {
"get": {
"tags": [
"integrations"
],
"summary": "Lookup the MARC XML from Symphony",
"description": "",
"operationId": "marcxml#marcxml",
"responses": {
"200": {
"description": "OK"
}
},
"parameters": [
{
"name": "barcode",
"in": "query",
"description": "barcode of an item",
"required": false,
"schema": {
"type": "string"
}
},
{
"name": "catkey",
"in": "query",
"description": "catalog identifier of an item",
"required": false,
"schema": {
"type": "string"
}
}
]
}
},
"/catalog/mods": {
"get": {
"tags": [
"integrations"
],
"summary": "Lookup the MODS for an item from Symphony",
"description": "",
"operationId": "marcxml#mods",
"responses": {
"200": {
"description": "OK"
}
},
"parameters": [
{
"name": "barcode",
"in": "query",
"description": "barcode of an item",
"required": false,
"schema": {
"type": "string"
}
},
{
"name": "catkey",
"in": "query",
"description": "catalog identifier of an item",
"required": false,
"schema": {
"type": "string"
}
}
]
}
},
"/catalog/catkey": {
"get": {
"tags": [
Expand Down
70 changes: 0 additions & 70 deletions spec/controllers/marcxml_controller_spec.rb
Expand Up @@ -33,80 +33,10 @@
end

describe 'GET catkey' do
it 'returns the provided catkey' do
get :catkey, params: { catkey: '12345' }
expect(response.body).to eq '12345'
end

it 'looks up an item by barcode' do
stub_request(:get, format(Settings.catalog.barcode_search_url, barcode: '98765')).to_return(body: { barcode: '98765', id: '12345' }.to_json)
get :catkey, params: { barcode: '98765' }
expect(response.body).to eq '12345'
end
end

describe 'GET marcxml' do
it 'retrieves MARCXML' do
stub_request(:get, format(Settings.catalog.symphony.json_url, catkey: resource.catkey)).to_return(body: body.to_json, headers: { 'Content-Length': 394 })
get :marcxml, params: { catkey: '12345' }
expect(response.body).to start_with '<record'
end
end

describe 'GET mods' do
it 'transforms the MARCXML into MODS' do
stub_request(:get, format(Settings.catalog.symphony.json_url, catkey: resource.catkey)).to_return(body: body.to_json, headers: { 'Content-Length': 394 })
get :mods, params: { catkey: '12345' }
expect(response.body).to match(/mods/)
end
end

describe 'errors in response from Symphony' do
context 'when incomplete response' do
before do
stub_request(:get, format(Settings.catalog.symphony.json_url, catkey: resource.catkey)).to_return(body: '{}', headers: { 'Content-Length': 0 })
end

it 'returns a 500 error' do
get :marcxml, params: { catkey: '12345' }
expect(response.status).to eq(500)
expect(response.body).to eq('Incomplete response received from Symphony for 12345 - expected 0 bytes but got 2')
end
end

context 'when catkey not found' do
before do
stub_request(:get, format(Settings.catalog.symphony.json_url, catkey: resource.catkey)).to_return(status: 404)
end

it 'returns a 500 error' do
get :marcxml, params: { catkey: '12345' }
expect(response.status).to eq(500)
expect(response.body).to eq('Record not found in Symphony: 12345')
end
end

context 'when other HTTP error' do
let(:err_body) do
{
messageList: [
{
code: 'oops',
message: 'Something somewhere went wrong.'
}
]
}
end

before do
stub_request(:get, format(Settings.catalog.symphony.json_url, catkey: resource.catkey)).to_return(status: 403, body: err_body.to_json)
end

it 'returns a 500 error' do
get :marcxml, params: { catkey: '12345' }
expect(response.status).to eq(500)
expect(response.body).to match(/^Got HTTP Status-Code 403 retrieving 12345 from Symphony:.*Something somewhere went wrong./)
end
end
end
end

0 comments on commit f446bc6

Please sign in to comment.