Sha256: 7ef62d96837c6b6a4d893d6f6a2e2194f53c8b40f93aead05c3e18ab52cf2d4e

Contents?: true

Size: 1.22 KB

Versions: 31

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module Dor
  module Services
    class Client
      # API calls that are about a repository objects
      class Objects < VersionedService
        # Creates a new object in DOR
        # @return [HashWithIndifferentAccess] the response, which includes a :pid
        def register(params:)
          json = register_response(params: params)
          JSON.parse(json).with_indifferent_access
        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 UnexpectedResponse, ResponseErrorFormatter.format(response: resp)
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
dor-services-client-4.11.0 lib/dor/services/client/objects.rb
dor-services-client-4.10.0 lib/dor/services/client/objects.rb
dor-services-client-4.9.0 lib/dor/services/client/objects.rb
dor-services-client-4.8.0 lib/dor/services/client/objects.rb
dor-services-client-4.7.0 lib/dor/services/client/objects.rb
dor-services-client-4.6.0 lib/dor/services/client/objects.rb
dor-services-client-4.5.0 lib/dor/services/client/objects.rb
dor-services-client-4.4.0 lib/dor/services/client/objects.rb
dor-services-client-4.3.0 lib/dor/services/client/objects.rb
dor-services-client-4.2.0 lib/dor/services/client/objects.rb
dor-services-client-4.1.0 lib/dor/services/client/objects.rb
dor-services-client-4.0.0 lib/dor/services/client/objects.rb
dor-services-client-3.9.2 lib/dor/services/client/objects.rb
dor-services-client-3.9.1 lib/dor/services/client/objects.rb
dor-services-client-3.9.0 lib/dor/services/client/objects.rb
dor-services-client-3.8.0 lib/dor/services/client/objects.rb
dor-services-client-3.7.0 lib/dor/services/client/objects.rb
dor-services-client-3.6.0 lib/dor/services/client/objects.rb
dor-services-client-3.5.0 lib/dor/services/client/objects.rb
dor-services-client-3.4.0 lib/dor/services/client/objects.rb