Skip to content

Conversation

@dnsanche
Copy link

@dnsanche dnsanche commented Sep 14, 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? I learned that there are get and post requests and each one can have different parameters. Each API has its own naming, so they will change depending the API.
Give a short summary of the request/response cycle. Where does your program fit into that scheme? User selects an option, then program runs and sends a get or post request to the server depending user input, server checks the request and sends back a response.
How does your program check for and handle errors when using the Slack API? the program checks that the query is valid and sends code different than 200 and ok if it is invalid.
Did you need to make any changes to the design work we did in class? If so, what were they? I did few changes. I didn't implement the abstract method in recipient.
Did you use any of the inheritance idioms we've talked about in class? How? Yes, I created a parent class called recipient, so user class and channel class inherit name and id from it.
How does VCR aid in testing a program that uses an API? It records the first time the program sends a request to the server in testing and then everytime, you run same test, it runs same recorded response preventing a new call to the server.

ohcloud and others added 30 commits September 10, 2019 15:38
…lso, set up test helper with all require_realtives.
@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 yes
Program runs without crashing yes
Implementation
API errors are handled appropriately yes
Inheritance model matches in-class activity no
Inheritance idioms (abstract class, template methods, polymorphism) used appropriately no, you've diverged pretty heavily in this case. You've completely removed template methods, meaning that your work for something like list_channels is duplicated.
Methods are used to break work down into simpler tasks mostly, see comment.
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 Good work overall! You've got a few bumps in terms of how you chose to deviate from the design we gave you, and I hope my comments help you understand why we laid the project out the way we did! Keep up the hard work.

@@ -0,0 +1,34 @@
#lib/channel.rb
require 'httparty'
require 'awesome_print'

Choose a reason for hiding this comment

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

and here! Doing this sort of double inclusion causes warnings like this:

/Users/devin/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/colorize-0.8.1/lib/colorize/class_methods.rb:97: warning: method redefined; discarding old red /Users/devin/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/awesome_print-1.8.0/lib/awesome_print/core_ext/string.rb:19: warning: previous definition of red was here /Users/devin/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/colorize-0.8.1/lib/colorize/class_methods.rb:97: warning: method redefined; discarding old green /Users/devin/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/awesome_print-1.8.0/lib/awesome_print/core_ext/string.rb:19: warning: previous definition of green was here /Users/devin/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/colorize-0.8.1/lib/colorize/class_methods.rb:97: warning: method redefined; discarding old yellow /Users/devin/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/awesome_print-1.8.0/lib/awesome_print/core_ext/string.rb:19: warning: previous definition of yellow was here /Users/devin/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/colorize-0.8.1/lib/colorize/class_methods.rb:97: warning: method redefined; discarding old blue /Users/devin/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/awesome_print-1.8.0/lib/awesome_print/core_ext/string.rb:19: warning: previous definition of blue was here /Users/devin/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/colorize-0.8.1/lib/colorize/class_methods.rb:97: warning: method redefined; discarding old cyan /Users/devin/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/awesome_print-1.8.0/lib/awesome_print/core_ext/string.rb:19: warning: previous definition of cyan was here /Users/devin/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/colorize-0.8.1/lib/colorize/class_methods.rb:97: warning: method redefined; discarding old white /Users/devin/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/awesome_print-1.8.0/lib/awesome_print/core_ext/string.rb:19: warning: previous definition of white was here /Users/devin/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/table_print-1.5.6/lib/table_print/column.rb:13: warning: method redefined; discarding old name= /Users/devin/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/table_print-1.5.6/lib/table_print/row_group.rb:224: warning: shadowing outer local variable - value /Users/devin/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/table_print-1.5.6/lib/table_print/returnable.rb:27: warning: mismatched indentations at 'end' with 'def' at 25 /Users/devin/Documents/Ada/c12/slack-cli/test/message_test.rb:20: warning: assigned but unused variable - response

Which are messy and make it hard to debug, but also often hint at bigger problems with code.

require "httparty"
require "awesome_print"
require "colorize"
require "table_print"

Choose a reason for hiding this comment

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

You've included this here...

@workspace = Slack::Workspace.new()
while true
puts "Welcome to the Ada Slack CLI!".colorize(:color => :orange, :mode => :bold)
puts "\nPlease Choose from the following options:

Choose a reason for hiding this comment

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

These two lines print every time you come back to the top of the loop, but it would make more sense for them to only print when the CLI starts.

when "select user", "3"
puts "Please enter username or Slack ID"
user_selection = gets.chomp
@workspace.select_user(user_selection)

Choose a reason for hiding this comment

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

I'd love to see some sort of confirmation message if things went right here.

elsif recipient.class == Slack::User
print "Please enter the message: "
message = gets.chomp
id = recipient.id

Choose a reason for hiding this comment

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

consider breaking these larger blocks out into helper methods so that this logic is easier to read!

class SlackApiError < StandardError ; end

module Slack
def self.send_msg(message, channel)

Choose a reason for hiding this comment

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

If you're going to go the route of making an API wrapper, move all of the messages into the wrapper!


def self.channels_list
channels = []
response = HTTParty.get("#{CHANNEL_URI}/channels.list", query: {token: CHANNEL_KEY})

Choose a reason for hiding this comment

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

The route I'd rather see you go here is to have a generic list method for both channels and users that you implement in recipient, which could call a method that actually parses the response appropriately, similar to what csv_record did in OO ride share

attr_reader :name, :id
def initialize(name, id)
@name = name
@id = id

Choose a reason for hiding this comment

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

If you're writing a class this short, ask yourself 2 questions:

  1. If it's this short, do I need it?
  2. If it's needed, is someone else doing its job?

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

Choose a reason for hiding this comment

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

I'd call this file 'slackapi_wrapper_test

@@ -0,0 +1,25 @@
#lib/message.rb

Choose a reason for hiding this comment

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

This isn't really a message class, it's a slackapi_wrapper class. This holds a bunch of information about how to contact the slack API

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