Sha256: 94988df3cb20a3cb72d8b7670b102be60d72f1d3f9bfce51431e88e5ffe77b7c

Contents?: true

Size: 1.26 KB

Versions: 117

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module Dor
  module Services
    class Client
      # API call that queries the members of a collection.
      class Members < VersionedService
        Member = Struct.new(:externalIdentifier, :type, keyword_init: true)

        # @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 members.
        # @raise [UnexpectedResponse] if the request is unsuccessful.
        # @return [Array<Member>]
        def members
          resp = connection.get do |req|
            req.url members_path
          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)['members'].map { |result| Member.new(**result.symbolize_keys) }
        end

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

        def members_path
          "#{object_path}/members"
        end

        attr_reader :object_identifier
      end
    end
  end
end

Version data entries

117 entries across 117 versions & 1 rubygems

Version Path
dor-services-client-13.4.0 lib/dor/services/client/members.rb
dor-services-client-13.3.0 lib/dor/services/client/members.rb
dor-services-client-13.2.0 lib/dor/services/client/members.rb
dor-services-client-13.1.1 lib/dor/services/client/members.rb
dor-services-client-13.1.0 lib/dor/services/client/members.rb
dor-services-client-13.0.1 lib/dor/services/client/members.rb
dor-services-client-13.0.0 lib/dor/services/client/members.rb
dor-services-client-12.18.0 lib/dor/services/client/members.rb
dor-services-client-12.17.0 lib/dor/services/client/members.rb
dor-services-client-12.16.0 lib/dor/services/client/members.rb
dor-services-client-12.15.0 lib/dor/services/client/members.rb
dor-services-client-12.14.0 lib/dor/services/client/members.rb
dor-services-client-12.13.1 lib/dor/services/client/members.rb
dor-services-client-12.13.0 lib/dor/services/client/members.rb
dor-services-client-12.12.1 lib/dor/services/client/members.rb
dor-services-client-12.12.0 lib/dor/services/client/members.rb
dor-services-client-12.11.0 lib/dor/services/client/members.rb
dor-services-client-12.10.0 lib/dor/services/client/members.rb
dor-services-client-12.9.1 lib/dor/services/client/members.rb
dor-services-client-12.9.0 lib/dor/services/client/members.rb