Sha256: b291c9c85f696e1929578b4ed87722cec12f141bd93f73c0da11458cb269ec43

Contents?: true

Size: 1.45 KB

Versions: 144

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

module Dor
  module Services
    class Client
      # API calls that are queries about a particular object.
      # This attempts to parallel the Valkyrie QueryService interface
      # (e.g. https://github.com/samvera/valkyrie/blob/master/lib/valkyrie/persistence/memory/query_service.rb)
      class Collections < VersionedService
        # @param object_identifier [String] the pid for the object
        def initialize(connection:, version:, object_identifier:)
          super(connection: connection, version: version)
          @object_identifier = object_identifier
        end

        # Get a list of the collections. (Similar to Valkyrie's find_inverse_references_by)
        # @raise [UnexpectedResponse] if the request is unsuccessful.
        # @return [Array<Cocina::Models::DRO>]
        def collections
          resp = connection.get do |req|
            req.url "#{query_path}/collections"
          end

          return response_to_models(resp) if resp.success?

          raise_exception_based_on_response!(resp, object_identifier)
        end

        private

        def response_to_models(resp)
          JSON.parse(resp.body)['collections'].map { |data| Cocina::Models.build(data) }
        end

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

        def query_path
          "#{object_path}/query"
        end

        attr_reader :object_identifier
      end
    end
  end
end

Version data entries

144 entries across 144 versions & 1 rubygems

Version Path
dor-services-client-7.5.0 lib/dor/services/client/collections.rb
dor-services-client-7.4.0 lib/dor/services/client/collections.rb
dor-services-client-7.3.1 lib/dor/services/client/collections.rb
dor-services-client-7.3.0 lib/dor/services/client/collections.rb
dor-services-client-7.2.0 lib/dor/services/client/collections.rb
dor-services-client-7.1.0 lib/dor/services/client/collections.rb
dor-services-client-7.0.0 lib/dor/services/client/collections.rb
dor-services-client-6.36.0 lib/dor/services/client/collections.rb
dor-services-client-6.35.0 lib/dor/services/client/collections.rb
dor-services-client-6.34.0 lib/dor/services/client/collections.rb
dor-services-client-6.33.0 lib/dor/services/client/collections.rb
dor-services-client-6.32.0 lib/dor/services/client/collections.rb
dor-services-client-6.31.0 lib/dor/services/client/collections.rb
dor-services-client-6.30.1 lib/dor/services/client/collections.rb
dor-services-client-6.30.0 lib/dor/services/client/collections.rb
dor-services-client-6.29.0 lib/dor/services/client/collections.rb
dor-services-client-6.28.0 lib/dor/services/client/collections.rb
dor-services-client-6.27.0 lib/dor/services/client/collections.rb
dor-services-client-6.26.0 lib/dor/services/client/collections.rb
dor-services-client-6.26.0.beta.1 lib/dor/services/client/collections.rb