- 
                Notifications
    You must be signed in to change notification settings 
- Fork 27
Sockets - Jansen & Rosalyn #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good error checking here.
| def show_details | ||
| details = @selected.details | ||
|  | ||
| rows = [] | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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