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 - Sarah/Riyo #14

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

Sockets - Sarah/Riyo #14

wants to merge 27 commits into from

Conversation

sjscotton
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 read through the Slack API docs, and also played around in Postman until we were able to create a proper get and post request. We would definitely do both of these again.
Give a short summary of the request/response cycle. Where does your program fit into that scheme? the request is send by a user using a HTTParty request. The response is returned in a HHTParty response object back to the user. In our program the recipient classes send the request based on user input, then receive the response and and process the json received.
How does your program check for and handle errors when using the Slack API? Our program Checks that the response status code is 200, which it always is for the slack api.... So we also check for the parsed_response, which should be 'ok'. We then raise a slack API error if this is not the case.
Did you need to make any changes to the design work we did in class? If so, what were they? All the changes we made were to align our design with the one we were given in class, which we agreed was a better design. At the very end we realized that we didn't have a self.get in our recipient class, so we refactored to use it to reduce dependancies
Did you use any of the inheritance idioms we've talked about in class? How? We used templating methods in the recipient class, for both details and self.list. We wanted to use polymorphism in the workspace class so that select_recipient and list_recipient were used on both users and channels in the same way, but didn't have time.
How does VCR aid in testing a program that uses an API? It allows you to use recorded API call data without needing to make calls to the API many times. This saves time, can save money, and reduces the dependency on the API being accessible

lib/slack.rb Outdated
puts "Sorry, no user with that information" if selected == nil
when "select channel"
puts "Please enter a channel name channel ID"
input = get_user_input

Choose a reason for hiding this comment

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

This crashes because get_user_input isn't passed message_to_user. You should either make the argument optional (say by adding a default value for the argument) or pass a message in here like you did above.

Choose a reason for hiding this comment

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

It's really easy to miss things like this in code that's difficult to unit test. Once we get to Rails it will be easier to write unit tests on your driver code.

def self.get(path_url)
query_parameters = { token: TOKEN }
response = HTTParty.get("#{BASE_URL}#{path_url}", query: query_parameters)
return response

Choose a reason for hiding this comment

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

I would have liked to see check_response_code called inside of self.get instead of outside. If you have to validate separately then it's easy to forget.

require_relative "../lib/workspace.rb"

def get_user_options_input(options)
input = gets.chomp.to_s.strip

Choose a reason for hiding this comment

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

Minor issue: .to_s is redundant here (gets already gives you a string).


def self.check_response_code(response)
unless response.code == 200 && response.parsed_response["ok"]
raise SlackApiError, "Error when posting #{message} to #{id}, error: #{response.parsed_response["error"]}"

Choose a reason for hiding this comment

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

This references message and id but those methods aren't defined here and the variables aren't passed in.

I suspect message should be a parameter here and id should be an attr_reader and required by initialize (since you want all Recipients to have an id).

end

def select_user(input)
found_user = @users.find do |user|

Choose a reason for hiding this comment

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

Good use of find.

found_user = @users.find do |user|
input == user.id || input == user.name
end
@selected = found_user

Choose a reason for hiding this comment

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

If you aren't going to do additional validation you can just directly assign @selected to found_user.

end

def send_message(message)
return false if !selected

Choose a reason for hiding this comment

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

I like that you checked for selected here.

Remember, you can use unless selected instead of if !selected to clarify things a touch (though that's mostly a matter of personal preference).

Suggested change
return false if !selected
return false unless selected

end

it "Initializes with selected equal to nil" do
assert_nil @workspace.selected

Choose a reason for hiding this comment

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

This is a little tricky to Google for but, you can use an expect style test with must_be_nil.

Suggested change
assert_nil @workspace.selected
expect(@workspace.selected).must_be_nil

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