Skip to content

Conversation

@paulentine
Copy link

slack.rb

Congratulations! You're submitting your assignment!

You and your partner should collaborate on the answers to these questions.

Comprehension Questions

Question Answer
How did you go about exploring the Slack API? Did you learn anything that would be useful for your next project involving an API? We read the documentations, learned how to post request and how to conceal our token with VCR.
Give a short summary of the request/response cycle. Where does your program fit into that scheme? The request/response cycle explains how an API retrieves information from the web. First, a request is made using HTTParty. Then, a response is sent back and we parse it for the information we want. Our program initiates this cycle when it retrieves the list of users and list of channels from slack and sends a message.
How does your program check for and handle errors when using the Slack API? We tests for error messages by posting bad requests, which should then raise a SlackApiError.
Did you need to make any changes to the design work we did in class? If so, what were they? We chose to load our user and channels in self.load in each of these methods instead of using self.get(url, params). We loaded the lists into workspace(users, channels:) so that workspace would be less coupled to the class User or class Channel.
Did you use any of the inheritance idioms we've talked about in class? How? We set up template methods (self.load, details, self.list) and polymorphism (send_message) in our abstract class (Recipient)
How does VCR aid in testing a program that uses an API? VCR records an API request and its response so that when a test is called, it does not make a new call, but instead plays back the recorded response. This saves us from having to make multiple calls which can be costly and is useful if Slack's server is down.

@kaidamasaki
Copy link

slack.rb

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene (no slack tokens) 👍🏼
Comprehension questions 👍🏼
Functionality
List users/channels 👍🏼
Select user/channel 👍🏼
Show details 👍🏼
Send message 👍🏼
Program runs without crashing 👍🏼
Implementation
API errors are handled appropriately Mostly. (You forgot in a couple of places.)
Inheritance model matches in-class activity Mostly. (Changes were clearly outlined and well thought out.)
Inheritance idioms (abstract class, template methods, polymorphism) used appropriately Yes.
Methods are used to break work down into simpler tasks Yes.
Class and instance methods are used appropriately Yes.
Overall Great job! Even though you missed a few edge cases your solution was really clear and well thought out.

token: TOKEN,
}
response = HTTParty.get(URL, query: query_parameters)['channels']
response.each do |channel|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to validate response.code and response.parsed_response["ok"].

raise SlackApiError, "Error when posting #{text} to #{name}, error: #{response.parsed_response["error"]}"
end

return response.code == 200 && response.parsed_response["ok"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider just returning true here since you've already done the check above.

end

def self.list
return @@all

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it doesn't cause a problem here generally class variables should be your tool of last resort. I probably would have only stored them in a field in Workspace instead of here and there.

def self.load
query_parameters = { token: TOKEN }
response = HTTParty.get(BASE_URL << USERS_LIST_PATH, query: query_parameters)
response["members"].length.times do |i|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to validate response.code and response.parsed_response["ok"].

@selected = selected
end

def select_channel(id_or_name:)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny issue: it's a little odd to use a keyword argument here since you only have a single argument.

@selected = user
end
end
return @selected

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ruby's .find enumerable method might be helpful to clean up this code.

describe "self.list" do

end
end No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also like to see a test that verifies that self.load raises NotImplementedError.

describe "User" do
before do
VCR.use_cassette("load_users") do
@response = SlackAPI::User.load

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see some edge case testing on User.load.

end
end

describe "send message" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also like to see some edge case tests on sending messages.

end
end

describe "select_user" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like a test on what happens if the user doesn't exist. Also, do you lose your selection if you attempt to select an invalid user? Should you?

@kaidamasaki
Copy link

slack.rb

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene (no slack tokens) 👍🏼
Comprehension questions 👍🏼
Functionality
List users/channels 👍🏼
Select user/channel select user works; select channel crashes. It looks like you added an argument to get_user_input and forgot to pass it in.
Show details 👍🏼
Send message 👍🏼
Program runs without crashing No, see above.
Implementation
API errors are handled appropriately Yes.
Inheritance model matches in-class activity Yes.
Inheritance idioms (abstract class, template methods, polymorphism) used appropriately Yes.
Methods are used to break work down into simpler tasks Yes.
Class and instance methods are used appropriately Yes.
Overall Great job! Aside from the ArgumentError mentioned above everything looks good. Your code is clear, concise and well factored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants