Sha256: 40142cbff9261b2bf282019b8880c5b15bc53135012f1479218242658922acce

Contents?: true

Size: 1.58 KB

Versions: 25

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

require 'deprecation'

module Dor
  module Services
    class Client
      # API calls that are about a repository objects
      class Objects < VersionedService
        # Creates a new object in DOR
        # @param params [Cocina::Models::RequestDRO,Cocina::Models::RequestCollection,Cocina::Models::RequestAPO]
        # @param assign_doi [Boolean]
        # @return [Cocina::Models::RequestDRO,Cocina::Models::RequestCollection,Cocina::Models::RequestAPO] the returned model
        def register(params:, assign_doi: false)
          json_str = register_response(params: params, assign_doi: assign_doi)
          json = JSON.parse(json_str)

          Cocina::Models.build(json)
        end

        private

        # make the registration request to the server
        # @param params [Hash] optional params (see dor-services-app)
        # @param assign_doi [Boolean]
        # @raise [UnexpectedResponse] on an unsuccessful response from the server
        # @return [String] the raw JSON from the server
        def register_response(params:, assign_doi:)
          resp = connection.post do |req|
            req.url "#{api_version}/objects"
            req.headers['Content-Type'] = 'application/json'
            # asking the service to return JSON (else it'll be plain text)
            req.headers['Accept'] = 'application/json'
            req.params[:assign_doi] = true if assign_doi
            req.body = params.to_json
          end
          return resp.body if resp.success?

          raise_exception_based_on_response!(resp)
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
dor-services-client-8.9.0 lib/dor/services/client/objects.rb
dor-services-client-8.8.0 lib/dor/services/client/objects.rb
dor-services-client-8.7.0 lib/dor/services/client/objects.rb
dor-services-client-8.6.0 lib/dor/services/client/objects.rb
dor-services-client-8.5.0 lib/dor/services/client/objects.rb
dor-services-client-8.4.0 lib/dor/services/client/objects.rb
dor-services-client-8.3.0 lib/dor/services/client/objects.rb
dor-services-client-8.2.0 lib/dor/services/client/objects.rb
dor-services-client-8.1.1 lib/dor/services/client/objects.rb
dor-services-client-8.1.0 lib/dor/services/client/objects.rb
dor-services-client-8.0.0 lib/dor/services/client/objects.rb
dor-services-client-7.12.0 lib/dor/services/client/objects.rb
dor-services-client-7.11.0 lib/dor/services/client/objects.rb
dor-services-client-7.10.0 lib/dor/services/client/objects.rb
dor-services-client-7.9.0 lib/dor/services/client/objects.rb
dor-services-client-7.8.0 lib/dor/services/client/objects.rb
dor-services-client-7.7.1 lib/dor/services/client/objects.rb
dor-services-client-7.7.0 lib/dor/services/client/objects.rb
dor-services-client-7.6.0 lib/dor/services/client/objects.rb
dor-services-client-7.5.0 lib/dor/services/client/objects.rb