+
+
+
-
+ 1
+
+
+
+
+
require 'dotenv'
+
+
+
+
+
-
+ 1
+
+
+
+
+
require 'httparty'
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
+ 1
+
+
+
+
+
Dotenv.load
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
+ 1
+
+
+
+
+
class SlackAPIError < Exception; end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
+ 1
+
+
+
+
+
class Recipient
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
+ 1
+
+
+
+
+
USER_LIST_URL = 'https://slack.com/api/users.list'
+
+
+
+
+
-
+ 1
+
+
+
+
+
CHANNEL_LIST_URL = 'https://slack.com/api/conversations.list'
+
+
+
+
+
-
+ 1
+
+
+
+
+
POST_MESSAGE_URL = 'https://slack.com/api/chat.postMessage'
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
+ 1
+
+
+
+
+
attr_reader :slack_id, :name
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
+ 1
+
+
+
+
+
def initialize(slack_id, name)
+
+
+
+
+
-
+ 203
+
+
+
+
+
@slack_id = slack_id
+
+
+
+
+
-
+ 203
+
+
+
+
+
@name = name
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
+ 203
+
+
+
+
+
raise ArgumentError,'Input cannot be empty' if name.empty? || slack_id.empty?
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
+ 1
+
+
+
+
+
def send_message(message)
+
+
+
+
+
-
+ 6
+
+
+
+
+
response = HTTParty.post(
+
+
+
+
+
-
+
+
+
+
+
+
POST_MESSAGE_URL,
+
+
+
+
+
-
+
+
+
+
+
+
headers: { 'Content-Type' => 'application/x-www-form-urlencoded' },
+
+
+
+
+
-
+
+
+
+
+
+
body:{
+
+
+
+
+
-
+
+
+
+
+
+
token: ENV['SLACK_TOKEN'],
+
+
+
+
+
-
+
+
+
+
+
+
text: message,
+
+
+
+
+
-
+
+
+
+
+
+
channel: @slack_id
+
+
+
+
+
-
+
+
+
+
+
+
}
+
+
+
+
+
-
+
+
+
+
+
+
)
+
+
+
+
+
-
+ 6
+
+
+
+
+
unless response['ok'] == true
+
+
+
+
+
-
+ 3
+
+
+
+
+
raise SlackAPIError, "API call failed - #{response['error']}"
+
+
+
+
+
-
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
+ 3
+
+
+
+
+
return true
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
+ 1
+
+
+
+
+
def self.get(url, params)
+
+
+
+
+
-
+ 58
+
+
+
+
+
response = HTTParty.get(url, params)
+
+
+
+
+
-
+ 58
+
+
+
+
+
unless response['ok'] == true
+
+
+
+
+
-
+ 6
+
+
+
+
+
raise SlackAPIError, "API call failed - #{response['error']}"
+
+
+
+
+
-
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
+ 52
+
+
+
+
+
return response
+
+
+
+
+
-
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
+ 1
+
+
+
+
+
def details
+
+
+
+
+
-
+ 1
+
+
+
+
+
raise NotImplementedError.new, 'Must implement me in child class!'
+
+
+
+
+
-
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
+ 1
+
+
+
+
+
def self.list_all
+
+
+
+
+
-
+ 1
+
+
+
+
+
raise NotImplementedError.new, 'Must implement me in child class!'
+
+
+
+
+
-
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
end
+
+
+
+
+