Class: Notification::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/ops/rails/lib/notification/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(notification_type: ENV['NOTIFICATION_TYPE'], notification_level: ENV['NOTIFICATION_LEVEL']) ⇒ Api

Returns a new instance of Api.



7
8
9
10
# File 'lib/capistrano/ops/rails/lib/notification/api.rb', line 7

def initialize(notification_type: ENV['NOTIFICATION_TYPE'], notification_level: ENV['NOTIFICATION_LEVEL'])
  self.notification_type = notification_type
  self.notification_level = notification_level || 'error'
end

Instance Attribute Details

#notification_levelObject

Returns the value of attribute notification_level.



5
6
7
# File 'lib/capistrano/ops/rails/lib/notification/api.rb', line 5

def notification_level
  @notification_level
end

#notification_typeObject

Returns the value of attribute notification_type.



5
6
7
# File 'lib/capistrano/ops/rails/lib/notification/api.rb', line 5

def notification_type
  @notification_type
end

Instance Method Details

#send_backup_notification(result, title, content, webhook_data = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/capistrano/ops/rails/lib/notification/api.rb', line 12

def send_backup_notification(result, title, content, webhook_data = nil)
  return if notification_type.nil?

  case notification_type
  when 'slack'
    Slack.new.backup_notification(result, title, content, notification_level)
  when 'webhook'
    Webhook.new.backup_notification(result, webhook_data, notification_level)
  end
end

#send_notification(message) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/capistrano/ops/rails/lib/notification/api.rb', line 23

def send_notification(message)
  return if notification_type.nil?

  case notification_type
  when 'slack'
    Slack.new.notify(message)
  when 'webhook'
    p 'webhook'
  end
end