Conversation
slack.rbWhat We're Looking For
|
| case selection | ||
| when "list channels" | ||
| puts Slack::Workspace.all_channels_details | ||
| when "select channel" |
There was a problem hiding this comment.
The way you have this here means the channel doesn't stay selected. It also means you have a lot of duplicate code in selecting users and channels and sending messages etc.
| def self.get | ||
| url = "https://slack.com/api/users.list" | ||
| params = { | ||
| token: ENV["KEY"], |
There was a problem hiding this comment.
In general don't name your environmental variable "KEY", make the name a bit more specific.
Also both the token and the URL would make great constants.
| @topic = topic | ||
| end | ||
|
|
||
| def self.get |
There was a problem hiding this comment.
You could implement this method in Recipient and inherit the behavior.
|
|
||
| message_request = HTTParty.post(url, query: params) | ||
| if message_request["ok"] == false | ||
| raise ArgumentError, "Request is unsuccessful" |
There was a problem hiding this comment.
You should also include the error message.
| Dotenv.load | ||
|
|
||
| module Slack | ||
| class Workspace |
There was a problem hiding this comment.
This works as a collection of class methods, but if you're using all class methods, you might as well just make Workspace a module. Instead I would suggest making Workspace a class with the attributes @users, @channels and @selected, which means you could keep track of the selected user or channel in your main app.
| expect(receiver).must_be_instance_of Slack::Recipient | ||
| end | ||
| end | ||
|
|
There was a problem hiding this comment.
You should also test that your abstract method raises an error.
| @@ -0,0 +1 @@ | |||
|
|
|||
| @@ -0,0 +1,106 @@ | |||
| require_relative "test_helper.rb" | |||
|
|
|||
There was a problem hiding this comment.
In this file you also need to have some negative-case tests with invalid arguments.
slack.rb
Congratulations! You're submitting your assignment!
You and your partner should collaborate on the answers to these questions.
Comprehension Questions