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

Fire - Alice & Madeline #25

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

Conversation

made-line
Copy link

Assignment Submission: Slack CLI

Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.

Reflection

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?
Give a short summary of the request/response cycle. Where does your program fit into that scheme?
How does your program check for and handle errors when using the Slack API?
How did the design and organization of your project change over time?
Did you use any of the inheritance idioms we've talked about in class? How?
How does VCR aid in testing a program that uses an API?

@codeandmorecode
Copy link

codeandmorecode commented Oct 10, 2020

SORRY FOR WRITING THIS HERE, WE SUBMITED WITHOUT ANSWERING THE QUESTIONS, SO WE WILL ANSWER THEM RIGHT HERE:

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 explored the documentation pages of the slack API more than anything, we also watched all the videos on Learn to understand how to use the information from the documentation pages.
Give a short summary of the request/response cycle. Where does your program fit into that scheme?  The request is sent from the client to the Service. The service processes the request, issues a response which travels from the service back to the client (our computer). Our program is in charge of sending the request to the service, and interpreting the response from the service.
How does your program check for and handle errors when using the Slack API?  We have a test file that checks if messages have been sent or not, users have been selected or not, etc.
How did the design and organization of your project change over time?  The most significant change was that initially our list and select methods gave back hashes with the information for the users and channels. We then changed them so that they return instances of users and channels classes, and therefore had to create those classes.
Did you use any of the inheritance idioms we've talked about in class? How?  We initially wanted to have a recipient class that would serve as a parent class but upon receiving help, we understood that it was not a requirement because the way our program was structured worked without the inheritance relationship. However, if we were to refactor, we could have a recipient class which would serve as an extension of the polymorphism our program already displays.
How does VCR aid in testing a program that uses an API? VCR aid in testing a program because using VCR means that your program creates a cassette which serves as a testing tool to keep the program from making api calls, and allows the program's testing to run even if your wifi is down, thereby lowering the cost of your testing because api calls aren't free ;)

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

Slack CLI

Major Learning Goals/Code Review

Criteria yes/no, and optionally any details/lines of code to reference
Practices best practices working with APIs. The .env is not checked into git, and no API token was directly used in the Ruby code without ENV. ✔️
Practices error handling with APIs. For all pieces of code that make an API call, it handles API requests that come back with errors/error status codes appropriately. ✔️
Implements inheritance and inheritance idioms. There is a Recipient class. User and Channel inherit from Recipient. In Recipient, there are appropriate methods defined that are used in both User and Channel. Some may be implemented. Some may be template methods. ⚠️ , No inheritance implemented.
Practices clean code. lib/slack.rb only interacts with Workspace to show a separation of responsibilities. Complex logic is broken into smaller helper methods. ⚠️, You have some repetitive, code in in your Workspace class regarding selection and getting users/channels.
Practices instance methods vs. class methods appropriately. The methods to list all Channels or Users is likely a class method within those respective classes. ✔️, However like I noted inline your methods to list users and channels would make an excellent factory method (class method).
Practices best practices for testing. The project has and uses VCR mocking when running tests, and can run offline. ✔️
Practices writing tests. The User, Channel, and Workspace classes have unit tests. ⚠️, you only have tests for workspace
Practices writing tests. There are tests for sending messages (the location of these tests may differ, but is likely in Recipient) ⚠️, you have one test for sending messages.
Practices git with at least 15 small commits and meaningful commit messages ⚠️, only 13 commits and a lot of your commit messages focus on waves. Instead make commit messages describing functionality.

Functional Requirements

Functional Requirement yes/no
As a user of the CLI program, I can list users and channels ✔️?
As a user of the CLI program, I can select users and channels ✔️?
As a user of the CLI program, I can show the details of a selected user or channel ✔️?
As a user of the CLI program, when I input something inappropriately, the program runs without crashing ✔️?

Overall Feedback

Overall Feedback Criteria yes/no
Yellow (Approaches Standards) 6+ in Code Review && 2+ in Functional Requirements

Code Style Bonus Awards

Was the code particularly impressive in code style for any of these reasons (or more...?)

Quality Yes?
Perfect Indentation
Descriptive/Readable
Concise

Summary

Your design has some duplication of functionality, you do make some unnecesary API calls and your testing is minimal at best. That said it works and hits most of the learning goals here.

Also you didn't answer the comprehension questions.

Comment on lines +24 to +36
def get_users
user_response = HTTParty.get(GET_USER_PATH, query: { token: ENV["SLACK_TOKEN"] })

@users = user_response["members"].map do |member|
User.new(member["name"], member["real_name"], member["id"])
end

unless user_response.code == 200
raise SlackApiError, "Error: #{user_response.parsed_response["error"]}"
end

return @users
end

Choose a reason for hiding this comment

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

I just want to point out that listing users is a lot like listing channels. You could abstract this content out into a parent class.

You could also create a factory method in your classes like we did in Ride Share or Grocery Store.

Comment on lines +38 to +43
def select_user(username_or_id)
selected_user = self.get_users
.select { |user| user.username == username_or_id || user.id == username_or_id }
.first
return selected_user
end

Choose a reason for hiding this comment

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

This makes an api call every time you select a user, why not instead use your instance variable @users if it's not empty.

Comment on lines +59 to +64
def select_channel(name_or_id)
selected_channel = self.get_channels
.select { |channel| channel.name == name_or_id || channel.id == name_or_id }
.first
return selected_channel
end

Choose a reason for hiding this comment

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

Just note how similar this is to select_user could you absract this into a helper method?

@@ -0,0 +1,13 @@
class User

Choose a reason for hiding this comment

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

Just noting the User and Channel classes are pretty small, you could make the method to retrieve all the users a method here inside User (class method), similar to how we did Ride share.

end
end

it "returns \"Message sent!\" when message is sent" do

Choose a reason for hiding this comment

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

What happens if you send a message with no channel or user selected?

require_relative "test_helper"
require_relative "../lib/workspace"

describe "Workspace" do

Choose a reason for hiding this comment

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

I suggest using some sub-describes for the functionality here. Like one for each method allowing you to group tests a bit.

end
end

it "select channel" do

Choose a reason for hiding this comment

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

What about selecting a channel that doesn't exist?

expect(@workspace.send_message(recipient_id, message)).must_be_same_as true
end
end
end

Choose a reason for hiding this comment

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

No tests for users or channels?

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