-
Couldn't load subscription status.
- Fork 27
Sockets - Cyndi and Maria #13
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
…elected before calling message or details
slack.rbWhat We're Looking For
|
| response = HTTParty.post(url, body: params) | ||
| unless response.code == 200 && response.parsed_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.
Line 21 raises an exception, but not the one you want.
select user
You chose to select a user. Please provide a username or Slack ID
dan
Traceback (most recent call last):
5: from lib/slack.rb:105:in `<main>'
4: from lib/slack.rb:40:in `main'
3: from lib/slack.rb:40:in `new'
2: from /Users/droberts/Ada/c11/projects/slack-cli/lib/workspace.rb:11:in `initialize'
1: from /Users/droberts/Ada/c11/projects/slack-cli/lib/user.rb:16:in `list'
/Users/droberts/Ada/c11/projects/slack-cli/lib/recipient.rb:33:in `get': uninitialized constant Recipient::SlackApiError (NameError)
Ruby doesn't know what a SlackApiError is, so you get a NameError when you try to raise one. Looks like you're missing require_relative 'apierror' at the top of this file.
| def initialize(slack_id:, name:) | ||
| @slack_id = slack_id | ||
| raise ArgumentError if !name.is_a? String | ||
| @name = name |
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.
Best practice is to avoid explicit type checking in a dynamic language like Ruby. This is for two reasons. First, if name really needs to be a String, then we'll get an error soon enough one way or the other. Second, if the user passes in something that close enough to a string to work (i.e. implements the String interface), there's no reason for our code to fail.
| def select_channel | ||
| channel_selected = channels.detect do |channel| | ||
| channel.slack_id == selected || channel.name == selected | ||
| 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.
This code is very similar to the code for select_user above. Could you DRY this up somehow?
| def send_message(message, recipient) | ||
| params = {} | ||
| params[:text] = message | ||
| params[:channel] = recipient.slack_id |
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.
Instead of taking the recipient as an argument here, you should send the message to whatever is saved in @selected. Similarly for details below.
| user_selected = users.detect do |user| | ||
| user.slack_id == selected || user.name == selected | ||
| end | ||
| return user_selected |
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 the .detect enumerable here.
Since this doesn't save the user in @selected, I'm confused what that instance variable is for.
| it "returns nil if username or slack id is not found" do | ||
| VCR.use_cassette("check nil returned") do | ||
| selected = "chewy" #id of nonexistent slackbot | ||
| @workspace2 = Workspace.new(selected: selected) |
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've done a great job of identifying and testing error cases throughout this project.
slack.rb
Congratulations! You're submitting your assignment!
You and your partner should collaborate on the answers to these questions.
Comprehension Questions