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

Ports - Kasey and Elle #15

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

Conversation

dev-elle-up
Copy link

@dev-elle-up dev-elle-up commented Mar 22, 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? We worked individually to explore the Slack API primarily by reading the documentation. We also used Postman to become familiar with the structure of sending GET and POST requests and examine the JSON that was returned.
Give a short summary of the request/response cycle. Where does your program fit into that scheme? In the request/response cycle, a request is sent to the server that includes query parameters. The server returns a response that contains a header and a body. Our program follows this scheme by first sending a query to the Slack API as a GET request. When the response is received, our program stores the data returned in a variable and then parses the data for use in our program. Similarly, we use a POST request to send a message (request). The response returned contains a parameter which indicates whether the action was successful; we use this in our program to raise an error if it was not successful.
How does your program check for and handle errors when using the Slack API? We check the response returned by the post request for the parameter "ok" and raise an error if this value is false. These errors are mostly useful for being detected by our tests.
Did you need to make any changes to the design work we did in class? If so, what were they? We decided not to have Channel and User inherit from a Recipient class.
Did you use any of the inheritance idioms we've talked about in class? How? We used the pattern of having the SlackError inherit from StandardError.
How does VCR aid in testing a program that uses an API? VCR reduces the number of API calls your program makes to the server by "recording" the results in a .yml file and then spoofing an API call by playing back the results of the last (recorded) call. This is helpful because API calls may be limited or charged for. It also helps by letting you continue to work if your computer or the server is offline.

dev-elle-up and others added 20 commits March 19, 2019 14:06
…s together (require statements) and circular reference with minitest.
…s selected' to not throw an error and crash. Worked on making 'send message' work on my machine; not done.
…kind of recipient (User or Channel) and set query parameters accordingly. Also put in a couple of catches for user or channel being nil, which can happen if you do 'select user/channel' and enter an invalid selection, and then select 'send message'. This now gets caught and redirects the user to the main prompt instead of crashing. TO DO: One test is now throwing an error. Need to fix test, the code works.
@CheezItMan
Copy link

slack.rb

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene (no slack tokens) Good number of commits and good commit messages except one detailing a wave.
Comprehension questions Check, nicely detailed answer on the request-response cycle
Functionality
List users/channels Check
Select user/channel Check
Show details Check
Send message Check
Program runs without crashing Check, well done
Implementation
API errors are handled appropriately Check
Inheritance model matches in-class activity No, y'all made different choices
Inheritance idioms (abstract class, template methods, polymorphism) used appropriately Not so much.
Methods are used to break work down into simpler tasks Check
Class and instance methods are used appropriately Check
Overall Well done, you hit most of the learning goals. Your design is pretty good, but you missed some opportunities to take advantage of inheritance and duck typing to simplify some of your code. See the instructor reference design and take a look at my inline comments. Let me know if you have any questions.


class SlackError < StandardError; end

class Slack

Choose a reason for hiding this comment

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

This class would be better named SlackWorkspace since slack can include multiple workspaces.

Also it would be good to wrap everything in a module

get_lists
end

def get_lists()

Choose a reason for hiding this comment

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

Just notice here how the loops look almost identical. This is a good indication that you can dry things up using duck typing / polymorphism.

end

url = "https://slack.com/api/chat.postMessage"
if recipient.class == Channel

Choose a reason for hiding this comment

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

The if and elsif here are identical, so you just need to check to see if recipient is not nil.


def main
puts "Welcome to the Ada Slack CLI!"
slack = Slack.new

Choose a reason for hiding this comment

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

It would be better to have main and the Slack class in separate files.


describe "select users and channels" do
it "select a user" do
VCR.use_cassette("slack_query") do

Choose a reason for hiding this comment

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

You should also test with an invalid user.

end
end

it "select a channel" do

Choose a reason for hiding this comment

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

ditto here

end
end

describe "select users and channels" do

Choose a reason for hiding this comment

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

This describe seems to include seeing details rather than select user and channels.

You should also test what happens when no user or channel is selected.

You should test with both a user and channel.

end
end

describe "send_msg" do

Choose a reason for hiding this comment

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

Good edge-case tests here.

@@ -0,0 +1,15 @@
require_relative "test_helper"

Choose a reason for hiding this comment

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

This file doesn't seem to fit here. Also where are tests on the User class.

}
url = "https://slack.com/api/conversations.list?"
response = HTTParty.get(url, query: query_parameters)
response["channels"].each do |x|

Choose a reason for hiding this comment

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

.map could also be used here to give you an array of Channel instances

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