sul-dlss/dor-services-app

View on GitHub
app/services/suri_service.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

# Use the SURI service to mint an identifier
class SuriService
  class MalformedDruidError < RuntimeError; end

  def self.mint_id
    # POST with no body
    response = Faraday.post("#{Settings.suri.url}/identifiers")
    druid = "druid:#{response.body}"
    return druid if DruidTools::Druid.valid?(druid, true)

    raise MalformedDruidError, "SURI service returned a malformed druid: #{druid}"
  end
end