class Glip::Poster
Constants
- GLIP_WEBHOOK_BASE_URL
- VERSION
Attributes
http[RW]
options[RW]
webhook_url[R]
Public Class Methods
new(webhook_url_or_id)
click to toggle source
# File lib/glip-poster/poster.rb, line 13 def initialize(webhook_url_or_id) set_webhook_url(webhook_url_or_id) @options = {} @http = Faraday.new(url: GLIP_WEBHOOK_BASE_URL) do |faraday| faraday.request :json faraday.response :logger faraday.adapter Faraday.default_adapter # use Net::HTTP end end
Public Instance Methods
send_message(message, opts = {})
click to toggle source
# File lib/glip-poster/poster.rb, line 35 def send_message(message, opts = {}) response = @http.post do |req| req.url @webhook_url req.body = @options.merge(opts).merge(body: message) end response end
set_webhook_url(webhook_url_or_id)
click to toggle source
# File lib/glip-poster/poster.rb, line 25 def set_webhook_url(webhook_url_or_id) if webhook_url_or_id.to_s !~ %r{/} @webhook_url = GLIP_WEBHOOK_BASE_URL + webhook_url_or_id elsif webhook_url_or_id =~ %r{^https?://} @webhook_url = webhook_url_or_id else fail ArgumentError, 'must include webhook URL or id argument' end end