Sha256: 02021d80a1c7e56e93b4f76972a7e690ed28ef00622be64e895aa410d04a88ca

Contents?: true

Size: 1.76 KB

Versions: 6

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

module Dor
  module Services
    class Client
      # Interact with release tags endpoint for a given object
      class ReleaseTags < 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

        # Create a release tag for an object
        #
        # @param tag [Cocina::Models::ReleaseTag]
        # @return [Boolean] true if successful
        # @raise [NotFoundResponse] when the response is a 404 (object not found)
        # @raise [UnexpectedResponse] if the request is unsuccessful.
        def create(tag:)
          resp = connection.post do |req|
            req.url "#{api_version}/objects/#{object_identifier}/release_tags"
            req.headers['Content-Type'] = 'application/json'
            req.body = tag.to_json
          end
          raise_exception_based_on_response!(resp, object_identifier) unless resp.success?

          true
        end

        # List release tags for an object
        #
        # @raise [NotFoundResponse] when the response is a 404 (object not found)
        # @raise [UnexpectedResponse] if the request is unsuccessful.
        # @return [Array<Cocina::Models::ReleaseTag>]
        def list
          resp = connection.get do |req|
            req.url "#{api_version}/objects/#{object_identifier}/release_tags"
          end

          raise_exception_based_on_response!(resp, object_identifier) unless resp.success?

          JSON.parse(resp.body).map { |tag_data| Cocina::Models::ReleaseTag.new(tag_data) }
        end

        private

        attr_reader :object_identifier
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dor-services-client-14.11.0 lib/dor/services/client/release_tags.rb
dor-services-client-14.7.0 lib/dor/services/client/release_tags.rb
dor-services-client-14.6.1 lib/dor/services/client/release_tags.rb
dor-services-client-14.6.0 lib/dor/services/client/release_tags.rb
dor-services-client-14.5.0 lib/dor/services/client/release_tags.rb
dor-services-client-14.4.0 lib/dor/services/client/release_tags.rb