Conversation
…mber of channels and users in main.
…hannel details methods
slack.rbWhat We're Looking For
|
| @current_session.users.each do |user| | ||
| puts "username: #{user.name} | real name: #{user.real_name} | Slack ID: #{user.slack_id}" | ||
| end | ||
| main |
There was a problem hiding this comment.
You call main again at the end of each of this options. That makes this method recursive! (A recursive method is just a method that calls itself).
This works, but it's not ideal. The main reason is as an engineer when I think about a command line interface, I think of a big loop, not a recursive function. This defies my expectations, and ends up being confusing. My instinct is to search around and try to figure out why you did it in this peculiar way. The loop would be much more clear.
| def main | ||
| puts "Welcome to the Ada Slack CLI!" | ||
| @current_session = Workspace.new | ||
|
|
There was a problem hiding this comment.
You use an instance variable here, but you're not inside of a class. It ends up working - can you tell me why? Can you tell me why it's generally considered bad form to do this? Hint: you run into a similar problem with global variables.
| when "1", "user" | ||
| print "Enter the name of user: " | ||
| selection_name = gets.chomp.downcase | ||
| print "Enter your message: " |
There was a problem hiding this comment.
You have a lot of repeated code between this and the previous method to get the name of the user or channel. Could you DRY this up?
| def send_msg_to_user(user, message) | ||
| x = select_user(user) | ||
| url = BASE_URL + "chat.postMessage" | ||
| params = { |
There was a problem hiding this comment.
Two observations here:
- This business logic might fit well as an instance method on
User. Then this code would look likex.send_message(message) - This code and the code to send a message to a channel look almost exactly the same, and should be DRYed up
The solution to both those problems might be to make send_message an instance method on Recipient.
| def show_user_details(name) | ||
| x = select_user(name) | ||
| return "username: #{x.name} | real name: #{x.real_name} | Slack id: #{x.slack_id}" | ||
| end |
There was a problem hiding this comment.
x is not a terribly descriptive variable name - could you use something that gives a little more info about what this is?
| describe "Select user method" do | ||
| it "can return a given user" do | ||
| VCR.use_cassette("select-user") do | ||
| test1 = Workspace.new |
There was a problem hiding this comment.
What if the user you try to select doesn't exist? What happens to a previously selected user if you try to select a bad user?
slack.rb
Congratulations! You're submitting your assignment!
You and your partner should collaborate on the answers to these questions.
Comprehension Questions