Conversation
… no recipient was selected
slack.rbWhat We're Looking For
|
| class SlackError < StandardError; end | ||
|
|
||
| class Channel | ||
| url = "https://slack.com/api/channels.list" |
There was a problem hiding this comment.
I would make these constants instead of just regular variables.
| end | ||
|
|
||
| def self.list(channels_list) | ||
| puts "\nHere are a list of your channels for this Workspace:" |
There was a problem hiding this comment.
You should try to separate the "display" functions of your app with the functionality and business logic. This "model-like" class shouldn't have to worry about printing things to the screen, instead it should work with the api and return data back.
| class SlackError < StandardError; end | ||
|
|
||
| class User | ||
| url = "https://slack.com/api/users.list" |
There was a problem hiding this comment.
Again, you should default to using constants unless you want to change the values of these variables.
| url = "https://slack.com/api/users.list" | ||
| key = ENV["SLACK_API_TOKEN"] | ||
|
|
||
| def self.user_api(url, key) |
There was a problem hiding this comment.
This method name could use a bit of work, rather than call it user_api I would call it, get_users. Also if key is already saved above, why do you need it as an argument?
| end | ||
|
|
||
| def self.list(users_list) | ||
| puts "\nHere are a list of your users for this Workspace:" |
There was a problem hiding this comment.
Again, I would separate out the presentation with the business logic of your application.
| end | ||
|
|
||
| def select_channel(user_input) | ||
| @channels.each do |channel| |
There was a problem hiding this comment.
You could also use the .find method as well.
| key = ENV["SLACK_API_TOKEN"] | ||
| channels_list = SlackApi::Channel.channel_api(url, key) | ||
|
|
||
| expect(channels_list.first["name"]).must_equal "general" |
There was a problem hiding this comment.
Different Slack orgs will return channels in different orders. I would instead try to verify that the list of channels contains "general" instead.
You can't make assumptions on the order that the API returns.
| key = ENV["SLACK_API_TOKEN"] | ||
| channels_list = SlackApi::Channel.channel_api(url, key) | ||
|
|
||
| expect(channels_list.first["id"]).must_equal "CH2RC3CNQ" |
There was a problem hiding this comment.
Since you're using this in several places, I would make the channel id a constant.
| key = ENV["SLACK_API_TOKEN"] | ||
| channels_list = SlackApi::Channel.channel_api(url, key) | ||
|
|
||
| expect(channels_list.first["num_members"]).must_equal 2 |
There was a problem hiding this comment.
Because a slack app will constantly change the number of users, I would instead just verify that the field exists and is a number.
You are also reusing the same test name in several different tests.
| channels_list = SlackApi::Channel.channel_api(url, key) | ||
|
|
||
| channels_list.each do |channel| | ||
| name = "Not a Channel" |
There was a problem hiding this comment.
You don't need to write a test to verify that a channel that does not exist doesn't appear in the list.
slack.rb
Congratulations! You're submitting your assignment!
You and your partner should collaborate on the answers to these questions.
Comprehension Questions