Class: WebhookService::Webhook
- Inherits:
-
Object
- Object
- WebhookService::Webhook
- Defined in:
- lib/slackhook/webhook_service.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Webhook
constructor
A new instance of Webhook.
- #send ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Webhook
Returns a new instance of Webhook.
8 9 10 11 12 13 14 |
# File 'lib/slackhook/webhook_service.rb', line 8 def initialize = {} @text = .fetch(:text, nil) @icon_type = .fetch(:icon_type, nil) @channel = .fetch(:channel, nil) @username = .fetch(:username, nil) @webhook_url = .fetch(:webhook_url, nil) end |
Instance Method Details
#send ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/slackhook/webhook_service.rb', line 16 def send uri = URI::encode(@webhook_url) @toSend = { channel: @channel, text: @text, username: @username, icon_emoji: @icon_type} uri = URI.parse(uri) https = Net::HTTP.new(uri.host,uri.port) https.use_ssl = true req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'}) req.body = JSON.dump @toSend res = https.request(req) res.code end |