Skip to content

Conversation

@minipaige02
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 used the documentation and Postman to test out the Slack API. We learned that it's useful to look through the documentation thoroughly -- we found additional endpoints to use that weren't in the project instructions.
Give a short summary of the request/response cycle. Where does your program fit into that scheme? The user sends a request to the API with a key and relevant parameters, then the API sends back a response containing the requested information or an error message. Our program constructs the request and then it interprets the response from the API. It then formats the response for the user to understand.
How does your program check for and handle errors when using the Slack API? It checks for and handles errors in the same methods that call the API. It interprets the JSON file when there is an error and sends back a message to the user. We also stop the user from entering information that might cause an error in sending a request to the API.
Did you need to make any changes to the design work we did in class? If so, what were they? Our initial design included a message class, which we removed because the message was not significant enough in this program.
Did you use any of the inheritance idioms we've talked about in class? How? We used polymorphism in the child classes of Recipient in self.get. The code was defined in Recipient and the only different between the implementations in User and Channel was that they passed in different URLs. Details was a template method defined in the abstract class, Recipient, but in User and Channel the code was different because they dealt with different pieces of information.
How does VCR aid in testing a program that uses an API? It aids in that it allows the tests to be run several times without actually calling the API, which could take time, money, and could have a rate limit.

minipaige02 and others added 30 commits September 10, 2019 13:56
…ponse, added test with cassette created with bad token
@kaidamasaki
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 Yes.
Implementation
API errors are handled appropriately Mostly. (Didn't check HTTP status.)
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.
Tests written for User functionality Yes.
Tests written for Channel Functionality Yes.
Tests written for sending a message Yes.
Overall Well done! There were a few little things I called out inline but overall things looked good!

/specs/cassettes/

# Ignore .DS_Store
.DS_Store

Choose a reason for hiding this comment

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

key = ENV["API_TOKEN"]
response = HTTParty.get("https://slack.com/api/channels.info", query: {token: key , channel: @slack_id})
if response.keys.include? "error" || response["ok"] == false
raise SlackCLI::SlackApiError

Choose a reason for hiding this comment

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

It would be nice if you'd included what the error was in the message here.

Suggested change
raise SlackCLI::SlackApiError
raise SlackCLI::SlackApiError.new(response["error"])

if response.keys.include? "error" || response["ok"] == false
raise SlackCLI::SlackApiError.new("Message not sent due to error: #{response["error"]}")
else
return true

Choose a reason for hiding this comment

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

I appreciate what you're doing here but since this method raises the only thing it can ever return is true so I probably wouldn't bother with returning something.

end

def self.list
raise NotImplementedError.new("Self.list should be implemented in child class")

Choose a reason for hiding this comment

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

Abstract methods! 🎉

puts "Select Channel"
print "Please enter a Channel Name or Slack ID: "
query = gets.chomp.downcase
query_result = workspace.select_channel(query)

Choose a reason for hiding this comment

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

I'd have liked to have seen the error here handled with an exception and then rescued down below. That way the message could be constructed inside of select_channel and you wouldn't need the extra check below.

Plus, it could give you to opportunity to DRY up your code by putting all of your error handling in a single begin/rescue within your until wrapping your case.

}
)

if response.keys.include? "error" || response["ok"] == false

Choose a reason for hiding this comment

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

You should be checking response.code here.


def details
key = ENV["API_TOKEN"]
response = HTTParty.get("https://slack.com/api/users.info", query: {token: key , user: @slack_id})

Choose a reason for hiding this comment

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

If you made self.get accept parameters then you could have avoided duplicating error handling.

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