Skip to content

Conversation

@stpatrickschild
Copy link

Assignment Submission: Slack CLI

Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.

Reflection

Question | Answer
1)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

  • I needed to go through multiple documentation and videos to help me figure out how to tackle this project. learned how to read through the documentation and how to find the endpoint and parameters.
  1. Give a short summary of the request/response cycle. Where does your program fit into that scheme?
  • My program acts as the client for making the requests and posting to the API, showing the full circle in the request/response cycle.
  1. How does your program check for and handle errors when using the Slack API?
    The program indicates of an error is "ok" field set to false in JSON. When this happens, my program raises a custom error.
    4.) How did the design and organization of your project change over time?
  • The design changed over time, trying to handle different waves, but as I understood it better, it changed my design to having a module and linking everything to that.
    5.) Did you use any of the inheritance idioms we've talked about in class?
  • Yes I wrapped everything inside a module, for namespacing purposes, had Recipient as abstract parent class and had a channel and user inherited from, and used polymorphism since both channel and user respond to name and slack_id.
    6.)How does VCR aid in testing a program that uses an API?
  • By making test independence of external factors and limiting calls to API, reducing project cost and allowing for testing even when not connected to the internet.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

Everything works and that's great it does what it's expected to do. Well done.

Suggestions for Improvement:

  • Divide up the roles for each component a little more clearly.
    • Like make Recipient-User-Channel do the API work and let Workspace manage them.
  • Use some factory methods in User and Channel like we did in Grocery Store, rather than putting them in Workspace. It's not bad, as is, it just could be more clean that way.
  • A bit more through testing and make sure you're only testing what you need in each test file.
    • Like don't test Channel in the user test file.

That said the above are minor criticisms, mostly on style and organization, not content. You did quite well here. Well done.

@member_count = member_count
end

def print_details

Choose a reason for hiding this comment

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

Minor suggestion, I would call this method get_details just because it doesn't actually print.

Comment on lines +3 to +6
module SlackCLI
class SlackApiError < Exception; end

class Recipient

Choose a reason for hiding this comment

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

👍

Comment on lines +6 to +7
module SlackCLI
class User < Recipient

Choose a reason for hiding this comment

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

👍

class Workspace
attr_reader :users, :channels, :selected, :selected, :query

Dotenv.load

Choose a reason for hiding this comment

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

I noticed you have this line in several places, just maybe there is a way to only need to do this once. Otherwise well done.

Comment on lines +21 to +29
def list_all_user
all_users = []
response = HTTParty.get(SlackCLI::User::BASE_URL, query: query)["members"]

response.each do |person|
all_users << SlackCLI::User.new(person["name"], person["id"])
end
return all_users
end

Choose a reason for hiding this comment

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

Methods like this for user and Channel could be instead class methods in the User and Channel class and that would help separate the command-line stuff in workspace with the HTTP requests in Recipient, Channel and User.

require_relative "test_helper"
require_relative "../lib/channel"

describe "Channel class" do

Choose a reason for hiding this comment

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

Since a channel is a recipient, you should probably also test sending a message and the print details as well.

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

Choose a reason for hiding this comment

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

Generally you're never instantiating Recipient, it makes more sense as an abstract class which you would test through Channel and User.

Also I suggest trying to test with minimal dependencies, so testing Recipient without having to use Workspace.

Comment on lines +26 to +33
it "prints detail for given channel" do
VCR.use_cassette("print_details") do
# select a channel
workspace = SlackCLI::Workspace.new
channel = workspace.select_channel("general")
expect(channel.print_details).must_be_instance_of Hash
end
end

Choose a reason for hiding this comment

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

You're testing a channel in the user_test.rb file?

require_relative "test_helper"
require "simplecov"

describe "Workspace class" do

Choose a reason for hiding this comment

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

This has good tests for what Workspace is doing.

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