Class: Dor::Services::Client::Events
- Inherits:
-
VersionedService
- Object
- VersionedService
- Dor::Services::Client::Events
- 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
-
#create(type:, data:) ⇒ Boolean
True if successful.
-
#initialize(connection:, version:, object_identifier:) ⇒ Events
constructor
A new instance of Events.
-
#list ⇒ Array<Event>, NilClass
The events for an object or nil if 404.
Methods inherited from VersionedService
#async_result, #with_querystring
Constructor Details
#initialize(connection:, version:, object_identifier:) ⇒ Events
Returns a new instance of Events.
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.
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 |
#list ⇒ Array<Event>, NilClass
Returns The events for an object or nil if 404.
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 |