Class: ApiAlerts::Event

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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 = message
  @channel = channel
  @event   = event
  @title   = title
  @tags    = tags
  @link    = link
  @data    = data
end

Instance Attribute Details

#channelObject (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

#dataObject (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

#eventObject (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

URL attached to the notification. Tapping the push opens it.



34
35
36
# File 'lib/apialerts/event.rb', line 34

def link
  @link
end

#messageObject (readonly)

Human-readable notification text. Required. Appears on the push lock screen.



22
23
24
# File 'lib/apialerts/event.rb', line 22

def message
  @message
end

#tagsObject (readonly)

Categorisation tags for filtering and search.



32
33
34
# File 'lib/apialerts/event.rb', line 32

def tags
  @tags
end

#titleObject (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_hObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/apialerts/event.rb', line 48

def to_h
  h = { message: message }
  h[:channel] = channel unless channel.nil?
  h[:event]   = event   unless event.nil?
  h[:title]   = title   unless title.nil?
  h[:tags]    = tags    unless tags.nil?
  h[:link]    = link    unless link.nil?
  h[:data]    = data    unless data.nil?
  h
end