Sha256: ffc9468dc596a8c544e84dddf67253eed214515f765df8e79ff34dc2f4afcaaa
Contents?: true
Size: 1.33 KB
Versions: 6
Compression:
Stored size: 1.33 KB
Contents
# frozen_string_literal: true require 'active_support/json' # required for serializing time as iso8601 module Dor module Services class Client # API calls that are about retrieving metadata class Events < VersionedService Event = Struct.new(:event_type, :data, :timestamp, 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 # @return [Array<Events>] The events for an object # @raise [UnexpectedResponse] on an unsuccessful response from the server 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 UnexpectedResponse, ResponseErrorFormatter.format(response: resp, object_identifier: object_identifier) end private attr_reader :object_identifier def response_to_models(resp) JSON.parse(resp.body).map { |data| Event.new(event_type: data['event_type'], data: data['data'], timestamp: data['created_at']) } end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems