Class: Dor::Services::Client::Events

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

Overview

API calls that are about retrieving metadata

Defined Under Namespace

Classes: Event

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:) ⇒ Events

Returns a new instance of Events.

Parameters:

  • object_identifier (String)

    the pid for the object



11
12
13
14
# File 'lib/dor/services/client/events.rb', line 11

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

Instance Method Details

#create(type:, data:) ⇒ Boolean

Returns true if successful.

Parameters:

  • type (String)

    a type for the event, e.g., publish, shelve

  • data (Hash)

    an unstructured hash of event data

Returns:

  • (Boolean)

    true if successful

Raises:



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

def create(type:, data:)
  resp = connection.post do |req|
    req.url "#{api_version}/objects/#{object_identifier}/events"
    req.headers['Content-Type'] = 'application/json'
    req.body = { event_type: type, data: data }.to_json
  end

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

  true
end

#listArray<Event>, NilClass

Returns The events for an object or nil if 404.

Returns:

  • (Array<Event>, NilClass)

    The events for an object or nil if 404

Raises:



35
36
37
38
39
40
41
42
43
# File 'lib/dor/services/client/events.rb', line 35

def list
  resp = connection.get do |req|
    req.url "#{api_version}/objects/#{object_identifier}/events"
  end
  return response_to_models(resp) if resp.success?
  return if resp.status == 404

  raise_exception_based_on_response!(resp, object_identifier)
end