Class: Hook0::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/hook0/client.rb

Overview

An event to send to Hook0.

event_id is the caller's to set when it already has one to key the event on. Left unset, the client generates a UUIDv7, sends it and answers it — which is what lets it repeat a request without risking a second copy of the event being ingested and delivered to every subscriber.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_type:, payload:, payload_content_type:, labels: {}, metadata: nil, occurred_at: nil, event_id: nil) ⇒ Event

Returns a new instance of Event.

Parameters:

  • event_type (String)
  • payload (String)
  • payload_content_type (String)
  • labels (Hash{String => String}) (defaults to: {})
  • metadata (Hash{String => String}, nil) (defaults to: nil)
  • occurred_at (Time, nil) (defaults to: nil)
  • event_id (String, nil) (defaults to: nil)


276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/hook0/client.rb', line 276

def initialize(
  event_type:,
  payload:,
  payload_content_type:,
  labels: {},
  metadata: nil,
  occurred_at: nil,
  event_id: nil
)
  @event_type = event_type
  @payload = payload
  @payload_content_type = payload_content_type
  @labels = labels
  @metadata = 
  @occurred_at = occurred_at
  @event_id = event_id
  freeze
end

Instance Attribute Details

#event_idString? (readonly)

Returns what to key the event on; the client chooses when unset.

Returns:

  • (String, nil)

    what to key the event on; the client chooses when unset



267
268
269
# File 'lib/hook0/client.rb', line 267

def event_id
  @event_id
end

#event_typeString (readonly)

Returns the type of the event, as the application declares it.

Returns:

  • (String)

    the type of the event, as the application declares it



249
250
251
# File 'lib/hook0/client.rb', line 249

def event_type
  @event_type
end

#labelsHash{String => String} (readonly)

Returns what Hook0 routes the event by.

Returns:

  • (Hash{String => String})

    what Hook0 routes the event by



258
259
260
# File 'lib/hook0/client.rb', line 258

def labels
  @labels
end

#metadataHash{String => String}? (readonly)

Returns anything else worth carrying.

Returns:

  • (Hash{String => String}, nil)

    anything else worth carrying



261
262
263
# File 'lib/hook0/client.rb', line 261

def 
  @metadata
end

#occurred_atTime? (readonly)

Returns when the event happened; the current moment when unset.

Returns:

  • (Time, nil)

    when the event happened; the current moment when unset



264
265
266
# File 'lib/hook0/client.rb', line 264

def occurred_at
  @occurred_at
end

#payloadString (readonly)

Returns what the event carries.

Returns:

  • (String)

    what the event carries



252
253
254
# File 'lib/hook0/client.rb', line 252

def payload
  @payload
end

#payload_content_typeString (readonly)

Returns how to read the payload.

Returns:

  • (String)

    how to read the payload



255
256
257
# File 'lib/hook0/client.rb', line 255

def payload_content_type
  @payload_content_type
end