Conversation
…ponse, added test with cassette created with bad token
…onality to workspace and tests.
…workspace_test to use VCR for show_details test.
slack.rbWhat We're Looking For
|
| /specs/cassettes/ | ||
|
|
||
| # Ignore .DS_Store | ||
| .DS_Store |
There was a problem hiding this comment.
You can ignore these globally:
https://coderwall.com/p/vz6ymw/how-to-globally-gitignore-ds_store
| key = ENV["API_TOKEN"] | ||
| response = HTTParty.get("https://slack.com/api/channels.info", query: {token: key , channel: @slack_id}) | ||
| if response.keys.include? "error" || response["ok"] == false | ||
| raise SlackCLI::SlackApiError |
There was a problem hiding this comment.
It would be nice if you'd included what the error was in the message here.
| raise SlackCLI::SlackApiError | |
| raise SlackCLI::SlackApiError.new(response["error"]) |
| if response.keys.include? "error" || response["ok"] == false | ||
| raise SlackCLI::SlackApiError.new("Message not sent due to error: #{response["error"]}") | ||
| else | ||
| return true |
There was a problem hiding this comment.
I appreciate what you're doing here but since this method raises the only thing it can ever return is true so I probably wouldn't bother with returning something.
| end | ||
|
|
||
| def self.list | ||
| raise NotImplementedError.new("Self.list should be implemented in child class") |
| puts "Select Channel" | ||
| print "Please enter a Channel Name or Slack ID: " | ||
| query = gets.chomp.downcase | ||
| query_result = workspace.select_channel(query) |
There was a problem hiding this comment.
I'd have liked to have seen the error here handled with an exception and then rescued down below. That way the message could be constructed inside of select_channel and you wouldn't need the extra check below.
Plus, it could give you to opportunity to DRY up your code by putting all of your error handling in a single begin/rescue within your until wrapping your case.
| } | ||
| ) | ||
|
|
||
| if response.keys.include? "error" || response["ok"] == false |
There was a problem hiding this comment.
You should be checking response.code here.
|
|
||
| def details | ||
| key = ENV["API_TOKEN"] | ||
| response = HTTParty.get("https://slack.com/api/users.info", query: {token: key , user: @slack_id}) |
There was a problem hiding this comment.
If you made self.get accept parameters then you could have avoided duplicating error handling.
slack.rb
Congratulations! You're submitting your assignment!
You and your partner should collaborate on the answers to these questions.
Comprehension Questions