Skip to content

Conversation

@raisahv
Copy link

@raisahv raisahv commented Sep 13, 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 utilized Postman in conjunction with the Slack API to test the syntax and keywords provided in the documentation. When doing the optional problems we also learned that the documentation does not always provide a complete picture of what information is needed for the API request. For example, we had to add additional headers and send in the data in a different format than in other api requests.
Give a short summary of the request/response cycle. Where does your program fit into that scheme? The request response cycle is when a user uses a client to send a request to a server, the server processes that request and sends back a response to the client. The client then displays the response to the user. In this assignment, we were sending requests to the slack server and anticipating possible responses (good and bad).
How does your program check for and handle errors when using the Slack API? We used Postman to discover types of errors that we expected to encounter (such as invalid_emoji_syntax or invalid_text). From that information, we knew how to raise errors or how to keep the program running with those errors.
Did you need to make any changes to the design work we did in class? If so, what were they? We followed the design for the most part with a few changes. We made self.get in the Recipient class an implemented method that calls a template method, self.parse_response, to parse JSON responses differently depending on which class called the self.get method. We also added list_users and list_channels as instance methods in workspace since a workspace already knows about all the users and channels upon instantiation.
Did you use any of the inheritance idioms we've talked about in class? How? Yes, Recipient was an Abstract Class with User and Channel as it's children. The Recipient class had two template methods: details and self.parse_response. We implemented polymorphism with our send_message method in Workspace, because we wanted the message to be able to be sent to a channel or user.
How does VCR aid in testing a program that uses an API? VCR allows us to test a consistent set of data as API information may be changing. It also allows us to reduce the number of calls we make to an API, and still run our tests if the server is down. When it is first called, the VCR records API requests and responses based on your tests. After that the VCR replaces the API by using responses recorded on the cassette.

end

def self.parse_response(response)
raise NotImplementedError, "Can't implement recipient class."

Choose a reason for hiding this comment

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

👍 Nice

puts "User was not found."
else
puts "User was selected."
end

Choose a reason for hiding this comment

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

I would break these larger chunks of functionality into little helper methods so that this section of code is easier to parse!

end

def send_message(message)
response = HTTParty.post( "#{BASE_URL}/chat.postMessage", body: { token: TOKEN, channel: selected.slack_id, text: message } )

Choose a reason for hiding this comment

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

In the future, I'd make a class that wraps all the calls to HTTParty on this specific API. That way, you only have to test those messages in isolation, which gives you more direct tests!

@dHelmgren
Copy link

slack.rb

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene (no slack tokens) great!
Comprehension questions good!
Functionality
List users/channels yes
Select user/channel yes
Show details yes
Send message ye
Program runs without crashing yes
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
Tests written for User functionality yes
Tests written for Channel Functionality yes
Tests written for sending a message yes
Overall Great work overall! It's clear to me that the learning goals for this assignment were met.

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.

2 participants