From ba612ba66c2fea61be3dac1ca769709ac3d07a29 Mon Sep 17 00:00:00 2001 From: sjscotton Date: Tue, 19 Mar 2019 13:44:43 -0700 Subject: [PATCH 01/26] created file structure --- lib/channel.rb | 0 lib/recipient.rb | 0 lib/user.rb | 0 lib/workspace.rb | 0 specs/channel_spec.rb | 0 specs/recipient_spec.rb | 0 specs/user_spec.rb | 0 specs/workspace_spec.rb | 0 8 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 lib/channel.rb create mode 100644 lib/recipient.rb create mode 100644 lib/user.rb create mode 100644 lib/workspace.rb create mode 100644 specs/channel_spec.rb create mode 100644 specs/recipient_spec.rb create mode 100644 specs/user_spec.rb create mode 100644 specs/workspace_spec.rb diff --git a/lib/channel.rb b/lib/channel.rb new file mode 100644 index 00000000..e69de29b diff --git a/lib/recipient.rb b/lib/recipient.rb new file mode 100644 index 00000000..e69de29b diff --git a/lib/user.rb b/lib/user.rb new file mode 100644 index 00000000..e69de29b diff --git a/lib/workspace.rb b/lib/workspace.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/user_spec.rb b/specs/user_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb new file mode 100644 index 00000000..e69de29b From 155a5c2f9f0a27507182ef03a53f61604d9ad2b5 Mon Sep 17 00:00:00 2001 From: Riyo Date: Tue, 19 Mar 2019 14:21:50 -0700 Subject: [PATCH 02/26] added tests to spec files --- lib/slack.rb | 28 ++++++++++++++++++++++------ specs/channel_spec.rb | 11 +++++++++++ specs/recipient_spec.rb | 9 +++++++++ specs/test_helper.rb | 19 ++++++++++++++++++- specs/user_spec.rb | 12 ++++++++++++ 5 files changed, 72 insertions(+), 7 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 960cf2f7..ce895ca0 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,11 +1,27 @@ #!/usr/bin/env ruby -def main - puts "Welcome to the Ada Slack CLI!" +require 'HTTParty' +require 'dotenv' +Dotenv.load - # TODO project +# url = 'https://slack.com/api/channels.list?' +# token = ENV['TOKEN'] - puts "Thank you for using the Ada Slack CLI" -end +# query_parameters = { +# token: token +# } -main if __FILE__ == $PROGRAM_NAME \ No newline at end of file +# response = HTTParty.get(url, query: query_parameters) + +# puts response + + +# def main +# puts "Welcome to the Ada Slack CLI!" + +# # TODO project + +# puts "Thank you for using the Ada Slack CLI" +# end + +# main if __FILE__ == $PROGRAM_NAME \ No newline at end of file diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index e69de29b..45619b09 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -0,0 +1,11 @@ +require_relative 'test_helper' + +describe "workplace" do + describe "self.list" do + # VCR.use_cassette("self.list") do + # response = SlackBot::Recipient.list + + # expect(response) + # end + end +end \ No newline at end of file diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index e69de29b..9f4f01b4 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -0,0 +1,9 @@ +require_relative 'test_helper' + +describe "workplace" do + describe "self.list" do + # expect { + # SlackBot::Recipient.list + # }.must_raise NotImplementedError + end +end \ No newline at end of file diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 81ccd06b..d1b44da5 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -6,10 +6,27 @@ require 'minitest/reporters' require 'minitest/skip_dsl' require 'vcr' +require 'webmock/minitest' +require 'dotenv' +Dotenv.load Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new VCR.configure do |config| config.cassette_library_dir = "specs/cassettes" config.hook_into :webmock -end \ No newline at end of file + config.default_cassette_options = { + :record => :new_episodes, + :match_requests_on => [:method, :uri, :body] + } + + config.filter_sensitive_data("") do + ENV["TOKEN"] + end +end + +require_relative "../lib/recipient.rb" +require_relative "../lib/user.rb" +require_relative "../lib/channel.rb" +require_relative "../lib/workspace.rb" +# require_relative "../lib/slack.rb" \ No newline at end of file diff --git a/specs/user_spec.rb b/specs/user_spec.rb index e69de29b..169b3566 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -0,0 +1,12 @@ +require_relative 'test_helper' + + +describe "workplace" do + describe "self.list" do + # VCR.use_cassette("self.list") do + # response = SlackBot::Recipient.list + + # expect(response) + # end + end +end \ No newline at end of file From 401fb02e5c612cd360eff0894d05bddd01287c16 Mon Sep 17 00:00:00 2001 From: sjscotton Date: Tue, 19 Mar 2019 14:36:13 -0700 Subject: [PATCH 03/26] Added recipient.list --- lib/recipient.rb | 7 +++++++ specs/recipient_spec.rb | 16 +++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index e69de29b..2b5242c7 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -0,0 +1,7 @@ +module SlackBot + class Recipient + def self.list + raise NotImplementedError + end + end +end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 9f4f01b4..991f722d 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -1,9 +1,11 @@ -require_relative 'test_helper' +require_relative "test_helper" -describe "workplace" do - describe "self.list" do - # expect { - # SlackBot::Recipient.list - # }.must_raise NotImplementedError +describe "Recipient" do + describe "self.list" do + it "Raises NotImplementedError if called directly on recipient" do + expect { + SlackBot::Recipient.list + }.must_raise NotImplementedError end -end \ No newline at end of file + end +end From 0f46e2650c1da40c642c9f672469d762c146e47f Mon Sep 17 00:00:00 2001 From: sjscotton Date: Tue, 19 Mar 2019 15:19:41 -0700 Subject: [PATCH 04/26] Added user self.list --- lib/slack.rb | 21 ++++++++++----------- lib/slack_api_error.rb | 0 lib/user.rb | 21 +++++++++++++++++++++ specs/test_helper.rb | 22 ++++++++++++---------- specs/user_spec.rb | 21 ++++++++++++--------- 5 files changed, 55 insertions(+), 30 deletions(-) create mode 100644 lib/slack_api_error.rb diff --git a/lib/slack.rb b/lib/slack.rb index ce895ca0..f7d374e9 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,20 +1,19 @@ #!/usr/bin/env ruby -require 'HTTParty' -require 'dotenv' +require "HTTParty" +require "dotenv" Dotenv.load -# url = 'https://slack.com/api/channels.list?' -# token = ENV['TOKEN'] +url = "https://slack.com/api/channels.list?" +token = ENV["TOKEN"] -# query_parameters = { -# token: token -# } +query_parameters = { + token: token, +} -# response = HTTParty.get(url, query: query_parameters) - -# puts response +response = HTTParty.get(url, query: query_parameters) +puts response # def main # puts "Welcome to the Ada Slack CLI!" @@ -24,4 +23,4 @@ # puts "Thank you for using the Ada Slack CLI" # end -# main if __FILE__ == $PROGRAM_NAME \ No newline at end of file +# main if __FILE__ == $PROGRAM_NAME diff --git a/lib/slack_api_error.rb b/lib/slack_api_error.rb new file mode 100644 index 00000000..e69de29b diff --git a/lib/user.rb b/lib/user.rb index e69de29b..6a139010 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -0,0 +1,21 @@ + + +module SlackBot + class User < Recipient + USER_LIST_URL = "https://slack.com/api/users.list?" + TOKEN = ENV["TOKEN"] + def self.list + query_parameters = { token: TOKEN } + response = HTTParty.get(USER_LIST_URL, query: query_parameters) + + users_array = response["members"].map do |user| + { + real_name: user["real_name"], + name: user["name"], + id: user["id"], + } + end + return users_array + end + end +end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index d1b44da5..007d8530 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -1,13 +1,15 @@ -require 'simplecov' +require "simplecov" SimpleCov.start -require 'minitest' -require 'minitest/autorun' -require 'minitest/reporters' -require 'minitest/skip_dsl' -require 'vcr' -require 'webmock/minitest' -require 'dotenv' +require "minitest" +require "minitest/autorun" +require "minitest/reporters" +require "minitest/skip_dsl" +require "HTTParty" +require "vcr" +require "webmock/minitest" +require "dotenv" +require "pry" Dotenv.load Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new @@ -17,7 +19,7 @@ config.hook_into :webmock config.default_cassette_options = { :record => :new_episodes, - :match_requests_on => [:method, :uri, :body] + :match_requests_on => [:method, :uri, :body], } config.filter_sensitive_data("") do @@ -29,4 +31,4 @@ require_relative "../lib/user.rb" require_relative "../lib/channel.rb" require_relative "../lib/workspace.rb" -# require_relative "../lib/slack.rb" \ No newline at end of file +# require_relative "../lib/slack.rb" diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 169b3566..5a199a8b 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -1,12 +1,15 @@ -require_relative 'test_helper' +require_relative "test_helper" +describe "user" do + describe "self.list" do + it "Returns an array of hashes" do + VCR.use_cassette("self.list") do + user_list = SlackBot::User.list -describe "workplace" do - describe "self.list" do - # VCR.use_cassette("self.list") do - # response = SlackBot::Recipient.list - - # expect(response) - # end + expect(user_list).must_be_kind_of Array + expect(user_list.first).must_be_kind_of Hash + expect(user_list.first).must_be_kind_of Hash + end end -end \ No newline at end of file + end +end From 309e1b383e66db70e9ad538fcd32f8150b3f9b28 Mon Sep 17 00:00:00 2001 From: Riyo Date: Tue, 19 Mar 2019 15:34:18 -0700 Subject: [PATCH 05/26] Added self.list to channel class --- lib/channel.rb | 20 ++++++++++++++++++++ lib/workspace.rb | 1 + specs/channel_spec.rb | 29 +++++++++++++++++++++-------- specs/user_spec.rb | 9 +++++++++ 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index e69de29b..85f3c7df 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -0,0 +1,20 @@ +module SlackBot + class Channel < Recipient + CHANNEL_LIST_URL = "https://slack.com/api/channels.list?" + TOKEN = ENV["TOKEN"] + def self.list + query_parameters = { token: TOKEN } + response = HTTParty.get(CHANNEL_LIST_URL, query: query_parameters) + + channels_array = response["channels"].map do |channel| + { + num_members: channel["num_members"], + name: channel["name"], + slack_id: channel["id"], + } + end + return channels_array + end + end + end + \ No newline at end of file diff --git a/lib/workspace.rb b/lib/workspace.rb index e69de29b..e8b4a614 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -0,0 +1 @@ +module Slack \ No newline at end of file diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 45619b09..01d34046 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -1,11 +1,24 @@ -require_relative 'test_helper' +require_relative "test_helper" -describe "workplace" do - describe "self.list" do - # VCR.use_cassette("self.list") do - # response = SlackBot::Recipient.list +describe "channel" do + describe "self.list" do + it "Returns an array of hashes" do + VCR.use_cassette("self.list") do + channel_list = SlackBot::Channel.list - # expect(response) - # end + expect(channel_list).must_be_kind_of Array + expect(channel_list.first).must_be_kind_of Hash + expect(channel_list.first).must_be_kind_of Hash + end end -end \ No newline at end of file + it "Returns a real_name" do + VCR.use_cassette("self.list") do + channel_list = SlackBot::Channel.list + + expect(channel_list.first[:num_members]).must_equal 2 + expect(channel_list.first[:slack_id]).must_equal "CH2P99HT5" + expect(channel_list.first[:name]).must_equal "slack-api-project" + end + end + end +end diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 5a199a8b..d5846942 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -11,5 +11,14 @@ expect(user_list.first).must_be_kind_of Hash end end + it "Returns a real_name" do + VCR.use_cassette("self.list") do + user_list = SlackBot::User.list + + expect(user_list.first[:real_name]).must_equal "Slackbot" + expect(user_list.first[:id]).must_equal "USLACKBOT" + expect(user_list.first[:name]).must_equal "slackbot" + end + end end end From 3b207cef2ea38dc845bfec24af794ffaff772394 Mon Sep 17 00:00:00 2001 From: Riyo Date: Tue, 19 Mar 2019 15:50:11 -0700 Subject: [PATCH 06/26] added workspace class and spec --- lib/workspace.rb | 10 +++++++++- specs/workspace_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index e8b4a614..b4ea77c9 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1 +1,9 @@ -module Slack \ No newline at end of file +module SlackBot + class Workspace + attr_reader :users, :channels + def initialize + @users = SlackBot::User.list + @channels = SlackBot::Channel.list + end + end +end \ No newline at end of file diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index e69de29b..f1b1ba3b 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -0,0 +1,21 @@ +require_relative "test_helper" + +describe "Workspace" do + describe "Initialize" do + it "Creates a workspace object" do + VCR.use_cassette("initialize") do + expect(SlackBot::Workspace.new).must_be_kind_of SlackBot::Workspace + end + end + it "Creates a list of users" do + VCR.use_cassette("initialize") do + user = SlackBot::Workspace.new + expect(user.users).must_be_kind_of Array + expect(user.users.first).must_be_kind_of Hash + expect(user.users.first.keys).must_equal [:real_name, :name, :id] + expect(user.users.first.values).must_equal ["Slackbot", "slackbot", "USLACKBOT"] + + end + end + end +end \ No newline at end of file From c6fed721a2267ef3706056a954be2c62f6d71222 Mon Sep 17 00:00:00 2001 From: sjscotton Date: Tue, 19 Mar 2019 16:16:53 -0700 Subject: [PATCH 07/26] Added main loop in main.rb --- lib/slack.rb | 69 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index f7d374e9..ca65d5f7 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,26 +1,53 @@ #!/usr/bin/env ruby - +require "table_print" require "HTTParty" require "dotenv" Dotenv.load -url = "https://slack.com/api/channels.list?" -token = ENV["TOKEN"] - -query_parameters = { - token: token, -} - -response = HTTParty.get(url, query: query_parameters) - -puts response - -# def main -# puts "Welcome to the Ada Slack CLI!" - -# # TODO project - -# puts "Thank you for using the Ada Slack CLI" -# end - -# main if __FILE__ == $PROGRAM_NAME +require_relative "../lib/recipient.rb" +require_relative "../lib/user.rb" +require_relative "../lib/channel.rb" +require_relative "../lib/workspace.rb" + +def get_user_input(options) + input = gets.chomp.to_s.strip + unless options.include?(input) + puts "Please choose option from list" + input = gets.chomp.to_s.strip + end + return input +end + +def list_options + puts "Please choose from these options" + puts "Enter 'list users' to view all users" + puts "Enter 'list channels' to view all channels" + puts "Enter 'quit' to quit" +end + +def create_table +end + +def main + puts "Welcome to the Ada Slack CLI!" + workspace = SlackBot::Workspace.new + + while true + list_options + options = ["list users", "list channels", "quit"] + choice = get_user_input(options) + case choice + when "list users" + puts "#{workspace.users}" + when "list channels" + puts "#{workspace.channels}" + when "quit" + puts "Goodbye!" + exit + end + end + + puts "Thank you for using the Ada Slack CLI" +end + +main if __FILE__ == $PROGRAM_NAME From 3f71bb8dbea485428c648fd35e05c2389bb46392 Mon Sep 17 00:00:00 2001 From: Riyo Date: Wed, 20 Mar 2019 14:01:59 -0700 Subject: [PATCH 08/26] added table_print for list user and channels --- lib/recipient.rb | 7 +++++++ lib/slack.rb | 9 ++++++--- lib/user.rb | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 2b5242c7..fa9c1d1d 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -3,5 +3,12 @@ class Recipient def self.list raise NotImplementedError end + + def Check_Error_Status(response) + binding.pry + if response.code != 200 + raise SlackApiError, "#{reponse.code} Error: #{response.message}" + end + end end end diff --git a/lib/slack.rb b/lib/slack.rb index ca65d5f7..0b0fc63f 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -25,7 +25,8 @@ def list_options puts "Enter 'quit' to quit" end -def create_table +def create_table(array) + tp array end def main @@ -38,9 +39,11 @@ def main choice = get_user_input(options) case choice when "list users" - puts "#{workspace.users}" + #puts "#{workspace.users}" + puts create_table(workspace.users) when "list channels" - puts "#{workspace.channels}" + #puts "#{workspace.channels}" + puts create_table(workspace.channels) when "quit" puts "Goodbye!" exit diff --git a/lib/user.rb b/lib/user.rb index 6a139010..a29a684a 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -7,6 +7,7 @@ class User < Recipient def self.list query_parameters = { token: TOKEN } response = HTTParty.get(USER_LIST_URL, query: query_parameters) + # Check_Error_Status(response) users_array = response["members"].map do |user| { From f614e2ac7e4df872b1d0f2f0fceb17626c753a81 Mon Sep 17 00:00:00 2001 From: Riyo Date: Wed, 20 Mar 2019 14:29:31 -0700 Subject: [PATCH 09/26] moved base_url to recipient --- lib/channel.rb | 4 ++-- lib/recipient.rb | 1 + lib/slack.rb | 10 ++-------- lib/user.rb | 9 ++++++--- specs/user_spec.rb | 10 ++++++++++ 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 85f3c7df..6efc8e18 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,10 +1,10 @@ module SlackBot class Channel < Recipient - CHANNEL_LIST_URL = "https://slack.com/api/channels.list?" + CHANNEL_PATH_URL = "channels.list?" TOKEN = ENV["TOKEN"] def self.list query_parameters = { token: TOKEN } - response = HTTParty.get(CHANNEL_LIST_URL, query: query_parameters) + response = HTTParty.get("#{BASE_URL}#{CHANNEL_PATH_URL}", query: query_parameters) channels_array = response["channels"].map do |channel| { diff --git a/lib/recipient.rb b/lib/recipient.rb index fa9c1d1d..3eecb5b0 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,5 +1,6 @@ module SlackBot class Recipient + BASE_URL = "https://slack.com/api/" def self.list raise NotImplementedError end diff --git a/lib/slack.rb b/lib/slack.rb index 0b0fc63f..a6b02bc8 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -25,10 +25,6 @@ def list_options puts "Enter 'quit' to quit" end -def create_table(array) - tp array -end - def main puts "Welcome to the Ada Slack CLI!" workspace = SlackBot::Workspace.new @@ -39,11 +35,9 @@ def main choice = get_user_input(options) case choice when "list users" - #puts "#{workspace.users}" - puts create_table(workspace.users) + tp workspace.users when "list channels" - #puts "#{workspace.channels}" - puts create_table(workspace.channels) + tp workspace.channels when "quit" puts "Goodbye!" exit diff --git a/lib/user.rb b/lib/user.rb index a29a684a..4ded1fe8 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,13 +1,16 @@ module SlackBot + class SlackApiError < StandardError; end class User < Recipient - USER_LIST_URL = "https://slack.com/api/users.list?" + USER_PATH_URL = "users.list?" TOKEN = ENV["TOKEN"] def self.list query_parameters = { token: TOKEN } - response = HTTParty.get(USER_LIST_URL, query: query_parameters) - # Check_Error_Status(response) + response = HTTParty.get("#{BASE_URL}#{USER_PATH_URL}", query: query_parameters) + unless response.code == 200 && response.parsed_response["ok"] + raise SlackApiError, "Error when listing users, error: #{response.parsed_response["error"]}" + end users_array = response["members"].map do |user| { diff --git a/specs/user_spec.rb b/specs/user_spec.rb index d5846942..76e16f10 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -20,5 +20,15 @@ expect(user_list.first[:name]).must_equal "slackbot" end end + # it "will raise an error when given an invalid token" do + # VCR.use_cassette("self.list") do + # exception = expect { + # SlackBot::User.list() + # }.must_raise SlackApi::SlackApiError + + # expect(exception.message).must_equal 'channel_not_found' + # end + # end + end end From 4e9634d5a77f46515f62d3ccded587937d4a863b Mon Sep 17 00:00:00 2001 From: sjscotton Date: Wed, 20 Mar 2019 15:13:59 -0700 Subject: [PATCH 10/26] added user initialize --- lib/user.rb | 9 +++++++++ specs/user_spec.rb | 19 ++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index 4ded1fe8..07eb3410 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -2,9 +2,18 @@ module SlackBot class SlackApiError < StandardError; end + class User < Recipient USER_PATH_URL = "users.list?" TOKEN = ENV["TOKEN"] + attr_reader :real_name, :name, :id + + def initialize(real_name:, name:, id:) + @real_name = real_name + @name = name + @id = id + end + def self.list query_parameters = { token: TOKEN } response = HTTParty.get("#{BASE_URL}#{USER_PATH_URL}", query: query_parameters) diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 76e16f10..480cb6cc 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -1,6 +1,15 @@ require_relative "test_helper" describe "user" do + describe "initialize" do + before do + @new_user = SlackBot::User.new(real_name: "Sarah", name: "Riyo", id: "USRJFDJFKD") + end + + it "creates an instance of user" do + expect(@new_user).must_be_kind_of SlackBot::User + end + end describe "self.list" do it "Returns an array of hashes" do VCR.use_cassette("self.list") do @@ -12,20 +21,20 @@ end end it "Returns a real_name" do - VCR.use_cassette("self.list") do - user_list = SlackBot::User.list + VCR.use_cassette("self.list") do + user_list = SlackBot::User.list - expect(user_list.first[:real_name]).must_equal "Slackbot" + expect(user_list.first[:real_name]).must_equal "Slackbot" expect(user_list.first[:id]).must_equal "USLACKBOT" expect(user_list.first[:name]).must_equal "slackbot" - end + end end # it "will raise an error when given an invalid token" do # VCR.use_cassette("self.list") do # exception = expect { # SlackBot::User.list() # }.must_raise SlackApi::SlackApiError - + # expect(exception.message).must_equal 'channel_not_found' # end # end From 83002b0d3ebe301de2bdca4e8ed9804333ddd3f8 Mon Sep 17 00:00:00 2001 From: Riyo Date: Wed, 20 Mar 2019 15:29:34 -0700 Subject: [PATCH 11/26] added user details method --- lib/recipient.rb | 4 ++++ lib/user.rb | 16 +++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 3eecb5b0..641e9fa0 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -11,5 +11,9 @@ def Check_Error_Status(response) raise SlackApiError, "#{reponse.code} Error: #{response.message}" end end + + def details + raise NotImplementedError + end end end diff --git a/lib/user.rb b/lib/user.rb index 07eb3410..092337e0 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -22,13 +22,19 @@ def self.list end users_array = response["members"].map do |user| - { - real_name: user["real_name"], - name: user["name"], - id: user["id"], - } + SlackBot::User.new(real_name: user["real name"], name: user["name"], id: user["id"]) end + + return users_array end + + def details + { + real_name: = @real_name, + name: = @user, + id: = @user + } + end end end From 017bbc009402aef970b368735c16af3f3c181ae9 Mon Sep 17 00:00:00 2001 From: sjscotton Date: Wed, 20 Mar 2019 15:54:42 -0700 Subject: [PATCH 12/26] Added workspace list users --- lib/slack.rb | 2 +- lib/user.rb | 16 +++++------ lib/workspace.rb | 39 ++++++++++++++++++++------ specs/user_spec.rb | 10 +++---- specs/workspace_spec.rb | 61 ++++++++++++++++++++++++++++++----------- 5 files changed, 90 insertions(+), 38 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index a6b02bc8..393b21e0 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -35,7 +35,7 @@ def main choice = get_user_input(options) case choice when "list users" - tp workspace.users + tp workspace.list_users when "list channels" tp workspace.channels when "quit" diff --git a/lib/user.rb b/lib/user.rb index 092337e0..a2102ef2 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,4 +1,4 @@ - +require "pry" module SlackBot class SlackApiError < StandardError; end @@ -22,19 +22,19 @@ def self.list end users_array = response["members"].map do |user| - SlackBot::User.new(real_name: user["real name"], name: user["name"], id: user["id"]) + SlackBot::User.new(real_name: user["real_name"], name: user["name"], id: user["id"]) end - return users_array end def details - { - real_name: = @real_name, - name: = @user, - id: = @user - } + user_details = { + real_name: @real_name, + name: @user, + id: @user, + } + return user_details end end end diff --git a/lib/workspace.rb b/lib/workspace.rb index b4ea77c9..a437accc 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,9 +1,32 @@ module SlackBot - class Workspace - attr_reader :users, :channels - def initialize - @users = SlackBot::User.list - @channels = SlackBot::Channel.list - end - end -end \ No newline at end of file + class Workspace + attr_reader :users, :channels, :selected + + def initialize + @users = SlackBot::User.list + @channels = SlackBot::Channel.list + @selected = nil + end + + def list_users + user_list = @users.map do |user| + user.details + end + return user_list + end + + def select_user(input) + found_user = @users.find do |user| + input == user.id || input == user.name + end + @selected = found_user + end + + def select_channel(input) + found_channel = @channels.find do |user| + input == user["id"] || input == user["name"] + end + @selected = found_channel + end + end +end diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 480cb6cc..f6df3704 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -16,17 +16,17 @@ user_list = SlackBot::User.list expect(user_list).must_be_kind_of Array - expect(user_list.first).must_be_kind_of Hash - expect(user_list.first).must_be_kind_of Hash + expect(user_list.first).must_be_kind_of SlackBot::User + expect(user_list.last).must_be_kind_of SlackBot::User end end it "Returns a real_name" do VCR.use_cassette("self.list") do user_list = SlackBot::User.list - expect(user_list.first[:real_name]).must_equal "Slackbot" - expect(user_list.first[:id]).must_equal "USLACKBOT" - expect(user_list.first[:name]).must_equal "slackbot" + expect(user_list.first.real_name).must_equal "Slackbot" + expect(user_list.first.id).must_equal "USLACKBOT" + expect(user_list.first.name).must_equal "slackbot" end end # it "will raise an error when given an invalid token" do diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index f1b1ba3b..2034cf58 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -1,21 +1,50 @@ require_relative "test_helper" describe "Workspace" do - describe "Initialize" do - it "Creates a workspace object" do - VCR.use_cassette("initialize") do - expect(SlackBot::Workspace.new).must_be_kind_of SlackBot::Workspace - end - end - it "Creates a list of users" do - VCR.use_cassette("initialize") do - user = SlackBot::Workspace.new - expect(user.users).must_be_kind_of Array - expect(user.users.first).must_be_kind_of Hash - expect(user.users.first.keys).must_equal [:real_name, :name, :id] - expect(user.users.first.values).must_equal ["Slackbot", "slackbot", "USLACKBOT"] + describe "Initialize" do + before do + VCR.use_cassette("initialize") do + @workspace = SlackBot::Workspace.new + end + end + it "Creates a workspace object" do + expect(@workspace).must_be_kind_of SlackBot::Workspace + end - end - end + it "Initializes with selected equal to nil" do + expect(@workspace.selected).must_equal nil + end + it "Creates a list of users" do + expect(@workspace.users).must_be_kind_of Array + expect(@workspace.users.first).must_be_kind_of SlackBot::User + # expect(@workspace.users.first.real_name).must_equal "Slackbot" + # expect(@workspace.users.first.name).must_equal "slackbot" + # expect(@workspace.users.first.name).must_equal "USLACKBOT" + end + end + describe "select" do + before do + VCR.use_cassette("select") do + @workspace = SlackBot::Workspace.new + end + end + it "returns nil if no user found with id given" do + selected = @workspace.select_user("USLACKNOT") + expect(selected).must_equal nil + end + it "returns nil if no user found with name given" do + selected = @workspace.select_user("Devin") + expect(selected).must_equal nil end -end \ No newline at end of file + # it "returns a User object if given a valid user id" do + # selected = @workspace.select_user("USLACKBOT") + # expect(selected).must_be_kind_of SlackBot::User + # expect(selected["name"]).must_equal "slackbot" + # end + # it "returns a User object if given a valid user name" do + # selected = @workspace.select_user("slackbot") + # expect(selected).must_be_kind_of SlackBot::User + # expect(selected["name"]).must_equal "USLACKBOT" + # end + end +end From 867f4bd43b72e23c1cdc03ec4cc29401799bdd21 Mon Sep 17 00:00:00 2001 From: Riyo Date: Wed, 20 Mar 2019 17:21:35 -0700 Subject: [PATCH 13/26] added initialize and details to channel --- lib/channel.rb | 50 ++++++++++++++++++++++++++++++++----------- lib/slack.rb | 2 +- lib/user.rb | 4 ++-- lib/workspace.rb | 11 ++++++++-- specs/channel_spec.rb | 10 ++++----- 5 files changed, 54 insertions(+), 23 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 6efc8e18..b3492c62 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -2,19 +2,43 @@ module SlackBot class Channel < Recipient CHANNEL_PATH_URL = "channels.list?" TOKEN = ENV["TOKEN"] - def self.list - query_parameters = { token: TOKEN } - response = HTTParty.get("#{BASE_URL}#{CHANNEL_PATH_URL}", query: query_parameters) - - channels_array = response["channels"].map do |channel| - { - num_members: channel["num_members"], - name: channel["name"], - slack_id: channel["id"], - } + attr_reader :num_members, :name, :id + + def initialize(num_members:, name:, id:) + @num_members = num_members + @name = name + @id = id + end + + def self.list + query_parameters = { token: TOKEN } + response = HTTParty.get("#{BASE_URL}#{CHANNEL_PATH_URL}", query: query_parameters) + unless response.code == 200 && response.parsed_response["ok"] + raise SlackApiError, "Error when listing channels, error: #{response.parsed_response["error"]}" + end + + channels_array = response["channels"].map do |channel| + SlackBot::Channel.new(num_members: channel["num_members"], name: channel["name"], id: channel["id"]) + end + + return channels_array + end + + def details + channel_details = { + num_members: @num_members, + name: @name, + id: @id, + } + return channel_details end - return channels_array - end - end end +end + + + + + + + \ No newline at end of file diff --git a/lib/slack.rb b/lib/slack.rb index 393b21e0..8e15f351 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -37,7 +37,7 @@ def main when "list users" tp workspace.list_users when "list channels" - tp workspace.channels + tp workspace.list_channels when "quit" puts "Goodbye!" exit diff --git a/lib/user.rb b/lib/user.rb index a2102ef2..d78dee4c 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -31,8 +31,8 @@ def self.list def details user_details = { real_name: @real_name, - name: @user, - id: @user, + name: @name, + id: @id, } return user_details end diff --git a/lib/workspace.rb b/lib/workspace.rb index a437accc..748fdb5e 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -15,6 +15,13 @@ def list_users return user_list end + def list_channels + channel_list = @channels.map do |channel| + channel.details + end + return channel_list + end + def select_user(input) found_user = @users.find do |user| input == user.id || input == user.name @@ -23,8 +30,8 @@ def select_user(input) end def select_channel(input) - found_channel = @channels.find do |user| - input == user["id"] || input == user["name"] + found_channel = @channels.find do |channel| + input == channel.id || input == channel.name end @selected = found_channel end diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 01d34046..ef7b76ed 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -7,17 +7,17 @@ channel_list = SlackBot::Channel.list expect(channel_list).must_be_kind_of Array - expect(channel_list.first).must_be_kind_of Hash - expect(channel_list.first).must_be_kind_of Hash + expect(channel_list.first).must_be_kind_of SlackBot::Channel + expect(channel_list.last).must_be_kind_of SlackBot::Channel end end it "Returns a real_name" do VCR.use_cassette("self.list") do channel_list = SlackBot::Channel.list - expect(channel_list.first[:num_members]).must_equal 2 - expect(channel_list.first[:slack_id]).must_equal "CH2P99HT5" - expect(channel_list.first[:name]).must_equal "slack-api-project" + expect(channel_list.first.num_members).must_equal 2 + expect(channel_list.first.id).must_equal "CH2P99HT5" + expect(channel_list.first.name).must_equal "slack-api-project" end end end From ac7172039f6a7893c8385ddcc175cc48c0800788 Mon Sep 17 00:00:00 2001 From: Riyo Date: Wed, 20 Mar 2019 17:42:00 -0700 Subject: [PATCH 14/26] added tests for list_users and list_channels for workspace --- specs/workspace_spec.rb | 70 +++++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 13 deletions(-) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 2034cf58..c49d45ea 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -17,11 +17,34 @@ it "Creates a list of users" do expect(@workspace.users).must_be_kind_of Array expect(@workspace.users.first).must_be_kind_of SlackBot::User - # expect(@workspace.users.first.real_name).must_equal "Slackbot" - # expect(@workspace.users.first.name).must_equal "slackbot" - # expect(@workspace.users.first.name).must_equal "USLACKBOT" + expect(@workspace.users.first.real_name).must_equal "Slackbot" + expect(@workspace.users.first.name).must_equal "slackbot" + expect(@workspace.users.first.id).must_equal "USLACKBOT" end end +describe "list" do + before do + VCR.use_cassette("list") do + @workspace = SlackBot::Workspace.new + end + end + it "returns an array of hashes for list_users" do + users = @workspace.list_users + expect(users).must_be_kind_of Array + expect(users.first).must_be_kind_of Hash + expect(users.first[:name]).must_equal "slackbot" + expect(users.first[:id]).must_equal "USLACKBOT" + expect(users.first[:real_name]).must_equal "Slackbot" + end + it "returns an array of hashes for list_channel" do + channels = @workspace.list_channels + expect(channels).must_be_kind_of Array + expect(channels.first).must_be_kind_of Hash + expect(channels.first[:name]).must_equal "slack-api-project" + expect(channels.first[:id]).must_equal "CH2P99HT5" + expect(channels.first[:num_members]).must_equal 2 + end +end describe "select" do before do VCR.use_cassette("select") do @@ -36,15 +59,36 @@ selected = @workspace.select_user("Devin") expect(selected).must_equal nil end - # it "returns a User object if given a valid user id" do - # selected = @workspace.select_user("USLACKBOT") - # expect(selected).must_be_kind_of SlackBot::User - # expect(selected["name"]).must_equal "slackbot" - # end - # it "returns a User object if given a valid user name" do - # selected = @workspace.select_user("slackbot") - # expect(selected).must_be_kind_of SlackBot::User - # expect(selected["name"]).must_equal "USLACKBOT" - # end + it "returns a User object if given a valid user id" do + selected = @workspace.select_user("USLACKBOT") + expect(selected).must_be_kind_of SlackBot::User + expect(selected.name).must_equal "slackbot" + end + it "returns a User object if given a valid user name" do + selected = @workspace.select_user("slackbot") + expect(selected).must_be_kind_of SlackBot::User + expect(selected.id).must_equal "USLACKBOT" + end + + + it "returns nil if no channel found with id given" do + selected = @workspace.select_channel("CH2P99HT6") + expect(selected).must_equal nil + end + it "returns nil if no user found with name given" do + selected = @workspace.select_channel("slack-bpi-project") + expect(selected).must_equal nil + end + it "returns a User object if given a valid user id" do + selected = @workspace.select_channel("CH2SL5C3C") + expect(selected).must_be_kind_of SlackBot::Channel + expect(selected.name).must_equal "everyone" + end + it "returns a User object if given a valid name" do + selected = @workspace.select_channel("random") + expect(selected).must_be_kind_of SlackBot::Channel + expect(selected.id).must_equal "CH2SL5DEW" + end + end end From 45da5c8009f3d3a799e0f20058cc502461c94de1 Mon Sep 17 00:00:00 2001 From: sjscotton Date: Wed, 20 Mar 2019 18:21:25 -0700 Subject: [PATCH 15/26] Updated slack.rb to include select users, channels and details in the CLI program options --- lib/slack.rb | 31 +++++++++++++++-- specs/workspace_spec.rb | 74 ++++++++++++++++++++--------------------- 2 files changed, 64 insertions(+), 41 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 8e15f351..3bc78d9e 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -9,7 +9,7 @@ require_relative "../lib/channel.rb" require_relative "../lib/workspace.rb" -def get_user_input(options) +def get_user_options_input(options) input = gets.chomp.to_s.strip unless options.include?(input) puts "Please choose option from list" @@ -18,10 +18,22 @@ def get_user_input(options) return input end +def get_user_input + input = gets.chomp.to_s.strip + unless input.length > 0 + puts "Please enter an ID or name" + input = gets.chomp.to_s.strip + end + return input +end + def list_options puts "Please choose from these options" puts "Enter 'list users' to view all users" puts "Enter 'list channels' to view all channels" + puts "Enter 'select user' to select a user" + puts "Enter 'select channel' to select a channel" + puts "Enter 'details' to display information about currently selected recipient" puts "Enter 'quit' to quit" end @@ -31,17 +43,30 @@ def main while true list_options - options = ["list users", "list channels", "quit"] - choice = get_user_input(options) + options = ["list users", "list channels", "select user", "select channel", "details", "quit"] + choice = get_user_options_input(options) case choice when "list users" tp workspace.list_users when "list channels" tp workspace.list_channels + when "select user" + puts "Please enter a user ID or user name" + input = get_user_input + selected = workspace.select_user(input) + 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 + selected = workspace.select_channel(input) + puts "Sorry, no channel with that information" if selected == nil + when "details" + tp [selected.details] when "quit" puts "Goodbye!" exit end + puts "\n\n" end puts "Thank you for using the Ada Slack CLI" diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index c49d45ea..771804d3 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -22,29 +22,29 @@ expect(@workspace.users.first.id).must_equal "USLACKBOT" end end -describe "list" do - before do - VCR.use_cassette("list") do - @workspace = SlackBot::Workspace.new - end - end + describe "list" do + before do + VCR.use_cassette("list") do + @workspace = SlackBot::Workspace.new + end + end it "returns an array of hashes for list_users" do - users = @workspace.list_users - expect(users).must_be_kind_of Array - expect(users.first).must_be_kind_of Hash - expect(users.first[:name]).must_equal "slackbot" - expect(users.first[:id]).must_equal "USLACKBOT" - expect(users.first[:real_name]).must_equal "Slackbot" + users = @workspace.list_users + expect(users).must_be_kind_of Array + expect(users.first).must_be_kind_of Hash + expect(users.first[:name]).must_equal "slackbot" + expect(users.first[:id]).must_equal "USLACKBOT" + expect(users.first[:real_name]).must_equal "Slackbot" end it "returns an array of hashes for list_channel" do - channels = @workspace.list_channels - expect(channels).must_be_kind_of Array - expect(channels.first).must_be_kind_of Hash - expect(channels.first[:name]).must_equal "slack-api-project" - expect(channels.first[:id]).must_equal "CH2P99HT5" - expect(channels.first[:num_members]).must_equal 2 + channels = @workspace.list_channels + expect(channels).must_be_kind_of Array + expect(channels.first).must_be_kind_of Hash + expect(channels.first[:name]).must_equal "slack-api-project" + expect(channels.first[:id]).must_equal "CH2P99HT5" + expect(channels.first[:num_members]).must_equal 2 end -end + end describe "select" do before do VCR.use_cassette("select") do @@ -70,25 +70,23 @@ expect(selected.id).must_equal "USLACKBOT" end - it "returns nil if no channel found with id given" do - selected = @workspace.select_channel("CH2P99HT6") - expect(selected).must_equal nil - end - it "returns nil if no user found with name given" do - selected = @workspace.select_channel("slack-bpi-project") - expect(selected).must_equal nil - end - it "returns a User object if given a valid user id" do - selected = @workspace.select_channel("CH2SL5C3C") - expect(selected).must_be_kind_of SlackBot::Channel - expect(selected.name).must_equal "everyone" - end - it "returns a User object if given a valid name" do - selected = @workspace.select_channel("random") - expect(selected).must_be_kind_of SlackBot::Channel - expect(selected.id).must_equal "CH2SL5DEW" - end - + selected = @workspace.select_channel("CH2P99HT6") + expect(selected).must_equal nil + end + it "returns nil if no user found with name given" do + selected = @workspace.select_channel("slack-bpi-project") + expect(selected).must_equal nil + end + it "returns a User object if given a valid user id" do + selected = @workspace.select_channel("CH2SL5C3C") + expect(selected).must_be_kind_of SlackBot::Channel + expect(selected.name).must_equal "everyone" + end + it "returns a User object if given a valid name" do + selected = @workspace.select_channel("random") + expect(selected).must_be_kind_of SlackBot::Channel + expect(selected.id).must_equal "CH2SL5DEW" + end end end From b210b3ca980d3189a3f45fefee58f94bd7d7e85f Mon Sep 17 00:00:00 2001 From: sjscotton Date: Fri, 22 Mar 2019 10:33:25 -0700 Subject: [PATCH 16/26] Added send message to recipient --- lib/recipient.rb | 31 +++++++++++++++++++++++-------- lib/user.rb | 1 - 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 641e9fa0..4832e702 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -4,16 +4,31 @@ class Recipient def self.list raise NotImplementedError end - - def Check_Error_Status(response) - binding.pry - if response.code != 200 - raise SlackApiError, "#{reponse.code} Error: #{response.message}" - end - end + + # def Check_Error_Status(response) + # binding.pry + # if response.code != 200 + # raise SlackApiError, "#{reponse.code} Error: #{response.message}" + # end + # end def details - raise NotImplementedError + raise NotImplementedError + end + + def send_message(message) + body = { + text: message, + channel: id, + token: TOKEN, + } + response = HTTParty.post("#{BASE_URL}chat.postMessage", body: body, headers: { "Content-type" => "application/x-www-form-urlencoded" }) + + unless response.code == 200 && response.parsed_response["ok"] + raise SlackApiError, "Error when posting #{message} to #{id} , error #{response.parsed_response["error"]}" + end + + return true end end end diff --git a/lib/user.rb b/lib/user.rb index d78dee4c..cbee6e89 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -20,7 +20,6 @@ def self.list unless response.code == 200 && response.parsed_response["ok"] raise SlackApiError, "Error when listing users, error: #{response.parsed_response["error"]}" end - users_array = response["members"].map do |user| SlackBot::User.new(real_name: user["real_name"], name: user["name"], id: user["id"]) end From 95d61b83ab087cd583ef971d00e11d0d1f40f5e8 Mon Sep 17 00:00:00 2001 From: sjscotton Date: Fri, 22 Mar 2019 10:53:39 -0700 Subject: [PATCH 17/26] added send message to workspace --- lib/channel.rb | 74 +++++++++++++++++++++--------------------------- lib/recipient.rb | 1 + lib/user.rb | 2 +- lib/workspace.rb | 14 ++++++--- 4 files changed, 45 insertions(+), 46 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index b3492c62..d5a957f6 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,44 +1,36 @@ module SlackBot - class Channel < Recipient - CHANNEL_PATH_URL = "channels.list?" - TOKEN = ENV["TOKEN"] - attr_reader :num_members, :name, :id - - def initialize(num_members:, name:, id:) - @num_members = num_members - @name = name - @id = id - end - - def self.list - query_parameters = { token: TOKEN } - response = HTTParty.get("#{BASE_URL}#{CHANNEL_PATH_URL}", query: query_parameters) - unless response.code == 200 && response.parsed_response["ok"] - raise SlackApiError, "Error when listing channels, error: #{response.parsed_response["error"]}" - end - - channels_array = response["channels"].map do |channel| - SlackBot::Channel.new(num_members: channel["num_members"], name: channel["name"], id: channel["id"]) - end - - return channels_array - end - - def details - channel_details = { - num_members: @num_members, - name: @name, - id: @id, - } - return channel_details - end + class Channel < Recipient + CHANNEL_PATH_URL = "channels.list?" + # TOKEN = ENV["TOKEN"] + attr_reader :num_members, :name, :id + + def initialize(num_members:, name:, id:) + @num_members = num_members + @name = name + @id = id + end + + def self.list + query_parameters = { token: TOKEN } + response = HTTParty.get("#{BASE_URL}#{CHANNEL_PATH_URL}", query: query_parameters) + unless response.code == 200 && response.parsed_response["ok"] + raise SlackApiError, "Error when listing channels, error: #{response.parsed_response["error"]}" + end + + channels_array = response["channels"].map do |channel| + SlackBot::Channel.new(num_members: channel["num_members"], name: channel["name"], id: channel["id"]) + end + + return channels_array + end + + def details + channel_details = { + num_members: @num_members, + name: @name, + id: @id, + } + return channel_details + end end end - - - - - - - - \ No newline at end of file diff --git a/lib/recipient.rb b/lib/recipient.rb index 4832e702..e64888d1 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,6 +1,7 @@ module SlackBot class Recipient BASE_URL = "https://slack.com/api/" + TOKEN = ENV["TOKEN"] def self.list raise NotImplementedError end diff --git a/lib/user.rb b/lib/user.rb index cbee6e89..5bcdd129 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -5,7 +5,7 @@ class SlackApiError < StandardError; end class User < Recipient USER_PATH_URL = "users.list?" - TOKEN = ENV["TOKEN"] + # TOKEN = ENV["TOKEN"] attr_reader :real_name, :name, :id def initialize(real_name:, name:, id:) diff --git a/lib/workspace.rb b/lib/workspace.rb index 748fdb5e..06a8430c 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -16,11 +16,11 @@ def list_users end def list_channels - channel_list = @channels.map do |channel| - channel.details - end - return channel_list + channel_list = @channels.map do |channel| + channel.details end + return channel_list + end def select_user(input) found_user = @users.find do |user| @@ -35,5 +35,11 @@ def select_channel(input) end @selected = found_channel end + + def send_message(message) + return false if !selected + selected.send_message(message) + return true + end end end From b2e70ab1bd179c000a739dc0ebe9a2e94e17efb0 Mon Sep 17 00:00:00 2001 From: Riyo Date: Fri, 22 Mar 2019 11:40:06 -0700 Subject: [PATCH 18/26] send message tests for workspace, user and channel --- lib/recipient.rb | 1 + lib/user.rb | 2 +- specs/channel_spec.rb | 23 +++++++++++++++++++++++ specs/user_spec.rb | 34 ++++++++++++++++++++++++++++++++++ specs/workspace_spec.rb | 27 +++++++++++++++++++++++++++ 5 files changed, 86 insertions(+), 1 deletion(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index e64888d1..0fa61e51 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,4 +1,5 @@ module SlackBot + class SlackApiError < StandardError; end class Recipient BASE_URL = "https://slack.com/api/" TOKEN = ENV["TOKEN"] diff --git a/lib/user.rb b/lib/user.rb index 5bcdd129..3d8ac39c 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,7 +1,7 @@ require "pry" module SlackBot - class SlackApiError < StandardError; end + # class SlackApiError < StandardError; end class User < Recipient USER_PATH_URL = "users.list?" diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index ef7b76ed..9646abea 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -21,4 +21,27 @@ end end end + describe "send message" do + before do + VCR.use_cassette("send message to channel") do + @channel_list = SlackBot::Channel.list + end + end + + it "returns true if given a valid message" do + VCR.use_cassette("send message with empty string to channel") do + message = "Hello!" + expect(@channel_list.first.send_message(message)).must_equal true + end + end + + it "returns a slackapierror when given an empty string" do + VCR.use_cassette("send message with empty string to channel") do + message = "" + expect { + @channel_list.first.send_message(message) + }.must_raise SlackBot::SlackApiError + end + end + end end diff --git a/specs/user_spec.rb b/specs/user_spec.rb index f6df3704..d0c7996f 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -1,4 +1,5 @@ require_relative "test_helper" +require "pry" describe "user" do describe "initialize" do @@ -40,4 +41,37 @@ # end end + describe "send message" do + before do + VCR.use_cassette("send message") do + @user_list = SlackBot::User.list + end + end + + + it "returns true if given a valid message" do + VCR.use_cassette("send working message") do + message = "Hello!" + expect(@user_list.first.send_message(message)).must_equal true + end + end + + it "returns a slackapierror when given an empty string" do + VCR.use_cassette("send message with empty string") do + message = "" + expect { + @user_list.first.send_message(message) + }.must_raise SlackBot::SlackApiError + end + end + + # it "returns a slackapierror when given too many characters" do + # VCR.use_cassette("send message with too many characters") do + # message = "N" * 40010 + # expect { + # @user_list.first.send_message(message) + # }.must_raise SlackBot::SlackApiError + # end + #end + end end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 771804d3..4f5b1cb3 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -89,4 +89,31 @@ expect(selected.id).must_equal "CH2SL5DEW" end end + describe "send message" do + before do + VCR.use_cassette("select") do + @workspace = SlackBot::Workspace.new + end + end + + it "returns false if no user or channel is selected" do + expect(@workspace.send_message("Hi")).must_equal false + end + + it "returns a slackapierror when given an empty message" do + VCR.use_cassette("send message with empty string") do + message = "" + expect { + @workspace.users.first.send_message(message) + }.must_raise SlackBot::SlackApiError + end + end + + it "returns true if given a valid message and valid user/channel selected" do + VCR.use_cassette("send message with empty string") do + message = "Hello!" + expect(@workspace.users.first.send_message(message)).must_equal true + end + end + end end From 0641e190c38e9407601b580f2235092e335884d9 Mon Sep 17 00:00:00 2001 From: sjscotton Date: Fri, 22 Mar 2019 11:52:28 -0700 Subject: [PATCH 19/26] added send message to main --- lib/slack.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/slack.rb b/lib/slack.rb index 3bc78d9e..14af5c7b 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -34,6 +34,7 @@ def list_options puts "Enter 'select user' to select a user" puts "Enter 'select channel' to select a channel" puts "Enter 'details' to display information about currently selected recipient" + puts "Enter 'send message' to send a message to selected recipient" puts "Enter 'quit' to quit" end @@ -43,7 +44,7 @@ def main while true list_options - options = ["list users", "list channels", "select user", "select channel", "details", "quit"] + options = ["list users", "list channels", "select user", "select channel", "details", "send message", "quit"] choice = get_user_options_input(options) case choice when "list users" @@ -62,6 +63,14 @@ def main puts "Sorry, no channel with that information" if selected == nil when "details" tp [selected.details] + when "send message" + if !workspace.selected + puts "A recipient needs to be selected first" + else + puts "Enter the message you would like to send: " + message = gets.chomp.to_s.strip + workspace.send_message(message) + end when "quit" puts "Goodbye!" exit From 4a3cd03b2d524da0fd847f92692517390a70714b Mon Sep 17 00:00:00 2001 From: sjscotton Date: Fri, 22 Mar 2019 11:53:32 -0700 Subject: [PATCH 20/26] edited error message --- lib/recipient.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index e64888d1..20c34ead 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -26,7 +26,7 @@ def send_message(message) response = HTTParty.post("#{BASE_URL}chat.postMessage", body: body, headers: { "Content-type" => "application/x-www-form-urlencoded" }) unless response.code == 200 && response.parsed_response["ok"] - raise SlackApiError, "Error when posting #{message} to #{id} , error #{response.parsed_response["error"]}" + raise SlackApiError, "Error when posting #{message} to #{id}, error: #{response.parsed_response["error"]}" end return true From d0809944f3fc6faabab0af26afd67c5ebd37abbf Mon Sep 17 00:00:00 2001 From: sjscotton Date: Fri, 22 Mar 2019 12:14:11 -0700 Subject: [PATCH 21/26] Added user input validation to slack.rb --- lib/slack.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 14af5c7b..2869e486 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -18,10 +18,10 @@ def get_user_options_input(options) return input end -def get_user_input +def get_user_input(message_to_user) input = gets.chomp.to_s.strip - unless input.length > 0 - puts "Please enter an ID or name" + until input.length > 0 + puts message_to_user input = gets.chomp.to_s.strip end return input @@ -53,7 +53,7 @@ def main tp workspace.list_channels when "select user" puts "Please enter a user ID or user name" - input = get_user_input + input = get_user_input("Please enter an ID or name") selected = workspace.select_user(input) puts "Sorry, no user with that information" if selected == nil when "select channel" @@ -68,8 +68,8 @@ def main puts "A recipient needs to be selected first" else puts "Enter the message you would like to send: " - message = gets.chomp.to_s.strip - workspace.send_message(message) + message_to_send = get_user_input("Message must be at least one character") + workspace.send_message(message_to_send) end when "quit" puts "Goodbye!" From e1e40f916c95cc853036070f2b1cf5afd346e63f Mon Sep 17 00:00:00 2001 From: Riyo Date: Fri, 22 Mar 2019 14:16:26 -0700 Subject: [PATCH 22/26] added self.get method --- lib/channel.rb | 5 ++--- lib/recipient.rb | 6 ++++++ lib/user.rb | 5 ++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index d5a957f6..52be91a7 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,6 +1,6 @@ module SlackBot class Channel < Recipient - CHANNEL_PATH_URL = "channels.list?" + PATH_URL = "channels.list?" # TOKEN = ENV["TOKEN"] attr_reader :num_members, :name, :id @@ -11,8 +11,7 @@ def initialize(num_members:, name:, id:) end def self.list - query_parameters = { token: TOKEN } - response = HTTParty.get("#{BASE_URL}#{CHANNEL_PATH_URL}", query: query_parameters) + response = get(PATH_URL) unless response.code == 200 && response.parsed_response["ok"] raise SlackApiError, "Error when listing channels, error: #{response.parsed_response["error"]}" end diff --git a/lib/recipient.rb b/lib/recipient.rb index 9ef065f6..a4493b40 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -18,6 +18,12 @@ def details raise NotImplementedError end + def self.get(path_url) + query_parameters = { token: TOKEN } + response = HTTParty.get("#{BASE_URL}#{path_url}", query: query_parameters) + return response + end + def send_message(message) body = { text: message, diff --git a/lib/user.rb b/lib/user.rb index 3d8ac39c..f4d2e242 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -4,7 +4,7 @@ module SlackBot # class SlackApiError < StandardError; end class User < Recipient - USER_PATH_URL = "users.list?" + PATH_URL = "users.list?" # TOKEN = ENV["TOKEN"] attr_reader :real_name, :name, :id @@ -15,8 +15,7 @@ def initialize(real_name:, name:, id:) end def self.list - query_parameters = { token: TOKEN } - response = HTTParty.get("#{BASE_URL}#{USER_PATH_URL}", query: query_parameters) + response = get(PATH_URL) unless response.code == 200 && response.parsed_response["ok"] raise SlackApiError, "Error when listing users, error: #{response.parsed_response["error"]}" end From 50f4ddfd1b103bc101bab01f57db9ebd1c5b9832 Mon Sep 17 00:00:00 2001 From: Riyo Date: Fri, 22 Mar 2019 14:45:50 -0700 Subject: [PATCH 23/26] cleaned up tests --- lib/channel.rb | 1 - lib/recipient.rb | 22 ++++++++-------------- lib/user.rb | 4 +--- specs/recipient_spec.rb | 9 +++++++++ specs/test_helper.rb | 1 - specs/user_spec.rb | 22 ++-------------------- 6 files changed, 20 insertions(+), 39 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 52be91a7..f664d11c 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,7 +1,6 @@ module SlackBot class Channel < Recipient PATH_URL = "channels.list?" - # TOKEN = ENV["TOKEN"] attr_reader :num_members, :name, :id def initialize(num_members:, name:, id:) diff --git a/lib/recipient.rb b/lib/recipient.rb index a4493b40..a732ef56 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -7,28 +7,15 @@ def self.list raise NotImplementedError end - # def Check_Error_Status(response) - # binding.pry - # if response.code != 200 - # raise SlackApiError, "#{reponse.code} Error: #{response.message}" - # end - # end - def details raise NotImplementedError end - def self.get(path_url) - query_parameters = { token: TOKEN } - response = HTTParty.get("#{BASE_URL}#{path_url}", query: query_parameters) - return response - end - def send_message(message) body = { text: message, channel: id, - token: TOKEN, + token: TOKEN } response = HTTParty.post("#{BASE_URL}chat.postMessage", body: body, headers: { "Content-type" => "application/x-www-form-urlencoded" }) @@ -38,5 +25,12 @@ def send_message(message) return true end + + private + def self.get(path_url) + query_parameters = { token: TOKEN } + response = HTTParty.get("#{BASE_URL}#{path_url}", query: query_parameters) + return response + end end end diff --git a/lib/user.rb b/lib/user.rb index f4d2e242..377a7684 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,11 +1,9 @@ require "pry" module SlackBot - # class SlackApiError < StandardError; end class User < Recipient PATH_URL = "users.list?" - # TOKEN = ENV["TOKEN"] attr_reader :real_name, :name, :id def initialize(real_name:, name:, id:) @@ -30,7 +28,7 @@ def details user_details = { real_name: @real_name, name: @name, - id: @id, + id: @id } return user_details end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 991f722d..f917f426 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -8,4 +8,13 @@ }.must_raise NotImplementedError end end + + describe "details" do + it "Raise NotImplementedError if called directory on recipient" do + recipient = SlackBot::Recipient.new + expect { + recipient.details + }.must_raise NotImplementedError + end + end end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 007d8530..24762ca6 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -31,4 +31,3 @@ require_relative "../lib/user.rb" require_relative "../lib/channel.rb" require_relative "../lib/workspace.rb" -# require_relative "../lib/slack.rb" diff --git a/specs/user_spec.rb b/specs/user_spec.rb index d0c7996f..a06aa668 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -21,7 +21,7 @@ expect(user_list.last).must_be_kind_of SlackBot::User end end - it "Returns a real_name" do + it "Returns users real_name, id and name" do VCR.use_cassette("self.list") do user_list = SlackBot::User.list @@ -30,19 +30,10 @@ expect(user_list.first.name).must_equal "slackbot" end end - # it "will raise an error when given an invalid token" do - # VCR.use_cassette("self.list") do - # exception = expect { - # SlackBot::User.list() - # }.must_raise SlackApi::SlackApiError - - # expect(exception.message).must_equal 'channel_not_found' - # end - # end end describe "send message" do - before do + before do VCR.use_cassette("send message") do @user_list = SlackBot::User.list end @@ -64,14 +55,5 @@ }.must_raise SlackBot::SlackApiError end end - - # it "returns a slackapierror when given too many characters" do - # VCR.use_cassette("send message with too many characters") do - # message = "N" * 40010 - # expect { - # @user_list.first.send_message(message) - # }.must_raise SlackBot::SlackApiError - # end - #end end end From 0ed53f22283fa52b193b3857fa2ac4db18b6ed88 Mon Sep 17 00:00:00 2001 From: sjscotton Date: Fri, 22 Mar 2019 15:25:00 -0700 Subject: [PATCH 24/26] refactored check response code into a method --- lib/channel.rb | 4 +--- lib/recipient.rb | 11 +++++++++-- lib/slack.rb | 17 ++++++++++++----- lib/user.rb | 8 +++----- specs/workspace_spec.rb | 11 ++++++----- 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index f664d11c..1f6d4e51 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -11,9 +11,7 @@ def initialize(num_members:, name:, id:) def self.list response = get(PATH_URL) - unless response.code == 200 && response.parsed_response["ok"] - raise SlackApiError, "Error when listing channels, error: #{response.parsed_response["error"]}" - end + check_response_code(response) channels_array = response["channels"].map do |channel| SlackBot::Channel.new(num_members: channel["num_members"], name: channel["name"], id: channel["id"]) diff --git a/lib/recipient.rb b/lib/recipient.rb index a732ef56..bed56070 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,5 +1,6 @@ module SlackBot class SlackApiError < StandardError; end + class Recipient BASE_URL = "https://slack.com/api/" TOKEN = ENV["TOKEN"] @@ -15,10 +16,9 @@ def send_message(message) body = { text: message, channel: id, - token: TOKEN + token: TOKEN, } response = HTTParty.post("#{BASE_URL}chat.postMessage", body: body, headers: { "Content-type" => "application/x-www-form-urlencoded" }) - unless response.code == 200 && response.parsed_response["ok"] raise SlackApiError, "Error when posting #{message} to #{id}, error: #{response.parsed_response["error"]}" end @@ -26,7 +26,14 @@ def send_message(message) return true end + 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"]}" + end + end + private + def self.get(path_url) query_parameters = { token: TOKEN } response = HTTParty.get("#{BASE_URL}#{path_url}", query: query_parameters) diff --git a/lib/slack.rb b/lib/slack.rb index 2869e486..e46f132f 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -11,10 +11,11 @@ def get_user_options_input(options) input = gets.chomp.to_s.strip - unless options.include?(input) + until options.include?(input) puts "Please choose option from list" input = gets.chomp.to_s.strip end + puts "\n" return input end @@ -24,18 +25,19 @@ def get_user_input(message_to_user) puts message_to_user input = gets.chomp.to_s.strip end + puts "\n" return input end def list_options - puts "Please choose from these options" + puts "\nPlease choose from these options:\n\n" puts "Enter 'list users' to view all users" puts "Enter 'list channels' to view all channels" puts "Enter 'select user' to select a user" puts "Enter 'select channel' to select a channel" puts "Enter 'details' to display information about currently selected recipient" puts "Enter 'send message' to send a message to selected recipient" - puts "Enter 'quit' to quit" + puts "Enter 'quit' to quit\n\n" end def main @@ -52,7 +54,7 @@ def main when "list channels" tp workspace.list_channels when "select user" - puts "Please enter a user ID or user name" + puts "Please enter a user ID or user name:" input = get_user_input("Please enter an ID or name") selected = workspace.select_user(input) puts "Sorry, no user with that information" if selected == nil @@ -62,7 +64,11 @@ def main selected = workspace.select_channel(input) puts "Sorry, no channel with that information" if selected == nil when "details" - tp [selected.details] + if workspace.selected + tp [selected.details] + else + puts "Please select a user or channel first" + end when "send message" if !workspace.selected puts "A recipient needs to be selected first" @@ -70,6 +76,7 @@ def main puts "Enter the message you would like to send: " message_to_send = get_user_input("Message must be at least one character") workspace.send_message(message_to_send) + puts "Message sent!" end when "quit" puts "Goodbye!" diff --git a/lib/user.rb b/lib/user.rb index 377a7684..9266bd6c 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,7 +1,6 @@ require "pry" module SlackBot - class User < Recipient PATH_URL = "users.list?" attr_reader :real_name, :name, :id @@ -14,9 +13,8 @@ def initialize(real_name:, name:, id:) def self.list response = get(PATH_URL) - unless response.code == 200 && response.parsed_response["ok"] - raise SlackApiError, "Error when listing users, error: #{response.parsed_response["error"]}" - end + check_response_code(response) + users_array = response["members"].map do |user| SlackBot::User.new(real_name: user["real_name"], name: user["name"], id: user["id"]) end @@ -28,7 +26,7 @@ def details user_details = { real_name: @real_name, name: @name, - id: @id + id: @id, } return user_details end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 4f5b1cb3..45b98873 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -74,16 +74,16 @@ selected = @workspace.select_channel("CH2P99HT6") expect(selected).must_equal nil end - it "returns nil if no user found with name given" do + it "returns nil if no channel found with name given" do selected = @workspace.select_channel("slack-bpi-project") expect(selected).must_equal nil end - it "returns a User object if given a valid user id" do + it "returns a Channel object if given a valid user id" do selected = @workspace.select_channel("CH2SL5C3C") expect(selected).must_be_kind_of SlackBot::Channel expect(selected.name).must_equal "everyone" end - it "returns a User object if given a valid name" do + it "returns a Channel object if given a valid name" do selected = @workspace.select_channel("random") expect(selected).must_be_kind_of SlackBot::Channel expect(selected.id).must_equal "CH2SL5DEW" @@ -104,7 +104,7 @@ VCR.use_cassette("send message with empty string") do message = "" expect { - @workspace.users.first.send_message(message) + @workspace.users.first.send_message(message) }.must_raise SlackBot::SlackApiError end end @@ -112,7 +112,8 @@ it "returns true if given a valid message and valid user/channel selected" do VCR.use_cassette("send message with empty string") do message = "Hello!" - expect(@workspace.users.first.send_message(message)).must_equal true + @workspace.select_user(@workspace.users.first.id) + expect(@workspace.send_message(message)).must_equal true end end end From 29c7e1d49e359ddae674cb9db2cda52149af77ec Mon Sep 17 00:00:00 2001 From: sjscotton Date: Fri, 29 Mar 2019 09:19:50 -0700 Subject: [PATCH 25/26] changed .must_equal nil to assert_nil --- specs/workspace_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 45b98873..746e4337 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -12,7 +12,7 @@ end it "Initializes with selected equal to nil" do - expect(@workspace.selected).must_equal nil + assert_nil @workspace.selected end it "Creates a list of users" do expect(@workspace.users).must_be_kind_of Array @@ -53,11 +53,11 @@ end it "returns nil if no user found with id given" do selected = @workspace.select_user("USLACKNOT") - expect(selected).must_equal nil + assert_nil selected end it "returns nil if no user found with name given" do selected = @workspace.select_user("Devin") - expect(selected).must_equal nil + assert_nil selected end it "returns a User object if given a valid user id" do selected = @workspace.select_user("USLACKBOT") @@ -72,11 +72,11 @@ it "returns nil if no channel found with id given" do selected = @workspace.select_channel("CH2P99HT6") - expect(selected).must_equal nil + assert_nil selected end it "returns nil if no channel found with name given" do selected = @workspace.select_channel("slack-bpi-project") - expect(selected).must_equal nil + assert_nil selected end it "returns a Channel object if given a valid user id" do selected = @workspace.select_channel("CH2SL5C3C") From bf083fae502052eca1edad4844f6ee1a1aa9a305 Mon Sep 17 00:00:00 2001 From: sjscotton Date: Mon, 1 Apr 2019 17:22:34 -0700 Subject: [PATCH 26/26] fixed no 0 parameter error in main --- lib/slack.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/slack.rb b/lib/slack.rb index e46f132f..69aec403 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -60,7 +60,7 @@ def main 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 + input = get_user_input("Please enter an ID or name") selected = workspace.select_channel(input) puts "Sorry, no channel with that information" if selected == nil when "details"