Conversation
…nd revise 'initialize' method for Recipient
…ient. Revise Recipient class tests. All tests passing
… up commented code in channel.rb and user.rb
…ss; Fix errors; All tests passing
…or 'select_channel' and 'select_user' for clarity
… find channel based on slack id OR name
…t user based on username OR slack id
…ecting the appropriate recipient
…methods for clarity
…t the user know if no channel/user has the supplied name or ID
slack.rbWhat We're Looking For
|
| def self.channels_get | ||
| query_params = { token: ENV["SLACK_API_TOKEN"] } | ||
| return Slack::Channel.get(CHANNEL_URL, query_params) | ||
| end |
There was a problem hiding this comment.
Since you're already inside of Slack::Channel, you can just say return get(...) on line 33.
|
|
||
| def self.get(url, params) | ||
| return HTTParty.get(url, query: params) | ||
| end |
There was a problem hiding this comment.
I think the params argument for this method is always the same: a hash containing the slack token. Could you supply that here and remove the extra argument?
Also, you should be doing things like error handling here.
In general, every time you add another layer to a piece of functionality, you should take care of some part of the puzzle in that layer. In this case, Channel.list is in charge of turning a response into an array of Channel objects, Channel.channels_get knows the URL and the query parameters, but this method doesn't add anything new.
| Dotenv.load | ||
|
|
||
| CHANNEL_URL = "https://slack.com/api/channels.list" | ||
| USER_URL = "https://slack.com/api/users.list" |
There was a problem hiding this comment.
You have these constants defined a few places. In general, each constant should be defined once. This makes your code easier to change, and avoids the problem of what to do if they don't have the same value.
|
|
||
| def clear_selected(workspace) | ||
| workspace.selected = nil | ||
| end |
There was a problem hiding this comment.
I would say this is a demeter violation. Instead of saying to the Workspace "your selected is now nil", it would be cleaner to call a method to ask it to clear itself.
It might be that you could move this method completely into Workspace.
|
|
||
| unless response.code == 200 && response["ok"] | ||
| raise SlackApiError, "#{response["error"]}" | ||
| end |
| def show_details | ||
| details = @selected.details | ||
|
|
||
| rows = [] |
There was a problem hiding this comment.
Good use of polymorphism to keep this code generic, not specific to users or channels.
| @@ -0,0 +1,5 @@ | |||
| { | |||
| "result": { | |||
| "covered_percent": 94.12 | |||
There was a problem hiding this comment.
Make sure that your coverage files aren't included in git!
| it "returns nil if given invalid identifier" do | ||
| @workspace.select_channel("INVALID_IDENTIFIER") | ||
| expect(@workspace.selected).must_equal nil | ||
| end |
There was a problem hiding this comment.
Nice failure case. What happens to a previously selected channel in this case?
| it "returns a table for a selected channel" do | ||
| @workspace.select_channel("general") | ||
| expect(@workspace.show_details).must_be_kind_of Terminal::Table | ||
| end |
There was a problem hiding this comment.
What happens if you call show_details without first selecting a user or channel?
slack.rb
Congratulations! You're submitting your assignment!
You and your partner should collaborate on the answers to these questions.
Comprehension Questions