Sha256: e8e14fc5d8df85a3cac7f068b7668f6e4d5ae9f2285b1c9655e544d609f69667

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

require 'nokogiri'
require 'deprecation'

module Dor
  module Services
    class Client
      # API calls that are about a repository object
      class Object < VersionedService
        # @param object [String] the pid for the object
        def initialize(connection:, version:, object:)
          super(connection: connection, version: version)
          @object = object
        end

        # Publish a new object
        # @raise [UnexpectedResponse] when the response is not successful.
        # @return [boolean] true on success
        def publish
          resp = connection.post do |req|
            req.url "#{api_version}/objects/#{object}/publish"
          end
          raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?

          true
        end

        # Notify the external Goobi system for a new object that was registered in DOR
        # @raise [UnexpectedResponse] when the response is not successful.
        # @return [boolean] true on success
        def notify_goobi
          resp = connection.post do |req|
            req.url "#{object_path}/notify_goobi"
          end
          raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?

          true
        end

        # Get the current_version for a DOR object. This comes from Dor::VersionMetadataDS
        # @raise [UnexpectedResponse] when the response is not successful.
        # @return [String] the version identifier
        def current_version
          resp = connection.get do |req|
            req.url "#{object_path}/versions/current"
          end
          raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?

          resp.body
        end

        private

        attr_reader :object

        def object_path
          "#{api_version}/objects/#{object}"
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dor-services-client-0.9.0 lib/dor/services/client/object.rb
dor-services-client-0.8.0 lib/dor/services/client/object.rb