From 6bfc7ffc65764dcb0be58daa88b4ddc80cbd7156 Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Mon, 5 Oct 2020 18:43:24 -0700 Subject: [PATCH 01/56] wave 0 --- lib/slack.rb | 1 + lib/workspace.rb | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 lib/workspace.rb diff --git a/lib/slack.rb b/lib/slack.rb index 8a0b659b..d9ccb5cb 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +require_relative 'workspace' def main puts "Welcome to the Ada Slack CLI!" diff --git a/lib/workspace.rb b/lib/workspace.rb new file mode 100644 index 00000000..e1be4db0 --- /dev/null +++ b/lib/workspace.rb @@ -0,0 +1,2 @@ +class Workspace +end \ No newline at end of file From 45892c2e916883ba6b2b58242dc6dd4e82a1eb94 Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Mon, 5 Oct 2020 18:43:35 -0700 Subject: [PATCH 02/56] wave 0 --- lib/workspace.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/workspace.rb b/lib/workspace.rb index e1be4db0..caec4cd0 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,2 +1,9 @@ class Workspace + attr_reader :users, :channels + + def initialize + @users = [] + @channels = [] + end + end \ No newline at end of file From b281d0e5e8f8b8668de622c617e7cdac152e7cbd Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Tue, 6 Oct 2020 14:47:22 -0700 Subject: [PATCH 03/56] Added Recipient, Channel, and User classes to project --- lib/Recipient.rb | 3 +++ lib/channel.rb | 2 ++ lib/user.rb | 2 ++ 3 files changed, 7 insertions(+) create mode 100644 lib/Recipient.rb create mode 100644 lib/channel.rb create mode 100644 lib/user.rb diff --git a/lib/Recipient.rb b/lib/Recipient.rb new file mode 100644 index 00000000..b4811471 --- /dev/null +++ b/lib/Recipient.rb @@ -0,0 +1,3 @@ +class Recipient + +end diff --git a/lib/channel.rb b/lib/channel.rb new file mode 100644 index 00000000..060074d9 --- /dev/null +++ b/lib/channel.rb @@ -0,0 +1,2 @@ +class Channel +end \ No newline at end of file diff --git a/lib/user.rb b/lib/user.rb new file mode 100644 index 00000000..a54c3fad --- /dev/null +++ b/lib/user.rb @@ -0,0 +1,2 @@ +class User +end \ No newline at end of file From 93cbf4fe4397c89cc18a73fc00eea30d984576ca Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Tue, 6 Oct 2020 14:50:36 -0700 Subject: [PATCH 04/56] Deleted duplicate code from test_helper file --- test/test_helper.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 1fcf2bab..4792d430 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -11,11 +11,6 @@ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new -VCR.configure do |config| - config.cassette_library_dir = "test/cassettes" - config.hook_into :webmock -end - VCR.configure do |config| config.cassette_library_dir = "test/cassettes" # folder where casettes will be located config.hook_into :webmock # tie into this other tool called webmock From 307b8c87dbdaf66bd1b2f30e30bcdb3ba759481c Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Tue, 6 Oct 2020 15:33:47 -0700 Subject: [PATCH 05/56] Added 'require dotenv' to file --- lib/workspace.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/workspace.rb b/lib/workspace.rb index caec4cd0..b57b0502 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,3 +1,7 @@ +require 'dotenv' + +Dotenv.load + class Workspace attr_reader :users, :channels From 842c464639b55445cdf3f41a06e6e6ce3ff3d830 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Tue, 6 Oct 2020 15:34:03 -0700 Subject: [PATCH 06/56] Added filter to vcr method --- test/test_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 4792d430..4cb636a9 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -20,5 +20,7 @@ } # Don't leave our token lying around in a cassette file. - + config.filter_sensitive_data("") do + ENV["SLACK_TOKEN"] + end end From b2217b5439b0170173e5eda674f37d619fd16143 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Tue, 6 Oct 2020 15:53:40 -0700 Subject: [PATCH 07/56] Latest update --- lib/Recipient.rb | 1 + lib/slack.rb | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Recipient.rb b/lib/Recipient.rb index b4811471..ecf10923 100644 --- a/lib/Recipient.rb +++ b/lib/Recipient.rb @@ -1,3 +1,4 @@ class Recipient + end diff --git a/lib/slack.rb b/lib/slack.rb index d9ccb5cb..a01b44d0 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,11 +1,17 @@ #!/usr/bin/env ruby +require 'table_print' require_relative 'workspace' def main puts "Welcome to the Ada Slack CLI!" workspace = Workspace.new - # TODO project + puts "There are #{number_channels} channels in this workspace" + puts "There are #{number_users} users in this workspace" + + puts "What would you like to do?" + puts "Options ('List Users', 'List Channels' 'Quit'). Please type your response below." + user_input = gets.chomp puts "Thank you for using the Ada Slack CLI" end From ff4662c7b00303cb091e61e032f72b9fa4c58f94 Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Tue, 6 Oct 2020 16:25:35 -0700 Subject: [PATCH 08/56] providing structure for Wave 1 --- lib/Recipient.rb | 4 ---- lib/recipient.rb | 46 ++++++++++++++++++++++++++++++++++++++++++++++ lib/workspace.rb | 3 +++ 3 files changed, 49 insertions(+), 4 deletions(-) delete mode 100644 lib/Recipient.rb create mode 100644 lib/recipient.rb diff --git a/lib/Recipient.rb b/lib/Recipient.rb deleted file mode 100644 index ecf10923..00000000 --- a/lib/Recipient.rb +++ /dev/null @@ -1,4 +0,0 @@ -class Recipient - - -end diff --git a/lib/recipient.rb b/lib/recipient.rb new file mode 100644 index 00000000..da6e9f47 --- /dev/null +++ b/lib/recipient.rb @@ -0,0 +1,46 @@ +require 'httparty' +require 'dotenv' + +Dotenv.load + +class Recipient + attr_reader :id #name ?? :user_name, :user_id, :channel_name, :channel_id + + def initialize(id) + #validate + @id = id + end + + + def self.get (url) + response = HTTParty.get(url, query: { + token: ENV["SLACK_TOKEN"], + format: 'json' + } + ) + + unless response.code == 200 + raise ArgumentError, 'Error in request' + end + + return response + end + + + + + private + + def self.list + raise NotImplementedError, 'Implement me in a child class' + end + + def self.send_message + raise NotImplementedError, 'Implement me in a child class' + + end + + + + +end diff --git a/lib/workspace.rb b/lib/workspace.rb index b57b0502..588f6967 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,5 +1,8 @@ require 'dotenv' +require_relative 'user' +require_relative 'channel' + Dotenv.load class Workspace From f2201eb6e439751d855e6953c1ca61f1b39ab71d Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Wed, 7 Oct 2020 11:00:35 -0700 Subject: [PATCH 09/56] Kayla's test files for experimenting --- test.rb | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 test.rb diff --git a/test.rb b/test.rb new file mode 100644 index 00000000..4a3f67bb --- /dev/null +++ b/test.rb @@ -0,0 +1,81 @@ +require 'dotenv' +require 'table_print' +require 'httparty' + + +Dotenv.load + +class Recipient + + attr_reader :slack_id, :name + + def initialize + @slack_id = slack_id + @name = name + end + + def self.get (url, query) + response = HTTParty.get(url, query: { + token: "xoxp-1222171918129-1247103087989-1411516914675-c0bbd2ed4a7aa434776028b2164bbfba", + format: 'json' + } + ) + end +end + class User #< Recipient + + attr_accessor :real_name, :name, :id + + def initialize(slack_id:nil, name:nil, real_name:nil) + # super(slack_id: slack_id, name: name) + + @real_name = real_name + end + + def self.get (url, data) + HTTParty.get(url, data) + # return new_query + end + + def self.list + url = "https://slack.com/api/users.list" + response = self.get(url, query: + { + token: ENV["SLACK_TOKEN"] + } + ) + + response["members"].each do |member| + users = [] + slack_id = member["id"] + name = member["name"] + real_name = member["real_name"] + + user = self.new(slack_id: slack_id, name: name, real_name: real_name) + users << user + end + return users + end +end +pp User.list + +# +# url = "https://slack.com/api/users.list" +# +# response = HTTParty.get(url, query: +# { +# token: ENV["SLACK_TOKEN"] +# } +# ) +# +# response["members"].each do |member| +# pp member["id"] +# pp member["real_name"] +# end +# +# +# +# pp response["members"].count +# pp new = response["members"].map {|member| member ["real_name"]} +# pp #new = response["members"].map {|member| member ["name"]} +# From 7bf23141b6ff59a020343e50c9577a7c0eb08004 Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Wed, 7 Oct 2020 11:00:37 -0700 Subject: [PATCH 10/56] scratch file for how to table_print --- lib/scratch.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 lib/scratch.rb diff --git a/lib/scratch.rb b/lib/scratch.rb new file mode 100644 index 00000000..573497d7 --- /dev/null +++ b/lib/scratch.rb @@ -0,0 +1,27 @@ +require 'httparty' +require 'table_print' + +response = HTTParty.get("https://slack.com/api/users.list", query: { + token: "xoxb-1222171918129-1435133326080-m7Gx3zpPOoFpTcqts6B4CIGK" +} +) + + +pp "#{response["members"].first["id"]}" + +USERS CLASS +def self.load_all +user_array = [] +response["members"].each do |user| + temp_user = { + "id" => user["id"], + "real_name" => user["profile"]["real_name"], + "user_name" => user["name"] + } + user_array << temp_user +end + +puts "####" +tp user_array + + From d0311124369280296e1da1929d117fe25f8caa03 Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Wed, 7 Oct 2020 11:40:03 -0700 Subject: [PATCH 11/56] got User to print as a table --- lib/recipient.rb | 34 ++++++++++++++-------------- lib/scratch.rb | 19 ++++++++-------- lib/user.rb | 58 ++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 83 insertions(+), 28 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index da6e9f47..a41493e9 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -4,34 +4,34 @@ Dotenv.load class Recipient - attr_reader :id #name ?? :user_name, :user_id, :channel_name, :channel_id + attr_reader :id, :name #name ?? :user_name, :user_id, :channel_name, :channel_id - def initialize(id) + def initialize(slack_id, name) #validate - @id = id + @slack_id = slack_id + @name = name end - def self.get (url) - response = HTTParty.get(url, query: { - token: ENV["SLACK_TOKEN"], - format: 'json' - } - ) - - unless response.code == 200 - raise ArgumentError, 'Error in request' - end - - return response - end + # def self.get (url) + # response = HTTParty.get(url, query: { + # token: ENV["SLACK_TOKEN"], + # } + # ) + # + # unless response.code == 200 + # raise ArgumentError, 'Error in request' + # end + # + # return response + # end private - def self.list + def self.load_all raise NotImplementedError, 'Implement me in a child class' end diff --git a/lib/scratch.rb b/lib/scratch.rb index 573497d7..6ca1a57c 100644 --- a/lib/scratch.rb +++ b/lib/scratch.rb @@ -11,17 +11,18 @@ USERS CLASS def self.load_all -user_array = [] -response["members"].each do |user| - temp_user = { - "id" => user["id"], - "real_name" => user["profile"]["real_name"], - "user_name" => user["name"] - } - user_array << temp_user + user_array = [] + response["members"].each do |user| + temp_user = { + "id" => user["id"], + "real_name" => user["profile"]["real_name"], + "user_name" => user["name"] + } + user_array << temp_user + end end - puts "####" tp user_array + diff --git a/lib/user.rb b/lib/user.rb index a54c3fad..6ad7efee 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,2 +1,56 @@ -class User -end \ No newline at end of file +require 'httparty' +require 'dotenv' +require 'table_print' + +require_relative 'recipient' + +Dotenv.load + +class User < Recipient + + attr_reader :slack_id, :name, :real_name + + def initialize (slack_id, name, real_name) + super(slack_id,name) + @real_name = real_name + end + + # def self.get (url, query) + # HTTParty.get(url, query) + # # return new_query + # end + + def self.load_all + # url = "https://slack.com/api/users.list" + # response = self.get(url, query: + # { + # token: "xoxb-1222171918129-1435133326080-m7Gx3zpPOoFpTcqts6B4CIGK" + # } + # ) + response = HTTParty.get("https://slack.com/api/users.list", query: { + token: "xoxb-1222171918129-1435133326080-m7Gx3zpPOoFpTcqts6B4CIGK" + } + ) + + user_array = [] + + response["members"].each do |user| + slack_id = user["id"] + name = user["name"] + real_name = user["profile"]["real_name"] + + + temp_user = self.new(slack_id, name, real_name) + user_array << temp_user + end + + tp user_array + return user_array + + + end + + +end + +User.load_all \ No newline at end of file From 135458b1d93965916945c679b80e3be46b002afe Mon Sep 17 00:00:00 2001 From: mvlofthus <61913088+mvlofthus@users.noreply.github.com> Date: Wed, 7 Oct 2020 11:42:38 -0700 Subject: [PATCH 12/56] Delete recipient.rb --- lib/recipient.rb | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 lib/recipient.rb diff --git a/lib/recipient.rb b/lib/recipient.rb deleted file mode 100644 index a41493e9..00000000 --- a/lib/recipient.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'httparty' -require 'dotenv' - -Dotenv.load - -class Recipient - attr_reader :id, :name #name ?? :user_name, :user_id, :channel_name, :channel_id - - def initialize(slack_id, name) - #validate - @slack_id = slack_id - @name = name - end - - - # def self.get (url) - # response = HTTParty.get(url, query: { - # token: ENV["SLACK_TOKEN"], - # } - # ) - # - # unless response.code == 200 - # raise ArgumentError, 'Error in request' - # end - # - # return response - # end - - - - - private - - def self.load_all - raise NotImplementedError, 'Implement me in a child class' - end - - def self.send_message - raise NotImplementedError, 'Implement me in a child class' - - end - - - - -end From 7a314b2ec85d19cb7115b391d6169384116a3f03 Mon Sep 17 00:00:00 2001 From: mvlofthus <61913088+mvlofthus@users.noreply.github.com> Date: Wed, 7 Oct 2020 11:42:53 -0700 Subject: [PATCH 13/56] Delete scratch.rb --- lib/scratch.rb | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 lib/scratch.rb diff --git a/lib/scratch.rb b/lib/scratch.rb deleted file mode 100644 index 6ca1a57c..00000000 --- a/lib/scratch.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'httparty' -require 'table_print' - -response = HTTParty.get("https://slack.com/api/users.list", query: { - token: "xoxb-1222171918129-1435133326080-m7Gx3zpPOoFpTcqts6B4CIGK" -} -) - - -pp "#{response["members"].first["id"]}" - -USERS CLASS -def self.load_all - user_array = [] - response["members"].each do |user| - temp_user = { - "id" => user["id"], - "real_name" => user["profile"]["real_name"], - "user_name" => user["name"] - } - user_array << temp_user - end -end -puts "####" -tp user_array - - - From 9a25e584f04f2efd021dda28583d789ba3891b2a Mon Sep 17 00:00:00 2001 From: mvlofthus <61913088+mvlofthus@users.noreply.github.com> Date: Wed, 7 Oct 2020 11:43:16 -0700 Subject: [PATCH 14/56] Delete user.rb --- lib/user.rb | 56 ----------------------------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 lib/user.rb diff --git a/lib/user.rb b/lib/user.rb deleted file mode 100644 index 6ad7efee..00000000 --- a/lib/user.rb +++ /dev/null @@ -1,56 +0,0 @@ -require 'httparty' -require 'dotenv' -require 'table_print' - -require_relative 'recipient' - -Dotenv.load - -class User < Recipient - - attr_reader :slack_id, :name, :real_name - - def initialize (slack_id, name, real_name) - super(slack_id,name) - @real_name = real_name - end - - # def self.get (url, query) - # HTTParty.get(url, query) - # # return new_query - # end - - def self.load_all - # url = "https://slack.com/api/users.list" - # response = self.get(url, query: - # { - # token: "xoxb-1222171918129-1435133326080-m7Gx3zpPOoFpTcqts6B4CIGK" - # } - # ) - response = HTTParty.get("https://slack.com/api/users.list", query: { - token: "xoxb-1222171918129-1435133326080-m7Gx3zpPOoFpTcqts6B4CIGK" - } - ) - - user_array = [] - - response["members"].each do |user| - slack_id = user["id"] - name = user["name"] - real_name = user["profile"]["real_name"] - - - temp_user = self.new(slack_id, name, real_name) - user_array << temp_user - end - - tp user_array - return user_array - - - end - - -end - -User.load_all \ No newline at end of file From a1e3f00e8a5a5cd177a8ec07a319fb08a3091f04 Mon Sep 17 00:00:00 2001 From: mvlofthus <61913088+mvlofthus@users.noreply.github.com> Date: Wed, 7 Oct 2020 11:43:35 -0700 Subject: [PATCH 15/56] Delete test.rb --- test.rb | 81 --------------------------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 test.rb diff --git a/test.rb b/test.rb deleted file mode 100644 index 4a3f67bb..00000000 --- a/test.rb +++ /dev/null @@ -1,81 +0,0 @@ -require 'dotenv' -require 'table_print' -require 'httparty' - - -Dotenv.load - -class Recipient - - attr_reader :slack_id, :name - - def initialize - @slack_id = slack_id - @name = name - end - - def self.get (url, query) - response = HTTParty.get(url, query: { - token: "xoxp-1222171918129-1247103087989-1411516914675-c0bbd2ed4a7aa434776028b2164bbfba", - format: 'json' - } - ) - end -end - class User #< Recipient - - attr_accessor :real_name, :name, :id - - def initialize(slack_id:nil, name:nil, real_name:nil) - # super(slack_id: slack_id, name: name) - - @real_name = real_name - end - - def self.get (url, data) - HTTParty.get(url, data) - # return new_query - end - - def self.list - url = "https://slack.com/api/users.list" - response = self.get(url, query: - { - token: ENV["SLACK_TOKEN"] - } - ) - - response["members"].each do |member| - users = [] - slack_id = member["id"] - name = member["name"] - real_name = member["real_name"] - - user = self.new(slack_id: slack_id, name: name, real_name: real_name) - users << user - end - return users - end -end -pp User.list - -# -# url = "https://slack.com/api/users.list" -# -# response = HTTParty.get(url, query: -# { -# token: ENV["SLACK_TOKEN"] -# } -# ) -# -# response["members"].each do |member| -# pp member["id"] -# pp member["real_name"] -# end -# -# -# -# pp response["members"].count -# pp new = response["members"].map {|member| member ["real_name"]} -# pp #new = response["members"].map {|member| member ["name"]} -# From bc839156fe5f20791b9f2b4b1a4318a3c31a5f94 Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Wed, 7 Oct 2020 11:54:22 -0700 Subject: [PATCH 16/56] User prints, no hardcoded tokens --- lib/scratch.rb | 2 +- lib/user.rb | 4 ++-- test.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/scratch.rb b/lib/scratch.rb index 6ca1a57c..39d14d82 100644 --- a/lib/scratch.rb +++ b/lib/scratch.rb @@ -2,7 +2,7 @@ require 'table_print' response = HTTParty.get("https://slack.com/api/users.list", query: { - token: "xoxb-1222171918129-1435133326080-m7Gx3zpPOoFpTcqts6B4CIGK" + token: ENV["SLACK_TOKEN"] } ) diff --git a/lib/user.rb b/lib/user.rb index 6ad7efee..b2744485 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -24,11 +24,11 @@ def self.load_all # url = "https://slack.com/api/users.list" # response = self.get(url, query: # { - # token: "xoxb-1222171918129-1435133326080-m7Gx3zpPOoFpTcqts6B4CIGK" + # token: # } # ) response = HTTParty.get("https://slack.com/api/users.list", query: { - token: "xoxb-1222171918129-1435133326080-m7Gx3zpPOoFpTcqts6B4CIGK" + token: ENV["SLACK_TOKEN"] } ) diff --git a/test.rb b/test.rb index 4a3f67bb..5a2cb482 100644 --- a/test.rb +++ b/test.rb @@ -16,7 +16,7 @@ def initialize def self.get (url, query) response = HTTParty.get(url, query: { - token: "xoxp-1222171918129-1247103087989-1411516914675-c0bbd2ed4a7aa434776028b2164bbfba", + token: ENV["SLACK_TOKEN"], format: 'json' } ) From 035321a9e0d5674f736b89bc6a61c700e5c91404 Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Wed, 7 Oct 2020 12:09:07 -0700 Subject: [PATCH 17/56] re made these files after we panic deleted them, no hardcoded tokens --- lib/recipient.rb | 37 ++++++++++++++++++++++++++++++++ lib/user.rb | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 lib/recipient.rb create mode 100644 lib/user.rb diff --git a/lib/recipient.rb b/lib/recipient.rb new file mode 100644 index 00000000..2887fb28 --- /dev/null +++ b/lib/recipient.rb @@ -0,0 +1,37 @@ +require 'httparty' +require 'dotenv' + +Dotenv.load + +class Recipient + attr_reader :id #name ?? :user_name, :user_id, :channel_name, :channel_id + + def initialize(id) + #validate + @id = id + end + + def self.get (url) + response = HTTParty.get(url, query: { + token: ENV["SLACK_TOKEN"], + format: 'json' + } + ) + unless response.code == 200 + raise ArgumentError, 'Error in request' + end + + return response + end + + private + def self.list + raise NotImplementedError, 'Implement me in a child class' + end + + def self.send_message + raise NotImplementedError, 'Implement me in a child class' + end + +end + diff --git a/lib/user.rb b/lib/user.rb new file mode 100644 index 00000000..07248c6e --- /dev/null +++ b/lib/user.rb @@ -0,0 +1,56 @@ +equire 'httparty' +require 'dotenv' +require 'table_print' + +require_relative 'recipient' + +Dotenv.load + +class User < Recipient + + attr_reader :slack_id, :name, :real_name + + def initialize (slack_id, name, real_name) + super(slack_id,name) + @real_name = real_name + end + + # def self.get (url, query) + # HTTParty.get(url, query) + # # return new_query + # end + + def self.load_all + # url = "https://slack.com/api/users.list" + # response = self.get(url, query: + # { + # token: + # } + # ) + response = HTTParty.get("https://slack.com/api/users.list", query: { + token: ENV["SLACK_TOKEN"] + } + ) + + user_array = [] + + response["members"].each do |user| + slack_id = user["id"] + name = user["name"] + real_name = user["profile"]["real_name"] + + + temp_user = self.new(slack_id, name, real_name) + user_array << temp_user + end + + tp user_array + return user_array + + + end + + +end + +User.load_all \ No newline at end of file From 0034a2aa8115055aacfc3dff249c3b3450342346 Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Wed, 7 Oct 2020 12:11:41 -0700 Subject: [PATCH 18/56] fixed typo --- lib/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/user.rb b/lib/user.rb index 07248c6e..b2744485 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,4 +1,4 @@ -equire 'httparty' +require 'httparty' require 'dotenv' require 'table_print' From c3fd363b8ee1dbbac2cee0ef1888bd3391cb68a6 Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Wed, 7 Oct 2020 12:12:10 -0700 Subject: [PATCH 19/56] called User.load_all --- lib/workspace.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index 588f6967..24429eb0 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -9,7 +9,7 @@ class Workspace attr_reader :users, :channels def initialize - @users = [] + @users = User.load_all @channels = [] end From 10cca2a918713a638f89723068843551d4d49562 Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Wed, 7 Oct 2020 12:14:09 -0700 Subject: [PATCH 20/56] made User print table again, got recipient back up to date --- lib/recipient.rb | 7 ++++--- lib/user.rb | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 2887fb28..4ecb1a07 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -4,11 +4,12 @@ Dotenv.load class Recipient - attr_reader :id #name ?? :user_name, :user_id, :channel_name, :channel_id + attr_reader :slack_id, :name #name ?? :user_name, :user_id, :channel_name, :channel_id - def initialize(id) + def initialize(slack_id, name) #validate - @id = id + @slack_id = slack_id + @name = name end def self.get (url) diff --git a/lib/user.rb b/lib/user.rb index b2744485..b82cef54 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -11,7 +11,7 @@ class User < Recipient attr_reader :slack_id, :name, :real_name def initialize (slack_id, name, real_name) - super(slack_id,name) + super(slack_id, name) @real_name = real_name end From e4984ba1fc294a5839e891a164f5b57b8cddcd68 Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Wed, 7 Oct 2020 12:30:34 -0700 Subject: [PATCH 21/56] pulls user information correctly --- lib/slack.rb | 14 +++++++------- lib/user.rb | 4 ++-- lib/workspace.rb | 6 ++++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index a01b44d0..9cd483b8 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -6,14 +6,14 @@ def main puts "Welcome to the Ada Slack CLI!" workspace = Workspace.new - puts "There are #{number_channels} channels in this workspace" - puts "There are #{number_users} users in this workspace" + # puts "There are #{number_channels} channels in this workspace" + puts "There are #{workspace.users.count} users in this workspace." - puts "What would you like to do?" - puts "Options ('List Users', 'List Channels' 'Quit'). Please type your response below." - user_input = gets.chomp - - puts "Thank you for using the Ada Slack CLI" + # puts "What would you like to do?" + # puts "Options ('List Users', 'List Channels' 'Quit'). Please type your response below." + # user_input = gets.chomp + # + # puts "Thank you for using the Ada Slack CLI" end main if __FILE__ == $PROGRAM_NAME \ No newline at end of file diff --git a/lib/user.rb b/lib/user.rb index b82cef54..98c5cb88 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -44,7 +44,7 @@ def self.load_all user_array << temp_user end - tp user_array + # tp user_array return user_array @@ -53,4 +53,4 @@ def self.load_all end -User.load_all \ No newline at end of file +# User.load_all \ No newline at end of file diff --git a/lib/workspace.rb b/lib/workspace.rb index 24429eb0..5473d3be 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -6,11 +6,13 @@ Dotenv.load class Workspace - attr_reader :users, :channels + attr_reader :users #, :channels def initialize @users = User.load_all - @channels = [] + # @channels = [] end + + end \ No newline at end of file From bb7073b677d7b70736a2a478b31c810a5f8a3147 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Wed, 7 Oct 2020 12:52:19 -0700 Subject: [PATCH 22/56] Added function to the channel.rb --- lib/channel.rb | 60 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 060074d9..a6d3530e 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,2 +1,58 @@ -class Channel -end \ No newline at end of file + require 'httparty' + require 'dotenv' + require 'table_print' + + require_relative 'recipient' + + Dotenv.load + + class Channel < Recipient + + attr_reader :topic, :member_count, :slack_id, :name + + def initialize (slack_id, name, topic, member_count) + super(slack_id, name) + + @topic = topic + @member_count = member_count + end + + def self.get (url, query) + HTTParty.get(url, query) + # return new_query + end + + def self.load_all + # url = "https://slack.com/api/channels.list" + # response = self.get(url, query: + # { + # token: + # } + # ) + # + response = HTTParty.get("https://slack.com/api/conversations.list", query: { + token: ENV["SLACK_TOKEN"] + } + ) + + channel_array = [] + + response["channels"].each do |channel| + slack_id = channel["id"] + name = channel["name"] + purpose = channel["purpose"]["value"] + member_count = channel["num_members"] + + temp_channel = self.new(slack_id, name, purpose, member_count) + channel_array << temp_channel + end + + return channel_array + + + end + + + end + + tp Channel.load_all From 3df54a5043712ba893b57fb9a3d3b2e3a202006d Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Wed, 7 Oct 2020 12:55:53 -0700 Subject: [PATCH 23/56] Channel prints and CLI prints channel count --- lib/channel.rb | 1 - lib/slack.rb | 2 +- lib/workspace.rb | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index a6d3530e..17039014 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -55,4 +55,3 @@ def self.load_all end - tp Channel.load_all diff --git a/lib/slack.rb b/lib/slack.rb index 9cd483b8..f22da0ed 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -6,7 +6,7 @@ def main puts "Welcome to the Ada Slack CLI!" workspace = Workspace.new - # puts "There are #{number_channels} channels in this workspace" + puts "There are #{workspace.channels.count} channels in this workspace" puts "There are #{workspace.users.count} users in this workspace." # puts "What would you like to do?" diff --git a/lib/workspace.rb b/lib/workspace.rb index 5473d3be..cb66970a 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -6,11 +6,11 @@ Dotenv.load class Workspace - attr_reader :users #, :channels + attr_reader :users, :channels def initialize @users = User.load_all - # @channels = [] + @channels = Channel.load_all end From ed32b2672e9e61e722b88afeb5dc1417e5b73bce Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Wed, 7 Oct 2020 15:24:33 -0700 Subject: [PATCH 24/56] Added case statements and program will now print list users and list channels --- lib/slack.rb | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index f22da0ed..432e3ce7 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -3,17 +3,37 @@ require_relative 'workspace' def main - puts "Welcome to the Ada Slack CLI!" + puts "Welcome to the Ada Slack CLI!\n\n" workspace = Workspace.new puts "There are #{workspace.channels.count} channels in this workspace" puts "There are #{workspace.users.count} users in this workspace." - # puts "What would you like to do?" - # puts "Options ('List Users', 'List Channels' 'Quit'). Please type your response below." - # user_input = gets.chomp - # - # puts "Thank you for using the Ada Slack CLI" -end + def options + puts "\n\nWhat would you like to do?\n" + puts "Choose the number that corresponds to the following options:" + puts "[1]'List Users'\n[2]'List Channels'\n[3] 'Quit'" + end + + puts + puts "*" * 40 + # puts options + + user_input = nil + until user_input == "3" || user_input == "quit" + puts options + user_input = gets.chomp.downcase + + case user_input + when "1", "list users" + tp workspace.users + when "2", "list channels" + tp workspace.channels + end + end + + puts "Thank you for using the Ada Slack CLI" + end + main if __FILE__ == $PROGRAM_NAME \ No newline at end of file From 686116b0ced8131a0b3a762e76e5173f4713a8cd Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Wed, 7 Oct 2020 16:39:57 -0700 Subject: [PATCH 25/56] refactored .list --- lib/channel.rb | 71 ++++++++++++++++++++---------------------------- lib/slack.rb | 12 ++++---- lib/user.rb | 57 ++++++++++++++++++++++++-------------- lib/workspace.rb | 4 +-- 4 files changed, 74 insertions(+), 70 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 17039014..26137eb5 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,57 +1,44 @@ - require 'httparty' - require 'dotenv' - require 'table_print' +require 'httparty' +require 'dotenv' +require 'table_print' - require_relative 'recipient' +require_relative 'recipient' - Dotenv.load +Dotenv.load - class Channel < Recipient +class Channel < Recipient - attr_reader :topic, :member_count, :slack_id, :name + attr_reader :topic, :member_count, :slack_id, :name - def initialize (slack_id, name, topic, member_count) - super(slack_id, name) + def initialize (slack_id, name, topic, member_count) + super(slack_id, name) - @topic = topic - @member_count = member_count - end - - def self.get (url, query) - HTTParty.get(url, query) - # return new_query - end - - def self.load_all - # url = "https://slack.com/api/channels.list" - # response = self.get(url, query: - # { - # token: - # } - # ) - # - response = HTTParty.get("https://slack.com/api/conversations.list", query: { - token: ENV["SLACK_TOKEN"] - } - ) - - channel_array = [] - - response["channels"].each do |channel| - slack_id = channel["id"] - name = channel["name"] - purpose = channel["purpose"]["value"] - member_count = channel["num_members"] + @topic = topic + @member_count = member_count + end - temp_channel = self.new(slack_id, name, purpose, member_count) - channel_array << temp_channel - end + def self.list + response = HTTParty.get("https://slack.com/api/conversations.list", query: { + token: ENV["SLACK_TOKEN"] + } + ) - return channel_array + channel_array = [] + response["channels"].each do |channel| + slack_id = channel["id"] + name = channel["name"] + purpose = channel["purpose"]["value"] + member_count = channel["num_members"] + temp_channel = self.new(slack_id, name, purpose, member_count) + channel_array << temp_channel end + return channel_array end + +end + diff --git a/lib/slack.rb b/lib/slack.rb index 432e3ce7..92a1a710 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -24,12 +24,12 @@ def options puts options user_input = gets.chomp.downcase - case user_input - when "1", "list users" - tp workspace.users - when "2", "list channels" - tp workspace.channels - end + case user_input + when "1", "list users" + tp workspace.users + when "2", "list channels" + tp workspace.channels + end end puts "Thank you for using the Ada Slack CLI" diff --git a/lib/user.rb b/lib/user.rb index 98c5cb88..52b43bd1 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -8,49 +8,66 @@ class User < Recipient - attr_reader :slack_id, :name, :real_name + attr_reader :slack_id, :name, :real_name, :status_emoji - def initialize (slack_id, name, real_name) + def initialize (slack_id, name, real_name, status_emoji) super(slack_id, name) @real_name = real_name + @status_emoji = status_emoji end - # def self.get (url, query) - # HTTParty.get(url, query) - # # return new_query - # end - def self.load_all - # url = "https://slack.com/api/users.list" - # response = self.get(url, query: - # { - # token: - # } - # ) + def self.list response = HTTParty.get("https://slack.com/api/users.list", query: { token: ENV["SLACK_TOKEN"] } ) user_array = [] - response["members"].each do |user| slack_id = user["id"] name = user["name"] real_name = user["profile"]["real_name"] + status_emoji = user["profile"]["status_emoji"] - temp_user = self.new(slack_id, name, real_name) + temp_user = self.new(slack_id, name, real_name, status_emoji) user_array << temp_user end - - # tp user_array return user_array + end + # def self.user_list + # all_users = self.load_all + # + # user_list = [] + # + # all_users.each do |user| + # temp_user = { + # "id" => user["id"], + # "name" => user["name"], + # "real_name" => user["profile"]["real_name"] + # } + # + # user_list << temp_user + # end + # + # return user_list + # + # end - end -end -# User.load_all \ No newline at end of file + + def self.details(identifier) + if response["id"].select(identifier) || response["name"].select(identifier) + return "" + else + return "that is not a valid selection" + end + + end + + +end \ No newline at end of file diff --git a/lib/workspace.rb b/lib/workspace.rb index cb66970a..35cae9be 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -9,8 +9,8 @@ class Workspace attr_reader :users, :channels def initialize - @users = User.load_all - @channels = Channel.load_all + @users = User.list + @channels = Channel.list end From 67881961a319bc7dcdd81a3fb489e9562622266f Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Wed, 7 Oct 2020 17:02:52 -0700 Subject: [PATCH 26/56] Select User, Selected Channel, Details all added to CLI --- lib/slack.rb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 432e3ce7..a0fa6eab 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -12,7 +12,7 @@ def main def options puts "\n\nWhat would you like to do?\n" puts "Choose the number that corresponds to the following options:" - puts "[1]'List Users'\n[2]'List Channels'\n[3] 'Quit'" + puts "[1]'List Users'\n[2]'List Channels'\n[3]'Select User'\n[4]'Select Channel'\n[5]'Details'\n[6]'Quit'" end puts @@ -20,7 +20,9 @@ def options # puts options user_input = nil - until user_input == "3" || user_input == "quit" + + selected_recipient = ["no recipient selected"] + until user_input == "6" || user_input == "quit" puts options user_input = gets.chomp.downcase @@ -28,10 +30,20 @@ def options when "1", "list users" tp workspace.users when "2", "list channels" + tp workspace.channels + when "3", "select user" + puts "Please enter User Name or ID" + user_id = gets.chomp.downcase + selected_recipient << user_id + when "4", "select channel" + puts "Please enter Chanell Name or ID" + channel_id = gets.chomp.downcase + selected_recipient << channel_id + when "5", "details" + puts selected_recipient.last end - end - + end puts "Thank you for using the Ada Slack CLI" end From 5308f947fdd8364b7846aa781d351eee19923af6 Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Wed, 7 Oct 2020 18:10:22 -0700 Subject: [PATCH 27/56] find_recipient method to print details --- lib/slack.rb | 10 ++++++++-- lib/workspace.rb | 24 +++++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 570792b1..6b1362a7 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -17,6 +17,8 @@ def options puts puts "*" * 40 + print workspace.users + puts "*" * 40 # puts options user_input = nil @@ -37,11 +39,15 @@ def options user_id = gets.chomp.downcase selected_recipient << user_id when "4", "select channel" - puts "Please enter Chanell Name or ID" + puts "Please enter Chanel Name or ID" channel_id = gets.chomp.downcase selected_recipient << channel_id when "5", "details" - puts selected_recipient.last + if selected_recipient.length < 2 + puts selected_recipient + else + puts workspace.find_recipient(selected_recipient.last) + end end end diff --git a/lib/workspace.rb b/lib/workspace.rb index 35cae9be..8ce63b05 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -3,6 +3,7 @@ require_relative 'user' require_relative 'channel' + Dotenv.load class Workspace @@ -15,4 +16,25 @@ def initialize -end \ No newline at end of file + def find_recipient(input) + if + @users.find do |user| + if user.slack_id.downcase == input.downcase || user.name.downcase == input.downcase + return ["-User Details-", "Slack ID: #{user.slack_id}", "Name: #{user.name}", "Real Name: #{user.real_name}", "Status Emoji: #{user.status_emoji}"] + end + end + elsif + @channels.find do |channel| + if channel.slack_id.downcase == input.downcase || channel.name.downcase == input.downcase + return ["-Channel Details-", "Slack ID: #{channel.slack_id}", "Name: #{channel.name}", "Topic: #{channel.topic}", "Member Count: #{channel.member_count}"] + end + end + else + return "Not found, please select a new recipient" + end + end + + + +end + From ffadce4d322d9e7097269fbefc7f071c7b2a282c Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Thu, 8 Oct 2020 09:30:44 -0700 Subject: [PATCH 28/56] to interface with new details methods --- lib/slack.rb | 2 +- lib/workspace.rb | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 6b1362a7..2b77ccfe 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -46,7 +46,7 @@ def options if selected_recipient.length < 2 puts selected_recipient else - puts workspace.find_recipient(selected_recipient.last) + puts workspace.find_recipient(selected_recipient.last).details end end end diff --git a/lib/workspace.rb b/lib/workspace.rb index 8ce63b05..9485c83b 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -20,13 +20,15 @@ def find_recipient(input) if @users.find do |user| if user.slack_id.downcase == input.downcase || user.name.downcase == input.downcase - return ["-User Details-", "Slack ID: #{user.slack_id}", "Name: #{user.name}", "Real Name: #{user.real_name}", "Status Emoji: #{user.status_emoji}"] + return user + # ["-User Details-", "Slack ID: #{user.slack_id}", "Name: #{user.name}", "Real Name: #{user.real_name}", "Status Emoji: #{user.status_emoji}"] end end elsif @channels.find do |channel| if channel.slack_id.downcase == input.downcase || channel.name.downcase == input.downcase - return ["-Channel Details-", "Slack ID: #{channel.slack_id}", "Name: #{channel.name}", "Topic: #{channel.topic}", "Member Count: #{channel.member_count}"] + return channel + #["-Channel Details-", "Slack ID: #{channel.slack_id}", "Name: #{channel.name}", "Topic: #{channel.topic}", "Member Count: #{channel.member_count}"] end end else From 853a12bf63a17f7328d2fe7538a2011ddd73d732 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Thu, 8 Oct 2020 09:37:22 -0700 Subject: [PATCH 29/56] Added new username instantiation --- lib/user.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index 52b43bd1..e6898be0 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -8,12 +8,13 @@ class User < Recipient - attr_reader :slack_id, :name, :real_name, :status_emoji + attr_reader :slack_id, :username, :real_name, :status_emoji - def initialize (slack_id, name, real_name, status_emoji) + def initialize (slack_id, username, real_name, status_emoji, name) super(slack_id, name) @real_name = real_name @status_emoji = status_emoji + @username = username end @@ -26,12 +27,13 @@ def self.list user_array = [] response["members"].each do |user| slack_id = user["id"] - name = user["name"] + username = user["name"] real_name = user["profile"]["real_name"] status_emoji = user["profile"]["status_emoji"] + name = user["name"] - temp_user = self.new(slack_id, name, real_name, status_emoji) + temp_user = self.new(slack_id, username, real_name, status_emoji, name) user_array << temp_user end return user_array From a7ac6f2838a2aec8e9937f11c8e91e2a4026517e Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Thu, 8 Oct 2020 09:40:53 -0700 Subject: [PATCH 30/56] Added changes to slack select user and select channel options --- lib/slack.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 2b77ccfe..4706c9fa 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -17,8 +17,6 @@ def options puts puts "*" * 40 - print workspace.users - puts "*" * 40 # puts options user_input = nil @@ -32,16 +30,17 @@ def options when "1", "list users" tp workspace.users when "2", "list channels" - tp workspace.channels when "3", "select user" puts "Please enter User Name or ID" user_id = gets.chomp.downcase selected_recipient << user_id + workspace.select_user(user_id) when "4", "select channel" puts "Please enter Chanel Name or ID" channel_id = gets.chomp.downcase selected_recipient << channel_id + workspace.select_channel(channel_id) when "5", "details" if selected_recipient.length < 2 puts selected_recipient From 659d6fc5278744bfe05897c0ffbe3a5f122b0848 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Thu, 8 Oct 2020 09:42:34 -0700 Subject: [PATCH 31/56] Added methods to deal with selected users and channels --- lib/workspace.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/workspace.rb b/lib/workspace.rb index 9485c83b..ef21534f 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -14,7 +14,41 @@ def initialize @channels = Channel.list end + def list_users(workspace) + tp workspace.users, "slack_id", "username", "real_name" + end + + def list_channels(workspace) + tp workspace.channels, "name", "topic", "member_count", "slack_id" + end + + def select_user(id) + users.each do |user| + if user.slack_id.downcase == id || user.username.downcase == id + # user.details(id) + return tp user + # "USER FOUND!\n" tp user.slack_id, Username: #{user.username}, Name: #{user.real_name}" + end + end + return "User does not exist" + end + def select_channel(id) + channels.each do |channel| + if channel.slack_id.downcase == id || channel.name.downcase == id + return tp channel + end + end + return "Channel does not exist" + end + + def user_details(id) + return User.details + end + + def channel_details(id) + + end def find_recipient(input) if From a257b604b63e022cbcd91862da00cf5af73b2ab0 Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Thu, 8 Oct 2020 10:18:32 -0700 Subject: [PATCH 32/56] cleaning up helper methods in workspace --- lib/slack.rb | 2 +- lib/user.rb | 4 ++-- lib/workspace.rb | 16 +--------------- test/user-test.rb | 1 + 4 files changed, 5 insertions(+), 18 deletions(-) create mode 100644 test/user-test.rb diff --git a/lib/slack.rb b/lib/slack.rb index 4706c9fa..79fac389 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -45,7 +45,7 @@ def options if selected_recipient.length < 2 puts selected_recipient else - puts workspace.find_recipient(selected_recipient.last).details + puts workspace.find_recipient(selected_recipient.last) end end end diff --git a/lib/user.rb b/lib/user.rb index e6898be0..8696a364 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -62,8 +62,8 @@ def self.list - def self.details(identifier) - if response["id"].select(identifier) || response["name"].select(identifier) + def self.details + if self.slack_id.select(identifier) || self["name"].select(identifier) return "" else return "that is not a valid selection" diff --git a/lib/workspace.rb b/lib/workspace.rb index ef21534f..8e11b682 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -51,21 +51,7 @@ def channel_details(id) end def find_recipient(input) - if - @users.find do |user| - if user.slack_id.downcase == input.downcase || user.name.downcase == input.downcase - return user - # ["-User Details-", "Slack ID: #{user.slack_id}", "Name: #{user.name}", "Real Name: #{user.real_name}", "Status Emoji: #{user.status_emoji}"] - end - end - elsif - @channels.find do |channel| - if channel.slack_id.downcase == input.downcase || channel.name.downcase == input.downcase - return channel - #["-Channel Details-", "Slack ID: #{channel.slack_id}", "Name: #{channel.name}", "Topic: #{channel.topic}", "Member Count: #{channel.member_count}"] - end - end - else + if select_user(input) == "User does not exist" && select_channel(input) == "Channel does not exist" return "Not found, please select a new recipient" end end diff --git a/test/user-test.rb b/test/user-test.rb new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/user-test.rb @@ -0,0 +1 @@ + From 7cd655c7ceae19e83acb4604fd263003c760148f Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Thu, 8 Oct 2020 10:21:34 -0700 Subject: [PATCH 33/56] Added required relatives to test_helper file and added a describe call to user-test file --- test/test_helper.rb | 8 ++++++++ test/user-test.rb | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index 4cb636a9..b5b9871b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -23,4 +23,12 @@ config.filter_sensitive_data("") do ENV["SLACK_TOKEN"] end + + #Require_relative your lib files here + require_relative '../lib/user.rb' + require_relative '../lib/channel.rb' + require_relative '../lib/recipient.rb' + require_relative '../lib/workspace.rb' + require_relative '../lib/slack.rb' + end diff --git a/test/user-test.rb b/test/user-test.rb index 8b137891..b34bfa87 100644 --- a/test/user-test.rb +++ b/test/user-test.rb @@ -1 +1,22 @@ +require_relative 'test_helper' +require_relative 'test_helper' + +describe User do + describe 'User instantiation' do + before do + slack_id = "U01CT3X9L2C" + username = "water_mmmkay" + real_name = "Water MmmKay" + status_emoji = "" + name = "" + @user= User.new(slack_id, username, real_name, status_emoji, name) + + end + + it 'is an instance of User' do + expect(@user).must_be_kind_of User + end + + end +end \ No newline at end of file From 0412387ac4edcb1e78a270fc683a44c0afcbf636 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Thu, 8 Oct 2020 10:31:09 -0700 Subject: [PATCH 34/56] Made typo change to test_helper.rb --- test/user-test.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/user-test.rb b/test/user-test.rb index b34bfa87..02e50e66 100644 --- a/test/user-test.rb +++ b/test/user-test.rb @@ -1,7 +1,5 @@ require_relative 'test_helper' -require_relative 'test_helper' - describe User do describe 'User instantiation' do before do From f40d1ec01fea8270c9fb8adf4e27d79ee420f7a1 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Thu, 8 Oct 2020 10:58:45 -0700 Subject: [PATCH 35/56] Not sure what this change is --- test/test_helper.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index b5b9871b..40c79900 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -9,6 +9,8 @@ require 'minitest/skip_dsl' require 'vcr' + + Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new VCR.configure do |config| @@ -23,12 +25,11 @@ config.filter_sensitive_data("") do ENV["SLACK_TOKEN"] end +end - #Require_relative your lib files here - require_relative '../lib/user.rb' - require_relative '../lib/channel.rb' - require_relative '../lib/recipient.rb' - require_relative '../lib/workspace.rb' - require_relative '../lib/slack.rb' +require_relative '../lib/user.rb' +require_relative '../lib/channel.rb' +require_relative '../lib/recipient.rb' +require_relative '../lib/workspace.rb' +require_relative '../lib/slack.rb' -end From 4383d442dc18143108b8e2a0f5c2be842ce0ffdd Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Thu, 8 Oct 2020 12:15:11 -0700 Subject: [PATCH 36/56] pulled details into child classes --- lib/slack.rb | 42 ++++++++++++++++++++---------------------- lib/user.rb | 37 +++++++------------------------------ lib/workspace.rb | 46 +++++++++++++++++++++++++--------------------- 3 files changed, 52 insertions(+), 73 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 79fac389..beda947a 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -21,34 +21,32 @@ def options user_input = nil - selected_recipient = ["no recipient selected"] until user_input == "6" || user_input == "quit" puts options user_input = gets.chomp.downcase - case user_input - when "1", "list users" - tp workspace.users - when "2", "list channels" - tp workspace.channels - when "3", "select user" - puts "Please enter User Name or ID" - user_id = gets.chomp.downcase - selected_recipient << user_id - workspace.select_user(user_id) - when "4", "select channel" - puts "Please enter Chanel Name or ID" - channel_id = gets.chomp.downcase - selected_recipient << channel_id - workspace.select_channel(channel_id) - when "5", "details" - if selected_recipient.length < 2 - puts selected_recipient - else - puts workspace.find_recipient(selected_recipient.last) + case user_input + when "1", "list users" + workspace.list_users + when "2", "list channels" + workspace.list_channels + when "3", "select user" + puts "Please enter User Name or ID" + user_identifier = gets.chomp.downcase + workspace.select_user(user_identifier) + when "4", "select channel" + puts "Please enter Chanel Name or ID" + channel_identifier = gets.chomp.downcase + workspace.select_channel(channel_identifier) + when "5", "details" + if workspace.selected_recipient == nil + puts "Please select a channel or user first to view details" + else + #### puts workspace.find_recipient(workspace.selected_recipient) + workspace.find_details + end end end - end puts "Thank you for using the Ada Slack CLI" end diff --git a/lib/user.rb b/lib/user.rb index 8696a364..e8268447 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -39,37 +39,14 @@ def self.list return user_array end - # def self.user_list - # all_users = self.load_all - # - # user_list = [] - # - # all_users.each do |user| - # temp_user = { - # "id" => user["id"], - # "name" => user["name"], - # "real_name" => user["profile"]["real_name"] - # } - # - # user_list << temp_user - # end - # - # return user_list - # - # end - - - - - - def self.details - if self.slack_id.select(identifier) || self["name"].select(identifier) - return "" - else - return "that is not a valid selection" - end - + def details + puts "User found, here's the scoop!\n Username: #{name} \n Slack ID: #{slack_id}\n Real Name: #{real_name}\n Status Emoji: #{status_emoji}" end + + + + + end \ No newline at end of file diff --git a/lib/workspace.rb b/lib/workspace.rb index 8e11b682..a525b841 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -8,53 +8,57 @@ class Workspace attr_reader :users, :channels + attr_accessor :selected_recipient def initialize @users = User.list @channels = Channel.list + @selected_recipient = nil end - def list_users(workspace) - tp workspace.users, "slack_id", "username", "real_name" + def list_users + tp @users, "slack_id", "username", "real_name" end - def list_channels(workspace) - tp workspace.channels, "name", "topic", "member_count", "slack_id" + def list_channels + tp @channels, "name", "topic", "member_count", "slack_id" end def select_user(id) - users.each do |user| + @users.each do |user| if user.slack_id.downcase == id || user.username.downcase == id - # user.details(id) - return tp user - # "USER FOUND!\n" tp user.slack_id, Username: #{user.username}, Name: #{user.real_name}" + @selected_recipient = user + puts "Valid user selected" + return @selected_recipient end end - return "User does not exist" + puts "User does not exist" end def select_channel(id) - channels.each do |channel| + @channels.each do |channel| if channel.slack_id.downcase == id || channel.name.downcase == id - return tp channel + @selected_recipient = channel + puts "Valid channel selected" + return @selected_recipient end end - return "Channel does not exist" + puts "Channel does not exist" end - def user_details(id) - return User.details + def find_details + if @selected_recipient != nil + return @selected_recipient.details + end end - def channel_details(id) - end - def find_recipient(input) - if select_user(input) == "User does not exist" && select_channel(input) == "Channel does not exist" - return "Not found, please select a new recipient" - end - end + # def find_recipient(input) + # if select_user(input) == "User does not exist" && select_channel(input) == "Channel does not exist" + # return "Not found, please select a new recipient" + # end + # end From 650969981b88692c5c2eece9a951e2eb23aabdd1 Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Thu, 8 Oct 2020 12:15:51 -0700 Subject: [PATCH 37/56] pulled details into child classes --- lib/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/user.rb b/lib/user.rb index e8268447..9a15657e 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -44,7 +44,7 @@ def details end - + From e4c732f2d8fb631dafc7b8d83f86a48963ac95bd Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Thu, 8 Oct 2020 12:24:12 -0700 Subject: [PATCH 38/56] added channel details --- lib/channel.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/channel.rb b/lib/channel.rb index 26137eb5..52693ad9 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -39,6 +39,9 @@ def self.list end + def details + puts "Channel found, Here's the scoop!\n Slack ID: #{slack_id}\n Name: #{name}\n Topic: #{topic}\n Member Count: #{member_count}" + end end From 9fbca53dcfe3c7c93f5e7abe72e6f8a88f024fc3 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Thu, 8 Oct 2020 12:31:09 -0700 Subject: [PATCH 39/56] Added 'send message' methods to channel, recipient, and slack classe --- lib/channel.rb | 3 +++ lib/recipient.rb | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lib/channel.rb b/lib/channel.rb index 52693ad9..0700f182 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -43,5 +43,8 @@ def details puts "Channel found, Here's the scoop!\n Slack ID: #{slack_id}\n Name: #{name}\n Topic: #{topic}\n Member Count: #{member_count}" end + def send_message + + end end diff --git a/lib/recipient.rb b/lib/recipient.rb index 4ecb1a07..b447902a 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -34,5 +34,8 @@ def self.send_message raise NotImplementedError, 'Implement me in a child class' end + def self.details + raise NotImplementedError, 'Implement me in a child class' + end end From 47b6075964ff498c860a987ec8e3419362287f9e Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Thu, 8 Oct 2020 14:34:21 -0700 Subject: [PATCH 40/56] Changed naem git push --- test/{user-test.rb => user_test.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{user-test.rb => user_test.rb} (100%) diff --git a/test/user-test.rb b/test/user_test.rb similarity index 100% rename from test/user-test.rb rename to test/user_test.rb From 3e7bf22b12c57e6570e402cd3eff3f440c60efc9 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Thu, 8 Oct 2020 15:22:27 -0700 Subject: [PATCH 41/56] Added send_msg method to recipient w/url --- lib/recipient.rb | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index b447902a..3ee812c9 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -25,14 +25,37 @@ def self.get (url) return response end + def self.send_msg(message, channel) + response = HTTParty.post("https://slack.com/api/chat.postMessage", + body: { + token: ENV["SLACK_TOKEN"], + text: message, + channel: channel + }, + headers: { 'Content-Type' => 'application/x-www-form-urlencoded'} + ) + + return response.code == 200 && response.parsed_response["ok"] + end +end + + + + } + + + + ) + + end + + private def self.list raise NotImplementedError, 'Implement me in a child class' end - def self.send_message - raise NotImplementedError, 'Implement me in a child class' - end + def self.details raise NotImplementedError, 'Implement me in a child class' From 5c13f20434c52773b524b69f015268743446d3ae Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Thu, 8 Oct 2020 15:22:57 -0700 Subject: [PATCH 42/56] Renamed file so it works--and added some required elements --- test/test_helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index 40c79900..def2aa9d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,6 +8,9 @@ require 'minitest/reporters' require 'minitest/skip_dsl' require 'vcr' +require 'webmock/minitest' +require 'dotenv' +Dotenv.load From 65a03c9fb49f8fc4678f337e6347c30b9b0a2c22 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Thu, 8 Oct 2020 15:32:14 -0700 Subject: [PATCH 43/56] started adding send message to slack.rb --- lib/slack.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/slack.rb b/lib/slack.rb index beda947a..ff38f9a6 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -45,6 +45,13 @@ def options #### puts workspace.find_recipient(workspace.selected_recipient) workspace.find_details end + when "6", "send message" + if workspace.selected_recipient == nil + puts "Please select a channel or user first to view details" + else + puts "Send a message!" + message = gets.chomp + workspace.send_msg(message, ) end end From 89389bd0dfb69dca534355641f1991238a6bc26e Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Thu, 8 Oct 2020 15:45:09 -0700 Subject: [PATCH 44/56] Send message works --- lib/recipient.rb | 15 ++------------- lib/slack.rb | 10 +++++----- lib/workspace.rb | 4 ++++ 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 3ee812c9..f459a343 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -25,29 +25,18 @@ def self.get (url) return response end - def self.send_msg(message, channel) + def self.send_msg(message, id) response = HTTParty.post("https://slack.com/api/chat.postMessage", body: { token: ENV["SLACK_TOKEN"], text: message, - channel: channel + channel: id }, headers: { 'Content-Type' => 'application/x-www-form-urlencoded'} ) return response.code == 200 && response.parsed_response["ok"] end -end - - - - } - - - - ) - - end private diff --git a/lib/slack.rb b/lib/slack.rb index ff38f9a6..fd57776f 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -12,7 +12,7 @@ def main def options puts "\n\nWhat would you like to do?\n" puts "Choose the number that corresponds to the following options:" - puts "[1]'List Users'\n[2]'List Channels'\n[3]'Select User'\n[4]'Select Channel'\n[5]'Details'\n[6]'Quit'" + puts "[1]'List Users'\n[2]'List Channels'\n[3]'Select User'\n[4]'Select Channel'\n[5]'Details'\n[6]'Send Message'\n[7]'Quit'" end puts @@ -21,7 +21,7 @@ def options user_input = nil - until user_input == "6" || user_input == "quit" + until user_input == "7" || user_input == "quit" puts options user_input = gets.chomp.downcase @@ -51,12 +51,12 @@ def options else puts "Send a message!" message = gets.chomp - workspace.send_msg(message, ) - end + workspace.send_msg(message) + end end puts "Thank you for using the Ada Slack CLI" end - +end main if __FILE__ == $PROGRAM_NAME \ No newline at end of file diff --git a/lib/workspace.rb b/lib/workspace.rb index a525b841..4917804e 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -52,6 +52,10 @@ def find_details end end + def send_msg(message) + Recipient.send_msg(message, @selected_recipient.slack_id) + end + # def find_recipient(input) From e457e140cc1b199d071f3260553b51e4ce8f661d Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Thu, 8 Oct 2020 16:10:24 -0700 Subject: [PATCH 45/56] formatting and comments --- lib/channel.rb | 7 +------ lib/recipient.rb | 11 +++++------ lib/slack.rb | 21 +++++++++------------ lib/user.rb | 12 ++---------- lib/workspace.rb | 11 ----------- 5 files changed, 17 insertions(+), 45 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 0700f182..c00614bb 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -12,7 +12,6 @@ class Channel < Recipient def initialize (slack_id, name, topic, member_count) super(slack_id, name) - @topic = topic @member_count = member_count end @@ -36,15 +35,11 @@ def self.list end return channel_array - end def details - puts "Channel found, Here's the scoop!\n Slack ID: #{slack_id}\n Name: #{name}\n Topic: #{topic}\n Member Count: #{member_count}" + puts "Channel found, here's the scoop!\n Slack ID: #{slack_id}\n Name: #{name}\n Topic: #{topic}\n Member Count: #{member_count}" end - def send_message - - end end diff --git a/lib/recipient.rb b/lib/recipient.rb index f459a343..68b2011d 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -4,10 +4,9 @@ Dotenv.load class Recipient - attr_reader :slack_id, :name #name ?? :user_name, :user_id, :channel_name, :channel_id + attr_reader :slack_id, :name def initialize(slack_id, name) - #validate @slack_id = slack_id @name = name end @@ -18,12 +17,13 @@ def self.get (url) format: 'json' } ) + unless response.code == 200 raise ArgumentError, 'Error in request' end return response - end + end def self.send_msg(message, id) response = HTTParty.post("https://slack.com/api/chat.postMessage", @@ -40,11 +40,10 @@ def self.send_msg(message, id) private + def self.list raise NotImplementedError, 'Implement me in a child class' - end - - + end def self.details raise NotImplementedError, 'Implement me in a child class' diff --git a/lib/slack.rb b/lib/slack.rb index fd57776f..cb0ba5e3 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -8,16 +8,8 @@ def main puts "There are #{workspace.channels.count} channels in this workspace" puts "There are #{workspace.users.count} users in this workspace." - - def options - puts "\n\nWhat would you like to do?\n" - puts "Choose the number that corresponds to the following options:" - puts "[1]'List Users'\n[2]'List Channels'\n[3]'Select User'\n[4]'Select Channel'\n[5]'Details'\n[6]'Send Message'\n[7]'Quit'" - end - puts puts "*" * 40 - # puts options user_input = nil @@ -42,21 +34,26 @@ def options if workspace.selected_recipient == nil puts "Please select a channel or user first to view details" else - #### puts workspace.find_recipient(workspace.selected_recipient) workspace.find_details end when "6", "send message" if workspace.selected_recipient == nil - puts "Please select a channel or user first to view details" + puts "Please select a channel or user first to send message" else puts "Send a message!" message = gets.chomp workspace.send_msg(message) + puts "\nMessage sent!" end + end end - puts "Thank you for using the Ada Slack CLI" - end +end +def options + puts "\nWhat would you like to do?\n" + puts "Choose the number that corresponds to the following options:" + puts "[1]'List Users'\n[2]'List Channels'\n[3]'Select User'\n[4]'Select Channel'\n[5]'Details'\n[6]'Send Message'\n[7]'Quit'" end + main if __FILE__ == $PROGRAM_NAME \ No newline at end of file diff --git a/lib/user.rb b/lib/user.rb index 9a15657e..0f3a9e99 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -14,10 +14,9 @@ def initialize (slack_id, username, real_name, status_emoji, name) super(slack_id, name) @real_name = real_name @status_emoji = status_emoji - @username = username + @username = username #for table print end - def self.list response = HTTParty.get("https://slack.com/api/users.list", query: { token: ENV["SLACK_TOKEN"] @@ -27,12 +26,11 @@ def self.list user_array = [] response["members"].each do |user| slack_id = user["id"] - username = user["name"] + username = user["name"] #for table print real_name = user["profile"]["real_name"] status_emoji = user["profile"]["status_emoji"] name = user["name"] - temp_user = self.new(slack_id, username, real_name, status_emoji, name) user_array << temp_user end @@ -43,10 +41,4 @@ def details puts "User found, here's the scoop!\n Username: #{name} \n Slack ID: #{slack_id}\n Real Name: #{real_name}\n Status Emoji: #{status_emoji}" end - - - - - - end \ No newline at end of file diff --git a/lib/workspace.rb b/lib/workspace.rb index 4917804e..92e63e37 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -3,7 +3,6 @@ require_relative 'user' require_relative 'channel' - Dotenv.load class Workspace @@ -56,15 +55,5 @@ def send_msg(message) Recipient.send_msg(message, @selected_recipient.slack_id) end - - - # def find_recipient(input) - # if select_user(input) == "User does not exist" && select_channel(input) == "Channel does not exist" - # return "Not found, please select a new recipient" - # end - # end - - - end From 57d3fbce47726dc1689a757983171cb3e5246bd9 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Thu, 8 Oct 2020 16:21:07 -0700 Subject: [PATCH 46/56] Added test for channel --- test/channel_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/channel_test.rb diff --git a/test/channel_test.rb b/test/channel_test.rb new file mode 100644 index 00000000..ba933a23 --- /dev/null +++ b/test/channel_test.rb @@ -0,0 +1,20 @@ +require_relative 'test_helper' + +describe Channel do + describe 'Channel instantiation' do + before do + slack_id = "C016J5DP925" + name = "getting-help" + topic = "Get some Help!" + member_count = "79" + @channel=Channel.new(slack_id, name, topic, member_count) + + end + + it 'is an instance of Channel' do + expect(@channel).must_be_kind_of Channel + end + + end +end + From 02d2307114a775b115b3c415768f2805a514320b Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Thu, 8 Oct 2020 16:32:54 -0700 Subject: [PATCH 47/56] using .get in recipient class appropriately, change was overwritten --- lib/channel.rb | 5 +---- lib/recipient.rb | 12 +++++------- lib/user.rb | 5 +---- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index c00614bb..b3de03a2 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -17,10 +17,7 @@ def initialize (slack_id, name, topic, member_count) end def self.list - response = HTTParty.get("https://slack.com/api/conversations.list", query: { - token: ENV["SLACK_TOKEN"] - } - ) + response = self.get("https://slack.com/api/conversations.list") channel_array = [] diff --git a/lib/recipient.rb b/lib/recipient.rb index 68b2011d..e23d2cf0 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -9,18 +9,17 @@ class Recipient def initialize(slack_id, name) @slack_id = slack_id @name = name - end + end - def self.get (url) + def self.get(url) response = HTTParty.get(url, query: { - token: ENV["SLACK_TOKEN"], - format: 'json' + token: ENV["SLACK_TOKEN"] } ) unless response.code == 200 raise ArgumentError, 'Error in request' - end + end return response end @@ -48,5 +47,4 @@ def self.list def self.details raise NotImplementedError, 'Implement me in a child class' end -end - +end \ No newline at end of file diff --git a/lib/user.rb b/lib/user.rb index 0f3a9e99..8f9931ca 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -18,10 +18,7 @@ def initialize (slack_id, username, real_name, status_emoji, name) end def self.list - response = HTTParty.get("https://slack.com/api/users.list", query: { - token: ENV["SLACK_TOKEN"] - } - ) + response = self.get("https://slack.com/api/users.list") user_array = [] response["members"].each do |user| From 6d8a0cf4745d5ffd2d680a1bce89700fe211f66e Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Thu, 8 Oct 2020 16:53:30 -0700 Subject: [PATCH 48/56] Added recipient test file and edited user_test --- test/recipient_test.rb | 11 +++++++++++ test/user_test.rb | 11 +++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 test/recipient_test.rb diff --git a/test/recipient_test.rb b/test/recipient_test.rb new file mode 100644 index 00000000..ebadbf04 --- /dev/null +++ b/test/recipient_test.rb @@ -0,0 +1,11 @@ +require_relative 'test_helper' +require 'httparty' + +describe Recipient do + it "can send a valid message" do + VCR.use_cassette("slack-posts") do + response = Recipient.send_msg("Let's test this!", "kayla.elizabeth89") + expect(response).must_equal true + end + end +end \ No newline at end of file diff --git a/test/user_test.rb b/test/user_test.rb index 02e50e66..63dd8449 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -1,5 +1,6 @@ require_relative 'test_helper' + describe User do describe 'User instantiation' do before do @@ -16,5 +17,11 @@ expect(@user).must_be_kind_of User end - end -end \ No newline at end of file + it 'user.list is an instance of an array' + expect(User.list).must_be_kind_of Array + expect(User.length).must_be_close_to 1 +end + + +end + From 2a694ec015fa584f0addb78c201b5b7267ba5237 Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Thu, 8 Oct 2020 17:48:42 -0700 Subject: [PATCH 49/56] VCR finally works and a few tests were written --- lib/recipient.rb | 8 +++++++- test/recipient_test.rb | 23 +++++++++++++++++++---- test/user_test.rb | 11 ++++++++--- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index e23d2cf0..e8d3c1b9 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -34,7 +34,13 @@ def self.send_msg(message, id) headers: { 'Content-Type' => 'application/x-www-form-urlencoded'} ) - return response.code == 200 && response.parsed_response["ok"] + # return response.code == 200 && response.parsed_response["ok"] + + unless response.code == 200 && response.parsed_response["ok"] + raise ArgumentError, "SlackApiError. Reason: #{response["error"]}" + end + + return response end diff --git a/test/recipient_test.rb b/test/recipient_test.rb index ebadbf04..3b0c222c 100644 --- a/test/recipient_test.rb +++ b/test/recipient_test.rb @@ -2,10 +2,25 @@ require 'httparty' describe Recipient do + before do + @slack_id = "U0179312KV3" + @name = "kayla.elizabeth89" + @recipient = Recipient.new(@slack_id, @name) + end + + describe "constructor" do + it "creates a new Recipient instance" do + expect(@recipient).must_be_instance_of Recipient + end + end + it "can send a valid message" do - VCR.use_cassette("slack-posts") do - response = Recipient.send_msg("Let's test this!", "kayla.elizabeth89") - expect(response).must_equal true + VCR.use_cassette("messages take 4") do + response = Recipient.send_msg("I can post messages!", "U0179312KV3") + expect(response.code).must_equal 200 end end -end \ No newline at end of file + + +end + diff --git a/test/user_test.rb b/test/user_test.rb index 63dd8449..57558753 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -11,15 +11,20 @@ name = "" @user= User.new(slack_id, username, real_name, status_emoji, name) + # VCR.use_cassette("members") do + # @response = User.list_all + # end + end it 'is an instance of User' do expect(@user).must_be_kind_of User end - it 'user.list is an instance of an array' - expect(User.list).must_be_kind_of Array - expect(User.length).must_be_close_to 1 + # it 'user.list is an instance of an array' + # expect(User.list).must_be_kind_of Array + # expect(User.length).must_be_close_to 1 + # end end From 1220e2573e8b23eaf33c170934d80a90d0ee7473 Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Thu, 8 Oct 2020 18:25:34 -0700 Subject: [PATCH 50/56] made more working tests - user instantiation, recipient messages --- test/recipient_test.rb | 19 +++++++++++++++++++ test/user_test.rb | 32 ++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/test/recipient_test.rb b/test/recipient_test.rb index 3b0c222c..2c3c0277 100644 --- a/test/recipient_test.rb +++ b/test/recipient_test.rb @@ -21,6 +21,25 @@ end end + it "can send a valid complicated message" do + VCR.use_cassette("messages take 4") do + response = Recipient.send_msg("Kayla! I'm testing a longer message with emojis :party_blob: :confused-dog: I'm sorry if this comes through to you multiple times but if it does I at least hope you are able to enjoy the emojis being sent through our bot!! :gem: :unicorn_face: :zap: **FIST BUMP** :right-facing_fist::left-facing_fist: ", "U0179312KV3") + expect(response.code).must_equal 200 + end + end + + it "will raise error for invalid address" do + VCR.use_cassette("messages take 4") do + expect{Recipient.send_msg("I can post messages!", "mvlofthus")}.must_raise ArgumentError + end + end + + it "will raise error for empty message" do + VCR.use_cassette("messages take 4") do + expect{Recipient.send_msg("", "U0179312KV3")}.must_raise ArgumentError + end + end + end diff --git a/test/user_test.rb b/test/user_test.rb index 57558753..13c13cd3 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -2,7 +2,6 @@ describe User do - describe 'User instantiation' do before do slack_id = "U01CT3X9L2C" username = "water_mmmkay" @@ -11,22 +10,27 @@ name = "" @user= User.new(slack_id, username, real_name, status_emoji, name) - # VCR.use_cassette("members") do - # @response = User.list_all - # end - + VCR.use_cassette("all the users") do + @response = User.list + end end - it 'is an instance of User' do - expect(@user).must_be_kind_of User + describe 'User instantiation' do + it 'is an instance of User' do + expect(@user).must_be_kind_of User + end + + it 'user.list is an instance of an array' do + expect(@response).must_be_kind_of Array + expect(@response.length).must_be_kind_of Integer + expect(@response.length).must_be_close_to 163 + end + + it 'returns the correct info for members' do + expect _(@response[1].slack_id).must_equal "U015QQ2BXFZ" + expect _(@response[2].real_name).must_equal "lisa" + end end - # it 'user.list is an instance of an array' - # expect(User.list).must_be_kind_of Array - # expect(User.length).must_be_close_to 1 - # end -end - end - From 776c135adbbbbabcfb14cd3123d6df122267bdfc Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Thu, 8 Oct 2020 20:00:26 -0700 Subject: [PATCH 51/56] Added more tests to test files --- lib/channel.rb | 2 +- lib/slack.rb | 4 ++-- lib/workspace.rb | 4 ++-- test/channel_test.rb | 30 +++++++++++++++++++++++++++--- test/recipient_test.rb | 2 +- test/user_test.rb | 19 ++++++++++++++++--- test/workspace_test.rb | 28 ++++++++++++++++++++++++++++ 7 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 test/workspace_test.rb diff --git a/lib/channel.rb b/lib/channel.rb index b3de03a2..59c5fcdd 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -35,7 +35,7 @@ def self.list end def details - puts "Channel found, here's the scoop!\n Slack ID: #{slack_id}\n Name: #{name}\n Topic: #{topic}\n Member Count: #{member_count}" + return "Channel found, here's the scoop!\n Slack ID: #{slack_id}\n Name: #{name}\n Topic: #{topic}\n Member Count: #{member_count}" end end diff --git a/lib/slack.rb b/lib/slack.rb index cb0ba5e3..1d38dac1 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -19,9 +19,9 @@ def main case user_input when "1", "list users" - workspace.list_users + tp workspace.list_users when "2", "list channels" - workspace.list_channels + tp workspace.list_channels when "3", "select user" puts "Please enter User Name or ID" user_identifier = gets.chomp.downcase diff --git a/lib/workspace.rb b/lib/workspace.rb index 92e63e37..8691f449 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -16,11 +16,11 @@ def initialize end def list_users - tp @users, "slack_id", "username", "real_name" + return @users, "slack_id", "username", "real_name" end def list_channels - tp @channels, "name", "topic", "member_count", "slack_id" + return @channels, "name", "topic", "member_count", "slack_id" end def select_user(id) diff --git a/test/channel_test.rb b/test/channel_test.rb index ba933a23..80a7fbb5 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -1,20 +1,44 @@ require_relative 'test_helper' describe Channel do - describe 'Channel instantiation' do before do slack_id = "C016J5DP925" name = "getting-help" topic = "Get some Help!" member_count = "79" - @channel=Channel.new(slack_id, name, topic, member_count) + @channel= Channel.new(slack_id, name, topic, member_count) + @detail = @channel.details + @slack_id = slack_id + @name = name + @topic = topic + @member_count = member_count + VCR.use_cassette("channels") do + @response = Channel.list + end end it 'is an instance of Channel' do expect(@channel).must_be_kind_of Channel end - end + it 'channel.list is an instance of an array' do + expect(@response).must_be_kind_of Array + expect(@response.length).must_be_kind_of Integer + expect(@response.length).must_be_close_to 48 + end + + it 'returns the correct info for members' do + expect _(@response[1].slack_id).must_equal "C0165NC8LHH" + expect _(@response[3].name).must_equal "csmemes" + end + + it 'returns a description of a selected channel' do + expect(@detail).must_equal "Channel found, here's the scoop!\n Slack ID: #{@slack_id}\n Name: #{@name}\n Topic: #{@topic}\n Member Count: #{@member_count}" + end + + it 'returns a string' do + expect(@detail).must_be_kind_of String + end end diff --git a/test/recipient_test.rb b/test/recipient_test.rb index 2c3c0277..489cee96 100644 --- a/test/recipient_test.rb +++ b/test/recipient_test.rb @@ -8,7 +8,7 @@ @recipient = Recipient.new(@slack_id, @name) end - describe "constructor" do + describe "instantiation" do it "creates a new Recipient instance" do expect(@recipient).must_be_instance_of Recipient end diff --git a/test/user_test.rb b/test/user_test.rb index 13c13cd3..29823d4e 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -6,9 +6,15 @@ slack_id = "U01CT3X9L2C" username = "water_mmmkay" real_name = "Water MmmKay" - status_emoji = "" + status_emoji = '' name = "" @user= User.new(slack_id, username, real_name, status_emoji, name) + @slack_id = slack_id + @name = name + @username = name + @real_name = real_name + @status_emoji = "" + @detail = @user.details VCR.use_cassette("all the users") do @response = User.list @@ -31,6 +37,13 @@ expect _(@response[2].real_name).must_equal "lisa" end end - - + describe 'User Details' do + it 'returns a description of a selected user' do + expect(@detail).must_equal "User found, here's the scoop!\n Username: #{@name} \n Slack ID: #{@slack_id}\n Real Name: #{@real_name}\n Status Emoji: #{@status_emoji}" + end + + it 'returns a string' do + expect(@detail).must_be_kind_of String + end + end end diff --git a/test/workspace_test.rb b/test/workspace_test.rb new file mode 100644 index 00000000..acd3143f --- /dev/null +++ b/test/workspace_test.rb @@ -0,0 +1,28 @@ +require_relative 'test_helper' +require 'httparty' + +describe Workspace do + before do + VCR.use_cassette("workspace_tests") do + @workspace = Workspace.new + + end + end + + describe 'instantiation' do + it "is an instance of Workspace" do + expect(@workspace).must_be_kind_of Workspace + end + end + + + it "holds user lists, channel lists, and nil selected recipient value" do + expect(@workspace.users).must_be_kind_of Array + expect(@workspace.users[1]).must_be_kind_of User + expect(@workspace.channels).must_be_kind_of Array + expect(@workspace.channels[1]).must_be_kind_of Channel + expect(@workspace.selected_recipient).must_be_nil + end + +end + From 23bfc2b36c0ba6e896f42a2ec23d78a8e3d412f4 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Thu, 8 Oct 2020 20:07:10 -0700 Subject: [PATCH 52/56] Tests now failing for details sections of user and channel. This is because if string is only returned and not 'putsed' it won't show up in slack.rb. --- lib/channel.rb | 2 +- lib/slack.rb | 4 ++-- lib/user.rb | 2 +- lib/workspace.rb | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 59c5fcdd..8285e47e 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -35,7 +35,7 @@ def self.list end def details - return "Channel found, here's the scoop!\n Slack ID: #{slack_id}\n Name: #{name}\n Topic: #{topic}\n Member Count: #{member_count}" + return puts "Channel found, here's the scoop!\n Slack ID: #{slack_id}\n Name: #{name}\n Topic: #{topic}\n Member Count: #{member_count}" end end diff --git a/lib/slack.rb b/lib/slack.rb index 1d38dac1..cb0ba5e3 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -19,9 +19,9 @@ def main case user_input when "1", "list users" - tp workspace.list_users + workspace.list_users when "2", "list channels" - tp workspace.list_channels + workspace.list_channels when "3", "select user" puts "Please enter User Name or ID" user_identifier = gets.chomp.downcase diff --git a/lib/user.rb b/lib/user.rb index 8f9931ca..91465097 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -35,7 +35,7 @@ def self.list end def details - puts "User found, here's the scoop!\n Username: #{name} \n Slack ID: #{slack_id}\n Real Name: #{real_name}\n Status Emoji: #{status_emoji}" + return puts "User found, here's the scoop!\n Username: #{name} \n Slack ID: #{slack_id}\n Real Name: #{real_name}\n Status Emoji: #{status_emoji}" end end \ No newline at end of file diff --git a/lib/workspace.rb b/lib/workspace.rb index 8691f449..530ce7b0 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -16,11 +16,11 @@ def initialize end def list_users - return @users, "slack_id", "username", "real_name" + return tp @users, "slack_id", "username", "real_name" end def list_channels - return @channels, "name", "topic", "member_count", "slack_id" + return tp @channels, "name", "topic", "member_count", "slack_id" end def select_user(id) From 83bfb590e017f1f936b012e8cb7884a91f10591c Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Fri, 9 Oct 2020 09:42:51 -0700 Subject: [PATCH 53/56] Renamed user test username to slackbot and changed channel test username to random. --- lib/channel.rb | 2 +- lib/user.rb | 2 +- lib/workspace.rb | 2 +- test/channel_test.rb | 8 ++++---- test/user_test.rb | 8 ++++---- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 8285e47e..59c5fcdd 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -35,7 +35,7 @@ def self.list end def details - return puts "Channel found, here's the scoop!\n Slack ID: #{slack_id}\n Name: #{name}\n Topic: #{topic}\n Member Count: #{member_count}" + return "Channel found, here's the scoop!\n Slack ID: #{slack_id}\n Name: #{name}\n Topic: #{topic}\n Member Count: #{member_count}" end end diff --git a/lib/user.rb b/lib/user.rb index 91465097..32cea773 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -35,7 +35,7 @@ def self.list end def details - return puts "User found, here's the scoop!\n Username: #{name} \n Slack ID: #{slack_id}\n Real Name: #{real_name}\n Status Emoji: #{status_emoji}" + return "User found, here's the scoop!\n Username: #{name} \n Slack ID: #{slack_id}\n Real Name: #{real_name}\n Status Emoji: #{status_emoji}" end end \ No newline at end of file diff --git a/lib/workspace.rb b/lib/workspace.rb index 530ce7b0..f0cda778 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -47,7 +47,7 @@ def select_channel(id) def find_details if @selected_recipient != nil - return @selected_recipient.details + puts @selected_recipient.details end end diff --git a/test/channel_test.rb b/test/channel_test.rb index 80a7fbb5..6409b321 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -2,9 +2,9 @@ describe Channel do before do - slack_id = "C016J5DP925" - name = "getting-help" - topic = "Get some Help!" + slack_id = "111" + name = "random" + topic = "random" member_count = "79" @channel= Channel.new(slack_id, name, topic, member_count) @detail = @channel.details @@ -13,7 +13,7 @@ @topic = topic @member_count = member_count - VCR.use_cassette("channels") do + VCR.use_cassette("random_channel") do @response = Channel.list end end diff --git a/test/user_test.rb b/test/user_test.rb index 29823d4e..22741830 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -3,9 +3,9 @@ describe User do before do - slack_id = "U01CT3X9L2C" - username = "water_mmmkay" - real_name = "Water MmmKay" + slack_id = "4" + username = "SlackBot" + real_name = "SlackBot" status_emoji = '' name = "" @user= User.new(slack_id, username, real_name, status_emoji, name) @@ -16,7 +16,7 @@ @status_emoji = "" @detail = @user.details - VCR.use_cassette("all the users") do + VCR.use_cassette("SlackBot Users") do @response = User.list end end From 6aca8326ef1f2a8b1ff9c88d1153785b32fad955 Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Fri, 9 Oct 2020 09:48:21 -0700 Subject: [PATCH 54/56] Added a 'Describe do' block for details section of channel --- test/channel_test.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/channel_test.rb b/test/channel_test.rb index 6409b321..1916034c 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -33,12 +33,14 @@ expect _(@response[3].name).must_equal "csmemes" end + describe 'channel details' do + it 'returns a description of a selected channel' do expect(@detail).must_equal "Channel found, here's the scoop!\n Slack ID: #{@slack_id}\n Name: #{@name}\n Topic: #{@topic}\n Member Count: #{@member_count}" end - it 'returns a string' do + it 'description returns a string' do expect(@detail).must_be_kind_of String end + end end - From 440c3666203af60995617a465db2384f351c4d7c Mon Sep 17 00:00:00 2001 From: Kayla Johnson Date: Fri, 9 Oct 2020 10:38:33 -0700 Subject: [PATCH 55/56] Added test to make sure Argument Error is raised when bogus Token is provided --- lib/recipient.rb | 6 ++---- test/recipient_test.rb | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index e8d3c1b9..a891426f 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -17,8 +17,8 @@ def self.get(url) } ) - unless response.code == 200 - raise ArgumentError, 'Error in request' + unless response.code == 200 && response.parsed_response["ok"] + raise ArgumentError#, #"SlackApiError. Reason: #{response["error"]}" end return response @@ -34,8 +34,6 @@ def self.send_msg(message, id) headers: { 'Content-Type' => 'application/x-www-form-urlencoded'} ) - # return response.code == 200 && response.parsed_response["ok"] - unless response.code == 200 && response.parsed_response["ok"] raise ArgumentError, "SlackApiError. Reason: #{response["error"]}" end diff --git a/test/recipient_test.rb b/test/recipient_test.rb index 489cee96..be7184f8 100644 --- a/test/recipient_test.rb +++ b/test/recipient_test.rb @@ -40,6 +40,28 @@ end end + describe 'private methods' do + it "will raise Argument error if Recipient.list is called" do + VCR.use_cassette("messages take 4") do + expect{Recipient.list}.must_raise NotImplementedError + end + end + + it "will raise Argument error if Recipient.details is called" do + VCR.use_cassette("messages take 4") do + expect{Recipient.details}.must_raise NotImplementedError + end + end + + describe 'failed SlackAPI request/post' do + + it "Will raise an Argument error if Token is bogus" do + VCR.use_cassette("SlackAPI failed") do + expect{Recipient.get("https://slack.com/api/users.list")}.must_raise ArgumentError + end + end + end + end end From e02e66bdf3b38cc79c74b2ce26df5baecf33cdb9 Mon Sep 17 00:00:00 2001 From: Mackenzie Date: Fri, 9 Oct 2020 11:44:18 -0700 Subject: [PATCH 56/56] added remaining method tests in workspace, adjusted methods so tests could run, added comments on tests as necessary --- lib/recipient.rb | 2 +- lib/slack.rb | 2 +- lib/workspace.rb | 4 +-- test/channel_test.rb | 2 +- test/recipient_test.rb | 2 +- test/user_test.rb | 2 +- test/workspace_test.rb | 62 ++++++++++++++++++++++++++++++++++++++++-- 7 files changed, 66 insertions(+), 10 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index a891426f..bb5e1ab5 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -18,7 +18,7 @@ def self.get(url) ) unless response.code == 200 && response.parsed_response["ok"] - raise ArgumentError#, #"SlackApiError. Reason: #{response["error"]}" + raise ArgumentError, "SlackApiError. Reason: #{response["error"]}" end return response diff --git a/lib/slack.rb b/lib/slack.rb index cb0ba5e3..420fc922 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -34,7 +34,7 @@ def main if workspace.selected_recipient == nil puts "Please select a channel or user first to view details" else - workspace.find_details + puts workspace.find_details end when "6", "send message" if workspace.selected_recipient == nil diff --git a/lib/workspace.rb b/lib/workspace.rb index f0cda778..aa5a4490 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -46,9 +46,7 @@ def select_channel(id) end def find_details - if @selected_recipient != nil - puts @selected_recipient.details - end + return @selected_recipient.details end def send_msg(message) diff --git a/test/channel_test.rb b/test/channel_test.rb index 1916034c..02713927 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -25,7 +25,7 @@ it 'channel.list is an instance of an array' do expect(@response).must_be_kind_of Array expect(@response.length).must_be_kind_of Integer - expect(@response.length).must_be_close_to 48 + expect(@response.length).must_be_close_to 49 #passes at time of submission end it 'returns the correct info for members' do diff --git a/test/recipient_test.rb b/test/recipient_test.rb index be7184f8..0a51503f 100644 --- a/test/recipient_test.rb +++ b/test/recipient_test.rb @@ -56,7 +56,7 @@ describe 'failed SlackAPI request/post' do - it "Will raise an Argument error if Token is bogus" do + it "Will raise an Argument error if Token is bogus" do #this will work if you give a bogus token in .env VCR.use_cassette("SlackAPI failed") do expect{Recipient.get("https://slack.com/api/users.list")}.must_raise ArgumentError end diff --git a/test/user_test.rb b/test/user_test.rb index 22741830..41b09949 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -29,7 +29,7 @@ it 'user.list is an instance of an array' do expect(@response).must_be_kind_of Array expect(@response.length).must_be_kind_of Integer - expect(@response.length).must_be_close_to 163 + expect(@response.length).must_be_close_to 163 #passes at time of submission end it 'returns the correct info for members' do diff --git a/test/workspace_test.rb b/test/workspace_test.rb index acd3143f..46181b3b 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -13,8 +13,6 @@ it "is an instance of Workspace" do expect(@workspace).must_be_kind_of Workspace end - end - it "holds user lists, channel lists, and nil selected recipient value" do expect(@workspace.users).must_be_kind_of Array @@ -23,6 +21,66 @@ expect(@workspace.channels[1]).must_be_kind_of Channel expect(@workspace.selected_recipient).must_be_nil end + end + + describe "list methods" do + it "will print a table for list_users" do + expect(@workspace.list_users).must_be_kind_of TablePrint::Returnable + end + + it "will print a table for list_channels" do + expect(@workspace.list_channels).must_be_kind_of TablePrint::Returnable + end + end + + describe "select recipeint" do + it "will return selected_recipient is user and valid" do + expect(@workspace.select_user("mvlofthus")).must_be_kind_of Recipient + end + + it "will return selected_recipient is user and invalid" do + expect(@workspace.select_user("MVLOFTHUS")).must_be_nil + end + + it "will return a string if @selected_recipient is channel and valid" do + name = "C017HQHHHRB".downcase + expect(@workspace.select_channel(name)).must_be_kind_of Channel + end + + it "will return a string if @selected_recipient is channel and invalid" do + name = "C017HQHHHRB" + expect(@workspace.select_channel(name)).must_be_nil + end + end + + describe "find_details" do + it "will return a string if @selected_recipient is user" do + @workspace.select_user("mvlofthus") + expect(@workspace.find_details).must_be_kind_of String + end + + it "will return a string if @selected_recipient is channel" do + name = "C017HQHHHRB".downcase + @workspace.select_channel(name) + expect(@workspace.find_details).must_be_kind_of String + end + end + + describe "send_msg" do + it "will send a message if selected_recipient is not nil" do + @workspace.select_user("kayla.elizabeth89") + VCR.use_cassette("workspace send_msg 1") do + response = @workspace.send_msg("hola!") + expect(response.code).must_equal 200 + end + end + + it "will send a message if selected_recipient is nil (though slack.rb will not let this go through)" do + VCR.use_cassette("workspace send_msg 2") do + expect{@workspace.send_msg("hola!")}.must_raise NoMethodError + end + end + end end