From 6593e4ba686c8f156385927f556c109b6318687d Mon Sep 17 00:00:00 2001 From: Monick Date: Tue, 10 Sep 2019 14:04:11 -0700 Subject: [PATCH 01/13] built methods for list_channel, list_users, and user-input interface --- lib/channel.rb | 0 lib/server.rb | 0 lib/slack.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++--- lib/user.rb | 0 lib/workspace.rb | 0 5 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 lib/channel.rb create mode 100644 lib/server.rb create mode 100644 lib/user.rb create mode 100644 lib/workspace.rb diff --git a/lib/channel.rb b/lib/channel.rb new file mode 100644 index 00000000..e69de29b diff --git a/lib/server.rb b/lib/server.rb new file mode 100644 index 00000000..e69de29b diff --git a/lib/slack.rb b/lib/slack.rb index 960cf2f7..b4e068f9 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,11 +1,68 @@ #!/usr/bin/env ruby +require 'dotenv' +require 'httparty' +require 'awesome_print' +Dotenv.load +class def main - puts "Welcome to the Ada Slack CLI!" + puts "Welcome to the Ada Slack CLI! What would you like to do?" + puts "list channels, list users, or quit" - # TODO project + user_input = gets.chomp + + case user_input + when "list channels" + list_channels + when "list users" + list_users + when quit + exit + end puts "Thank you for using the Ada Slack CLI" end +main + +def list_channels + method_url = "https://slack.com/api/channels.list" + query_params = { + # key: ENV["SLACK-TOKEN"] + token: "xoxp-741657849778-756645927222-757736307830-f34cbca9bdbe14b7faed9993862f15a6" + } + response = HTTParty.get(method_url, query: query_params) + + #DO NOT REMOVE - getting one name for one channel + # ap response.parsed_response["channels"][0]["name"] + + channels = response.parsed_response["channels"] + i = 0 + channels.each do |channel| + channel_name = response.parsed_response["channels"][i]["name"] + i += 1 + puts channel_name + end +end +# list_channels + +def list_users + method_url = "https://slack.com/api/users.list" + query_params = { + # key: ENV["SLACK-TOKEN"] + token: "xoxp-741657849778-756645927222-757736307830-f34cbca9bdbe14b7faed9993862f15a6" + } + response = HTTParty.get(method_url, query: query_params) + + users = response.parsed_response["members"] + i = 0 + users.each do |user| + user_name = response.parsed_response["members"][i]["name"] + i += 1 + puts user_name + end + +end +# list_users + -main if __FILE__ == $PROGRAM_NAME \ No newline at end of file +# main if __FILE__ == $PROGRAM_NAME \ No newline at end of file diff --git a/lib/user.rb b/lib/user.rb new file mode 100644 index 00000000..e69de29b diff --git a/lib/workspace.rb b/lib/workspace.rb new file mode 100644 index 00000000..e69de29b From 77a88ac82217af22bb5b784f4f58186e6f7c563d Mon Sep 17 00:00:00 2001 From: mfunkemomo <47875499+mfunkemomo@users.noreply.github.com> Date: Tue, 10 Sep 2019 14:16:14 -0700 Subject: [PATCH 02/13] Update slack.rb --- lib/slack.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index b4e068f9..ee9d27a2 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -28,7 +28,7 @@ def list_channels method_url = "https://slack.com/api/channels.list" query_params = { # key: ENV["SLACK-TOKEN"] - token: "xoxp-741657849778-756645927222-757736307830-f34cbca9bdbe14b7faed9993862f15a6" + token: "NEW TOKEN" } response = HTTParty.get(method_url, query: query_params) @@ -65,4 +65,4 @@ def list_users # list_users -# main if __FILE__ == $PROGRAM_NAME \ No newline at end of file +# main if __FILE__ == $PROGRAM_NAME From e9c203a24fbaa1ae8c1708471fb3dd2f87a23b60 Mon Sep 17 00:00:00 2001 From: Monick Date: Tue, 10 Sep 2019 15:00:06 -0700 Subject: [PATCH 03/13] was able to get env file working --- .gitignore | 1 + lib/slack.rb | 22 +++++++--------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 8d6a243f..feaa51d7 100644 --- a/.gitignore +++ b/.gitignore @@ -51,6 +51,7 @@ build-iPhoneSimulator/ # Ignore environemnt variables .env +instructor-design.png # Ignore cassette files /specs/cassettes/ diff --git a/lib/slack.rb b/lib/slack.rb index b4e068f9..e0f69cce 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,40 +1,33 @@ -#!/usr/bin/env ruby require 'dotenv' require 'httparty' require 'awesome_print' Dotenv.load -class + def main puts "Welcome to the Ada Slack CLI! What would you like to do?" puts "list channels, list users, or quit" user_input = gets.chomp - case user_input when "list channels" list_channels when "list users" list_users - when quit + when "quit" + puts "Thank you for using the Ada Slack CLI" exit end - - puts "Thank you for using the Ada Slack CLI" end -main +# main def list_channels method_url = "https://slack.com/api/channels.list" query_params = { - # key: ENV["SLACK-TOKEN"] - token: "xoxp-741657849778-756645927222-757736307830-f34cbca9bdbe14b7faed9993862f15a6" + token: ENV["SLACK_TOKEN"] } response = HTTParty.get(method_url, query: query_params) - #DO NOT REMOVE - getting one name for one channel - # ap response.parsed_response["channels"][0]["name"] - channels = response.parsed_response["channels"] i = 0 channels.each do |channel| @@ -43,13 +36,12 @@ def list_channels puts channel_name end end -# list_channels +list_channels def list_users method_url = "https://slack.com/api/users.list" query_params = { - # key: ENV["SLACK-TOKEN"] - token: "xoxp-741657849778-756645927222-757736307830-f34cbca9bdbe14b7faed9993862f15a6" + token: ENV["SLACK_TOKEN"] } response = HTTParty.get(method_url, query: query_params) From cb6bc9343ba1475cfeeb2db85ead3f27c8a3959b Mon Sep 17 00:00:00 2001 From: Monick Date: Tue, 10 Sep 2019 16:21:35 -0700 Subject: [PATCH 04/13] created user, channel, server class and completed user class to print all necessary data --- lib/channel.rb | 40 +++++++++++++++++++++++++++ lib/server.rb | 21 ++++++++++++++ lib/slack.rb | 75 +++++++++++++++++--------------------------------- lib/user.rb | 41 +++++++++++++++++++++++++++ 4 files changed, 128 insertions(+), 49 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index e69de29b..b5ac56f3 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -0,0 +1,40 @@ +require 'dotenv' +require 'httparty' +require 'awesome_print' +Dotenv.load + +require_relative 'server' + +module SlackCli + class Channel < Server + attr_reader :topic + + def initialize(topic:) + @topic = topic + end + + def self.list + method_url = "https://slack.com/api/channels.list" + query_params = { + token: ENV["SLACK_TOKEN"] + } + response = HTTParty.get(method_url, query: query_params) + + channels = response.parsed_response["channels"] + i = 0 + channels.each do |channel| + name = response.parsed_response["channels"][i]["name"] + topic = response.parsed_response["channels"][i]["topic"] + id = response.parsed_response["channels"][i]["id"] + member_count = response.parsed_response["channels"][i]["member_count"] + user_hash[:user_name] = user_name + user_hash[:real_name] = real_name + user_hash[:id] = id + all_slack_users.push(user_hash) + i += 1 + i += 1 + end + end + + end +end \ No newline at end of file diff --git a/lib/server.rb b/lib/server.rb index e69de29b..d59e751a 100644 --- a/lib/server.rb +++ b/lib/server.rb @@ -0,0 +1,21 @@ +require 'dotenv' +require 'httparty' +require 'awesome_print' +Dotenv.load + +module SlackCli + class Server + attr_reader :slack_id, :name + + def initialize(slack_id:, name:) + @slack_id = slack_id + @name = name + end + + # def self.list + # puts "Who knows" + # end + + end + +end \ No newline at end of file diff --git a/lib/slack.rb b/lib/slack.rb index d9435f9d..e737892a 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -3,58 +3,35 @@ require 'awesome_print' Dotenv.load - -def main - puts "Welcome to the Ada Slack CLI! What would you like to do?" - puts "list channels, list users, or quit" - - user_input = gets.chomp - case user_input - when "list channels" - list_channels - when "list users" - list_users - when "quit" - puts "Thank you for using the Ada Slack CLI" - exit - end -end -# main - -def list_channels - method_url = "https://slack.com/api/channels.list" - query_params = { - token: ENV["SLACK_TOKEN"] - } - response = HTTParty.get(method_url, query: query_params) - - channels = response.parsed_response["channels"] - i = 0 - channels.each do |channel| - channel_name = response.parsed_response["channels"][i]["name"] - i += 1 - puts channel_name - end -end -list_channels - -def list_users - method_url = "https://slack.com/api/users.list" - query_params = { - token: ENV["SLACK_TOKEN"] - } - response = HTTParty.get(method_url, query: query_params) - - users = response.parsed_response["members"] - i = 0 - users.each do |user| - user_name = response.parsed_response["members"][i]["name"] - i += 1 - puts user_name +require_relative 'channel' +require_relative 'user' + +module SlackCli + class SlackSpace + attr_reader :users, :channels, :selected + + def initialize(users:, channels:, selected:) + @users = users + @channels = channels + @selected = selected + end + + puts "Welcome to the Ada Slack CLI! What would you like to do?" + puts "list channels, list users, or quit" + + user_input = gets.chomp + case user_input + when "list channels" + Channel.list + when "list users" + User.list + when "quit" + puts "Thank you for using the Ada Slack CLI" + exit + end end end -# list_users # main if __FILE__ == $PROGRAM_NAME diff --git a/lib/user.rb b/lib/user.rb index e69de29b..a73c1f38 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -0,0 +1,41 @@ +require 'dotenv' +require 'httparty' +require 'awesome_print' +Dotenv.load + +require_relative 'server' + +module SlackCli + class User < Server + attr_reader :real_name + + def initialize(real_name:) + @real_name = real_name + end + + def self.list + method_url = "https://slack.com/api/users.list" + query_params = { + token: ENV["SLACK_TOKEN"] + } + response = HTTParty.get(method_url, query: query_params) + + users = response.parsed_response["members"] + i = 0 + all_slack_users = [] + users.each do |user| + user_hash = {} + user_name = response.parsed_response["members"][i]["name"] + real_name = response.parsed_response["members"][i]["real_name"] + id = response.parsed_response["members"][i]["id"] + user_hash[:user_name] = user_name + user_hash[:real_name] = real_name + user_hash[:id] = id + all_slack_users.push(user_hash) + i += 1 + end + ap all_slack_users + end + + end +end \ No newline at end of file From 29649d744ff3f0d90886072180b8c8b372045166 Mon Sep 17 00:00:00 2001 From: Monick Date: Tue, 10 Sep 2019 16:29:57 -0700 Subject: [PATCH 05/13] completed channels class and displaying all necessary info --- lib/channel.rb | 19 +++++++++++-------- lib/user.rb | 4 ++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index b5ac56f3..0e17e963 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -19,21 +19,24 @@ def self.list token: ENV["SLACK_TOKEN"] } response = HTTParty.get(method_url, query: query_params) - + channels = response.parsed_response["channels"] i = 0 + all_channels = [] channels.each do |channel| + channel_hash = {} name = response.parsed_response["channels"][i]["name"] - topic = response.parsed_response["channels"][i]["topic"] + topic = response.parsed_response["channels"][i]["topic"]["value"] id = response.parsed_response["channels"][i]["id"] - member_count = response.parsed_response["channels"][i]["member_count"] - user_hash[:user_name] = user_name - user_hash[:real_name] = real_name - user_hash[:id] = id - all_slack_users.push(user_hash) - i += 1 + member_count = response.parsed_response["channels"][i]["num_members"] + channel_hash[:name] = name + channel_hash[:topic] = topic + channel_hash[:id] = id + channel_hash[:num_members] = member_count + all_channels.push(channel_hash) i += 1 end + ap all_channels end end diff --git a/lib/user.rb b/lib/user.rb index a73c1f38..b15c9098 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -22,7 +22,7 @@ def self.list users = response.parsed_response["members"] i = 0 - all_slack_users = [] + all_users = [] users.each do |user| user_hash = {} user_name = response.parsed_response["members"][i]["name"] @@ -34,7 +34,7 @@ def self.list all_slack_users.push(user_hash) i += 1 end - ap all_slack_users + ap all_users end end From c3365d1c6f0cf00b16f917469f2f4cc3d49396b4 Mon Sep 17 00:00:00 2001 From: Monick Date: Wed, 11 Sep 2019 16:00:01 -0700 Subject: [PATCH 06/13] completed user and channel tests. vcr works --- lib/channel.rb | 17 +- lib/{server.rb => recipient.rb} | 8 +- lib/slack.rb | 33 ++-- lib/user.rb | 17 +- test/cassettes/slack_details.yml | 309 +++++++++++++++++++++++++++++++ test/channel_test.rb | 55 ++++++ test/recipient_test.rb | 11 ++ test/slack_test.rb | 0 test/test_helper.rb | 19 +- test/user_test.rb | 49 +++++ 10 files changed, 482 insertions(+), 36 deletions(-) rename lib/{server.rb => recipient.rb} (62%) create mode 100644 test/cassettes/slack_details.yml create mode 100644 test/channel_test.rb create mode 100644 test/recipient_test.rb create mode 100644 test/slack_test.rb create mode 100644 test/user_test.rb diff --git a/lib/channel.rb b/lib/channel.rb index 0e17e963..80f7afba 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -3,17 +3,20 @@ require 'awesome_print' Dotenv.load -require_relative 'server' +require_relative 'recipient' module SlackCli - class Channel < Server - attr_reader :topic + class Channel < Recipient + attr_reader :name, :topic, :id, :num_members - def initialize(topic:) + def initialize(name:, id:, topic:, num_members:) + @name = name + @id = id @topic = topic + @num_members = num_members end - def self.list + def list method_url = "https://slack.com/api/channels.list" query_params = { token: ENV["SLACK_TOKEN"] @@ -28,11 +31,11 @@ def self.list name = response.parsed_response["channels"][i]["name"] topic = response.parsed_response["channels"][i]["topic"]["value"] id = response.parsed_response["channels"][i]["id"] - member_count = response.parsed_response["channels"][i]["num_members"] + num_members = response.parsed_response["channels"][i]["num_members"] channel_hash[:name] = name channel_hash[:topic] = topic channel_hash[:id] = id - channel_hash[:num_members] = member_count + channel_hash[:num_members] = num_members all_channels.push(channel_hash) i += 1 end diff --git a/lib/server.rb b/lib/recipient.rb similarity index 62% rename from lib/server.rb rename to lib/recipient.rb index d59e751a..a17622fd 100644 --- a/lib/server.rb +++ b/lib/recipient.rb @@ -4,11 +4,11 @@ Dotenv.load module SlackCli - class Server - attr_reader :slack_id, :name + class Recipient + attr_reader :id, :name - def initialize(slack_id:, name:) - @slack_id = slack_id + def initialize(id:, name:) + @id = id @name = name end diff --git a/lib/slack.rb b/lib/slack.rb index e737892a..b6322bae 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -16,22 +16,27 @@ def initialize(users:, channels:, selected:) @selected = selected end - puts "Welcome to the Ada Slack CLI! What would you like to do?" - puts "list channels, list users, or quit" - - user_input = gets.chomp - case user_input - when "list channels" - Channel.list - when "list users" - User.list - when "quit" - puts "Thank you for using the Ada Slack CLI" - exit + def start_program + ap "Welcome to the Ada Slack CLI!" + ap "What would you like ot do? Type one of the following: list channels, list users, or quit." + user_input = gets.chomp.downcase + + while user_input != "quit" + case user_input + when "list channels" + Channel.list + when "list users" + User.list + else + # raise ArgumentError.new("Invalid input") + puts "ARGUMENTERROR - FIX THIS" + end + puts "What would you like to do? Type one of the following: list channels, list users, or quit." + user_input = gets.chomp + end + puts "Thank you for using the Sara & Monick Slack CLI" end end - end - # main if __FILE__ == $PROGRAM_NAME diff --git a/lib/user.rb b/lib/user.rb index b15c9098..c692ee81 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -3,17 +3,19 @@ require 'awesome_print' Dotenv.load -require_relative 'server' +require_relative 'recipient' module SlackCli - class User < Server - attr_reader :real_name + class User < Recipient + attr_reader :name, :real_name, :id - def initialize(real_name:) + def initialize(name:, real_name:, id:) @real_name = real_name + @name = name + @id = id end - def self.list + def list method_url = "https://slack.com/api/users.list" query_params = { token: ENV["SLACK_TOKEN"] @@ -31,11 +33,10 @@ def self.list user_hash[:user_name] = user_name user_hash[:real_name] = real_name user_hash[:id] = id - all_slack_users.push(user_hash) + all_users.push(user_hash) i += 1 end - ap all_users + return all_users end - end end \ No newline at end of file diff --git a/test/cassettes/slack_details.yml b/test/cassettes/slack_details.yml new file mode 100644 index 00000000..2623ba76 --- /dev/null +++ b/test/cassettes/slack_details.yml @@ -0,0 +1,309 @@ +--- +http_interactions: +- request: + method: get + uri: https://slack.com/api/users.list?token= + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '930' + Connection: + - keep-alive + Date: + - Wed, 11 Sep 2019 22:07:31 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 58415489-ed1e-4ed2-ba69-5fa302291b2f + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - users:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-pcsw + X-Cache: + - Miss from cloudfront + Via: + - 1.1 d0387b833e3ca8cb748a1296b4b4bf2b.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C1 + X-Amz-Cf-Id: + - RUtgLMtffX4G7lZtbTv4_Pf97Q2jl0ZPJUZmVAyfbkQGVQ-N8sixzQ== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TMTKBQZNW","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":null,"tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Slackbot","real_name_normalized":"Slackbot","display_name":"Slackbot","display_name_normalized":"Slackbot","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"sv41d8cd98f0","always_active":true,"first_name":"slackbot","last_name":"","image_24":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/80588\/marketing\/img\/avatars\/slackbot\/avatar-slackbot.png","image_512":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_512.png","status_text_canonical":"","team":"TMTKBQZNW"},"is_admin":false,"is_owner":false,"is_primary_owner":false,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":0},{"id":"UN8JZT96J","team_id":"TMTKBQZNW","name":"monick.keo","deleted":false,"color":"9f69e7","real_name":"monick.keo","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"monick.keo","real_name_normalized":"monick.keo","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g2c3fdb549fe","image_24":"https:\/\/secure.gravatar.com\/avatar\/2c3fdb549feab0cd8aae6d289dd5697f.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0015-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/2c3fdb549feab0cd8aae6d289dd5697f.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0015-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/2c3fdb549feab0cd8aae6d289dd5697f.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0015-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/2c3fdb549feab0cd8aae6d289dd5697f.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0015-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/2c3fdb549feab0cd8aae6d289dd5697f.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0015-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/2c3fdb549feab0cd8aae6d289dd5697f.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0015-512.png","status_text_canonical":"","team":"TMTKBQZNW"},"is_admin":true,"is_owner":true,"is_primary_owner":true,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":1568082002,"has_2fa":false},{"id":"UN8LCAGES","team_id":"TMTKBQZNW","name":"sarashahbaig","deleted":false,"color":"4bbe2e","real_name":"sara + shah","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"sara + shah","real_name_normalized":"sara shah","display_name":"sara shah","display_name_normalized":"sara + shah","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gbb5b56e38f3","first_name":"","last_name":"","image_24":"https:\/\/secure.gravatar.com\/avatar\/bb5b56e38f33ff58749dca957a693f1f.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0021-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/bb5b56e38f33ff58749dca957a693f1f.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0021-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/bb5b56e38f33ff58749dca957a693f1f.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0021-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/bb5b56e38f33ff58749dca957a693f1f.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0021-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/bb5b56e38f33ff58749dca957a693f1f.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0021-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/bb5b56e38f33ff58749dca957a693f1f.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0021-512.png","status_text_canonical":"","team":"TMTKBQZNW"},"is_admin":false,"is_owner":false,"is_primary_owner":false,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":1568087174,"has_2fa":false}],"cache_ts":1568239651,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 11 Sep 2019 22:07:31 GMT +- request: + method: get + uri: https://slack.com/api/users.list?token= + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '930' + Connection: + - keep-alive + Date: + - Wed, 11 Sep 2019 22:07:31 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 9df2a638-d959-4398-9bc0-2b0384143cb2 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - users:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-vdbk + X-Cache: + - Miss from cloudfront + Via: + - 1.1 599f04a365a179d553682d476509c389.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C1 + X-Amz-Cf-Id: + - 6iT6cOlmeLJt_6uhkL9IdKvcwVzX9xd-mcayD-BMVmwnwsUwoYKMLg== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TMTKBQZNW","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":null,"tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Slackbot","real_name_normalized":"Slackbot","display_name":"Slackbot","display_name_normalized":"Slackbot","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"sv41d8cd98f0","always_active":true,"first_name":"slackbot","last_name":"","image_24":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/80588\/marketing\/img\/avatars\/slackbot\/avatar-slackbot.png","image_512":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_512.png","status_text_canonical":"","team":"TMTKBQZNW"},"is_admin":false,"is_owner":false,"is_primary_owner":false,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":0},{"id":"UN8JZT96J","team_id":"TMTKBQZNW","name":"monick.keo","deleted":false,"color":"9f69e7","real_name":"monick.keo","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"monick.keo","real_name_normalized":"monick.keo","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g2c3fdb549fe","image_24":"https:\/\/secure.gravatar.com\/avatar\/2c3fdb549feab0cd8aae6d289dd5697f.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0015-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/2c3fdb549feab0cd8aae6d289dd5697f.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0015-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/2c3fdb549feab0cd8aae6d289dd5697f.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0015-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/2c3fdb549feab0cd8aae6d289dd5697f.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0015-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/2c3fdb549feab0cd8aae6d289dd5697f.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0015-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/2c3fdb549feab0cd8aae6d289dd5697f.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0015-512.png","status_text_canonical":"","team":"TMTKBQZNW"},"is_admin":true,"is_owner":true,"is_primary_owner":true,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":1568082002,"has_2fa":false},{"id":"UN8LCAGES","team_id":"TMTKBQZNW","name":"sarashahbaig","deleted":false,"color":"4bbe2e","real_name":"sara + shah","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"sara + shah","real_name_normalized":"sara shah","display_name":"sara shah","display_name_normalized":"sara + shah","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gbb5b56e38f3","first_name":"","last_name":"","image_24":"https:\/\/secure.gravatar.com\/avatar\/bb5b56e38f33ff58749dca957a693f1f.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0021-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/bb5b56e38f33ff58749dca957a693f1f.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0021-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/bb5b56e38f33ff58749dca957a693f1f.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0021-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/bb5b56e38f33ff58749dca957a693f1f.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0021-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/bb5b56e38f33ff58749dca957a693f1f.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0021-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/bb5b56e38f33ff58749dca957a693f1f.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0021-512.png","status_text_canonical":"","team":"TMTKBQZNW"},"is_admin":false,"is_owner":false,"is_primary_owner":false,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":1568087174,"has_2fa":false}],"cache_ts":1568239651,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 11 Sep 2019 22:07:31 GMT +- request: + method: get + uri: https://slack.com/api/channels.list?token= + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '549' + Connection: + - keep-alive + Date: + - Wed, 11 Sep 2019 22:34:47 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 0510f30a-f12a-4fae-9ea6-6b7939f0909e + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - channels:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-f2n6 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 d6a002c70d55f415107618b0750d493d.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C2 + X-Amz-Cf-Id: + - KhLjVxHEo9qEgrIB8O8_t3tgei94_ubnVJUJPdstN5v-1oVg2iEhFw== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CMTKBR8P4","name":"general","is_channel":true,"created":1568082002,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UN8JZT96J","name_normalized":"general","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UN8JZT96J","UN8LCAGES"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UN8JZT96J","last_set":1568082002},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UN8JZT96J","last_set":1568082002},"previous_names":[],"num_members":2},{"id":"CN6CW5FBP","name":"random","is_channel":true,"created":1568082002,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN8JZT96J","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UN8JZT96J","UN8LCAGES"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UN8JZT96J","last_set":1568082002},"purpose":{"value":"A + place for non-work-related flimflam, faffing, hodge-podge or jibber-jabber + you''d prefer to keep out of more focused work-related channels.","creator":"UN8JZT96J","last_set":1568082002},"previous_names":[],"num_members":2},{"id":"CN88Q9RAB","name":"slack-cli","is_channel":true,"created":1568082003,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN8JZT96J","name_normalized":"slack-cli","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UN8JZT96J","UN8LCAGES"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 11 Sep 2019 22:34:47 GMT +- request: + method: get + uri: https://slack.com/api/channels.list?token= + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '549' + Connection: + - keep-alive + Date: + - Wed, 11 Sep 2019 22:34:47 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - caa2b1c4-4e15-4cdd-af89-7915f39b43cf + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - channels:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-lx8n + X-Cache: + - Miss from cloudfront + Via: + - 1.1 b2f9564ebf9c745cc2ceae96d434977e.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C2 + X-Amz-Cf-Id: + - xJfCSGBBOlCkgNCAvKQiBvk5NFWPuBTx45JAobb7lAssOriZpAgunA== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CMTKBR8P4","name":"general","is_channel":true,"created":1568082002,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UN8JZT96J","name_normalized":"general","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UN8JZT96J","UN8LCAGES"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UN8JZT96J","last_set":1568082002},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UN8JZT96J","last_set":1568082002},"previous_names":[],"num_members":2},{"id":"CN6CW5FBP","name":"random","is_channel":true,"created":1568082002,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN8JZT96J","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UN8JZT96J","UN8LCAGES"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UN8JZT96J","last_set":1568082002},"purpose":{"value":"A + place for non-work-related flimflam, faffing, hodge-podge or jibber-jabber + you''d prefer to keep out of more focused work-related channels.","creator":"UN8JZT96J","last_set":1568082002},"previous_names":[],"num_members":2},{"id":"CN88Q9RAB","name":"slack-cli","is_channel":true,"created":1568082003,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN8JZT96J","name_normalized":"slack-cli","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UN8JZT96J","UN8LCAGES"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 11 Sep 2019 22:34:47 GMT +recorded_with: VCR 5.0.0 diff --git a/test/channel_test.rb b/test/channel_test.rb new file mode 100644 index 00000000..0441ea92 --- /dev/null +++ b/test/channel_test.rb @@ -0,0 +1,55 @@ +require_relative 'test_helper' + +describe "user class tests" do + before do + @channel = SlackCli::Channel.new(name:"Sara", id: "6", topic:"general", num_members: "3") + end + + it "should instanitate as SlackCli::User" do + expect(@channel).must_be_kind_of SlackCli::Channel + end +end + +describe "self.list method should return correct values" do + before do + @channel = SlackCli::Channel.new(name:"Sara", id: "6", topic: "general", num_members: "3") + end + + it "all_users returns as an array with correct number of parameters" do + VCR.use_cassette("slack_details") do + expect(@channel.list).must_be_kind_of Array + expect(@channel.list.length).must_equal 3 + end + end + + it "channel list method returns correct name" do + VCR.use_cassette("slack_details") do + expect(@channel.list[1][:name]).must_equal "random" + end + end + + it "user_hash contains name" do + VCR.use_cassette("slack_details") do + expect(@channel.list[1][:topic]).must_be_kind_of String + end + end + + it "user_hash contains name" do + VCR.use_cassette("slack_details") do + expect(@channel.list[1][:id]).must_equal "CN6CW5FBP" + end + end + + it "user_hash contains id" do + VCR.use_cassette("slack_details") do + expect(@channel.list[1][:num_members]).must_equal 2 + expect(@channel.list[1][:num_members]).must_be_kind_of Integer + end + end + + # it "should conceal token in public domains" do + # VCR.use_cassette("slack_details") do + + # end + # end +end \ No newline at end of file diff --git a/test/recipient_test.rb b/test/recipient_test.rb new file mode 100644 index 00000000..a638ec1c --- /dev/null +++ b/test/recipient_test.rb @@ -0,0 +1,11 @@ +require_relative 'test_helper' + +describe "user class tests" do + before do + @recipient1 = SlackCli::Recipient.new(name:"Sara", id: "6") + end + + it "should instanitate as SlackCli::User" do + expect(@recipient1).must_be_kind_of SlackCli::Recipient + end +end diff --git a/test/slack_test.rb b/test/slack_test.rb new file mode 100644 index 00000000..e69de29b diff --git a/test/test_helper.rb b/test/test_helper.rb index 90aeb408..8d098687 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -11,7 +11,20 @@ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new +require_relative '../lib/channel' +require_relative '../lib/user' +require_relative '../lib/slack' +require_relative '../lib/recipient' + VCR.configure do |config| - config.cassette_library_dir = "test/cassettes" - config.hook_into :webmock -end + config.cassette_library_dir = "test/cassettes" # folder where casettes will be located + config.hook_into :webmock # tie into this other tool called webmock + config.default_cassette_options = { + :record => :new_episodes, # record new data when we don't have it yet + :match_requests_on => [:method, :uri, :body], # The http method, URI and body of a request all need to match + } + + config.filter_sensitive_data("") do + ENV["SLACK_TOKEN"] + end +end \ No newline at end of file diff --git a/test/user_test.rb b/test/user_test.rb new file mode 100644 index 00000000..6cf22365 --- /dev/null +++ b/test/user_test.rb @@ -0,0 +1,49 @@ +require_relative 'test_helper' + +describe "user class tests" do + before do + @user1 = SlackCli::User.new(name:"Sara", real_name:"Monick", id: "6") + end + + it "should instanitate as SlackCli::User" do + expect(@user1).must_be_kind_of SlackCli::User + end +end + +describe "self.list method should return correct values" do + before do + @user1 = SlackCli::User.new(name:"Sara", real_name:"Monick", id: "6") + end + + it "all_users returns as an array with correct number of parameters" do + VCR.use_cassette("slack_details") do + expect(@user1.list).must_be_kind_of Array + expect(@user1.list.length).must_equal 3 + end + end + + it "user_hash contains name" do + VCR.use_cassette("slack_details") do + expect(@user1.name).must_equal "Sara" + end + end + + it "user_hash contains real name" do + VCR.use_cassette("slack_details") do + expect(@user1.real_name).must_equal "Monick" + end + end + + it "user_hash contains id" do + VCR.use_cassette("slack_details") do + expect(@user1.id).must_equal "6" + expect(@user1.id).must_be_kind_of String + end + end + + # it "should conceal token in public domains" do + # VCR.use_cassette("slack_details") do + + # end + # end +end \ No newline at end of file From 87ac6ef3af99eaf8d544a4a66e2d7105d2db8c1e Mon Sep 17 00:00:00 2001 From: Monick Date: Wed, 11 Sep 2019 21:52:14 -0700 Subject: [PATCH 07/13] refactored channel and user tests --- lib/channel.rb | 2 +- test/user_test.rb | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 80f7afba..aae1dec4 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -39,7 +39,7 @@ def list all_channels.push(channel_hash) i += 1 end - ap all_channels + return all_channels end end diff --git a/test/user_test.rb b/test/user_test.rb index 6cf22365..3f0ee882 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -24,20 +24,19 @@ it "user_hash contains name" do VCR.use_cassette("slack_details") do - expect(@user1.name).must_equal "Sara" + expect(@user1.list[1][:user_name]).must_equal "monick.keo" end end it "user_hash contains real name" do VCR.use_cassette("slack_details") do - expect(@user1.real_name).must_equal "Monick" + expect(@user1.list[1][:real_name]).must_equal "monick.keo" end end it "user_hash contains id" do VCR.use_cassette("slack_details") do - expect(@user1.id).must_equal "6" - expect(@user1.id).must_be_kind_of String + expect(@user1.list[1][:id]).must_equal "UN8JZT96J" end end From 1a5e09e68d1ce1ed1fa5db8931d58dbaad6ffd71 Mon Sep 17 00:00:00 2001 From: Monick Date: Thu, 12 Sep 2019 16:48:09 -0700 Subject: [PATCH 08/13] refactored slack.rb and updated. also began selected user method --- lib/channel.rb | 4 +-- lib/slack.rb | 58 +++++++++++++++++++++----------------------- lib/user.rb | 4 +-- test/channel_test.rb | 4 +-- test/slack_test.rb | 53 ++++++++++++++++++++++++++++++++++++++++ test/user_test.rb | 4 +-- 6 files changed, 88 insertions(+), 39 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index aae1dec4..c32b63c9 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -16,7 +16,7 @@ def initialize(name:, id:, topic:, num_members:) @num_members = num_members end - def list + def self.list method_url = "https://slack.com/api/channels.list" query_params = { token: ENV["SLACK_TOKEN"] @@ -39,7 +39,7 @@ def list all_channels.push(channel_hash) i += 1 end - return all_channels + ap all_channels end end diff --git a/lib/slack.rb b/lib/slack.rb index b6322bae..2eaa327f 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -3,40 +3,36 @@ require 'awesome_print' Dotenv.load -require_relative 'channel' +require_relative './channel' require_relative 'user' -module SlackCli - class SlackSpace - attr_reader :users, :channels, :selected - - def initialize(users:, channels:, selected:) - @users = users - @channels = channels - @selected = selected - end - - def start_program - ap "Welcome to the Ada Slack CLI!" - ap "What would you like ot do? Type one of the following: list channels, list users, or quit." - user_input = gets.chomp.downcase - - while user_input != "quit" - case user_input - when "list channels" - Channel.list - when "list users" - User.list - else - # raise ArgumentError.new("Invalid input") - puts "ARGUMENTERROR - FIX THIS" - end - puts "What would you like to do? Type one of the following: list channels, list users, or quit." - user_input = gets.chomp +def start_program + ap "Welcome to the Ada Slack CLI!" + ap "What would you like ot do? Type one of the following: list channels, list users, or quit." + user_input = gets.chomp.downcase + while user_input != "quit" + case user_input + when "list channels" + SlackCli::Channel.list + when "list users" + SlackCli::User.list + when "select user" + ap "Type a username or Slack ID (case sensitivity matters)" + search_user = gets.chomp + selected = SlackCli::User.list.find do |i| + i[:user_name]== search_user || i[:id] == search_user + end + if selected == nil + ap "Us or iner not foundvalid username or id" + else + ap selected end - puts "Thank you for using the Sara & Monick Slack CLI" + else + ap "Not a valid command" end + ap "What would you like to do? Type one of the following: list channels, list users, or quit." + user_input = gets.chomp end + return "Thank you for using the Sara & Monick Slack CLI" end - -# main if __FILE__ == $PROGRAM_NAME +start_program diff --git a/lib/user.rb b/lib/user.rb index c692ee81..2260d460 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -15,7 +15,7 @@ def initialize(name:, real_name:, id:) @id = id end - def list + def self.list method_url = "https://slack.com/api/users.list" query_params = { token: ENV["SLACK_TOKEN"] @@ -36,7 +36,7 @@ def list all_users.push(user_hash) i += 1 end - return all_users + ap all_users end end end \ No newline at end of file diff --git a/test/channel_test.rb b/test/channel_test.rb index 0441ea92..fffe9ca5 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -1,6 +1,6 @@ require_relative 'test_helper' -describe "user class tests" do +describe "channel instantiate" do before do @channel = SlackCli::Channel.new(name:"Sara", id: "6", topic:"general", num_members: "3") end @@ -10,7 +10,7 @@ end end -describe "self.list method should return correct values" do +describe "channel list method should return correct values" do before do @channel = SlackCli::Channel.new(name:"Sara", id: "6", topic: "general", num_members: "3") end diff --git a/test/slack_test.rb b/test/slack_test.rb index e69de29b..b3cfdb1e 100644 --- a/test/slack_test.rb +++ b/test/slack_test.rb @@ -0,0 +1,53 @@ +require_relative 'test_helper' + +xdescribe "SlackSpace instantiate" do + before do + @slack = SlackCli::SlackSpace.new() + end + + it "should instanitate as SlackCli::SlackSpace" do + expect(@slack).must_be_kind_of SlackCli::SlackSpace + end +end + +xdescribe "start_program method should run menu" do + before do + @slack = SlackCli::SlackSpace.new() + end + + it "welcome message displays with menu items and returns user_input" do + VCR.use_cassette("slack_details") do + expect(@slack.welcome('list channels')).must_be_kind_of String + end + end + + xit "if user wants to list users, list of users is printed" do + VCR.use_cassette("slack_details") do + #if user_input is list users, User.list should be returened + end + end + + xit "if user wants to list channels, list of channels is printed" do + VCR.use_cassette("slack_details") do + #if user_input is list channels, User.list should be returened + end + end + + xit "if user does not select/type a correct item, raise argumenterror" do + VCR.use_cassette("slack_details") do + + end + end + + xit "returns to main menu when completing a task" do + VCR.use_cassette("slack_details") do + + end + end + + xit "quits program when user types 'quit'" do + VCR.use_cassette("slack_details") do + + end + end +end \ No newline at end of file diff --git a/test/user_test.rb b/test/user_test.rb index 3f0ee882..c5f86d1a 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -1,6 +1,6 @@ require_relative 'test_helper' -describe "user class tests" do +describe "user instantiate" do before do @user1 = SlackCli::User.new(name:"Sara", real_name:"Monick", id: "6") end @@ -10,7 +10,7 @@ end end -describe "self.list method should return correct values" do +describe "user list method should return correct values" do before do @user1 = SlackCli::User.new(name:"Sara", real_name:"Monick", id: "6") end From a0adb7ee7684dc6c6a7e354b4bebe20b3dae6aed Mon Sep 17 00:00:00 2001 From: Monick Date: Thu, 12 Sep 2019 19:48:00 -0700 Subject: [PATCH 09/13] refactored slack.rb, updated with selected user recipient and details. Updated tests after refactoring --- lib/recipient.rb | 10 +-------- lib/slack.rb | 44 +++++++++++++++++++++++++++--------- test/channel_test.rb | 29 +++++++----------------- test/slack_test.rb | 53 -------------------------------------------- test/test_helper.rb | 2 +- test/user_test.rb | 25 +++++---------------- 6 files changed, 50 insertions(+), 113 deletions(-) delete mode 100644 test/slack_test.rb diff --git a/lib/recipient.rb b/lib/recipient.rb index a17622fd..05452c25 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -5,17 +5,9 @@ module SlackCli class Recipient - attr_reader :id, :name + def send_message - def initialize(id:, name:) - @id = id - @name = name end - - # def self.list - # puts "Who knows" - # end - end end \ No newline at end of file diff --git a/lib/slack.rb b/lib/slack.rb index 2eaa327f..0a749229 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -6,9 +6,11 @@ require_relative './channel' require_relative 'user' +#CONTROLLER-WIDE ISSUE - FOR SOME REASON, USER/CHANNEL LIST GETS PRINTED WHEN NOT CALLED ON + def start_program ap "Welcome to the Ada Slack CLI!" - ap "What would you like ot do? Type one of the following: list channels, list users, or quit." + print "What would you like to do? Type one of the following:\n list channels\n list users\n select user\n select channel\n details\n quit\n" user_input = gets.chomp.downcase while user_input != "quit" case user_input @@ -17,22 +19,44 @@ def start_program when "list users" SlackCli::User.list when "select user" - ap "Type a username or Slack ID (case sensitivity matters)" + ap "Type a username or Slack ID." search_user = gets.chomp - selected = SlackCli::User.list.find do |i| + selected_recipient = SlackCli::User.list.find do |i| i[:user_name]== search_user || i[:id] == search_user end - if selected == nil - ap "Us or iner not foundvalid username or id" + if selected_recipient == nil + ap "User not found" + else + selected_recipient = SlackCli::User.new( + name: selected_recipient[:user_name], + real_name: selected_recipient[:real_name], + id: selected_recipient[:id] + ) + ap "Recipient has been selected." + end + when "details" + if selected_recipient.class == SlackCli::Channel + ap "Your selected recipient details:" + ap selected_recipient.name + ap selected_recipient.topic + ap selected_recipient.id + ap selected_recipient.num_members + elsif selected_recipient.class == SlackCli::User + ap "Your selected recipient details:" + ap selected_recipient.name + ap selected_recipient.real_name + ap selected_recipient.id + # RIGHT NOW THIS ALSO PRINTS THE INSTANCE AFTER THE DETAILS else - ap selected + ap "No recipient is currently selected. Select a recipient in the main menu." end + ap selected_recipient else ap "Not a valid command" end - ap "What would you like to do? Type one of the following: list channels, list users, or quit." - user_input = gets.chomp + print "\nWhat would you like to do? Type one of the following:\n list channels\n list users\n select user\n select channel\n details\n quit\n" + user_input = gets.chomp.downcase end - return "Thank you for using the Sara & Monick Slack CLI" + ap "Thank you for using the Sara & Monick Slack CLI." end -start_program +start_program \ No newline at end of file diff --git a/test/channel_test.rb b/test/channel_test.rb index fffe9ca5..04be02a5 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -1,55 +1,42 @@ require_relative 'test_helper' describe "channel instantiate" do - before do - @channel = SlackCli::Channel.new(name:"Sara", id: "6", topic:"general", num_members: "3") - end - it "should instanitate as SlackCli::User" do + @channel = SlackCli::Channel.new(name:"Sara", id: "6", topic:"general", num_members: "3") expect(@channel).must_be_kind_of SlackCli::Channel end end describe "channel list method should return correct values" do - before do - @channel = SlackCli::Channel.new(name:"Sara", id: "6", topic: "general", num_members: "3") - end - it "all_users returns as an array with correct number of parameters" do VCR.use_cassette("slack_details") do - expect(@channel.list).must_be_kind_of Array - expect(@channel.list.length).must_equal 3 + expect(SlackCli::Channel.list).must_be_kind_of Array + expect(SlackCli::Channel.list.length).must_equal 3 end end it "channel list method returns correct name" do VCR.use_cassette("slack_details") do - expect(@channel.list[1][:name]).must_equal "random" + expect(SlackCli::Channel.list[1][:name]).must_equal "random" end end it "user_hash contains name" do VCR.use_cassette("slack_details") do - expect(@channel.list[1][:topic]).must_be_kind_of String + expect(SlackCli::Channel.list[1][:topic]).must_be_kind_of String end end it "user_hash contains name" do VCR.use_cassette("slack_details") do - expect(@channel.list[1][:id]).must_equal "CN6CW5FBP" + expect(SlackCli::Channel.list[1][:id]).must_equal "CN6CW5FBP" end end it "user_hash contains id" do VCR.use_cassette("slack_details") do - expect(@channel.list[1][:num_members]).must_equal 2 - expect(@channel.list[1][:num_members]).must_be_kind_of Integer + expect(SlackCli::Channel.list[1][:num_members]).must_equal 2 + expect(SlackCli::Channel.list[1][:num_members]).must_be_kind_of Integer end end - - # it "should conceal token in public domains" do - # VCR.use_cassette("slack_details") do - - # end - # end end \ No newline at end of file diff --git a/test/slack_test.rb b/test/slack_test.rb deleted file mode 100644 index b3cfdb1e..00000000 --- a/test/slack_test.rb +++ /dev/null @@ -1,53 +0,0 @@ -require_relative 'test_helper' - -xdescribe "SlackSpace instantiate" do - before do - @slack = SlackCli::SlackSpace.new() - end - - it "should instanitate as SlackCli::SlackSpace" do - expect(@slack).must_be_kind_of SlackCli::SlackSpace - end -end - -xdescribe "start_program method should run menu" do - before do - @slack = SlackCli::SlackSpace.new() - end - - it "welcome message displays with menu items and returns user_input" do - VCR.use_cassette("slack_details") do - expect(@slack.welcome('list channels')).must_be_kind_of String - end - end - - xit "if user wants to list users, list of users is printed" do - VCR.use_cassette("slack_details") do - #if user_input is list users, User.list should be returened - end - end - - xit "if user wants to list channels, list of channels is printed" do - VCR.use_cassette("slack_details") do - #if user_input is list channels, User.list should be returened - end - end - - xit "if user does not select/type a correct item, raise argumenterror" do - VCR.use_cassette("slack_details") do - - end - end - - xit "returns to main menu when completing a task" do - VCR.use_cassette("slack_details") do - - end - end - - xit "quits program when user types 'quit'" do - VCR.use_cassette("slack_details") do - - end - end -end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 8d098687..359e8d43 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -13,7 +13,7 @@ require_relative '../lib/channel' require_relative '../lib/user' -require_relative '../lib/slack' +# require_relative '../lib/slack' require_relative '../lib/recipient' VCR.configure do |config| diff --git a/test/user_test.rb b/test/user_test.rb index c5f86d1a..74b84d1b 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -1,48 +1,35 @@ require_relative 'test_helper' describe "user instantiate" do - before do - @user1 = SlackCli::User.new(name:"Sara", real_name:"Monick", id: "6") - end - it "should instanitate as SlackCli::User" do + @user1 = SlackCli::User.new(name:"Sara", real_name:"Monick", id: "6") expect(@user1).must_be_kind_of SlackCli::User end end describe "user list method should return correct values" do - before do - @user1 = SlackCli::User.new(name:"Sara", real_name:"Monick", id: "6") - end - it "all_users returns as an array with correct number of parameters" do VCR.use_cassette("slack_details") do - expect(@user1.list).must_be_kind_of Array - expect(@user1.list.length).must_equal 3 + expect(SlackCli::User.list).must_be_kind_of Array + expect(SlackCli::User.list.length).must_equal 3 end end it "user_hash contains name" do VCR.use_cassette("slack_details") do - expect(@user1.list[1][:user_name]).must_equal "monick.keo" + expect(SlackCli::User.list[1][:user_name]).must_equal "monick.keo" end end it "user_hash contains real name" do VCR.use_cassette("slack_details") do - expect(@user1.list[1][:real_name]).must_equal "monick.keo" + expect(SlackCli::User.list[1][:real_name]).must_equal "monick.keo" end end it "user_hash contains id" do VCR.use_cassette("slack_details") do - expect(@user1.list[1][:id]).must_equal "UN8JZT96J" + expect(SlackCli::User.list[1][:id]).must_equal "UN8JZT96J" end end - - # it "should conceal token in public domains" do - # VCR.use_cassette("slack_details") do - - # end - # end end \ No newline at end of file From 62397bf7e2df46213f3811ff965125904f3a7735 Mon Sep 17 00:00:00 2001 From: Monick Date: Thu, 12 Sep 2019 22:12:15 -0700 Subject: [PATCH 10/13] added psuedocode for wave 3 --- lib/recipient.rb | 10 ++++++++-- lib/slack.rb | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 05452c25..454514d0 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -5,8 +5,14 @@ module SlackCli class Recipient - def send_message - + def send_message(recipient:, message:) + method_url = "https://slack.com/api/chat.postMessage" + query_params = { + token: ENV["SLACK_TOKEN"], + channel: recipient, + text: message + } + response = HTTParty.post(method_url, query: query_params) end end diff --git a/lib/slack.rb b/lib/slack.rb index 0a749229..d4576cfc 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -51,6 +51,11 @@ def start_program ap "No recipient is currently selected. Select a recipient in the main menu." end ap selected_recipient + when "send message" + #check if a recipient is selected + #if recipient hasn't been selected tell user to select a recipient at the main menu + #if a recipient has been selected then ask user to type a message + #send the message to the recipient else ap "Not a valid command" end From f5571b57bad8b432a871a493d6a66acc6f8dbbd7 Mon Sep 17 00:00:00 2001 From: Monick Date: Thu, 12 Sep 2019 23:11:40 -0700 Subject: [PATCH 11/13] created send_message method in recipient class. Has controller send a message to slackcli and it works --- lib/recipient.rb | 10 ++++++---- lib/slack.rb | 5 ++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 454514d0..f09a5bf4 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -5,14 +5,16 @@ module SlackCli class Recipient - def send_message(recipient:, message:) + def self.send_message(channel:, text:) method_url = "https://slack.com/api/chat.postMessage" query_params = { token: ENV["SLACK_TOKEN"], - channel: recipient, - text: message + channel: channel, + text: text } - response = HTTParty.post(method_url, query: query_params) + slack_post = HTTParty.post(method_url, query: query_params) + puts slack_post + puts channel end end diff --git a/lib/slack.rb b/lib/slack.rb index d4576cfc..2b3edecc 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -55,7 +55,10 @@ def start_program #check if a recipient is selected #if recipient hasn't been selected tell user to select a recipient at the main menu #if a recipient has been selected then ask user to type a message - #send the message to the recipient + ap "Type a message to send:" + message = gets.chomp + #send the message in recipient class method send_message + SlackCli::Recipient.send_message(channel:selected_recipient.id, text:message) else ap "Not a valid command" end From 513a01ace923b22af9e532513f91049d6f0334b6 Mon Sep 17 00:00:00 2001 From: Monick Date: Fri, 13 Sep 2019 11:31:31 -0700 Subject: [PATCH 12/13] added selected channel in controller and started tests for send_message --- lib/recipient.rb | 9 +- lib/slack.rb | 21 ++++- lib/workspace.rb | 0 test/cassettes/slack_details.yml | 142 +++++++++++++++++++++++++++++++ test/recipient_test.rb | 21 +++-- 5 files changed, 179 insertions(+), 14 deletions(-) delete mode 100644 lib/workspace.rb diff --git a/lib/recipient.rb b/lib/recipient.rb index f09a5bf4..d010f6bf 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -5,16 +5,15 @@ module SlackCli class Recipient - def self.send_message(channel:, text:) + def self.send_message(recipient:, message:) method_url = "https://slack.com/api/chat.postMessage" query_params = { token: ENV["SLACK_TOKEN"], - channel: channel, - text: text + channel: recipient, + text: message } slack_post = HTTParty.post(method_url, query: query_params) - puts slack_post - puts channel + return slack_post end end diff --git a/lib/slack.rb b/lib/slack.rb index 2b3edecc..26fd8265 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -10,7 +10,7 @@ def start_program ap "Welcome to the Ada Slack CLI!" - print "What would you like to do? Type one of the following:\n list channels\n list users\n select user\n select channel\n details\n quit\n" + print "What would you like to do? Type one of the following:\n list channels\n list users\n select user\n select channel\n details\n send message\n quit\n" user_input = gets.chomp.downcase while user_input != "quit" case user_input @@ -34,6 +34,23 @@ def start_program ) ap "Recipient has been selected." end + when "select channel" + ap "Type a username or Slack ID." + search_channel = gets.chomp + selected_recipient = SlackCli::Channel.list.find do |i| + i[:name]== search_channel || i[:id] == search_channel + end + if selected_recipient == nil + ap "Channel not found" + else + selected_recipient = SlackCli::Channel.new( + name: selected_recipient[:name], + topic: selected_recipient[:topic], + id: selected_recipient[:id], + num_members: selected_recipient[:num_members] + ) + ap "Recipient has been selected." + end when "details" if selected_recipient.class == SlackCli::Channel ap "Your selected recipient details:" @@ -58,7 +75,7 @@ def start_program ap "Type a message to send:" message = gets.chomp #send the message in recipient class method send_message - SlackCli::Recipient.send_message(channel:selected_recipient.id, text:message) + SlackCli::Recipient.send_message(recipient:selected_recipient.id, message:message) else ap "Not a valid command" end diff --git a/lib/workspace.rb b/lib/workspace.rb deleted file mode 100644 index e69de29b..00000000 diff --git a/test/cassettes/slack_details.yml b/test/cassettes/slack_details.yml index 2623ba76..73cf1899 100644 --- a/test/cassettes/slack_details.yml +++ b/test/cassettes/slack_details.yml @@ -306,4 +306,146 @@ http_interactions: you''d prefer to keep out of more focused work-related channels.","creator":"UN8JZT96J","last_set":1568082002},"previous_names":[],"num_members":2},{"id":"CN88Q9RAB","name":"slack-cli","is_channel":true,"created":1568082003,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN8JZT96J","name_normalized":"slack-cli","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UN8JZT96J","UN8LCAGES"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' http_version: recorded_at: Wed, 11 Sep 2019 22:34:47 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage?channel=UN8JZT96J&text=%23%3CProc:0x00007ff717d91d48@/Users/monick/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/minitest-5.11.3/lib/minitest/assertions.rb:518%3E&token= + body: + encoding: UTF-8 + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '253' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 18:16:26 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - f03e4575-eaee-44b3-8d97-f0122bbe2edf + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:bot + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-m81p + X-Cache: + - Miss from cloudfront + Via: + - 1.1 d2bb0dc1233d3ab1747a4a160c14c25b.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - HIO51-C1 + X-Amz-Cf-Id: + - 8pPuh_jIEJnMki58UfBwWt43lRELTV9MD2GCt9JCau9swws1qskDgg== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channel":"DN6CP2UKS","ts":"1568398586.000100","message":{"type":"message","subtype":"bot_message","text":"#<Proc:0x00007ff717d91d48@\/Users\/monick\/.rbenv\/versions\/2.5.5\/lib\/ruby\/gems\/2.5.0\/gems\/minitest-5.11.3\/lib\/minitest\/assertions.rb:518>","ts":"1568398586.000100","username":"slack-cli","bot_id":"BN7MB352R"}}' + http_version: + recorded_at: Fri, 13 Sep 2019 18:16:26 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage?channel=UN8JZT96J&text=%23%3CProc:0x00007fb378674f98@/Users/monick/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/minitest-5.11.3/lib/minitest/assertions.rb:518%3E&token= + body: + encoding: UTF-8 + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '253' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 18:17:28 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - b7573b4b-9fc1-4dcf-86bf-9d360a800291 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:bot + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-wsq7 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 bf747dc419d7840e37c22083d04ecd8e.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - HIO51-C1 + X-Amz-Cf-Id: + - 8ZnIAnloArrm-ub8AboKbUMeAYuWYrNxP4olEqUvi1KluKkgad9zxA== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channel":"DN6CP2UKS","ts":"1568398648.000200","message":{"type":"message","subtype":"bot_message","text":"#<Proc:0x00007fb378674f98@\/Users\/monick\/.rbenv\/versions\/2.5.5\/lib\/ruby\/gems\/2.5.0\/gems\/minitest-5.11.3\/lib\/minitest\/assertions.rb:518>","ts":"1568398648.000200","username":"slack-cli","bot_id":"BN7MB352R"}}' + http_version: + recorded_at: Fri, 13 Sep 2019 18:17:28 GMT recorded_with: VCR 5.0.0 diff --git a/test/recipient_test.rb b/test/recipient_test.rb index a638ec1c..2a19261f 100644 --- a/test/recipient_test.rb +++ b/test/recipient_test.rb @@ -1,11 +1,18 @@ require_relative 'test_helper' -describe "user class tests" do - before do - @recipient1 = SlackCli::Recipient.new(name:"Sara", id: "6") - end - - it "should instanitate as SlackCli::User" do - expect(@recipient1).must_be_kind_of SlackCli::Recipient +describe "recipent class tests" do + before do + @selected_recipient = SlackCli::User.new( + name: "monick.keo", + real_name: "monick.keo", + id: "UN8JZT96J" + ) + message = "IT WORKS!" + end + + it "should send a message to selected recipient" do + VCR.use_cassette("slack_details") do + expect(SlackCli::Recipient.send_message(channel:@selected_recipient.id, text:message)).must_equal "IT WORKS!" end + end end From 6337b09feb384a11338c71c65fb3cfa8384b9bdf Mon Sep 17 00:00:00 2001 From: Monick Date: Fri, 13 Sep 2019 14:27:48 -0700 Subject: [PATCH 13/13] updated slack.rb with notification if recipient was or was not selected --- lib/channel.rb | 2 +- lib/slack.rb | 45 ++++++++++---------- lib/user.rb | 2 +- test/cassettes/slack_details.yml | 72 ++++++++++++++++++++++++++++++++ test/recipient_test.rb | 6 ++- 5 files changed, 100 insertions(+), 27 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index c32b63c9..9ed648e5 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -39,7 +39,7 @@ def self.list all_channels.push(channel_hash) i += 1 end - ap all_channels + return all_channels end end diff --git a/lib/slack.rb b/lib/slack.rb index 26fd8265..6503cc96 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -6,18 +6,18 @@ require_relative './channel' require_relative 'user' -#CONTROLLER-WIDE ISSUE - FOR SOME REASON, USER/CHANNEL LIST GETS PRINTED WHEN NOT CALLED ON - def start_program ap "Welcome to the Ada Slack CLI!" - print "What would you like to do? Type one of the following:\n list channels\n list users\n select user\n select channel\n details\n send message\n quit\n" + print "What would you like to do? Type one of the following:\n - list channels\n - list users\n - select user\n - select channel\n - details\n - send message\n - quit\n" user_input = gets.chomp.downcase + + while user_input != "quit" case user_input when "list channels" - SlackCli::Channel.list + ap SlackCli::Channel.list when "list users" - SlackCli::User.list + ap SlackCli::User.list when "select user" ap "Type a username or Slack ID." search_user = gets.chomp @@ -34,6 +34,7 @@ def start_program ) ap "Recipient has been selected." end + when "select channel" ap "Type a username or Slack ID." search_channel = gets.chomp @@ -51,35 +52,33 @@ def start_program ) ap "Recipient has been selected." end + when "details" if selected_recipient.class == SlackCli::Channel - ap "Your selected recipient details:" - ap selected_recipient.name - ap selected_recipient.topic - ap selected_recipient.id - ap selected_recipient.num_members + ap "Channel name: #{selected_recipient.name}" + ap "Channel topic: #{selected_recipient.topic}" + ap "Channel id: #{selected_recipient.id}" + ap "Channel members count: #{selected_recipient.num_members}" elsif selected_recipient.class == SlackCli::User - ap "Your selected recipient details:" - ap selected_recipient.name - ap selected_recipient.real_name - ap selected_recipient.id - # RIGHT NOW THIS ALSO PRINTS THE INSTANCE AFTER THE DETAILS + ap "Username: #{selected_recipient.name}" + ap "User real name: #{selected_recipient.real_name}" + ap "User id: #{selected_recipient.id}" else ap "No recipient is currently selected. Select a recipient in the main menu." end ap selected_recipient when "send message" - #check if a recipient is selected - #if recipient hasn't been selected tell user to select a recipient at the main menu - #if a recipient has been selected then ask user to type a message - ap "Type a message to send:" - message = gets.chomp - #send the message in recipient class method send_message - SlackCli::Recipient.send_message(recipient:selected_recipient.id, message:message) + if selected_recipient == nil + ap "No recipient selected." + else + ap "Type a message to send:" + message = gets.chomp + SlackCli::Recipient.send_message(recipient:selected_recipient.id, message:message) + end else ap "Not a valid command" end - print "\nWhat would you like to do? Type one of the following:\n list channels\n list users\n select user\n select channel\n details\n quit\n" + print "What would you like to do? Type one of the following:\n - list channels\n - list users\n - select user\n - select channel\n - details\n - send message\n - quit\n" user_input = gets.chomp.downcase end ap "Thank you for using the Sara & Monick Slack CLI." diff --git a/lib/user.rb b/lib/user.rb index 2260d460..31a347cb 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -36,7 +36,7 @@ def self.list all_users.push(user_hash) i += 1 end - ap all_users + return all_users end end end \ No newline at end of file diff --git a/test/cassettes/slack_details.yml b/test/cassettes/slack_details.yml index 73cf1899..69cdc26e 100644 --- a/test/cassettes/slack_details.yml +++ b/test/cassettes/slack_details.yml @@ -448,4 +448,76 @@ http_interactions: string: '{"ok":true,"channel":"DN6CP2UKS","ts":"1568398648.000200","message":{"type":"message","subtype":"bot_message","text":"#<Proc:0x00007fb378674f98@\/Users\/monick\/.rbenv\/versions\/2.5.5\/lib\/ruby\/gems\/2.5.0\/gems\/minitest-5.11.3\/lib\/minitest\/assertions.rb:518>","ts":"1568398648.000200","username":"slack-cli","bot_id":"BN7MB352R"}}' http_version: recorded_at: Fri, 13 Sep 2019 18:17:28 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage?channel=UN8JZT96J&text=IT%20WORKS!&token= + body: + encoding: UTF-8 + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '161' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 19:06:52 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 5fb1f208-801a-4af6-842f-be131f86c7ad + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:bot + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-wycu + X-Cache: + - Miss from cloudfront + Via: + - 1.1 ceb7b8c925a9435b9b08b23014561fbb.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - HIO51-C1 + X-Amz-Cf-Id: + - XosWWMjNp3-mCDReiIa9aJtatbxrR34d5bUNhbmI2BohS2-W9zVFCg== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channel":"DN6CP2UKS","ts":"1568401612.000400","message":{"type":"message","subtype":"bot_message","text":"IT + WORKS!","ts":"1568401612.000400","username":"slack-cli","bot_id":"BN7MB352R"}}' + http_version: + recorded_at: Fri, 13 Sep 2019 19:06:52 GMT recorded_with: VCR 5.0.0 diff --git a/test/recipient_test.rb b/test/recipient_test.rb index 2a19261f..19a7ff4e 100644 --- a/test/recipient_test.rb +++ b/test/recipient_test.rb @@ -7,12 +7,14 @@ real_name: "monick.keo", id: "UN8JZT96J" ) - message = "IT WORKS!" + @message = "IT WORKS!" end it "should send a message to selected recipient" do VCR.use_cassette("slack_details") do - expect(SlackCli::Recipient.send_message(channel:@selected_recipient.id, text:message)).must_equal "IT WORKS!" + test = SlackCli::Recipient.send_message(recipient:@selected_recipient.id, message:@message) + expect(test.code).must_equal 200 + expect(test.body).must_include "IT WORKS!" end end end