Class: Dor::Services::Client::AdministrativeTags

Inherits:
VersionedService show all
Defined in:
lib/dor/services/client/administrative_tags.rb

Overview

Interact with administrative tags endpoint for a given object

Constant Summary

Constants inherited from VersionedService

VersionedService::EXCEPTION_CLASS, VersionedService::JSON_API_MIME_TYPE

Instance Method Summary collapse

Methods inherited from VersionedService

#async_result, #with_querystring

Constructor Details

#initialize(connection:, version:, object_identifier:) ⇒ AdministrativeTags

Returns a new instance of AdministrativeTags.

Parameters:

  • object_identifier (String)

    the pid for the object



9
10
11
12
# File 'lib/dor/services/client/administrative_tags.rb', line 9

def initialize(connection:, version:, object_identifier:)
  super(connection: connection, version: version)
  @object_identifier = object_identifier
end

Instance Method Details

#create(tags:) ⇒ Boolean

Creates one or more administrative tags for an object

Parameters:

  • tags (Array<String>)

Returns:

  • (Boolean)

    true if successful

Raises:



20
21
22
23
24
25
26
27
28
29
# File 'lib/dor/services/client/administrative_tags.rb', line 20

def create(tags:)
  resp = connection.post do |req|
    req.url "#{api_version}/objects/#{object_identifier}/administrative_tags"
    req.headers['Content-Type'] = 'application/json'
    req.body = { administrative_tags: tags }.to_json
  end
  raise_exception_based_on_response!(resp, object_identifier) unless resp.success?

  true
end

#destroy(tag:) ⇒ Boolean

Destroys an administrative tag for an object

Parameters:

  • tag (String)

    a tag to destroy

Returns:

  • (Boolean)

    true if successful

Raises:



87
88
89
90
91
92
93
94
# File 'lib/dor/services/client/administrative_tags.rb', line 87

def destroy(tag:)
  resp = connection.delete do |req|
    req.url "#{api_version}/objects/#{object_identifier}/administrative_tags/#{CGI.escape(tag)}"
  end
  raise_exception_based_on_response!(resp, object_identifier) unless resp.success?

  true
end

#listArray<String>

List administrative tags for an object

Returns:

  • (Array<String>)

Raises:



53
54
55
56
57
58
59
60
61
# File 'lib/dor/services/client/administrative_tags.rb', line 53

def list
  resp = connection.get do |req|
    req.url "#{api_version}/objects/#{object_identifier}/administrative_tags"
  end

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

  JSON.parse(resp.body)
end

#replace(tags:) ⇒ Boolean

Replaces one or more administrative tags for an object

Parameters:

  • tags (Array<String>)

Returns:

  • (Boolean)

    true if successful

Raises:



37
38
39
40
41
42
43
44
45
46
# File 'lib/dor/services/client/administrative_tags.rb', line 37

def replace(tags:)
  resp = connection.post do |req|
    req.url "#{api_version}/objects/#{object_identifier}/administrative_tags"
    req.headers['Content-Type'] = 'application/json'
    req.body = { administrative_tags: tags, replace: true }.to_json
  end
  raise_exception_based_on_response!(resp, object_identifier) unless resp.success?

  true
end

#update(current:, new:) ⇒ Boolean

Updates an administrative tag for an object

Parameters:

  • current (String)

    current tag to update

  • new (String)

    new tag to replace current tag

Returns:

  • (Boolean)

    true if successful

Raises:



70
71
72
73
74
75
76
77
78
79
# File 'lib/dor/services/client/administrative_tags.rb', line 70

def update(current:, new:)
  resp = connection.put do |req|
    req.url "#{api_version}/objects/#{object_identifier}/administrative_tags/#{CGI.escape(current)}"
    req.headers['Content-Type'] = 'application/json'
    req.body = { administrative_tag: new }.to_json
  end
  raise_exception_based_on_response!(resp, object_identifier) unless resp.success?

  true
end