Sha256: 4b05247abc69948689c6ac9879daf948d53189ce0734da2d564981ce7a2c344a

Contents?: true

Size: 1.39 KB

Versions: 44

Compression:

Stored size: 1.39 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 [Cocina::Models::RequestDRO,Cocina::Models::RequestCollection,Cocina::Models::RequestAPO]
        # @return [Cocina::Models::RequestDRO,Cocina::Models::RequestCollection,Cocina::Models::RequestAPO] the returned model
        def register(params:)
          json_str = register_response(params: params)
          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)
        # @raise [UnexpectedResponse] on an unsuccessful response from the server
        # @return [String] the raw JSON from the server
        def register_response(params:)
          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.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

44 entries across 44 versions & 1 rubygems

Version Path
dor-services-client-7.0.0 lib/dor/services/client/objects.rb
dor-services-client-6.36.0 lib/dor/services/client/objects.rb
dor-services-client-6.35.0 lib/dor/services/client/objects.rb
dor-services-client-6.34.0 lib/dor/services/client/objects.rb
dor-services-client-6.33.0 lib/dor/services/client/objects.rb
dor-services-client-6.32.0 lib/dor/services/client/objects.rb
dor-services-client-6.31.0 lib/dor/services/client/objects.rb
dor-services-client-6.30.1 lib/dor/services/client/objects.rb
dor-services-client-6.30.0 lib/dor/services/client/objects.rb
dor-services-client-6.29.0 lib/dor/services/client/objects.rb
dor-services-client-6.28.0 lib/dor/services/client/objects.rb
dor-services-client-6.27.0 lib/dor/services/client/objects.rb
dor-services-client-6.26.0 lib/dor/services/client/objects.rb
dor-services-client-6.26.0.beta.1 lib/dor/services/client/objects.rb
dor-services-client-6.25.0 lib/dor/services/client/objects.rb
dor-services-client-6.24.0 lib/dor/services/client/objects.rb
dor-services-client-6.23.0 lib/dor/services/client/objects.rb
dor-services-client-6.22.0 lib/dor/services/client/objects.rb
dor-services-client-6.21.0 lib/dor/services/client/objects.rb
dor-services-client-6.20.0 lib/dor/services/client/objects.rb