Module: SlackNotify::Connection

Included in:
Client
Defined in:
lib/slack-notify/connection.rb

Instance Method Summary collapse

Instance Method Details

#handle_response(response) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/slack-notify/connection.rb', line 18

def handle_response(response)
  unless response.success?
    if response.body.include?("\n")
      raise SlackNotify::Error
    else
      raise SlackNotify::Error.new(response.body)
    end
  end
end

#send_payload(payload) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/slack-notify/connection.rb', line 3

def send_payload(payload)
  conn = Faraday.new(@webhook_url) do |c|
    c.use(Faraday::Request::UrlEncoded)
    c.adapter(Faraday.default_adapter)
    c.options.timeout      = 5
    c.options.open_timeout = 5
  end

  response = conn.post do |req|
    req.body = JSON.dump(payload.to_hash)
  end

  handle_response(response)
end