Class: ExceptionNotificationLarkNotifier::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/exception_notification-lark-notifier/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



3
4
5
6
7
8
9
# File 'lib/exception_notification-lark-notifier/client.rb', line 3

def initialize(options)
  @secret = options[:webhook_secret].to_s.strip
  @http = Http.new(
    uri: options.fetch(:webhook_url),
    options: options[:http] || {}
  )
end

Instance Method Details

#ping(payload) ⇒ Object



11
12
13
14
# File 'lib/exception_notification-lark-notifier/client.rb', line 11

def ping(payload)
  payload = {text: payload} unless payload.is_a?(Hash)
  post(payload)
end

#post(payload) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/exception_notification-lark-notifier/client.rb', line 16

def post(payload)
  message = build_message(payload)

  unless @secret.empty?
    timestamp = Time.now.to_i
    sign = Signer.generate(timestamp, @secret)
    message[:timestamp] = timestamp
    message[:sign] = sign
  end

  @http.post(json: message)
end