Class: Messenger::Slack
- Inherits:
-
Object
- Object
- Messenger::Slack
- Defined in:
- lib/messenger/slack.rb
Class Method Summary collapse
-
.deliver(url, body, options = {}) ⇒ Object
URL format: slack://[email protected]/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX/#room Slack supports the notion of attachments, so the messages can be a little fancier.
- .obfuscate(url) ⇒ Object
- .valid_url?(url) ⇒ Boolean
Class Method Details
.deliver(url, body, options = {}) ⇒ Object
URL format:
slack://[email protected]/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX/#room
Slack supports the notion of attachments, so the messages can be a little fancier. If body is a string, that string will simply be sent to the room as text. ‘body` can also be an array of attachments, or a single attachment. Attachment reference: api.slack.com/docs/attachments
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/messenger/slack.rb', line 15 def self.deliver(url, body, ={}) raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url) parsed_url = matcher(url) [:headers] ||= {} response = HTTParty.post( "https://#{parsed_url[:base_url]}/#{parsed_url[:key_one]}/#{parsed_url[:key_two]}/#{parsed_url[:secret]}", :headers => { "Content-Type" => "application/json"}.merge([:headers]), :body => (parsed_url[:channel], parsed_url[:display_name], body, ) ) Messenger::Result.new(success?(response), response) end |
.obfuscate(url) ⇒ Object
28 29 30 31 32 |
# File 'lib/messenger/slack.rb', line 28 def self.obfuscate(url) raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url) parsed_url = matcher(url) "slack://#{parsed_url[:display_name]}@#{parsed_url[:base_url]}/T********/B********/************************/#{parsed_url[:channel]}" end |
.valid_url?(url) ⇒ Boolean
6 7 8 |
# File 'lib/messenger/slack.rb', line 6 def self.valid_url?(url) !!matcher(url) end |