Class: Slackly
- Inherits:
-
Object
- Object
- Slackly
- Defined in:
- lib/slackly.rb,
lib/slackly/version.rb
Defined Under Namespace
Classes: InvalidMessageTextError
Constant Summary collapse
- DEFAULT_OPTIONS =
{ username: 'slackly', icon_emoji: ':sunglasses:', unfurl_links: true }.freeze
- VERSION =
'0.1.1'.freeze
Instance Attribute Summary collapse
-
#client_options ⇒ Object
Returns the value of attribute client_options.
-
#webhook_uri ⇒ Object
Returns the value of attribute webhook_uri.
Instance Method Summary collapse
-
#initialize(webhook_url, client_options = {}) ⇒ Slackly
constructor
A new instance of Slackly.
- #message(message_options = {}) ⇒ Object
- #message!(message_options = {}) ⇒ Object
Constructor Details
#initialize(webhook_url, client_options = {}) ⇒ Slackly
Returns a new instance of Slackly.
16 17 18 19 |
# File 'lib/slackly.rb', line 16 def initialize(webhook_url, = {}) @webhook_uri = URI.parse(webhook_url) = DEFAULT_OPTIONS.merge() end |
Instance Attribute Details
#client_options ⇒ Object
Returns the value of attribute client_options.
8 9 10 |
# File 'lib/slackly.rb', line 8 def end |
#webhook_uri ⇒ Object
Returns the value of attribute webhook_uri.
7 8 9 |
# File 'lib/slackly.rb', line 7 def webhook_uri @webhook_uri end |
Instance Method Details
#message(message_options = {}) ⇒ Object
31 32 33 34 35 |
# File 'lib/slackly.rb', line 31 def ( = {}) () rescue => exception warn "Error while sending message to Slack: #{exception.message}" end |
#message!(message_options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/slackly.rb', line 21 def ( = {}) fail Slackly::InvalidMessageTextError, 'Please supply a valid message text' if [:text].nil? request = Net::HTTP::Post.new(webhook_uri.request_uri) request.body = "payload=#{client_options.merge(message_options).to_json}" Net::HTTP.start(webhook_uri.host, webhook_uri.port, use_ssl: webhook_uses_ssl?) do |http| http.request(request) end end |