Class: SmartTodo::SlackClient
- Inherits:
-
Object
- Object
- SmartTodo::SlackClient
- Defined in:
- lib/smart_todo/slack_client.rb
Overview
A simple client around the Slack API.
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
-
#initialize(slack_token) ⇒ SlackClient
constructor
A new instance of SlackClient.
-
#lookup_user_by_email(email) ⇒ Hash
Retrieve the Slack ID of a user from his email.
-
#post_message(channel, text) ⇒ Hash
Send a message to a Slack channel or to a user.
Constructor Details
#initialize(slack_token) ⇒ SlackClient
Returns a new instance of SlackClient.
27 28 29 30 |
# File 'lib/smart_todo/slack_client.rb', line 27 def initialize(slack_token) @slack_token = slack_token @client = HttpClientBuilder.build("slack.com") end |
Instance Method Details
#lookup_user_by_email(email) ⇒ Hash
Retrieve the Slack ID of a user from his email
41 42 43 44 45 |
# File 'lib/smart_todo/slack_client.rb', line 41 def lookup_user_by_email(email) headers = default_headers.merge("Content-Type" => "application/x-www-form-urlencoded") request = Net::HTTP::Get.new("/api/users.lookupByEmail?email=#{CGI.escape(email)}", headers) dispatch(request) end |
#post_message(channel, text) ⇒ Hash
Send a message to a Slack channel or to a user
57 58 59 60 61 62 |
# File 'lib/smart_todo/slack_client.rb', line 57 def (channel, text) headers = default_headers request = Net::HTTP::Post.new("/api/chat.postMessage", headers) request.body = JSON.dump(channel: channel, text: text) dispatch(request) end |