Class: Dor::Services::Client::Marcxml

Inherits:
VersionedService show all
Defined in:
lib/dor/services/client/marcxml.rb

Overview

API calls around MARCXML-based operations from dor-services-app

Instance Method Summary collapse

Methods inherited from VersionedService

#async_result, #initialize

Constructor Details

This class inherits a constructor from Dor::Services::Client::VersionedService

Instance Method Details

#catkey(barcode:) ⇒ String

Get a catkey corresponding to a barcode

Parameters:

  • barcode (String)

    required string representing a barcode

Returns:

  • (String)

    catkey

Raises:



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dor/services/client/marcxml.rb', line 15

def catkey(barcode:)
  resp = connection.get do |req|
    req.url "#{api_version}/catalog/catkey"
    req.params['barcode'] = barcode
  end

  return resp.body if resp.success? && resp.body.present?

  # This method needs its own exception handling logic due to how the endpoint service (SearchWorks) operates
  raise NotFoundResponse, ResponseErrorFormatter.format(response: resp) if resp.success? && resp.body.blank?

  raise UnexpectedResponse, ResponseErrorFormatter.format(response: resp)
end

#marcxml(barcode: nil, catkey: nil) ⇒ String

Gets MARCXML corresponding to a barcode or catkey

Parameters:

  • barcode (String) (defaults to: nil)

    required string representing a barcode

  • catkey (String) (defaults to: nil)

    required string representing a catkey

Returns:

  • (String)

    MARCXML

Raises:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dor/services/client/marcxml.rb', line 35

def marcxml(barcode: nil, catkey: nil)
  check_args(barcode, catkey)

  resp = connection.get do |req|
    req.url "#{api_version}/catalog/marcxml"
    req.params['barcode'] = barcode unless barcode.nil?
    req.params['catkey'] = catkey unless catkey.nil?
  end

  # This method needs its own exception handling logic due to how the endpoint service (Symphony) operates
  #
  # DOR Services App does not respond with a 404 when no match in Symphony.
  # Rather, it responds with a 500 containing "Record not found in Symphony" in the body.
  raise NotFoundResponse, ResponseErrorFormatter.format(response: resp) if !resp.success? && resp.body.match?(/Record not found in Symphony/)
  raise UnexpectedResponse, ResponseErrorFormatter.format(response: resp) unless resp.success?

  resp.body
end