Class: SlackNotifiee::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/slack_notifiee/notification.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attributes) ⇒ Notification

Returns a new instance of Notification.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/slack_notifiee/notification.rb', line 27

def initialize(**attributes)
  @webhook_url = attributes[:webhook_url]
  @username = attributes[:username]
  @channel = attributes[:channel]
  @attachments = attributes[:attachments]
  @blocks = attributes[:blocks]
  @text = attributes[:text]
  @icon_emoji = attributes[:icon_emoji]
  @icon_url = attributes[:icon_url]
  @datetime = attributes[:datetime]
end

Instance Attribute Details

#attachmentsObject (readonly)

Returns the value of attribute attachments.



9
10
11
# File 'lib/slack_notifiee/notification.rb', line 9

def attachments
  @attachments
end

#blocksObject (readonly)

Returns the value of attribute blocks.



9
10
11
# File 'lib/slack_notifiee/notification.rb', line 9

def blocks
  @blocks
end

#channelObject (readonly)

Returns the value of attribute channel.



9
10
11
# File 'lib/slack_notifiee/notification.rb', line 9

def channel
  @channel
end

#datetimeObject (readonly)

Returns the value of attribute datetime.



9
10
11
# File 'lib/slack_notifiee/notification.rb', line 9

def datetime
  @datetime
end

#icon_emojiObject (readonly)

Returns the value of attribute icon_emoji.



9
10
11
# File 'lib/slack_notifiee/notification.rb', line 9

def icon_emoji
  @icon_emoji
end

#icon_urlObject (readonly)

Returns the value of attribute icon_url.



9
10
11
# File 'lib/slack_notifiee/notification.rb', line 9

def icon_url
  @icon_url
end

#textObject (readonly)

Returns the value of attribute text.



9
10
11
# File 'lib/slack_notifiee/notification.rb', line 9

def text
  @text
end

#usernameObject (readonly)

Returns the value of attribute username.



9
10
11
# File 'lib/slack_notifiee/notification.rb', line 9

def username
  @username
end

#webhook_urlObject (readonly)

Returns the value of attribute webhook_url.



9
10
11
# File 'lib/slack_notifiee/notification.rb', line 9

def webhook_url
  @webhook_url
end

Class Method Details

.build_from_json(json) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/slack_notifiee/notification.rb', line 11

def self.build_from_json(json)
  attributes = ::JSON.parse(json)

  new(
    webhook_url: ::URI.parse(attributes['webhook_url']),
    username: attributes['username'],
    channel: attributes['channel'],
    attachments: attributes['attachments'],
    blocks: attributes['blocks'],
    text: attributes['text'],
    icon_emoji: attributes['icon_emoji'],
    icon_url: attributes['icon_url'].nil? ? nil : ::URI.parse(attributes['icon_url']),
    datetime: ::Time.parse(attributes['datetime'])
  )
end

Instance Method Details

#attributesObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/slack_notifiee/notification.rb', line 39

def attributes
  {
    webhook_url: webhook_url,
    username: username,
    channel: channel,
    attachments: attachments,
    blocks: blocks,
    text: text,
    icon_emoji: icon_emoji,
    icon_url: icon_url,
    datetime: datetime
  }
end