Class: ApiAlerts::Event
- Inherits:
-
Object
- Object
- ApiAlerts::Event
- Defined in:
- lib/apialerts/event.rb
Overview
An event to send to the API Alerts platform.
Only message is required. All other fields are optional and omitted from the JSON payload when nil.
# Minimal
event = ApiAlerts::Event.new(message: 'Deploy complete')
# Full
event = ApiAlerts::Event.new(
message: 'Deploy complete',
channel: 'releases',
event: 'ci.deploy.success',
title: 'Deployed',
tags: ['CI/CD', 'Ruby'],
link: 'https://github.com/apialerts/apialerts-ruby/actions',
data: { commit: 'a1b2c3d' }
)
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Workspace channel the push fires on.
-
#data ⇒ Object
readonly
Arbitrary key-value metadata.
-
#event ⇒ Object
readonly
What kind of thing happened.
-
#link ⇒ Object
readonly
URL attached to the notification.
-
#message ⇒ Object
readonly
Human-readable notification text.
-
#tags ⇒ Object
readonly
Categorisation tags for filtering and search.
-
#title ⇒ Object
readonly
Short headline some destinations render separately from the body.
Instance Method Summary collapse
-
#initialize(message:, channel: nil, event: nil, title: nil, tags: nil, link: nil, data: nil) ⇒ Event
constructor
A new instance of Event.
- #to_h ⇒ Object
Constructor Details
#initialize(message:, channel: nil, event: nil, title: nil, tags: nil, link: nil, data: nil) ⇒ Event
Returns a new instance of Event.
38 39 40 41 42 43 44 45 46 |
# File 'lib/apialerts/event.rb', line 38 def initialize(message:, channel: nil, event: nil, title: nil, tags: nil, link: nil, data: nil) @message = @channel = channel @event = event @title = title @tags = @link = link @data = data end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Workspace channel the push fires on. Defaults to the workspace default when omitted.
24 25 26 |
# File 'lib/apialerts/event.rb', line 24 def channel @channel end |
#data ⇒ Object (readonly)
Arbitrary key-value metadata. Available to non-push destinations for templating.
36 37 38 |
# File 'lib/apialerts/event.rb', line 36 def data @data end |
#event ⇒ Object (readonly)
What kind of thing happened. Optional but recommended. Dotted notation (“ci.deploy.success”, “payment.failed”) so routing rules can match with wildcards (“ci.*”, “*.failed”).
28 29 30 |
# File 'lib/apialerts/event.rb', line 28 def event @event end |
#link ⇒ Object (readonly)
URL attached to the notification. Tapping the push opens it.
34 35 36 |
# File 'lib/apialerts/event.rb', line 34 def link @link end |
#message ⇒ Object (readonly)
Human-readable notification text. Required. Appears on the push lock screen.
22 23 24 |
# File 'lib/apialerts/event.rb', line 22 def @message end |
#tags ⇒ Object (readonly)
Categorisation tags for filtering and search.
32 33 34 |
# File 'lib/apialerts/event.rb', line 32 def @tags end |
#title ⇒ Object (readonly)
Short headline some destinations render separately from the body.
30 31 32 |
# File 'lib/apialerts/event.rb', line 30 def title @title end |
Instance Method Details
#to_h ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/apialerts/event.rb', line 48 def to_h h = { message: } h[:channel] = channel unless channel.nil? h[:event] = event unless event.nil? h[:title] = title unless title.nil? h[:tags] = unless .nil? h[:link] = link unless link.nil? h[:data] = data unless data.nil? h end |