Skip to content
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

Sockets-Grace & Bita #23

Open
wants to merge 56 commits into
base: master
Choose a base branch
from
Open

Sockets-Grace & Bita #23

wants to merge 56 commits into from

Conversation

Bitaman
Copy link

@Bitaman Bitaman commented Mar 23, 2019

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? It was a good practice reading through the API documents and list our query parameters and writing code to make the get request and get data and then pars it for what we needed. The whole process of how to get data and how to use it made much more sense after doing this project.
Give a short summary of the request/response cycle. Where does your program fit into that scheme? for example for printing the list of users with their name, ID and real name. we made a get request for the list user url which gave us a Json file as a response with a hash of data for each member. we then had to write methods to go through each hash and get the data that we needed.
How does your program check for and handle errors when using the Slack API? for example we checked if for a channel we get error if trying to send a message to an invalid ID.
Did you need to make any changes to the design work we did in class? If so, what were they? In addition to Recipient, user, channel and workspace, we add a new file to interact with the user. It calls slack.rb.
Did you use any of the inheritance idioms we've talked about in class? How? both user and channel class are inheriting from the recipient. there are methods in recipient which never get implemented and we implemented them in user and channel separately.
How does VCR aid in testing a program that uses an API? when a call get made to an API, VCR record the data and each time running a test instead of making a new call the test use the VCR which is like a recording of the actual call. this way we don't need to make a call for each test.

@droberts-sea
Copy link

slack.rb

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene (no slack tokens) yes
Comprehension questions yes
Functionality
List users/channels yes
Select user/channel yes
Show details yes
Send message yes
Program runs without crashing No - There were a number of bugs that made the program crash, including one as soon as you run it. None of these are subtle - they're things like passing the wrong number of arguments to a method. This is sloppy work, and you two can do better.
Implementation
API errors are handled appropriately some - You do a good job of defining and raising a custom exception, but your command line code does not rescue that exception, so the user still sees a stack trace instead of a polite error message.
Inheritance model matches in-class activity yes
Inheritance idioms (abstract class, template methods, polymorphism) used appropriately mostly - see inline
Methods are used to break work down into simpler tasks yes
Class and instance methods are used appropriately yes
Overall

In general this is a strong submission. You do a good job of implementing the design, and it is clear to me that the learning goals around the request/response cycle and consuming an API, as well as working with inheritance, were met. I do see room for growth around identifying test cases, and around general attention to detail. Please review my inline comments below, and keep up the hard work!


CHANNEL_URL = "https://slack.com/api/channels.list"
USER_URL = "https://slack.com/api/users.list"
POST_URL = "https://slack.com/api/chat.postMessage"

Choose a reason for hiding this comment

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

Ideally the superclass would not need to know these details from the subclass. One of the benefits of inheritance is it allows you to add new subclasses without changing the parent class.

To do so, instead of using a constant for this, you could define a template method list_url which is overridden in the child classes to return the correct endpoint.

That would also allow you to get rid of the if statement in self.get below.

when "list users"
puts workspace.show_details("users")
when "list channels"
puts workspace.show_details("channels")

Choose a reason for hiding this comment

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

These should be calling print_details, not show_details

else
puts workspace.show_details
end
when "send message"

Choose a reason for hiding this comment

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

You have the wrong number of arguments to show_details here.

name = member["name"]
real_name = member["real_name"]
new_member = User.new(slack_id, name, real_name)
members_list << new_member

Choose a reason for hiding this comment

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

You are missing two arguments in the call to User.new here

selected = channels.select do |channel|
channel.name == user_input || channel.slack_id == user_input
end
@selected = selected.first

Choose a reason for hiding this comment

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

Ruby's .find enumerable does the same thing as .select.first.

it "returns channel details from show_details" do
VCR.use_cassette("slack_workspace") do
@workspace.select_channel("random")
expect(@workspace.show_details).must_be_kind_of String

Choose a reason for hiding this comment

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

What if you try to show details without having first selected something?

it "returns user details from show_details" do
VCR.use_cassette("slack_workspace") do
@workspace.select_user("grace.m.shea")
expect(@workspace.show_details).must_be_kind_of String

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 and send_message without first selecting a user or channel?

it "raises an error for invalid channel" do
VCR.use_cassette("slack-posts") do
@workspace.select_channel("everyone")
@workspace.selected.slack_id = "whatever"

Choose a reason for hiding this comment

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

I like these edge cases!

user = response.first

expect(response).wont_be_nil
expect(response.first.name).must_equal user.name

Choose a reason for hiding this comment

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

The expectation on line 11 is not useful, you've essentially said expect(response.first.name).must_equal response.first.name, which will always be true.

describe "User class" do
describe "self.list" do
it "can return all users" do
VCR.use_cassette("slack_user") do

Choose a reason for hiding this comment

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

You should include tests for User's entire public interface: User.list, the constructor, User#details, and User#send_message.

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