From b7f136a7457b2045bf1ad56240d7364a97b01d26 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Mon, 18 Mar 2019 17:17:00 -0700 Subject: [PATCH 01/69] added .env and did verification --- .gitignore | 2 +- lib/slack.rb | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 8d6a243f..b78e0506 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,7 @@ /tmp/ # Used by dotenv library to load environment variables. -# .env +.env ## Specific to RubyMotion: .dat* diff --git a/lib/slack.rb b/lib/slack.rb index 960cf2f7..cac3849b 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,11 +1,25 @@ #!/usr/bin/env ruby +require "dotenv" +require "httparty" +require "pry" +require "awesome_print" +Dotenv.load def main puts "Welcome to the Ada Slack CLI!" - # TODO project + url = "https://slack.com/api/channels.list" + query_params = { token: ENV["API_KEY"] } + + response = HTTParty.get(url, query: query_params) + + response["channels"].each do |channel| + puts channel["name"] + end puts "Thank you for using the Ada Slack CLI" end -main if __FILE__ == $PROGRAM_NAME \ No newline at end of file +main if __FILE__ == $PROGRAM_NAME + +# response["channels"][0]["name"] From 3eb6a7c756f459fda23002a131a29c01a22d21b2 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Mon, 18 Mar 2019 17:17:16 -0700 Subject: [PATCH 02/69] removed comment --- lib/slack.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/slack.rb b/lib/slack.rb index cac3849b..0e14aa08 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -22,4 +22,3 @@ def main main if __FILE__ == $PROGRAM_NAME -# response["channels"][0]["name"] From af9d38f2f316da7dfc9e5b2501a19957a5ef9be6 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 19 Mar 2019 13:41:45 -0700 Subject: [PATCH 03/69] creating necessary class files --- lib/channel.rb | 0 lib/recipient.rb | 0 lib/user.rb | 0 lib/workspace.rb | 0 specs/channel_spec.rb | 0 specs/recipient_spec.rb | 0 specs/slack_speck.rb | 0 specs/user_spec.rb | 0 specs/workspace_spec.rb | 0 9 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 lib/channel.rb create mode 100644 lib/recipient.rb create mode 100644 lib/user.rb create mode 100644 lib/workspace.rb create mode 100644 specs/channel_spec.rb create mode 100644 specs/recipient_spec.rb create mode 100644 specs/slack_speck.rb create mode 100644 specs/user_spec.rb create mode 100644 specs/workspace_spec.rb diff --git a/lib/channel.rb b/lib/channel.rb new file mode 100644 index 00000000..e69de29b diff --git a/lib/recipient.rb b/lib/recipient.rb new file mode 100644 index 00000000..e69de29b diff --git a/lib/user.rb b/lib/user.rb new file mode 100644 index 00000000..e69de29b diff --git a/lib/workspace.rb b/lib/workspace.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/slack_speck.rb b/specs/slack_speck.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/user_spec.rb b/specs/user_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb new file mode 100644 index 00000000..e69de29b From e0c01e4203a4d3e63bad12db66b2c7b2c6a3369a Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 19 Mar 2019 13:46:13 -0700 Subject: [PATCH 04/69] configuring test_helper.rb --- specs/test_helper.rb | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 81ccd06b..96f5db76 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -1,15 +1,21 @@ -require 'simplecov' +require "simplecov" SimpleCov.start -require 'minitest' -require 'minitest/autorun' -require 'minitest/reporters' -require 'minitest/skip_dsl' -require 'vcr' +require "minitest" +require "minitest/autorun" +require "minitest/reporters" +require "minitest/skip_dsl" +require "vcr" + +require_relative "lib/slack" +require_relative "lib/channel" +require_relative "lib/user" +require_relative "lib/workspace" +require_relative "lib/recipient" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new VCR.configure do |config| config.cassette_library_dir = "specs/cassettes" config.hook_into :webmock -end \ No newline at end of file +end From b8ef5d21948b849f9c46892c75156147cdf8df09 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 19 Mar 2019 13:51:58 -0700 Subject: [PATCH 05/69] debugging test_helper --- specs/slack_speck.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/specs/slack_speck.rb b/specs/slack_speck.rb index e69de29b..f51753fd 100644 --- a/specs/slack_speck.rb +++ b/specs/slack_speck.rb @@ -0,0 +1,8 @@ +# # require_relative "test_helper.rb" + +# describe "Slack" do +# describe "test" do +# it "passes" do +# end +# end +# end From 8d2236b0eab42814311f823f4dfb617eab922eda Mon Sep 17 00:00:00 2001 From: Hana Date: Tue, 19 Mar 2019 13:58:02 -0700 Subject: [PATCH 06/69] set up test spec files --- set_up.rb | 24 ++++++++++++++++++++++++ specs/slack_spec.rb | 8 ++++++++ specs/slack_speck.rb | 8 -------- specs/test_helper.rb | 10 +++++----- 4 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 set_up.rb create mode 100644 specs/slack_spec.rb delete mode 100644 specs/slack_speck.rb diff --git a/set_up.rb b/set_up.rb new file mode 100644 index 00000000..7443a72c --- /dev/null +++ b/set_up.rb @@ -0,0 +1,24 @@ +# Use the dotenv gem to load environment variables +# Use HTTParty to send a GET request to the channels.list endpoint +# Check that the request completed successfully, and print relevant information to the console if it didn't +# Loop through the results and print out the name of each channel + +require 'dotenv' +Dotenv.load + +require 'HTTParty' +require 'pry' + +BASE_URL = "https://slack.com/api/channels.list" + +query_params = { + token: ENV['BANANA'] +} + +response = HTTParty.get(BASE_URL, query: query_params) + + + +response["channels"].each do |channel| + puts "#{channel["name"]}" +end diff --git a/specs/slack_spec.rb b/specs/slack_spec.rb new file mode 100644 index 00000000..0a0524dd --- /dev/null +++ b/specs/slack_spec.rb @@ -0,0 +1,8 @@ +require_relative "test_helper.rb" + +describe "Slack" do + describe "test" do + it "passes" do + end + end +end diff --git a/specs/slack_speck.rb b/specs/slack_speck.rb deleted file mode 100644 index f51753fd..00000000 --- a/specs/slack_speck.rb +++ /dev/null @@ -1,8 +0,0 @@ -# # require_relative "test_helper.rb" - -# describe "Slack" do -# describe "test" do -# it "passes" do -# end -# end -# end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 96f5db76..bdfa9202 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -7,11 +7,11 @@ require "minitest/skip_dsl" require "vcr" -require_relative "lib/slack" -require_relative "lib/channel" -require_relative "lib/user" -require_relative "lib/workspace" -require_relative "lib/recipient" +require_relative "../lib/slack" +require_relative "../lib/channel" +require_relative "../lib/user" +require_relative "../lib/workspace" +require_relative "../lib/recipient" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 268e8a78fef74b3cce272c00dbeeaed6e79ca13e Mon Sep 17 00:00:00 2001 From: Hana Date: Tue, 19 Mar 2019 14:26:09 -0700 Subject: [PATCH 07/69] initialize and create send message method --- lib/recipient.rb | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lib/recipient.rb b/lib/recipient.rb index e69de29b..0ec017cd 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -0,0 +1,37 @@ +require 'HTTParty' +require 'pry' + +class Recipient + # constants + MSG_URL = "https://slack.com/api/chat.postMessage" + USER_URL = "https://slack.com/api/users.list" + CHANNEL_URL = "https://slack.com/api/channels.list" + + attr_reader :send_message, :name, :slack_id + + def initialize + @slack_id = slack_id + @name = name + end + + def self.send_message(name, message) + # using HTTParty.post(MSG_URL, message, slack_id) + query_params = { + token: ENV["SLACK_TOKEN"], + channel: name, + text: message, + } + # send a message to a recipient that matches provided slack_id + response = HTTParty.post(MSG_URL, query: query_params) + + binding.pry + # return response message/code + if response["ok"] + return "#{response.code}: Message sent!" + else + return "#{response.code}: Message failed :(" + end + end +end + +Recipient.send_message("everyone", "this is a string!") \ No newline at end of file From 33024d0872919f85e4a5f21fe92b3d422b2ec22d Mon Sep 17 00:00:00 2001 From: Hana Date: Tue, 19 Mar 2019 14:27:59 -0700 Subject: [PATCH 08/69] require dotenv --- lib/recipient.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/recipient.rb b/lib/recipient.rb index 0ec017cd..a2e20e2e 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,6 +1,9 @@ require 'HTTParty' require 'pry' +require 'dotenv' +Dotenv.load + class Recipient # constants MSG_URL = "https://slack.com/api/chat.postMessage" From daed6bdeda24cac18764b278b416e525dec34c73 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 19 Mar 2019 15:18:24 -0700 Subject: [PATCH 09/69] debugging bad token and string escape characters may be needed --- lib/recipient.rb | 27 ++++++++++++++------------- specs/recipient_spec.rb | 18 ++++++++++++++++++ specs/test_helper.rb | 7 +++++++ 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index a2e20e2e..a59d81e3 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,7 +1,7 @@ -require 'HTTParty' -require 'pry' +require "HTTParty" +require "pry" -require 'dotenv' +require "dotenv" Dotenv.load class Recipient @@ -13,9 +13,9 @@ class Recipient attr_reader :send_message, :name, :slack_id def initialize - @slack_id = slack_id + @slack_id = slack_id @name = name - end + end def self.send_message(name, message) # using HTTParty.post(MSG_URL, message, slack_id) @@ -26,15 +26,16 @@ def self.send_message(name, message) } # send a message to a recipient that matches provided slack_id response = HTTParty.post(MSG_URL, query: query_params) - - binding.pry # return response message/code - if response["ok"] - return "#{response.code}: Message sent!" - else - return "#{response.code}: Message failed :(" - end + # if response["ok"] + # return response + # else + # "#{response}: Message failed :(" + # end + return response end end -Recipient.send_message("everyone", "this is a string!") \ No newline at end of file +# test = Recipient.send_message("everyone", "this is a string!") + +# puts test diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index e69de29b..e3cf2598 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -0,0 +1,18 @@ +require_relative "test_helper" + +describe "Recipient" do + describe "initialize" do + end + + describe "send message" do + it "can post a message on the everyone slack channel" do + VCR.use_cassette("message_post") do + name = "everyone" + text = "Hey there" + pigeon = Recipient.send_message(name, text) + + expect(pigeon["ok"]).must_equal true + end + end + end +end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index bdfa9202..f8b7d3ee 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -18,4 +18,11 @@ VCR.configure do |config| config.cassette_library_dir = "specs/cassettes" config.hook_into :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 From d35b5ea1f5672cb6ae2da7413ce0c02a2cfa919d Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 19 Mar 2019 15:21:54 -0700 Subject: [PATCH 10/69] added kwards to #send_message --- lib/recipient.rb | 4 ++-- specs/recipient_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index a59d81e3..e5e9ff38 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -17,7 +17,7 @@ def initialize @name = name end - def self.send_message(name, message) + def self.send_message(name:, message:) # using HTTParty.post(MSG_URL, message, slack_id) query_params = { token: ENV["SLACK_TOKEN"], @@ -38,4 +38,4 @@ def self.send_message(name, message) # test = Recipient.send_message("everyone", "this is a string!") -# puts test +# puts test.code diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index e3cf2598..613855ba 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -8,8 +8,8 @@ it "can post a message on the everyone slack channel" do VCR.use_cassette("message_post") do name = "everyone" - text = "Hey there" - pigeon = Recipient.send_message(name, text) + text = "Hey there%21" + pigeon = Recipient.send_message(name: name, message: text) expect(pigeon["ok"]).must_equal true end From 8095052a8046e46535c48f98d11bc401c5321b86 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 19 Mar 2019 15:26:54 -0700 Subject: [PATCH 11/69] #correction .send_message --- lib/recipient.rb | 4 ++-- specs/recipient_spec.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index e5e9ff38..91bd94a2 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -7,8 +7,8 @@ class Recipient # constants MSG_URL = "https://slack.com/api/chat.postMessage" - USER_URL = "https://slack.com/api/users.list" - CHANNEL_URL = "https://slack.com/api/channels.list" + USER_URL = "https://slack.com/api/users.list" # Move to User + CHANNEL_URL = "https://slack.com/api/channels.list" #move to Channel attr_reader :send_message, :name, :slack_id diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 613855ba..327d902e 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -5,6 +5,7 @@ end describe "send message" do + it "can post a message on the everyone slack channel" do VCR.use_cassette("message_post") do name = "everyone" @@ -13,6 +14,10 @@ expect(pigeon["ok"]).must_equal true end + + it "raises an exception for bad request" do + + end end end end From 531e18ffbc31f19dac32f98dd38910bc130bb9e7 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 19 Mar 2019 15:53:19 -0700 Subject: [PATCH 12/69] wrote tests for .send_message and tests are green --- lib/recipient.rb | 22 +++++++++------------- specs/recipient_spec.rb | 14 ++++++++++---- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 91bd94a2..e31953e3 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -4,7 +4,10 @@ require "dotenv" Dotenv.load +class SlackError < StandardError; end + class Recipient + # constants MSG_URL = "https://slack.com/api/chat.postMessage" USER_URL = "https://slack.com/api/users.list" # Move to User @@ -18,24 +21,17 @@ def initialize end def self.send_message(name:, message:) - # using HTTParty.post(MSG_URL, message, slack_id) query_params = { token: ENV["SLACK_TOKEN"], channel: name, text: message, } - # send a message to a recipient that matches provided slack_id response = HTTParty.post(MSG_URL, query: query_params) - # return response message/code - # if response["ok"] - # return response - # else - # "#{response}: Message failed :(" - # end - return response + + if response["ok"] != true + raise SlackError, "#{response["error"]}" + else + return response + end end end - -# test = Recipient.send_message("everyone", "this is a string!") - -# puts test.code diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 327d902e..8238d53a 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -5,18 +5,24 @@ end describe "send message" do - it "can post a message on the everyone slack channel" do VCR.use_cassette("message_post") do name = "everyone" - text = "Hey there%21" + text = "hello world" pigeon = Recipient.send_message(name: name, message: text) expect(pigeon["ok"]).must_equal true end + end + + it "raises a SlackError with bad parameters" do + VCR.use_cassette("message_post") do + name = "" + text = "this should not send" - it "raises an exception for bad request" do - + expect { + Recipient.send_message(name: name, message: text) + }.must_raise SlackError end end end From 3688e725a5c78a3ce987bc2a4f7d2db1ac96b676 Mon Sep 17 00:00:00 2001 From: Hana Date: Tue, 19 Mar 2019 16:06:05 -0700 Subject: [PATCH 13/69] self.get method and test --- lib/recipient.rb | 5 +++++ specs/recipient_spec.rb | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/recipient.rb b/lib/recipient.rb index e31953e3..4cc5278f 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -34,4 +34,9 @@ def self.send_message(name:, message:) return response end end + + def self.get(url, params) + response = HTTParty.get(url, query: params) + return response + end end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 8238d53a..90a59203 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -26,4 +26,18 @@ end end end + + describe "self.get method" do + it "returns an HTTP response object" do + VCR.use_cassette("get_response") do + url = "https://slack.com/api/users.list" + params = { + token: ENV["SLACK_TOKEN"], + } + party_people = Recipient.get(url, params) + + expect(party_people["ok"]).must_equal true + end + end + end end From 9c3d836edda9bf552d935260f26cf2d21e8d43d1 Mon Sep 17 00:00:00 2001 From: Hana Date: Tue, 19 Mar 2019 16:09:35 -0700 Subject: [PATCH 14/69] SlackError for bad parameters test --- specs/recipient_spec.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 90a59203..2c201fd3 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -28,7 +28,7 @@ end describe "self.get method" do - it "returns an HTTP response object" do + it "successfully returns users list HTTP response object" do VCR.use_cassette("get_response") do url = "https://slack.com/api/users.list" params = { @@ -39,5 +39,17 @@ expect(party_people["ok"]).must_equal true end end + + it "raises SlackError for bad parameters" do + VCR.use_cassette("get_response") do + url = "https://slack.com/api/users.list" + params = { + token: "thisisbadtoken", + } + party_people = Recipient.get(url, params) + + expect(party_people["ok"]).must_equal false + end + end end end From 4dc98b3443c8204b64f327b2337a21c04670f7d0 Mon Sep 17 00:00:00 2001 From: Hana Date: Tue, 19 Mar 2019 16:29:20 -0700 Subject: [PATCH 15/69] SlackError for inauthorization --- lib/recipient.rb | 17 +++++++++++------ specs/recipient_spec.rb | 7 ++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 4cc5278f..9c1f4cb0 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -13,7 +13,7 @@ class Recipient USER_URL = "https://slack.com/api/users.list" # Move to User CHANNEL_URL = "https://slack.com/api/channels.list" #move to Channel - attr_reader :send_message, :name, :slack_id + attr_reader :send_message, :name, :slack_id, :error_helper def initialize @slack_id = slack_id @@ -28,15 +28,20 @@ def self.send_message(name:, message:) } response = HTTParty.post(MSG_URL, query: query_params) + error_helper(response) + end + + def self.get(url, params) + response = HTTParty.get(url, query: params) + + error_helper(response) + end + + def self.error_helper(response) if response["ok"] != true raise SlackError, "#{response["error"]}" else return response end end - - def self.get(url, params) - response = HTTParty.get(url, query: params) - return response - end end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 2c201fd3..99ddfee8 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -40,15 +40,16 @@ end end - it "raises SlackError for bad parameters" do + it "raises SlackError for inauthorization" do VCR.use_cassette("get_response") do url = "https://slack.com/api/users.list" params = { token: "thisisbadtoken", } - party_people = Recipient.get(url, params) - expect(party_people["ok"]).must_equal false + expect { + Recipient.get(url, params) + }.must_raise SlackError end end end From 0ac44dfeb4b8cc2ae9d7270eaf74b35d44392b70 Mon Sep 17 00:00:00 2001 From: Hana Date: Tue, 19 Mar 2019 17:16:13 -0700 Subject: [PATCH 16/69] added details and self.list --- lib/recipient.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/recipient.rb b/lib/recipient.rb index 9c1f4cb0..475abdae 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -44,4 +44,12 @@ def self.error_helper(response) return response end end + + def details + raise NotImplementedError + end + + def self.list + raise NotImplementedError + end end From fd2d0c97d2fc34de9326f0b03ad9ee7e50ab8aea Mon Sep 17 00:00:00 2001 From: Hana Date: Tue, 19 Mar 2019 17:26:59 -0700 Subject: [PATCH 17/69] create and move constants to respective classes --- lib/recipient.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 475abdae..b3e95234 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -10,8 +10,7 @@ class Recipient # constants MSG_URL = "https://slack.com/api/chat.postMessage" - USER_URL = "https://slack.com/api/users.list" # Move to User - CHANNEL_URL = "https://slack.com/api/channels.list" #move to Channel + TOKEN = ENV["SLACK_TOKEN"] attr_reader :send_message, :name, :slack_id, :error_helper @@ -22,7 +21,7 @@ def initialize def self.send_message(name:, message:) query_params = { - token: ENV["SLACK_TOKEN"], + token: TOKEN, channel: name, text: message, } From 637be8c16ff1b652247c85c1febea70fd2926c2c Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 19 Mar 2019 17:31:43 -0700 Subject: [PATCH 18/69] "adding channel class" --- lib/channel.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/channel.rb b/lib/channel.rb index e69de29b..5d7959e6 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -0,0 +1,29 @@ +require_relative "recipient" + +class Channel < Recipient + attr_reader + CHANNEL_URL = "https://slack.com/api/channels.list" + + def initialize + @topic + @member_count + end + + def self.list + # calls the self.get method from parent + # retrieves the channel payload + # iteratest through the channel payload + # and displays list of channel names to the CLI + # as an array + params = { + token: TOKEN, + } + response = Channel.get(CHANNEL_URL, query: params) + return response + end + + def details + end +end + +test = Channel.list From a3fc48cebceaa1acc088903675032f77ac3b6e8b Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 19 Mar 2019 18:21:26 -0700 Subject: [PATCH 19/69] working on self.list channel.rb --- lib/channel.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 5d7959e6..6841e392 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -2,7 +2,7 @@ class Channel < Recipient attr_reader - CHANNEL_URL = "https://slack.com/api/channels.list" + LIST_URL = "https://slack.com/api/channels.list" def initialize @topic @@ -15,10 +15,10 @@ def self.list # iteratest through the channel payload # and displays list of channel names to the CLI # as an array - params = { + query_params = { token: TOKEN, } - response = Channel.get(CHANNEL_URL, query: params) + response = Channel.get(query: query_params) return response end @@ -26,4 +26,4 @@ def details end end -test = Channel.list +# test = Channel.list From 6a2a7c8f6e38e398feb5f203b8ad842a817680d9 Mon Sep 17 00:00:00 2001 From: Hana Date: Tue, 19 Mar 2019 18:51:17 -0700 Subject: [PATCH 20/69] refactor self.get and define constants --- lib/recipient.rb | 8 +++++-- specs/recipient_spec.rb | 52 ++++++++++++++++++++--------------------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index b3e95234..ad8288f6 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -10,6 +10,7 @@ class Recipient # constants MSG_URL = "https://slack.com/api/chat.postMessage" + LIST_URL = nil TOKEN = ENV["SLACK_TOKEN"] attr_reader :send_message, :name, :slack_id, :error_helper @@ -30,8 +31,11 @@ def self.send_message(name:, message:) error_helper(response) end - def self.get(url, params) - response = HTTParty.get(url, query: params) + def self.get + query_params = { + token: TOKEN + } + response = HTTParty.get(LIST_URL, query: query_params) error_helper(response) end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 99ddfee8..60c0a233 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -27,30 +27,30 @@ end end - describe "self.get method" do - it "successfully returns users list HTTP response object" do - VCR.use_cassette("get_response") do - url = "https://slack.com/api/users.list" - params = { - token: ENV["SLACK_TOKEN"], - } - party_people = Recipient.get(url, params) - - expect(party_people["ok"]).must_equal true - end - end - - it "raises SlackError for inauthorization" do - VCR.use_cassette("get_response") do - url = "https://slack.com/api/users.list" - params = { - token: "thisisbadtoken", - } - - expect { - Recipient.get(url, params) - }.must_raise SlackError - end - end - end + # describe "self.get method" do + # it "successfully returns users list HTTP response object" do + # VCR.use_cassette("get_response") do + # url = "https://slack.com/api/users.list" + # params = { + # token: ENV["SLACK_TOKEN"], + # } + # party_people = Recipient.get(url, params) + + # expect(party_people["ok"]).must_equal true + # end + # end + + # it "raises SlackError for inauthorization" do + # VCR.use_cassette("get_response") do + # url = "https://slack.com/api/users.list" + # params = { + # token: "thisisbadtoken", + # } + + # expect { + # Recipient.get(url, params) + # }.must_raise SlackError + # end + # end + # end end From 0f4cff013736445e5de21c3e5bdcb197d626b742 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 19 Mar 2019 18:59:01 -0700 Subject: [PATCH 21/69] added .list and #details --- lib/channel.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 6841e392..6369273a 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -10,20 +10,24 @@ def initialize end def self.list - # calls the self.get method from parent - # retrieves the channel payload - # iteratest through the channel payload - # and displays list of channel names to the CLI - # as an array query_params = { token: TOKEN, } - response = Channel.get(query: query_params) - return response + + channels_json = Channel.get(query: query_params) + + list_of_channels = channels_json["channels"].select { |channel| channel["name"] } + return list_of_channels end - def details + def details(name) + list.each do |channel| + if channel["name"] == name + puts channel["purpose"]["value"] + end + end end end -# test = Channel.list +test = HTTParty.get("https://slack.com/api/channels.list?token=xoxp-581967218119-580781269267-579777948256-23a22653dd928edbcbe9830d05729d53") +binding.pry From c55c990fcf9d80af1209d0af3ef810e27ab6b1cf Mon Sep 17 00:00:00 2001 From: Hana Date: Tue, 19 Mar 2019 19:02:06 -0700 Subject: [PATCH 22/69] move constants and refactor self.get --- lib/user.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/user.rb b/lib/user.rb index e69de29b..ea59f926 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -0,0 +1,32 @@ +require 'pry' + +require_relative 'recipient' + +class User < Recipient + LIST_URL = "https://slack.com/api/users.list" + TOKEN = ENV["SLACK_TOKEN"] + + attr_reader :real_name + + def initialize + @real_name = real_name + @status_text = status_text + @status_emoji = status_emoji + end + + def self.list + # calls self.get from parent + # receives user payload + # iterate through payload to store in array + # return array + response = User.get + + user_list = response["members"].map do |user| + user["name"] + end + + binding.pry + end +end + +puts User.list \ No newline at end of file From b5ff3182cf177348241571f71dcdb5593a03804e Mon Sep 17 00:00:00 2001 From: Hana Date: Tue, 19 Mar 2019 19:25:02 -0700 Subject: [PATCH 23/69] update self.list and self.list_users methods --- lib/recipient.rb | 4 ++-- lib/user.rb | 15 ++++++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index ad8288f6..c72e6018 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -13,7 +13,7 @@ class Recipient LIST_URL = nil TOKEN = ENV["SLACK_TOKEN"] - attr_reader :send_message, :name, :slack_id, :error_helper + attr_reader :send_message, :name, :slack_id, :error_helper, :list def initialize @slack_id = slack_id @@ -35,7 +35,7 @@ def self.get query_params = { token: TOKEN } - response = HTTParty.get(LIST_URL, query: query_params) + response = HTTParty.get(self::LIST_URL, query: query_params) error_helper(response) end diff --git a/lib/user.rb b/lib/user.rb index ea59f926..b6e9259d 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -6,7 +6,7 @@ class User < Recipient LIST_URL = "https://slack.com/api/users.list" TOKEN = ENV["SLACK_TOKEN"] - attr_reader :real_name + attr_reader :real_name, :list_users def initialize @real_name = real_name @@ -15,18 +15,15 @@ def initialize end def self.list - # calls self.get from parent - # receives user payload - # iterate through payload to store in array - # return array response = User.get + return response + end - user_list = response["members"].map do |user| + def self.list_users + user_list = list["members"].map do |user| user["name"] end - - binding.pry + return user_list end end -puts User.list \ No newline at end of file From 489063b5218fcaf6acbe281a94ae4139c3c46b85 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 19 Mar 2019 19:26:07 -0700 Subject: [PATCH 24/69] "adding tests to channel_spec" --- lib/channel.rb | 10 +++------- specs/channel_spec.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 6369273a..39c5f9a0 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -10,13 +10,9 @@ def initialize end def self.list - query_params = { - token: TOKEN, - } - - channels_json = Channel.get(query: query_params) + channels_json = Channel.get - list_of_channels = channels_json["channels"].select { |channel| channel["name"] } + list_of_channels = channels_json["channels"].select { |channel| channel["name"] } return list_of_channels end @@ -29,5 +25,5 @@ def details(name) end end -test = HTTParty.get("https://slack.com/api/channels.list?token=xoxp-581967218119-580781269267-579777948256-23a22653dd928edbcbe9830d05729d53") +test = Channel.get binding.pry diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index e69de29b..1c43f56d 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -0,0 +1,26 @@ + describe "self.get method" do + it "successfully returns users list HTTP response object" do + VCR.use_cassette("get_response") do + url = "https://slack.com/api/users.list" + params = { + token: ENV["SLACK_TOKEN"], + } + party_people = Channel.get + + expect(party_people["ok"]).must_equal true + end + end + + it "raises SlackError for inauthorization" do + VCR.use_cassette("get_response") do + url = "https://slack.com/api/users.list" + params = { + token: "thisisbadtoken", + } + + expect { + Recipient.get(url, params) + }.must_raise SlackError + end + end + end \ No newline at end of file From b31c6e783e7d58ce4f8c240812875745fd946af7 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 19 Mar 2019 19:37:01 -0700 Subject: [PATCH 25/69] "first test passed in channel_spec" --- lib/recipient.rb | 10 +++++----- specs/channel_spec.rb | 34 +++++++++++----------------------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index c72e6018..8bae2100 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -13,7 +13,7 @@ class Recipient LIST_URL = nil TOKEN = ENV["SLACK_TOKEN"] - attr_reader :send_message, :name, :slack_id, :error_helper, :list + attr_reader :send_message, :name, :slack_id, :error_helper def initialize @slack_id = slack_id @@ -32,12 +32,12 @@ def self.send_message(name:, message:) end def self.get - query_params = { - token: TOKEN + query_params = { + token: TOKEN, } response = HTTParty.get(self::LIST_URL, query: query_params) - - error_helper(response) + return response + # error_helper(response) end def self.error_helper(response) diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 1c43f56d..1355061b 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -1,26 +1,14 @@ - describe "self.get method" do - it "successfully returns users list HTTP response object" do - VCR.use_cassette("get_response") do - url = "https://slack.com/api/users.list" - params = { - token: ENV["SLACK_TOKEN"], - } - party_people = Channel.get +require_relative "test_helper" - expect(party_people["ok"]).must_equal true - end - end - - it "raises SlackError for inauthorization" do - VCR.use_cassette("get_response") do - url = "https://slack.com/api/users.list" - params = { - token: "thisisbadtoken", - } +describe "self get method" do + it "successfully returns users list HTTP response object" do + VCR.use_cassette("get_response") do + party_people = Channel.get - expect { - Recipient.get(url, params) - }.must_raise SlackError - end + expect(party_people["ok"]).must_equal true end - end \ No newline at end of file + end + + it "raises SlackError for inauthorization" do + end +end From 85cc32e4b5cf1eddc2992ec61b17f8920a23d9a2 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 19 Mar 2019 22:12:09 -0700 Subject: [PATCH 26/69] updating self.list in Channel --- lib/channel.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 39c5f9a0..ac9041dd 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,19 +1,27 @@ require_relative "recipient" class Channel < Recipient - attr_reader + attr_reader :slack_id, :name, :topic, :member_count LIST_URL = "https://slack.com/api/channels.list" - def initialize - @topic + def initialize(slack_id:, name:, topic:, member_count:) + @slack_id = slack_id + @name = name + @topic = topic @member_count end def self.list - channels_json = Channel.get + response = Channel.get - list_of_channels = channels_json["channels"].select { |channel| channel["name"] } - return list_of_channels + channels = response["channels"].map do|channel| + slack_id = channel["id"] + name = channel["name"] + topic = channel["topic"] + member_count = channel["num_member"] + self.new(slack_id: slack_id, name: name, topic: topic, member_count: ) + end + return list_of_channels end def details(name) @@ -25,5 +33,3 @@ def details(name) end end -test = Channel.get -binding.pry From 45f1f1b747f60f17f623a88e568f956f65494eda Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 19 Mar 2019 22:18:05 -0700 Subject: [PATCH 27/69] added #details in channel class --- lib/channel.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index ac9041dd..ecfc6221 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -25,11 +25,7 @@ def self.list end def details(name) - list.each do |channel| - if channel["name"] == name - puts channel["purpose"]["value"] - end - end + return "#{name}, #{slack_id}, #{topic}, #{member_count}" end end From bca0e4d9bd598ea6910baff25b6585d869004231 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 19 Mar 2019 22:46:22 -0700 Subject: [PATCH 28/69] added details and updated list to reference correct values --- lib/channel.rb | 23 +++++++++++++---------- lib/recipient.rb | 3 ++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index ecfc6221..b2ac09c9 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,31 +1,34 @@ require_relative "recipient" class Channel < Recipient - attr_reader :slack_id, :name, :topic, :member_count + attr_reader :topic, :member_count LIST_URL = "https://slack.com/api/channels.list" - def initialize(slack_id:, name:, topic:, member_count:) + def initialize(slack_id, name, topic, member_count) @slack_id = slack_id @name = name @topic = topic - @member_count + @member_count = member_count end def self.list response = Channel.get - channels = response["channels"].map do|channel| + channels = response["channels"].map do |channel| + # binding.pry slack_id = channel["id"] name = channel["name"] - topic = channel["topic"] - member_count = channel["num_member"] - self.new(slack_id: slack_id, name: name, topic: topic, member_count: ) + topic = channel["topic"]["value"] + member_count = channel["num_members"] + self.new(slack_id, name, topic, member_count) end - return list_of_channels + return channels end - def details(name) - return "#{name}, #{slack_id}, #{topic}, #{member_count}" + def details + print "Channel name: #{name} \nID: #{slack_id} \ntopic: #{topic}, \nMember count:#{member_count}\n" end end +test = Channel.list +binding.pry diff --git a/lib/recipient.rb b/lib/recipient.rb index 8bae2100..1c1aa128 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -13,7 +13,7 @@ class Recipient LIST_URL = nil TOKEN = ENV["SLACK_TOKEN"] - attr_reader :send_message, :name, :slack_id, :error_helper + attr_reader :send_message, :name, :slack_id, :error_helper, :details, :list def initialize @slack_id = slack_id @@ -48,6 +48,7 @@ def self.error_helper(response) end end + #private def details raise NotImplementedError end From 963e0a95fe241ced4308de796b9727d5f4a7bb66 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 19 Mar 2019 23:12:24 -0700 Subject: [PATCH 29/69] wrote nominal tests for channel_spec --- lib/channel.rb | 14 +++++++++++--- specs/channel_spec.rb | 38 ++++++++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index b2ac09c9..e41827df 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -3,6 +3,7 @@ class Channel < Recipient attr_reader :topic, :member_count LIST_URL = "https://slack.com/api/channels.list" + MSG_URL = "" def initialize(slack_id, name, topic, member_count) @slack_id = slack_id @@ -26,9 +27,16 @@ def self.list end def details - print "Channel name: #{name} \nID: #{slack_id} \ntopic: #{topic}, \nMember count:#{member_count}\n" + return "Channel name: #{name} \nID: #{slack_id} \ntopic: #{topic}, \nMember count:#{member_count}\n" end end -test = Channel.list -binding.pry +#add this to recipient? +# def send_message(message) +# query_params = { +# token: TOKEN +# name: self +# message: message +# } +# response = HTTParty.post(self::MSG_URL, query: query_params) +#end diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 1355061b..32d79804 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -1,14 +1,40 @@ require_relative "test_helper" -describe "self get method" do - it "successfully returns users list HTTP response object" do - VCR.use_cassette("get_response") do - party_people = Channel.get +describe "Channel" do + describe "self get method" do + it "successfully returns users list HTTP response object" do + VCR.use_cassette("get_response") do + channels = Channel.get - expect(party_people["ok"]).must_equal true + expect(channels["ok"]).must_equal true + end + end + + it "raises SlackError for for bad request" do + # VCR.use_cassette("get_response") do + # end end end + describe "list" do + it "creates a list of all channels" do + VCR.use_cassette("get_response") do + channels = Channel.list - it "raises SlackError for inauthorization" do + expect(channels).must_be_kind_of Array + expect(channels.first).must_be_instance_of Channel + expect(channels.last).must_be_instance_of Channel + end + end + end + + describe "details" do + it "lists details for an instance of channel" do + VCR.use_cassette("get_response") do + channels = Channel.list + channel_deets = channels[1].details + + expect(channel_deets).must_equal channels[1].details + end + end end end From 3094413a2caeb13427d0ed1ac3131b9951d3a209 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Tue, 19 Mar 2019 23:13:59 -0700 Subject: [PATCH 30/69] generating test ideas for channel_spec --- specs/channel_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 32d79804..237058d1 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -25,6 +25,9 @@ expect(channels.last).must_be_instance_of Channel end end + + it "returns nil for a channel that doesn't exist" do + end end describe "details" do @@ -36,5 +39,8 @@ expect(channel_deets).must_equal channels[1].details end end + + it "returns nil for a channel that doesn't exist" do + end end end From 84530e46e45fd9b3187aaeff41df360586084727 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Wed, 20 Mar 2019 12:32:29 -0700 Subject: [PATCH 31/69] renamed httparty gem in recipient and moved private methods --- lib/channel.rb | 1 - lib/recipient.rb | 20 ++++++++++---------- specs/test_helper.rb | 3 --- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index e41827df..e16388a9 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -16,7 +16,6 @@ def self.list response = Channel.get channels = response["channels"].map do |channel| - # binding.pry slack_id = channel["id"] name = channel["name"] topic = channel["topic"]["value"] diff --git a/lib/recipient.rb b/lib/recipient.rb index 1c1aa128..cbf46fcb 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,4 +1,4 @@ -require "HTTParty" +require "httparty" require "pry" require "dotenv" @@ -37,15 +37,7 @@ def self.get } response = HTTParty.get(self::LIST_URL, query: query_params) return response - # error_helper(response) - end - - def self.error_helper(response) - if response["ok"] != true - raise SlackError, "#{response["error"]}" - else - return response - end + error_helper(response) end #private @@ -56,4 +48,12 @@ def details def self.list raise NotImplementedError end + + def self.error_helper(response) + if response["ok"] != true + raise SlackError, "#{response["error"]}" + else + return response + end + end end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index f8b7d3ee..ad890d1a 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -1,6 +1,3 @@ -require "simplecov" -SimpleCov.start - require "minitest" require "minitest/autorun" require "minitest/reporters" From a48e230a3b17979970fbedd67efb2781c805cff2 Mon Sep 17 00:00:00 2001 From: Hana Date: Wed, 20 Mar 2019 12:33:07 -0700 Subject: [PATCH 32/69] user self.get self.details and tests --- copy recipient_spec.rb | 56 ------------------------------------------ lib/user.rb | 15 ++++++++++- lib/workspace.rb | 27 ++++++++++++++++++++ set_up.rb | 24 ------------------ specs/user_spec.rb | 40 ++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 81 deletions(-) delete mode 100644 copy recipient_spec.rb delete mode 100644 set_up.rb diff --git a/copy recipient_spec.rb b/copy recipient_spec.rb deleted file mode 100644 index 60c0a233..00000000 --- a/copy recipient_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -require_relative "test_helper" - -describe "Recipient" do - describe "initialize" do - end - - describe "send message" do - it "can post a message on the everyone slack channel" do - VCR.use_cassette("message_post") do - name = "everyone" - text = "hello world" - pigeon = Recipient.send_message(name: name, message: text) - - expect(pigeon["ok"]).must_equal true - end - end - - it "raises a SlackError with bad parameters" do - VCR.use_cassette("message_post") do - name = "" - text = "this should not send" - - expect { - Recipient.send_message(name: name, message: text) - }.must_raise SlackError - end - end - end - - # describe "self.get method" do - # it "successfully returns users list HTTP response object" do - # VCR.use_cassette("get_response") do - # url = "https://slack.com/api/users.list" - # params = { - # token: ENV["SLACK_TOKEN"], - # } - # party_people = Recipient.get(url, params) - - # expect(party_people["ok"]).must_equal true - # end - # end - - # it "raises SlackError for inauthorization" do - # VCR.use_cassette("get_response") do - # url = "https://slack.com/api/users.list" - # params = { - # token: "thisisbadtoken", - # } - - # expect { - # Recipient.get(url, params) - # }.must_raise SlackError - # end - # end - # end -end diff --git a/lib/user.rb b/lib/user.rb index b6e9259d..a47fe4db 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -6,7 +6,7 @@ class User < Recipient LIST_URL = "https://slack.com/api/users.list" TOKEN = ENV["SLACK_TOKEN"] - attr_reader :real_name, :list_users + attr_reader :real_name, :status_text, :status_emoji, :list_users, :details def initialize @real_name = real_name @@ -25,5 +25,18 @@ def self.list_users end return user_list end + + def self.details + user_details = list["members"].map do |user| + { + real_name: user["profile"]["real_name"], + status_text: user["profile"]["status_text"], + status_emoji: user["profile"]["status_emoji"] + } + end + + return user_details + end end +puts User.details \ No newline at end of file diff --git a/lib/workspace.rb b/lib/workspace.rb index e69de29b..c237e2a4 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -0,0 +1,27 @@ +# workspace + +class Workspace + attr_reader :users, :channels, :selected + + def initialize + @users = users, + @channels = channels, + @selected = selected + end + + def select_channel(channel) + # takes channel as user input + end + + def select_user(user) + # takes user as user input + end + + def show_details(selected_item) + # show details of either user/channel + end + + def send_message(selected_item) + # send a message to either user/channel + end +end \ No newline at end of file diff --git a/set_up.rb b/set_up.rb deleted file mode 100644 index 7443a72c..00000000 --- a/set_up.rb +++ /dev/null @@ -1,24 +0,0 @@ -# Use the dotenv gem to load environment variables -# Use HTTParty to send a GET request to the channels.list endpoint -# Check that the request completed successfully, and print relevant information to the console if it didn't -# Loop through the results and print out the name of each channel - -require 'dotenv' -Dotenv.load - -require 'HTTParty' -require 'pry' - -BASE_URL = "https://slack.com/api/channels.list" - -query_params = { - token: ENV['BANANA'] -} - -response = HTTParty.get(BASE_URL, query: query_params) - - - -response["channels"].each do |channel| - puts "#{channel["name"]}" -end diff --git a/specs/user_spec.rb b/specs/user_spec.rb index e69de29b..b5fc9a06 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -0,0 +1,40 @@ +describe "User child class" do + describe "initialize" do + end + + describe "user self.list method" do + it "successfully returns an HTTParty response object" do + VCR.use_cassette("user_response") do + expect(User.list["ok"]).must_equal true + end + end + end + + describe "user self.list_users method" do + it "returns all usernames in workspace in array" do + VCR.use_cassette("user_response") do + expect(User.list_users).must_be_kind_of Array + expect(User.list_users.length).must_equal 3 + end + end + end + + describe "user self.details method" do + it "returns an array of hashes" do + VCR.use_cassette("user_response") do + expect(User.details).must_be_kind_of Array + User.details.each do |user| + user.must_be_kind_of Hash + end + end + end + + it "returns the correct details" do + VCR.use_cassette("user_response") do + expect(User.details.last[:real_name]).must_equal "Hana Clements" + expect(User.details.last[:status_text]).must_equal ":heart:" + expect(User.details.last[:status_emoji]).must_equal ":green_heart:" + end + end + end +end \ No newline at end of file From cf221f1633e69150fea2f5b7ffd47b785141201a Mon Sep 17 00:00:00 2001 From: Hana Date: Wed, 20 Mar 2019 14:25:26 -0700 Subject: [PATCH 33/69] refactored self.list to instantiate User --- lib/channel.rb | 1 + lib/user.rb | 37 ++++++++++++++++++++++--------------- specs/user_spec.rb | 43 +++++++++++++++++++++++-------------------- 3 files changed, 46 insertions(+), 35 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index e16388a9..8f07c551 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -39,3 +39,4 @@ def details # } # response = HTTParty.post(self::MSG_URL, query: query_params) #end + diff --git a/lib/user.rb b/lib/user.rb index a47fe4db..2078f85f 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -8,7 +8,9 @@ class User < Recipient attr_reader :real_name, :status_text, :status_emoji, :list_users, :details - def initialize + def initialize(name, slack_id, real_name, status_text, status_emoji) + @name = name + @slack_id = slack_id @real_name = real_name @status_text = status_text @status_emoji = status_emoji @@ -16,27 +18,32 @@ def initialize def self.list response = User.get - return response + + users = response["members"].map do |user| + name = user["name"] + slack_id = user["id"] + real_name = user["profile"]["real_name"] + status_text = user["profile"]["status_text"] + status_emoji = user["profile"]["status_emoji"] + self.new(name, slack_id, real_name, status_text, status_emoji) + end + + return users end def self.list_users - user_list = list["members"].map do |user| - user["name"] + user_list = list.map do |user| + user.name end return user_list end def self.details - user_details = list["members"].map do |user| - { - real_name: user["profile"]["real_name"], - status_text: user["profile"]["status_text"], - status_emoji: user["profile"]["status_emoji"] - } - end - + user_details = "Username: #{name} + Slack ID: #{slack_id} + Real Name: #{real_name} + Status Text: #{status_text} + Status Emoji: #{status_emoji}" return user_details end -end - -puts User.details \ No newline at end of file +end \ No newline at end of file diff --git a/specs/user_spec.rb b/specs/user_spec.rb index b5fc9a06..00205c71 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -2,13 +2,27 @@ describe "initialize" do end - describe "user self.list method" do + describe "user self.get method" do it "successfully returns an HTTParty response object" do VCR.use_cassette("user_response") do - expect(User.list["ok"]).must_equal true + expect(User.get["ok"]).must_equal true end end end + describe "user self.list method" do + it "creates a list of all user objects" do + VCR.use_cassette("user_response") do + user_list = User.list + + expect(user_list).must_be_kind_of Array + expect(user_list.first).must_be_instance_of User + expect(user_list.last).must_be_instance_of User + end + end + + it "returns nil for a user that doesn't exist" do + end + end describe "user self.list_users method" do it "returns all usernames in workspace in array" do @@ -19,22 +33,11 @@ end end - describe "user self.details method" do - it "returns an array of hashes" do - VCR.use_cassette("user_response") do - expect(User.details).must_be_kind_of Array - User.details.each do |user| - user.must_be_kind_of Hash - end - end - end - - it "returns the correct details" do - VCR.use_cassette("user_response") do - expect(User.details.last[:real_name]).must_equal "Hana Clements" - expect(User.details.last[:status_text]).must_equal ":heart:" - expect(User.details.last[:status_emoji]).must_equal ":green_heart:" - end - end - end + # describe "user self.details method" do + # it "returns a string" do + # VCR.use_cassette("user_response") do + # expect(User.details).must_be_kind_of String + # end + # end + # end end \ No newline at end of file From 3ed78f2b02a6f050524435b589f1cc745f3980cc Mon Sep 17 00:00:00 2001 From: Hana Date: Wed, 20 Mar 2019 14:42:15 -0700 Subject: [PATCH 34/69] namespace with a SlackCli module --- lib/user.rb | 76 ++++++++++++++++++++++++---------------------- specs/user_spec.rb | 22 +++++--------- 2 files changed, 47 insertions(+), 51 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index 2078f85f..994fe95d 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -2,48 +2,50 @@ require_relative 'recipient' -class User < Recipient - LIST_URL = "https://slack.com/api/users.list" - TOKEN = ENV["SLACK_TOKEN"] - - attr_reader :real_name, :status_text, :status_emoji, :list_users, :details - - def initialize(name, slack_id, real_name, status_text, status_emoji) - @name = name - @slack_id = slack_id - @real_name = real_name - @status_text = status_text - @status_emoji = status_emoji - end +module SlackCli + class User < Recipient + LIST_URL = "https://slack.com/api/users.list" + TOKEN = ENV["SLACK_TOKEN"] + + attr_reader :real_name, :status_text, :status_emoji, :list_users, :details + + def initialize(name, slack_id, real_name, status_text, status_emoji) + @name = name + @slack_id = slack_id + @real_name = real_name + @status_text = status_text + @status_emoji = status_emoji + end - def self.list - response = User.get + def self.list + response = SlackCli::User.get - users = response["members"].map do |user| - name = user["name"] - slack_id = user["id"] - real_name = user["profile"]["real_name"] - status_text = user["profile"]["status_text"] - status_emoji = user["profile"]["status_emoji"] - self.new(name, slack_id, real_name, status_text, status_emoji) - end + users = response["members"].map do |user| + name = user["name"] + slack_id = user["id"] + real_name = user["profile"]["real_name"] + status_text = user["profile"]["status_text"] + status_emoji = user["profile"]["status_emoji"] + self.new(name, slack_id, real_name, status_text, status_emoji) + end - return users - end + return users + end - def self.list_users - user_list = list.map do |user| - user.name + def self.list_users + user_list = list.map do |user| + user.name + end + return user_list end - return user_list - end - def self.details - user_details = "Username: #{name} - Slack ID: #{slack_id} - Real Name: #{real_name} - Status Text: #{status_text} - Status Emoji: #{status_emoji}" - return user_details + def self.details + user_details = "Username: #{name} + Slack ID: #{slack_id} + Real Name: #{real_name} + Status Text: #{status_text} + Status Emoji: #{status_emoji}" + return user_details + end end end \ No newline at end of file diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 00205c71..4266926b 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -1,3 +1,5 @@ +require_relative "test_helper.rb" + describe "User child class" do describe "initialize" do end @@ -5,18 +7,18 @@ describe "user self.get method" do it "successfully returns an HTTParty response object" do VCR.use_cassette("user_response") do - expect(User.get["ok"]).must_equal true + expect(SlackCli::User.get["ok"]).must_equal true end end end describe "user self.list method" do it "creates a list of all user objects" do VCR.use_cassette("user_response") do - user_list = User.list + user_list = SlackCli::User.list expect(user_list).must_be_kind_of Array - expect(user_list.first).must_be_instance_of User - expect(user_list.last).must_be_instance_of User + expect(user_list.first).must_be_instance_of SlackCli::User + expect(user_list.last).must_be_instance_of SlackCli::User end end @@ -27,17 +29,9 @@ describe "user self.list_users method" do it "returns all usernames in workspace in array" do VCR.use_cassette("user_response") do - expect(User.list_users).must_be_kind_of Array - expect(User.list_users.length).must_equal 3 + expect(SlackCli::User.list_users).must_be_kind_of Array + expect(SlackCli::User.list_users.length).must_equal 3 end end end - - # describe "user self.details method" do - # it "returns a string" do - # VCR.use_cassette("user_response") do - # expect(User.details).must_be_kind_of String - # end - # end - # end end \ No newline at end of file From 0484e3a3673cae462f17f41ed7047c2ec273516b Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Wed, 20 Mar 2019 14:45:16 -0700 Subject: [PATCH 35/69] added module and refactored channel_spec --- lib/channel.rb | 5 ++- lib/recipient.rb | 84 +++++++++++++++++++++-------------------- specs/channel_spec.rb | 40 +++++++++----------- specs/recipient_spec.rb | 27 ------------- 4 files changed, 63 insertions(+), 93 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index e16388a9..bf31a36b 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,6 +1,7 @@ require_relative "recipient" -class Channel < Recipient +module SlackCli +class Channel < SlackCli::Recipient attr_reader :topic, :member_count LIST_URL = "https://slack.com/api/channels.list" MSG_URL = "" @@ -13,7 +14,7 @@ def initialize(slack_id, name, topic, member_count) end def self.list - response = Channel.get + response = SlackCli::Channel.get channels = response["channels"].map do |channel| slack_id = channel["id"] diff --git a/lib/recipient.rb b/lib/recipient.rb index cbf46fcb..8d7a0d2c 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -3,57 +3,59 @@ require "dotenv" Dotenv.load + +module SlackCli + class SlackError < StandardError; end -class SlackError < StandardError; end + class Recipient + -class Recipient + MSG_URL = "https://slack.com/api/chat.postMessage" + LIST_URL = nil + TOKEN = ENV["SLACK_TOKEN"] - # constants - MSG_URL = "https://slack.com/api/chat.postMessage" - LIST_URL = nil - TOKEN = ENV["SLACK_TOKEN"] + attr_reader :send_message, :name, :slack_id, :error_helper, :details, :list - attr_reader :send_message, :name, :slack_id, :error_helper, :details, :list - - def initialize - @slack_id = slack_id - @name = name - end + def initialize + @slack_id = slack_id + @name = name + end - def self.send_message(name:, message:) - query_params = { - token: TOKEN, - channel: name, - text: message, - } - response = HTTParty.post(MSG_URL, query: query_params) + def self.send_message(name:, message:) + query_params = { + token: TOKEN, + channel: name, + text: message, + } + response = HTTParty.post(MSG_URL, query: query_params) - error_helper(response) - end + error_helper(response) + end - def self.get - query_params = { - token: TOKEN, - } - response = HTTParty.get(self::LIST_URL, query: query_params) - return response - error_helper(response) - end + def self.get + query_params = { + token: TOKEN, + } + response = HTTParty.get(self::LIST_URL, query: query_params) + return response + error_helper(response) + end - #private - def details - raise NotImplementedError - end + #private + def details + raise NotImplementedError + end - def self.list - raise NotImplementedError - end + def self.list + raise NotImplementedError + end - def self.error_helper(response) - if response["ok"] != true - raise SlackError, "#{response["error"]}" - else - return response + def self.error_helper(response) + if response["ok"] != true + raise SlackError, "#{response["error"]}" + else + return response + end end end end diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 237058d1..2c62d034 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -1,28 +1,27 @@ require_relative "test_helper" describe "Channel" do - describe "self get method" do - it "successfully returns users list HTTP response object" do - VCR.use_cassette("get_response") do - channels = Channel.get + let(:get_response) do + VCR.use_cassette("slack/get") { SlackCli::Channel.get } + end + let(:channel_list) do + VCR.use_cassette("slack/list") { SlackCli::Channel.list } + end - expect(channels["ok"]).must_equal true - end - end + describe "self get method" do + it "successfully returns an HTTP response object" do + channels = get_response - it "raises SlackError for for bad request" do - # VCR.use_cassette("get_response") do - # end + expect(channels["ok"]).must_equal true end end describe "list" do it "creates a list of all channels" do - VCR.use_cassette("get_response") do - channels = Channel.list + channels = channel_list - expect(channels).must_be_kind_of Array - expect(channels.first).must_be_instance_of Channel - expect(channels.last).must_be_instance_of Channel + expect(channels).must_be_kind_of Array + channels.each do |channel| + expect(channel).must_be_instance_of SlackCli::Channel end end @@ -31,16 +30,11 @@ end describe "details" do + channels = channel_list it "lists details for an instance of channel" do - VCR.use_cassette("get_response") do - channels = Channel.list - channel_deets = channels[1].details + channel_deets = channels[1].details - expect(channel_deets).must_equal channels[1].details - end - end - - it "returns nil for a channel that doesn't exist" do + expect(channel_deets).must_equal channels[1].details end end end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 60c0a233..8238d53a 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -26,31 +26,4 @@ end end end - - # describe "self.get method" do - # it "successfully returns users list HTTP response object" do - # VCR.use_cassette("get_response") do - # url = "https://slack.com/api/users.list" - # params = { - # token: ENV["SLACK_TOKEN"], - # } - # party_people = Recipient.get(url, params) - - # expect(party_people["ok"]).must_equal true - # end - # end - - # it "raises SlackError for inauthorization" do - # VCR.use_cassette("get_response") do - # url = "https://slack.com/api/users.list" - # params = { - # token: "thisisbadtoken", - # } - - # expect { - # Recipient.get(url, params) - # }.must_raise SlackError - # end - # end - # end end From 0f9ce9d4373a09388f1d2962a4b66066e626a23b Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Wed, 20 Mar 2019 14:51:38 -0700 Subject: [PATCH 36/69] "namespacing in recipient_spec and removed unnecessary test in channel_spec --- specs/channel_spec.rb | 3 --- specs/recipient_spec.rb | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 2c62d034..423f128d 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -24,9 +24,6 @@ expect(channel).must_be_instance_of SlackCli::Channel end end - - it "returns nil for a channel that doesn't exist" do - end end describe "details" do diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 8238d53a..7b105467 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -9,7 +9,7 @@ VCR.use_cassette("message_post") do name = "everyone" text = "hello world" - pigeon = Recipient.send_message(name: name, message: text) + pigeon = SlackCli::Recipient.send_message(name: name, message: text) expect(pigeon["ok"]).must_equal true end @@ -21,7 +21,7 @@ text = "this should not send" expect { - Recipient.send_message(name: name, message: text) + SlackCli::Recipient.send_message(name: name, message: text) }.must_raise SlackError end end From bc9cc58491721fc8e2eb4d54aa51ac6840fbb7a8 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Wed, 20 Mar 2019 14:52:54 -0700 Subject: [PATCH 37/69] replaced missing end --- lib/channel.rb | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 1f61dfbb..53841df8 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,33 +1,34 @@ require_relative "recipient" module SlackCli -class Channel < SlackCli::Recipient - attr_reader :topic, :member_count - LIST_URL = "https://slack.com/api/channels.list" - MSG_URL = "" + class Channel < SlackCli::Recipient + attr_reader :topic, :member_count + LIST_URL = "https://slack.com/api/channels.list" + MSG_URL = "" - def initialize(slack_id, name, topic, member_count) - @slack_id = slack_id - @name = name - @topic = topic - @member_count = member_count - end + def initialize(slack_id, name, topic, member_count) + @slack_id = slack_id + @name = name + @topic = topic + @member_count = member_count + end - def self.list - response = SlackCli::Channel.get + def self.list + response = SlackCli::Channel.get - channels = response["channels"].map do |channel| - slack_id = channel["id"] - name = channel["name"] - topic = channel["topic"]["value"] - member_count = channel["num_members"] - self.new(slack_id, name, topic, member_count) + channels = response["channels"].map do |channel| + slack_id = channel["id"] + name = channel["name"] + topic = channel["topic"]["value"] + member_count = channel["num_members"] + self.new(slack_id, name, topic, member_count) + end + return channels end - return channels - end - def details - return "Channel name: #{name} \nID: #{slack_id} \ntopic: #{topic}, \nMember count:#{member_count}\n" + def details + return "Channel name: #{name} \nID: #{slack_id} \ntopic: #{topic}, \nMember count:#{member_count}\n" + end end end From 6a9bdf004f05cc6c9f4c57bc2205a82f74a00433 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Wed, 20 Mar 2019 14:55:08 -0700 Subject: [PATCH 38/69] added namespace to SlackError in recipient spec --- specs/channel_spec.rb | 2 +- specs/recipient_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 423f128d..dcf9a4da 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -27,8 +27,8 @@ end describe "details" do - channels = channel_list it "lists details for an instance of channel" do + channels = channel_list channel_deets = channels[1].details expect(channel_deets).must_equal channels[1].details diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 7b105467..635365da 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -22,7 +22,7 @@ expect { SlackCli::Recipient.send_message(name: name, message: text) - }.must_raise SlackError + }.must_raise SlackCli::SlackError end end end From d42ca8f6f8f792a3ac7234863f5f80e6530c49bf Mon Sep 17 00:00:00 2001 From: Hana Date: Wed, 20 Mar 2019 15:43:52 -0700 Subject: [PATCH 39/69] refactor list_users so it returns nil --- lib/channel.rb | 1 + lib/user.rb | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 53841df8..aaec63e4 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -42,3 +42,4 @@ def details # response = HTTParty.post(self::MSG_URL, query: query_params) #end +binding.pry \ No newline at end of file diff --git a/lib/user.rb b/lib/user.rb index 994fe95d..0a732bad 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -33,10 +33,10 @@ def self.list end def self.list_users - user_list = list.map do |user| - user.name + list.each do |user| + puts "#{user.real_name} Slack ID: #{user.slack_id}" end - return user_list + return nil end def self.details @@ -48,4 +48,6 @@ def self.details return user_details end end -end \ No newline at end of file +end + +binding.pry \ No newline at end of file From aeb1918b0cbf72ac90acd3d14d348bb7a218df1d Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Wed, 20 Mar 2019 15:44:07 -0700 Subject: [PATCH 40/69] adding driver code to workspace in main --- lib/channel.rb | 10 ++++++++-- lib/workspace.rb | 45 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 53841df8..22f7fa73 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -2,7 +2,7 @@ module SlackCli class Channel < SlackCli::Recipient - attr_reader :topic, :member_count + attr_reader :topic, :member_count, :list_channels LIST_URL = "https://slack.com/api/channels.list" MSG_URL = "" @@ -26,6 +26,13 @@ def self.list return channels end + def self.list_channels + list.each do |channel| + puts "Channel name: #{channel.name} ID: #{channel.slack_id} topic: #{channel.topic}, Member count:#{channel.member_count}" + end + return nil + end + def details return "Channel name: #{name} \nID: #{slack_id} \ntopic: #{topic}, \nMember count:#{member_count}\n" end @@ -41,4 +48,3 @@ def details # } # response = HTTParty.post(self::MSG_URL, query: query_params) #end - diff --git a/lib/workspace.rb b/lib/workspace.rb index c237e2a4..711a0bdb 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,11 +1,14 @@ # workspace +require_relative "user" +require_relative "channel" +require "terminal-table" class Workspace attr_reader :users, :channels, :selected def initialize @users = users, - @channels = channels, + @channels = channels, @selected = selected end @@ -18,10 +21,44 @@ def select_user(user) end def show_details(selected_item) - # show details of either user/channel + #puts selected_item.details end def send_message(selected_item) - # send a message to either user/channel + # puts "What would you like to say to #{selected_item}" + # message = gets.chomp + # selected_item.send_message("message") end -end \ No newline at end of file +end + +#driver code +def main + puts "TatiHana Slack Channels loaded #{SlackCli::Channel.list.length} channels" + puts "TatiHana Users loaded #{SlackCli::User.list.length} users" + + def options + puts "Please choose one of the following options: + - list users + - list channels + - quit + Enter your choice now:" + end + + options + choice = gets.chomp + loop do + case choice + when "list users" + puts SlackCli::User.list_users + when "list channels" + puts SlackCli::Channel.list_channels + when "quit" + puts "Thanks for checking out TatiHana! Bye bye..." + exit + end + options + choice = gets.chomp + end +end + +main if __FILE__ == $0 From 08fc989f9e4df059fb85d53b3f09ae9b9fb00a48 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Wed, 20 Mar 2019 15:49:27 -0700 Subject: [PATCH 41/69] added comment for me to revisit in channel#details --- lib/channel.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 355b118e..ca5472ba 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -15,7 +15,7 @@ def initialize(slack_id, name, topic, member_count) def self.list response = SlackCli::Channel.get - + channels = response["channels"].map do |channel| slack_id = channel["id"] name = channel["name"] @@ -33,7 +33,7 @@ def self.list_channels return nil end - def details + def details # what should I be????? return "Channel name: #{name} \nID: #{slack_id} \ntopic: #{topic}, \nMember count:#{member_count}\n" end end From 63370476376000bbebded30da7b500dd2e2a2aa3 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Wed, 20 Mar 2019 15:57:28 -0700 Subject: [PATCH 42/69] writing more driver code in workspace --- lib/workspace.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/workspace.rb b/lib/workspace.rb index 711a0bdb..bd45cfae 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -40,6 +40,9 @@ def options puts "Please choose one of the following options: - list users - list channels + - select user + - select channel + - details - quit Enter your choice now:" end @@ -52,9 +55,20 @@ def options puts SlackCli::User.list_users when "list channels" puts SlackCli::Channel.list_channels + when "select user" + puts "what user would you like to select?" + selected_user = gets.chomp + sought_user = SlackCli::Workspace.select_user(selected_user) + when "select channel" + selected_channel = gets.chomp + sought_channel = SlackCli::Workspace.select_channel(selected_channel) + when "details" + # think about logic when "quit" puts "Thanks for checking out TatiHana! Bye bye..." exit + else + # add something here end options choice = gets.chomp From 34733dd35d4ea11dece70de146e9ba7d403ee5b6 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Wed, 20 Mar 2019 15:58:32 -0700 Subject: [PATCH 43/69] removed binding.pry --- lib/channel.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index ca5472ba..e8089771 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -48,8 +48,3 @@ def details # what should I be????? # } # response = HTTParty.post(self::MSG_URL, query: query_params) #end -<<<<<<< HEAD -======= - -binding.pry ->>>>>>> d42ca8f6f8f792a3ac7234863f5f80e6530c49bf From e6aa86f812049fe8899a164d8e27abf2ddf74e5f Mon Sep 17 00:00:00 2001 From: Hana Date: Wed, 20 Mar 2019 17:10:56 -0700 Subject: [PATCH 44/69] refactor self.list_users method --- lib/user.rb | 2 -- specs/user_spec.rb | 5 ++--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index 0a732bad..02184019 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -49,5 +49,3 @@ def self.details end end end - -binding.pry \ No newline at end of file diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 4266926b..67504df8 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -27,10 +27,9 @@ end describe "user self.list_users method" do - it "returns all usernames in workspace in array" do + it "returns all usernames in workspace as a string" do VCR.use_cassette("user_response") do - expect(SlackCli::User.list_users).must_be_kind_of Array - expect(SlackCli::User.list_users.length).must_equal 3 + expect(SlackCli::User.list_users).must_equal nil end end end From a88b86de125b777875dfec2b9c515a5815fddee1 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Wed, 20 Mar 2019 17:50:33 -0700 Subject: [PATCH 45/69] DRYed up channel/user and workspace --- lib/channel.rb | 14 +++----------- lib/recipient.rb | 2 +- lib/slack.rb | 35 +++++++++++++++++------------------ lib/user.rb | 21 ++++++--------------- lib/workspace.rb | 44 ++++++++++++++++++++++++++++++-------------- specs/user_spec.rb | 23 +++++++---------------- 6 files changed, 64 insertions(+), 75 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index e8089771..66f213ad 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -2,9 +2,8 @@ module SlackCli class Channel < SlackCli::Recipient - attr_reader :topic, :member_count, :list_channels + attr_reader :topic, :member_count LIST_URL = "https://slack.com/api/channels.list" - MSG_URL = "" def initialize(slack_id, name, topic, member_count) @slack_id = slack_id @@ -14,7 +13,7 @@ def initialize(slack_id, name, topic, member_count) end def self.list - response = SlackCli::Channel.get + response = get channels = response["channels"].map do |channel| slack_id = channel["id"] @@ -26,14 +25,7 @@ def self.list return channels end - def self.list_channels - list.each do |channel| - puts "Channel name: #{channel.name} ID: #{channel.slack_id} topic: #{channel.topic}, Member count:#{channel.member_count}" - end - return nil - end - - def details # what should I be????? + def details return "Channel name: #{name} \nID: #{slack_id} \ntopic: #{topic}, \nMember count:#{member_count}\n" end end diff --git a/lib/recipient.rb b/lib/recipient.rb index 8d7a0d2c..29e9d354 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -37,8 +37,8 @@ def self.get token: TOKEN, } response = HTTParty.get(self::LIST_URL, query: query_params) - return response error_helper(response) + return response end #private diff --git a/lib/slack.rb b/lib/slack.rb index 0e14aa08..c53dbedf 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,24 +1,23 @@ -#!/usr/bin/env ruby -require "dotenv" -require "httparty" -require "pry" -require "awesome_print" -Dotenv.load +# #!/usr/bin/env ruby +# require "dotenv" +# require "httparty" +# require "pry" +# require "awesome_print" +# Dotenv.load -def main - puts "Welcome to the Ada Slack CLI!" +# def main +# puts "Welcome to the Ada Slack CLI!" - url = "https://slack.com/api/channels.list" +# url = "https://slack.com/api/channels.list" - query_params = { token: ENV["API_KEY"] } +# query_params = { token: ENV["API_KEY"] } - response = HTTParty.get(url, query: query_params) +# response = HTTParty.get(url, query: query_params) - response["channels"].each do |channel| - puts channel["name"] - end - puts "Thank you for using the Ada Slack CLI" -end - -main if __FILE__ == $PROGRAM_NAME +# response["channels"].each do |channel| +# puts channel["name"] +# end +# puts "Thank you for using the Ada Slack CLI" +# end +# main if __FILE__ == $PROGRAM_NAME diff --git a/lib/user.rb b/lib/user.rb index 0a732bad..674a8040 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,24 +1,24 @@ -require 'pry' +require "pry" -require_relative 'recipient' +require_relative "recipient" module SlackCli - class User < Recipient + class User < Recipient LIST_URL = "https://slack.com/api/users.list" TOKEN = ENV["SLACK_TOKEN"] - attr_reader :real_name, :status_text, :status_emoji, :list_users, :details + attr_reader :real_name, :status_text, :status_emoji def initialize(name, slack_id, real_name, status_text, status_emoji) @name = name @slack_id = slack_id @real_name = real_name - @status_text = status_text + @status_text = status_text @status_emoji = status_emoji end def self.list - response = SlackCli::User.get + response = get users = response["members"].map do |user| name = user["name"] @@ -32,13 +32,6 @@ def self.list return users end - def self.list_users - list.each do |user| - puts "#{user.real_name} Slack ID: #{user.slack_id}" - end - return nil - end - def self.details user_details = "Username: #{name} Slack ID: #{slack_id} @@ -49,5 +42,3 @@ def self.details end end end - -binding.pry \ No newline at end of file diff --git a/lib/workspace.rb b/lib/workspace.rb index bd45cfae..6ffa9346 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -4,30 +4,43 @@ require "terminal-table" class Workspace - attr_reader :users, :channels, :selected + attr_reader :users, :channels, :selected, :list_users, :list_channels def initialize - @users = users, - @channels = channels, + @users = User.list + @channels = Channel.list @selected = selected end - def select_channel(channel) - # takes channel as user input + def select_channel(name) + # @selected = @channels.select { |channel| if channel.name == name || channel.slack_id == name } # test this end def select_user(user) - # takes user as user input + # @selected = @users.select { |user| if user.name == name || user.slack_id == name } # test this end def show_details(selected_item) - #puts selected_item.details + @selected.details end - def send_message(selected_item) - # puts "What would you like to say to #{selected_item}" - # message = gets.chomp - # selected_item.send_message("message") + def send_message + message = gets.chomp + @selected.send_message(name: @selected.name, message: message) + end + + def self.list_channels + @channels.each do |channel| + puts "Channel name: #{channel.name} ID: #{channel.slack_id} topic: #{channel.topic}, Member count:#{channel.member_count}" + end + return nil + end + + def self.list_users + @users.each do |user| + puts "#{user.real_name} Slack ID: #{user.slack_id}" + end + return nil end end @@ -45,6 +58,7 @@ def options - details - quit Enter your choice now:" + # selected = false end options @@ -52,16 +66,18 @@ def options loop do case choice when "list users" - puts SlackCli::User.list_users + puts SlackCli::Workspace.list_users when "list channels" - puts SlackCli::Channel.list_channels + puts SlackCli::Workspace.list_channels when "select user" puts "what user would you like to select?" selected_user = gets.chomp sought_user = SlackCli::Workspace.select_user(selected_user) + # selected = true if sought_user != nil + when "select channel" selected_channel = gets.chomp - sought_channel = SlackCli::Workspace.select_channel(selected_channel) + # sought_channel = SlackCli::Workspace.select_channel(selected_channel) when "details" # think about logic when "quit" diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 4266926b..4095523a 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -4,34 +4,25 @@ describe "initialize" do end - describe "user self.get method" do + describe "user self.get method" do it "successfully returns an HTTParty response object" do - VCR.use_cassette("user_response") do + VCR.use_cassette("user_response") do expect(SlackCli::User.get["ok"]).must_equal true end end end - describe "user self.list method" do + describe "user self.list method" do it "creates a list of all user objects" do - VCR.use_cassette("user_response") do + VCR.use_cassette("user_response") do user_list = SlackCli::User.list expect(user_list).must_be_kind_of Array - expect(user_list.first).must_be_instance_of SlackCli::User + expect(user_list.first).must_be_instance_of SlackCli::User expect(user_list.last).must_be_instance_of SlackCli::User end end - it "returns nil for a user that doesn't exist" do + it "returns nil for a user that doesn't exist" do end end - - describe "user self.list_users method" do - it "returns all usernames in workspace in array" do - VCR.use_cassette("user_response") do - expect(SlackCli::User.list_users).must_be_kind_of Array - expect(SlackCli::User.list_users.length).must_equal 3 - end - end - end -end \ No newline at end of file +end From 79412b7b7ad334fbdabb1af3688654f7964b6f82 Mon Sep 17 00:00:00 2001 From: Hana Date: Wed, 20 Mar 2019 18:23:23 -0700 Subject: [PATCH 46/69] list_channels and list_users methods --- lib/workspace.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index 6ffa9346..70300129 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -2,13 +2,15 @@ require_relative "user" require_relative "channel" require "terminal-table" +require 'pry' + class Workspace attr_reader :users, :channels, :selected, :list_users, :list_channels def initialize - @users = User.list - @channels = Channel.list + @users = SlackCli::User.list + @channels = SlackCli::Channel.list @selected = selected end @@ -29,23 +31,24 @@ def send_message @selected.send_message(name: @selected.name, message: message) end - def self.list_channels + def list_channels @channels.each do |channel| puts "Channel name: #{channel.name} ID: #{channel.slack_id} topic: #{channel.topic}, Member count:#{channel.member_count}" end return nil end - def self.list_users + def list_users @users.each do |user| puts "#{user.real_name} Slack ID: #{user.slack_id}" end - return nil + return nil end end #driver code def main + workspace = Workspace.new puts "TatiHana Slack Channels loaded #{SlackCli::Channel.list.length} channels" puts "TatiHana Users loaded #{SlackCli::User.list.length} users" @@ -66,9 +69,9 @@ def options loop do case choice when "list users" - puts SlackCli::Workspace.list_users + puts workspace.list_users when "list channels" - puts SlackCli::Workspace.list_channels + puts workspace.list_channels when "select user" puts "what user would you like to select?" selected_user = gets.chomp From c981d7118f89169118f5dab4519c4c2cd8fc5f40 Mon Sep 17 00:00:00 2001 From: Hana Date: Wed, 20 Mar 2019 19:12:03 -0700 Subject: [PATCH 47/69] working logic for select, bug for send_message --- lib/channel.rb | 2 +- lib/user.rb | 4 ++-- lib/workspace.rb | 33 ++++++++++++++++++++++----------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 66f213ad..c28c4136 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -26,7 +26,7 @@ def self.list end def details - return "Channel name: #{name} \nID: #{slack_id} \ntopic: #{topic}, \nMember count:#{member_count}\n" + puts "Channel name: #{name} \nID: #{slack_id} \ntopic: #{topic}, \nMember count:#{member_count}\n" end end end diff --git a/lib/user.rb b/lib/user.rb index 674a8040..d862dcd8 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -32,13 +32,13 @@ def self.list return users end - def self.details + def details user_details = "Username: #{name} Slack ID: #{slack_id} Real Name: #{real_name} Status Text: #{status_text} Status Emoji: #{status_emoji}" - return user_details + puts user_details end end end diff --git a/lib/workspace.rb b/lib/workspace.rb index 70300129..a551cd78 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -15,18 +15,22 @@ def initialize end def select_channel(name) - # @selected = @channels.select { |channel| if channel.name == name || channel.slack_id == name } # test this + @selected = @channels.find do |channel| + channel.name == name || channel.slack_id == name + end end - def select_user(user) - # @selected = @users.select { |user| if user.name == name || user.slack_id == name } # test this + def select_user(name) + @selected = @users.find do |user| + user.name == name || user.slack_id == name + end end - def show_details(selected_item) + def show_details @selected.details end - def send_message + def send_messagea # wrong number of arguments bug? message = gets.chomp @selected.send_message(name: @selected.name, message: message) end @@ -59,6 +63,7 @@ def options - select user - select channel - details + - send message - quit Enter your choice now:" # selected = false @@ -66,6 +71,7 @@ def options options choice = gets.chomp + loop do case choice when "list users" @@ -75,20 +81,25 @@ def options when "select user" puts "what user would you like to select?" selected_user = gets.chomp - sought_user = SlackCli::Workspace.select_user(selected_user) - # selected = true if sought_user != nil - + workspace.select_user(selected_user) when "select channel" + puts "What channel would you like to select?" selected_channel = gets.chomp - # sought_channel = SlackCli::Workspace.select_channel(selected_channel) + workspace.select_channel(selected_channel) + puts "Channels selected: #{your_selection.name}" when "details" - # think about logic + puts "Details for #{workspace.selected.name}..." + workspace.show_details + when "send message" + puts "What would you like to send to #{workspace.selected.name}?" + workspace.send_messagea # wrong number of arguments bug? when "quit" puts "Thanks for checking out TatiHana! Bye bye..." exit else - # add something here + puts "Invalid option! :(" end + options choice = gets.chomp end From e31cacec4eed3978a75872e9e7a689f5388d347a Mon Sep 17 00:00:00 2001 From: Hana Date: Thu, 21 Mar 2019 12:37:56 -0700 Subject: [PATCH 48/69] refactor send_message method and write some tests --- lib/recipient.rb | 22 ++++++++--------- lib/workspace.rb | 18 +++++++++----- specs/workspace_spec.rb | 54 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 17 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 29e9d354..b4a254b4 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -21,15 +21,16 @@ def initialize @name = name end - def self.send_message(name:, message:) - query_params = { + def send_message(name, message) + body_params = { token: TOKEN, + as_user: true, channel: name, text: message, } - response = HTTParty.post(MSG_URL, query: query_params) - - error_helper(response) + response = HTTParty.post(MSG_URL, body: body_params) + # error_helper(response) + return response end def self.get @@ -37,7 +38,7 @@ def self.get token: TOKEN, } response = HTTParty.get(self::LIST_URL, query: query_params) - error_helper(response) + # error_helper(response) return response end @@ -50,12 +51,11 @@ def self.list raise NotImplementedError end - def self.error_helper(response) - if response["ok"] != true - raise SlackError, "#{response["error"]}" - else - return response + def error_helper(response) + unless response.code != 200 || !response["ok"] + raise SlackError, "Error #{response.code}: #{response["error"]}" end + return response end end end diff --git a/lib/workspace.rb b/lib/workspace.rb index a551cd78..90a4ff08 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -12,6 +12,10 @@ def initialize @users = SlackCli::User.list @channels = SlackCli::Channel.list @selected = selected + + unless selected == nil + raise SlackCli::SlackError, "No user or channel selected" + end end def select_channel(name) @@ -30,14 +34,18 @@ def show_details @selected.details end - def send_messagea # wrong number of arguments bug? + def send_messagea + puts "What would you like to send to #{@selected.name}?" message = gets.chomp - @selected.send_message(name: @selected.name, message: message) + @selected.send_message(@selected.slack_id, message) end def list_channels @channels.each do |channel| - puts "Channel name: #{channel.name} ID: #{channel.slack_id} topic: #{channel.topic}, Member count:#{channel.member_count}" + puts "Channel name: #{channel.name} + ID: #{channel.slack_id} + Topic: #{channel.topic} + Member count:#{channel.member_count}" end return nil end @@ -86,13 +94,11 @@ def options puts "What channel would you like to select?" selected_channel = gets.chomp workspace.select_channel(selected_channel) - puts "Channels selected: #{your_selection.name}" when "details" puts "Details for #{workspace.selected.name}..." workspace.show_details when "send message" - puts "What would you like to send to #{workspace.selected.name}?" - workspace.send_messagea # wrong number of arguments bug? + workspace.send_messagea when "quit" puts "Thanks for checking out TatiHana! Bye bye..." exit diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index e69de29b..cc21aa6b 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -0,0 +1,54 @@ +require_relative 'test_helper' + +describe "Workspace class" do + before(:each) do + VCR.insert_cassette("workspace_response") + end + after(:each) do + VCR.eject_cassette + end + let(:workspace) { + workspace = Workspace.new + } + + describe "initialize" do + it "returns an array of User instances" do + expect(workspace.users).must_be_kind_of Array + expect(workspace.users.first).must_be_kind_of SlackCli::User + end + + it "returns an array of Channel instances" do + expect(workspace.channels).must_be_kind_of Array + expect(workspace.channels.first).must_be_kind_of SlackCli::Channel + end + + it "returns nil for no selected class" do + expect(workspace.selected).must_equal nil + # expect { + # workspace.selected + # }.must_raise SlackCli::SlackError + end + end + + describe "select_channel method" do + it "returns selected instance of channel" do + expect(workspace.select_channel("everyone")).must_be_instance_of SlackCli::Channel + expect(workspace.select_channel("everyone").name).must_equal "everyone" + end + + it "returns nil if no channel selected" do + expect(workspace.select_channel("")).must_equal nil + end + end + + describe "select_user method" do + it "returns selected instance of user" do + expect(workspace.select_user("hanalways")).must_be_instance_of SlackCli::User + expect(workspace.select_user("tatsqui").name).must_equal "tatsqui" + end + + it "returns nil if no user selected" do + expect(workspace.select_user("")).must_equal nil + end + end +end \ No newline at end of file From b230f924ed62f7959d9d130a3d79bd36538a7575 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Thu, 21 Mar 2019 13:19:34 -0700 Subject: [PATCH 49/69] moved driver code into slack.rb --- lib/slack.rb | 67 ++++++++++++++++++++++++++++++++++++------------ lib/workspace.rb | 57 +--------------------------------------- 2 files changed, 51 insertions(+), 73 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index c53dbedf..03f5b526 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,23 +1,56 @@ -# #!/usr/bin/env ruby -# require "dotenv" -# require "httparty" -# require "pry" -# require "awesome_print" -# Dotenv.load +require_relative 'workspace' -# def main -# puts "Welcome to the Ada Slack CLI!" +#driver code +def main + workspace = Workspace.new + puts "TatiHana Slack Channels loaded #{SlackCli::Channel.list.length} channels" + puts "TatiHana Users loaded #{SlackCli::User.list.length} users" -# url = "https://slack.com/api/channels.list" + def options + puts "Please choose one of the following options: + - list users + - list channels + - select user + - select channel + - details + - send message + - quit + Enter your choice now:" + # selected = false + end -# query_params = { token: ENV["API_KEY"] } + options + choice = gets.chomp -# response = HTTParty.get(url, query: query_params) + loop do + case choice + when "list users" + puts workspace.list_users + when "list channels" + puts workspace.list_channels + when "select user" + puts "what user would you like to select?" + selected_user = gets.chomp + workspace.select_user(selected_user) + when "select channel" + puts "What channel would you like to select?" + selected_channel = gets.chomp + workspace.select_channel(selected_channel) + when "details" + puts "Details for #{workspace.selected.name}..." + workspace.show_details + when "send message" + workspace.send_messagea + when "quit" + puts "Thanks for checking out TatiHana! Bye bye..." + exit + else + puts "Invalid option! :(" + end -# response["channels"].each do |channel| -# puts channel["name"] -# end -# puts "Thank you for using the Ada Slack CLI" -# end + options + choice = gets.chomp + end +end -# main if __FILE__ == $PROGRAM_NAME +main if __FILE__ == $0 diff --git a/lib/workspace.rb b/lib/workspace.rb index 90a4ff08..acc116bf 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -56,59 +56,4 @@ def list_users end return nil end -end - -#driver code -def main - workspace = Workspace.new - puts "TatiHana Slack Channels loaded #{SlackCli::Channel.list.length} channels" - puts "TatiHana Users loaded #{SlackCli::User.list.length} users" - - def options - puts "Please choose one of the following options: - - list users - - list channels - - select user - - select channel - - details - - send message - - quit - Enter your choice now:" - # selected = false - end - - options - choice = gets.chomp - - loop do - case choice - when "list users" - puts workspace.list_users - when "list channels" - puts workspace.list_channels - when "select user" - puts "what user would you like to select?" - selected_user = gets.chomp - workspace.select_user(selected_user) - when "select channel" - puts "What channel would you like to select?" - selected_channel = gets.chomp - workspace.select_channel(selected_channel) - when "details" - puts "Details for #{workspace.selected.name}..." - workspace.show_details - when "send message" - workspace.send_messagea - when "quit" - puts "Thanks for checking out TatiHana! Bye bye..." - exit - else - puts "Invalid option! :(" - end - - options - choice = gets.chomp - end -end - -main if __FILE__ == $0 +end \ No newline at end of file From 6b0725b0e60da840a7875ea9d7be4408064973d0 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Thu, 21 Mar 2019 13:26:22 -0700 Subject: [PATCH 50/69] commented out tests for superclass Recipient --- specs/recipient_spec.rb | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 635365da..978b678d 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -1,29 +1,19 @@ require_relative "test_helper" -describe "Recipient" do - describe "initialize" do - end +# probably don't need any tests for abstract superclass. +# describe "Recipient" do +# describe "initialize" do +# end - describe "send message" do - it "can post a message on the everyone slack channel" do - VCR.use_cassette("message_post") do - name = "everyone" - text = "hello world" - pigeon = SlackCli::Recipient.send_message(name: name, message: text) +# describe "send message" do +# it "can post a message on the everyone slack channel" do +# VCR.use_cassette("message_post") do +# name = "everyone" +# text = "hello world" +# pigeon = SlackCli::Recipient.send_message(name: name, message: text) - expect(pigeon["ok"]).must_equal true - end - end - - it "raises a SlackError with bad parameters" do - VCR.use_cassette("message_post") do - name = "" - text = "this should not send" - - expect { - SlackCli::Recipient.send_message(name: name, message: text) - }.must_raise SlackCli::SlackError - end - end - end -end +# expect(pigeon["ok"]).must_equal true +# end +# end +# end +# end From 1d12a37fae1d02f2019b8dbcde14ac67903eb524 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Thu, 21 Mar 2019 13:48:42 -0700 Subject: [PATCH 51/69] miscellaneous changes in channel and user specs --- lib/channel.rb | 13 ++----------- specs/channel_spec.rb | 9 ++++----- specs/user_spec.rb | 27 ++++++++++++++------------- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index c28c4136..6f827a4b 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -26,17 +26,8 @@ def self.list end def details - puts "Channel name: #{name} \nID: #{slack_id} \ntopic: #{topic}, \nMember count:#{member_count}\n" + deets = "Channel name: #{name} \nID: #{slack_id} \ntopic: #{topic}, \nMember count:#{member_count}\n" + return deets end end end - -#add this to recipient? -# def send_message(message) -# query_params = { -# token: TOKEN -# name: self -# message: message -# } -# response = HTTParty.post(self::MSG_URL, query: query_params) -#end diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index dcf9a4da..bae6db28 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -2,10 +2,10 @@ describe "Channel" do let(:get_response) do - VCR.use_cassette("slack/get") { SlackCli::Channel.get } + VCR.use_cassette("slack/channel_get") { SlackCli::Channel.get } end let(:channel_list) do - VCR.use_cassette("slack/list") { SlackCli::Channel.list } + VCR.use_cassette("slack/channel_list") { SlackCli::Channel.list } end describe "self get method" do @@ -15,6 +15,7 @@ expect(channels["ok"]).must_equal true end end + describe "list" do it "creates a list of all channels" do channels = channel_list @@ -29,9 +30,7 @@ describe "details" do it "lists details for an instance of channel" do channels = channel_list - channel_deets = channels[1].details - - expect(channel_deets).must_equal channels[1].details + expect(channels[1].details).must_be_kind_of String end end end diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 4095523a..76a0183d 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -1,28 +1,29 @@ require_relative "test_helper.rb" describe "User child class" do - describe "initialize" do + let(:get_response) do + VCR.use_cassette("slack/user_get") { SlackCli::User.get } + end + let(:users_list) do + VCR.use_cassette("slack/user_list") { SlackCli::User.list } end describe "user self.get method" do it "successfully returns an HTTParty response object" do - VCR.use_cassette("user_response") do - expect(SlackCli::User.get["ok"]).must_equal true - end + users = get_response + + expect(users["ok"]).must_equal true end end + describe "user self.list method" do it "creates a list of all user objects" do - VCR.use_cassette("user_response") do - user_list = SlackCli::User.list - - expect(user_list).must_be_kind_of Array - expect(user_list.first).must_be_instance_of SlackCli::User - expect(user_list.last).must_be_instance_of SlackCli::User - end - end + + user_list = users_list - it "returns nil for a user that doesn't exist" do + expect(user_list).must_be_kind_of Array + expect(user_list.first).must_be_instance_of SlackCli::User + expect(user_list.last).must_be_instance_of SlackCli::User end end end From 624b2b47e63f17f1cf0c9ee10301e5844360c9c1 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Thu, 21 Mar 2019 13:50:55 -0700 Subject: [PATCH 52/69] changed #details to return variable in method --- lib/user.rb | 2 +- specs/channel_spec.rb | 8 ++++---- specs/user_spec.rb | 10 ++++++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index d862dcd8..ac860778 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -38,7 +38,7 @@ def details Real Name: #{real_name} Status Text: #{status_text} Status Emoji: #{status_emoji}" - puts user_details + return user_details end end end diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index bae6db28..1bb8e274 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -15,7 +15,7 @@ expect(channels["ok"]).must_equal true end end - + describe "list" do it "creates a list of all channels" do channels = channel_list @@ -28,9 +28,9 @@ end describe "details" do - it "lists details for an instance of channel" do - channels = channel_list - expect(channels[1].details).must_be_kind_of String + it "lists details for an instance of Channel" do + channel = channel_list[1] + expect(channel.details).must_be_kind_of String end end end diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 76a0183d..85c317d5 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -11,14 +11,13 @@ describe "user self.get method" do it "successfully returns an HTTParty response object" do users = get_response - + expect(users["ok"]).must_equal true end end describe "user self.list method" do it "creates a list of all user objects" do - user_list = users_list expect(user_list).must_be_kind_of Array @@ -26,4 +25,11 @@ expect(user_list.last).must_be_instance_of SlackCli::User end end + + describe "details" do + it "lists details for an instance of User" do + user = users_list[1] + expect(user.details).must_be_kind_of String + end + end end From 0f95b0703da9df2f4d2fdcf86e5f1ede63a7465b Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Thu, 21 Mar 2019 13:52:10 -0700 Subject: [PATCH 53/69] making tests in user and channel specs more congruent --- specs/channel_spec.rb | 2 ++ specs/user_spec.rb | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 1bb8e274..0e11fd12 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -21,6 +21,7 @@ channels = channel_list expect(channels).must_be_kind_of Array + channels.each do |channel| expect(channel).must_be_instance_of SlackCli::Channel end @@ -30,6 +31,7 @@ describe "details" do it "lists details for an instance of Channel" do channel = channel_list[1] + expect(channel.details).must_be_kind_of String end end diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 85c317d5..b6646f4a 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -1,4 +1,4 @@ -require_relative "test_helper.rb" +require_relative "test_helper" describe "User child class" do let(:get_response) do @@ -29,6 +29,7 @@ describe "details" do it "lists details for an instance of User" do user = users_list[1] + expect(user.details).must_be_kind_of String end end From 1a18c7dded5ca42777bcda236938d7bff7204507 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Thu, 21 Mar 2019 14:05:37 -0700 Subject: [PATCH 54/69] added more selected_user/channel validation tests --- specs/workspace_spec.rb | 45 ++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index cc21aa6b..8c86c625 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -1,6 +1,6 @@ -require_relative 'test_helper' +require_relative "test_helper" -describe "Workspace class" do +describe "Workspace class" do before(:each) do VCR.insert_cassette("workspace_response") end @@ -12,43 +12,46 @@ } describe "initialize" do - it "returns an array of User instances" do + it "returns an array of User instances" do expect(workspace.users).must_be_kind_of Array - expect(workspace.users.first).must_be_kind_of SlackCli::User + expect(workspace.users.first).must_be_instance_of SlackCli::User + expect(workspace.users.last).must_be_instance_of SlackCli::User end - it "returns an array of Channel instances" do - expect(workspace.channels).must_be_kind_of Array - expect(workspace.channels.first).must_be_kind_of SlackCli::Channel + it "returns an array of Channel instances" do + expect(workspace.channels).must_be_kind_of Array + expect(workspace.channels.first).must_be_instance_of SlackCli::Channel + expect(workspace.channels.last).must_be_instance_of SlackCli::Channel end - it "returns nil for no selected class" do - expect(workspace.selected).must_equal nil - # expect { - # workspace.selected - # }.must_raise SlackCli::SlackError - end + it "@selected is nil prior to selecting a user or channel" do + assert_nil(workspace.selected) + end end - describe "select_channel method" do - it "returns selected instance of channel" do + describe "select_channel method" do + it "returns selected instance of channel" do expect(workspace.select_channel("everyone")).must_be_instance_of SlackCli::Channel expect(workspace.select_channel("everyone").name).must_equal "everyone" + expect(workspace.selected.name).must_equal "everyone" + expect(workspace.selected.slack_id).must_equal "CH2RAKATW" end - it "returns nil if no channel selected" do + it "returns nil if no channel selected" do expect(workspace.select_channel("")).must_equal nil end end - describe "select_user method" do - it "returns selected instance of user" do + describe "select_user method" do + it "returns selected instance of user" do expect(workspace.select_user("hanalways")).must_be_instance_of SlackCli::User expect(workspace.select_user("tatsqui").name).must_equal "tatsqui" + expect(workspace.selected.name).must_equal "tatsqui" + expect(workspace.selected.slack_id).must_equal "UH2NZ7X7V" end - it "returns nil if no user selected" do - expect(workspace.select_user("")).must_equal nil + it "returns nil if no user selected" do + assert_nil(workspace.select_user("")) end end -end \ No newline at end of file +end From 54b43c0a96f87bed0b4de7a867a26348638c69e3 Mon Sep 17 00:00:00 2001 From: Hana Date: Thu, 21 Mar 2019 15:41:10 -0700 Subject: [PATCH 55/69] details method updated with error --- lib/workspace.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index acc116bf..1c4413f9 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -31,7 +31,12 @@ def select_user(name) end def show_details - @selected.details + if @selected == nil + raise SlackCli::SlackError, "No user or channel selected!" + else + puts "Details for #{workspace.selected.name}..." + @selected.details + end end def send_messagea From 64d648f4801157df91d243a72e72fb49a90edf55 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Thu, 21 Mar 2019 15:41:15 -0700 Subject: [PATCH 56/69] "working out #details exception" --- lib/recipient.rb | 6 ++---- specs/slack_spec.rb | 9 +-------- specs/workspace_spec.rb | 6 ++++++ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index b4a254b4..af2e8c22 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -3,13 +3,11 @@ require "dotenv" Dotenv.load - + module SlackCli class SlackError < StandardError; end class Recipient - - MSG_URL = "https://slack.com/api/chat.postMessage" LIST_URL = nil TOKEN = ENV["SLACK_TOKEN"] @@ -21,7 +19,7 @@ def initialize @name = name end - def send_message(name, message) + def post_message(name, message) body_params = { token: TOKEN, as_user: true, diff --git a/specs/slack_spec.rb b/specs/slack_spec.rb index 0a0524dd..550681f1 100644 --- a/specs/slack_spec.rb +++ b/specs/slack_spec.rb @@ -1,8 +1 @@ -require_relative "test_helper.rb" - -describe "Slack" do - describe "test" do - it "passes" do - end - end -end +# AS WE LEARNED TODAY IN CLASS, WE DON'T NEED TO WRITE TESTS FOR DRIVER CODE!!! WOOOOOOOOO!!! \ No newline at end of file diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 8c86c625..5de47c40 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -54,4 +54,10 @@ assert_nil(workspace.select_user("")) end end + + describe "cases when our program should raise an exception created by user" do + end + + describe "cases when our program should raise an exception created by changes to API" do + end end From 1bba049fe487edb5966e5f379ab16d2baf881e8f Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Thu, 21 Mar 2019 15:43:56 -0700 Subject: [PATCH 57/69] trying out tri-error block --- lib/slack.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 03f5b526..4c6ec6b6 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -21,7 +21,6 @@ def options options choice = gets.chomp - loop do case choice when "list users" @@ -37,20 +36,21 @@ def options selected_channel = gets.chomp workspace.select_channel(selected_channel) when "details" - puts "Details for #{workspace.selected.name}..." - workspace.show_details + begin + puts workspace.show_details + rescue SlackCli::SlackError + break + end when "send message" - workspace.send_messagea + workspace.send_message when "quit" puts "Thanks for checking out TatiHana! Bye bye..." exit - else + end puts "Invalid option! :(" end - - options - choice = gets.chomp - end + options + choice = gets.chomp end main if __FILE__ == $0 From 4de51889c195f4975c9216382704bc0ba335a8f6 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Thu, 21 Mar 2019 15:59:07 -0700 Subject: [PATCH 58/69] rescue details when selected nil --- lib/slack.rb | 10 +++++----- lib/workspace.rb | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 4c6ec6b6..a6afab9c 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -37,9 +37,10 @@ def options workspace.select_channel(selected_channel) when "details" begin - puts workspace.show_details - rescue SlackCli::SlackError - break + puts workspace.show_details + puts "this worked!!!!!!!!!" + rescue + puts "it's calling this instead" end when "send message" workspace.send_message @@ -47,10 +48,9 @@ def options puts "Thanks for checking out TatiHana! Bye bye..." exit end - puts "Invalid option! :(" - end options choice = gets.chomp + end end main if __FILE__ == $0 diff --git a/lib/workspace.rb b/lib/workspace.rb index 1c4413f9..5ad88aae 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -34,12 +34,12 @@ def show_details if @selected == nil raise SlackCli::SlackError, "No user or channel selected!" else - puts "Details for #{workspace.selected.name}..." + # puts "Details for #{workspace.selected.name}..." @selected.details end end - def send_messagea + def send_message puts "What would you like to send to #{@selected.name}?" message = gets.chomp @selected.send_message(@selected.slack_id, message) From 6b7fd8ea2cdfc97ffea400f757b97ad82e6e263d Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Thu, 21 Mar 2019 15:59:56 -0700 Subject: [PATCH 59/69] added real error message --- lib/slack.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index a6afab9c..26a5361a 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,4 +1,4 @@ -require_relative 'workspace' +require_relative "workspace" #driver code def main @@ -37,10 +37,9 @@ def options workspace.select_channel(selected_channel) when "details" begin - puts workspace.show_details - puts "this worked!!!!!!!!!" + puts workspace.show_details rescue - puts "it's calling this instead" + puts "No user or channel selected, try again." end when "send message" workspace.send_message @@ -48,8 +47,8 @@ def options puts "Thanks for checking out TatiHana! Bye bye..." exit end - options - choice = gets.chomp + options + choice = gets.chomp end end From bf211e27e513d55fcdef7c6fb2fd9f93c2ab127d Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Thu, 21 Mar 2019 16:43:09 -0700 Subject: [PATCH 60/69] "writing edge case tests for workspace" --- lib/slack.rb | 4 +++- lib/workspace.rb | 11 +++++---- specs/workspace_spec.rb | 50 ++++++++++++++++++++++++++++++++++++----- 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 26a5361a..3c731e8e 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -42,7 +42,9 @@ def options puts "No user or channel selected, try again." end when "send message" - workspace.send_message + puts "What would you like to send to #{@selected.name}?" + message = gets.chomp + workspace.send_message(message) when "quit" puts "Thanks for checking out TatiHana! Bye bye..." exit diff --git a/lib/workspace.rb b/lib/workspace.rb index 5ad88aae..7731fbd0 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -39,10 +39,13 @@ def show_details end end - def send_message - puts "What would you like to send to #{@selected.name}?" - message = gets.chomp - @selected.send_message(@selected.slack_id, message) + def send_message(message) + message.strip! + if message.length == 0 + raise SlackCli::SlackError, "Message must cannot be nil or blank..." + else + @selected.send_message(@selected.slack_id, message) + end end def list_channels diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 5de47c40..1b03e2ea 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -24,7 +24,7 @@ expect(workspace.channels.last).must_be_instance_of SlackCli::Channel end - it "@selected is nil prior to selecting a user or channel" do + it "@selected is nil prior to selecting a user or channel" do assert_nil(workspace.selected) end end @@ -38,7 +38,8 @@ end it "returns nil if no channel selected" do - expect(workspace.select_channel("")).must_equal nil + assert_nil(workspace.select_channel("")) + assert_nil(workspace.select_channel(nil)) end end @@ -52,12 +53,51 @@ it "returns nil if no user selected" do assert_nil(workspace.select_user("")) + assert_nil(workspace.select_user(nil)) end end - describe "cases when our program should raise an exception created by user" do - end + describe "cases when our program should raise an exception..." do + it "should raise an exception created by changes to API" do + class Dummy < SlackCli::Recipient + LIST_URL = "http://slack.com/api/users.list" + BADTOKEN = "123" + def self.get + query_params = { + token: BADTOKEN, + } + response = HTTParty.get(self::LIST_URL, query: query_params) + # error_helper(response) + return response + end + end + + test_dummy = Dummy.get + expect(test_dummy["ok"]).must_equal false + expect(test_dummy["error"]).must_equal "invalid_auth" + end + + it "should raise an exception created by changes to API URI" do + class Dummy < SlackCli::Recipient + LIST_URL = "http://slack.com/api/users.lis" + def self.get + query_params = { + token: TOKEN, + } + response = HTTParty.get(self::LIST_URL, query: query_params) + # error_helper(response) + return response + end + end - describe "cases when our program should raise an exception created by changes to API" do + test_dummy = Dummy.get + expect(test_dummy["ok"]).must_equal false + expect(test_dummy["req_method"]).must_equal "users.lis" + end + + it "raise an exception when a user enters nil in send_message" do + message = "" + expect { workspace.send_message(message) }.must_raise SlackCli::SlackError + end end end From 0f93205395219daf6d1b2e71519f7bc699f5cac3 Mon Sep 17 00:00:00 2001 From: Hana Date: Thu, 21 Mar 2019 18:25:51 -0700 Subject: [PATCH 61/69] additional tests for coverage --- lib/recipient.rb | 4 +- lib/workspace.rb | 9 +---- specs/recipient_spec.rb | 87 +++++++++++++++++++++++++++++++++-------- specs/test_helper.rb | 4 ++ specs/workspace_spec.rb | 66 +++++++++++++++---------------- 5 files changed, 111 insertions(+), 59 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index af2e8c22..473765e9 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -40,7 +40,6 @@ def self.get return response end - #private def details raise NotImplementedError end @@ -49,8 +48,9 @@ def self.list raise NotImplementedError end + # private def error_helper(response) - unless response.code != 200 || !response["ok"] + unless response.code == 200 && response["ok"] raise SlackError, "Error #{response.code}: #{response["error"]}" end return response diff --git a/lib/workspace.rb b/lib/workspace.rb index 7731fbd0..5ab63695 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,7 +1,7 @@ # workspace require_relative "user" require_relative "channel" -require "terminal-table" +require "table_print" require 'pry' @@ -12,10 +12,6 @@ def initialize @users = SlackCli::User.list @channels = SlackCli::Channel.list @selected = selected - - unless selected == nil - raise SlackCli::SlackError, "No user or channel selected" - end end def select_channel(name) @@ -34,7 +30,6 @@ def show_details if @selected == nil raise SlackCli::SlackError, "No user or channel selected!" else - # puts "Details for #{workspace.selected.name}..." @selected.details end end @@ -44,7 +39,7 @@ def send_message(message) if message.length == 0 raise SlackCli::SlackError, "Message must cannot be nil or blank..." else - @selected.send_message(@selected.slack_id, message) + @selected.post_message(@selected.slack_id, message) end end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 978b678d..6f1254ad 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -1,19 +1,72 @@ require_relative "test_helper" -# probably don't need any tests for abstract superclass. -# describe "Recipient" do -# describe "initialize" do -# end - -# describe "send message" do -# it "can post a message on the everyone slack channel" do -# VCR.use_cassette("message_post") do -# name = "everyone" -# text = "hello world" -# pigeon = SlackCli::Recipient.send_message(name: name, message: text) - -# expect(pigeon["ok"]).must_equal true -# end -# end -# end -# end +# tests for abstract methods for classes + +describe "cases when our program should raise an exception..." do + before(:each) do + VCR.insert_cassette("recipient_response") + end + after(:each) do + VCR.eject_cassette + end + let(:workspace) { + workspace = Workspace.new + } + + it "should raise an exception created by changes to API" do + class Dummy < SlackCli::Recipient + LIST_URL = "http://slack.com/api/users.list" + BADTOKEN = "123" + def self.get + query_params = { + token: BADTOKEN, + } + response = HTTParty.get(self::LIST_URL, query: query_params) + return response + end + end + + test_dummy = Dummy.get + expect(test_dummy["ok"]).must_equal false + expect(test_dummy["error"]).must_equal "invalid_auth" + end + + it "should raise an exception created by changes to API URI" do + class Dummy < SlackCli::Recipient + LIST_URL = "http://slack.com/api/users.lis" + def self.get + query_params = { + token: TOKEN, + } + response = HTTParty.get(self::LIST_URL, query: query_params) + return response + end + end + + test_dummy = Dummy.get + expect(test_dummy["ok"]).must_equal false + expect(test_dummy["req_method"]).must_equal "users.lis" + end + + + + # it "should raise an exception for bad POST token" do + # class Dummy < SlackCli::Recipient + # MSG_URL = "https://slack.com/api/chat.postMessage" + # def self.post_message + # params = { + # token: "BADTOKEN", + # as_user: true, + # channel: name, + # text: message, + # } + # response = HTTParty.post(MSG_URL, body: params) + # return response + # end + # end + + # test_dummy = Dummy.new + # expect(test_dummy.post_message("everyone", "test string")["ok"]).must_equal false + # expect(test_dummy["error"]).must_equal "invalid_auth" + # end +end \ No newline at end of file diff --git a/specs/test_helper.rb b/specs/test_helper.rb index ad890d1a..f4cdba18 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -1,3 +1,7 @@ +require 'simplecov' +SimpleCov.start do + add_filter %r{^/specs?/} +end require "minitest" require "minitest/autorun" require "minitest/reporters" diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 1b03e2ea..69785312 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -57,47 +57,47 @@ end end - describe "cases when our program should raise an exception..." do - it "should raise an exception created by changes to API" do - class Dummy < SlackCli::Recipient - LIST_URL = "http://slack.com/api/users.list" - BADTOKEN = "123" - def self.get - query_params = { - token: BADTOKEN, - } - response = HTTParty.get(self::LIST_URL, query: query_params) - # error_helper(response) - return response - end - end - - test_dummy = Dummy.get - expect(test_dummy["ok"]).must_equal false - expect(test_dummy["error"]).must_equal "invalid_auth" + describe "show details method" do + it "returns details for a selected user" do + workspace.select_user("hanalways") + expect(workspace.show_details).must_be_kind_of String end - it "should raise an exception created by changes to API URI" do - class Dummy < SlackCli::Recipient - LIST_URL = "http://slack.com/api/users.lis" - def self.get - query_params = { - token: TOKEN, - } - response = HTTParty.get(self::LIST_URL, query: query_params) - # error_helper(response) - return response - end - end + it "returns details for a selected channel" do + workspace.select_channel("everyone") + expect(workspace.show_details).must_be_kind_of String + end - test_dummy = Dummy.get - expect(test_dummy["ok"]).must_equal false - expect(test_dummy["req_method"]).must_equal "users.lis" + it "must raise SlackError for no selected user or channel" do + workspace.select_channel("") + expect { + workspace.show_details + }.must_raise SlackCli::SlackError end + end + describe "send_message method" do it "raise an exception when a user enters nil in send_message" do message = "" expect { workspace.send_message(message) }.must_raise SlackCli::SlackError end + + it "successfully sends a message with selected user" do + workspace.select_user("tatsqui") + test_message = workspace.send_message("test") + expect(test_message["ok"]).must_equal true + end + end + + describe "list_channels method" do + it "returns details of a channel as nil" do + assert_nil(workspace.list_channels) + end + end + + describe "list_users method" do + it "returns details of a user as nil" do + assert_nil(workspace.list_users) + end end end From 53788e2570c88ae0b72928240bd2e229fb20698c Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Thu, 21 Mar 2019 20:49:46 -0700 Subject: [PATCH 62/69] "made .error_helper a class method" --- lib/recipient.rb | 11 +++++------ lib/workspace.rb | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index af2e8c22..6c287173 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -27,8 +27,8 @@ def post_message(name, message) text: message, } response = HTTParty.post(MSG_URL, body: body_params) - # error_helper(response) - return response + return error_helper(response) + # return response end def self.get @@ -36,8 +36,7 @@ def self.get token: TOKEN, } response = HTTParty.get(self::LIST_URL, query: query_params) - # error_helper(response) - return response + return error_helper(response) end #private @@ -49,8 +48,8 @@ def self.list raise NotImplementedError end - def error_helper(response) - unless response.code != 200 || !response["ok"] + def self.error_helper(response) + unless response.code == 200 && response["ok"] raise SlackError, "Error #{response.code}: #{response["error"]}" end return response diff --git a/lib/workspace.rb b/lib/workspace.rb index 7731fbd0..af0aa473 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -44,7 +44,7 @@ def send_message(message) if message.length == 0 raise SlackCli::SlackError, "Message must cannot be nil or blank..." else - @selected.send_message(@selected.slack_id, message) + @selected.post_message(@selected.slack_id, message) end end From a33963fafe19819c6cf781783e7a35cc900b49d4 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Fri, 22 Mar 2019 10:59:17 -0700 Subject: [PATCH 63/69] list_url template method, moved some tests into recipient --- lib/channel.rb | 7 +++-- lib/recipient.rb | 20 ++++++++----- lib/slack.rb | 11 ++++++-- lib/user.rb | 7 +++-- lib/workspace.rb | 29 ++++++++++--------- specs/recipient_spec.rb | 62 +++++++++++++++++++++++++++++++---------- specs/test_helper.rb | 5 ++++ specs/workspace_spec.rb | 43 +++++----------------------- 8 files changed, 103 insertions(+), 81 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 6f827a4b..2faf7d15 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -3,8 +3,6 @@ module SlackCli class Channel < SlackCli::Recipient attr_reader :topic, :member_count - LIST_URL = "https://slack.com/api/channels.list" - def initialize(slack_id, name, topic, member_count) @slack_id = slack_id @name = name @@ -12,9 +10,12 @@ def initialize(slack_id, name, topic, member_count) @member_count = member_count end + def self.list_url + return "https://slack.com/api/channels.list" + end + def self.list response = get - channels = response["channels"].map do |channel| slack_id = channel["id"] name = channel["name"] diff --git a/lib/recipient.rb b/lib/recipient.rb index 6c287173..ee5b1673 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -9,7 +9,6 @@ class SlackError < StandardError; end class Recipient MSG_URL = "https://slack.com/api/chat.postMessage" - LIST_URL = nil TOKEN = ENV["SLACK_TOKEN"] attr_reader :send_message, :name, :slack_id, :error_helper, :details, :list @@ -19,6 +18,10 @@ def initialize @name = name end + def self.list_url + raise NotImplementedError, "TODO: implement me in a child class" + end + def post_message(name, message) body_params = { token: TOKEN, @@ -27,25 +30,28 @@ def post_message(name, message) text: message, } response = HTTParty.post(MSG_URL, body: body_params) - return error_helper(response) - # return response + + if response != 200 && !response["ok"] + raise SlackCli::SlackError "Error: #{response["error"]}" + else + return response + end end def self.get query_params = { token: TOKEN, } - response = HTTParty.get(self::LIST_URL, query: query_params) + response = HTTParty.get(list_url, query: query_params) return error_helper(response) end - #private def details - raise NotImplementedError + raise NotImplementedError "TODO: implement me in a child class" end def self.list - raise NotImplementedError + raise NotImplementedError "TODO: implement me in a child class" end def self.error_helper(response) diff --git a/lib/slack.rb b/lib/slack.rb index 3c731e8e..33ecf0a7 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -42,9 +42,14 @@ def options puts "No user or channel selected, try again." end when "send message" - puts "What would you like to send to #{@selected.name}?" - message = gets.chomp - workspace.send_message(message) + begin + puts "What would you like to send to #{workspace.selected.name}?" + message = gets.chomp + workspace.send_message(message) + binding.pry + rescue SlackCli::SlackError + puts "No user or channel selected, try again" + end when "quit" puts "Thanks for checking out TatiHana! Bye bye..." exit diff --git a/lib/user.rb b/lib/user.rb index ac860778..9ce3c4f3 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -4,9 +4,6 @@ module SlackCli class User < Recipient - LIST_URL = "https://slack.com/api/users.list" - TOKEN = ENV["SLACK_TOKEN"] - attr_reader :real_name, :status_text, :status_emoji def initialize(name, slack_id, real_name, status_text, status_emoji) @@ -17,6 +14,10 @@ def initialize(name, slack_id, real_name, status_text, status_emoji) @status_emoji = status_emoji end + def self.list_url + return "https://slack.com/api/users.list" + end + def self.list response = get diff --git a/lib/workspace.rb b/lib/workspace.rb index af0aa473..207bd733 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -2,8 +2,7 @@ require_relative "user" require_relative "channel" require "terminal-table" -require 'pry' - +require "pry" class Workspace attr_reader :users, :channels, :selected, :list_users, :list_channels @@ -11,21 +10,17 @@ class Workspace def initialize @users = SlackCli::User.list @channels = SlackCli::Channel.list - @selected = selected - - unless selected == nil - raise SlackCli::SlackError, "No user or channel selected" - end + @selected = nil end def select_channel(name) - @selected = @channels.find do |channel| + @selected = @channels.find do |channel| channel.name == name || channel.slack_id == name end end def select_user(name) - @selected = @users.find do |user| + @selected = @users.find do |user| user.name == name || user.slack_id == name end end @@ -40,11 +35,15 @@ def show_details end def send_message(message) - message.strip! - if message.length == 0 - raise SlackCli::SlackError, "Message must cannot be nil or blank..." + if @selected == nil + raise SlackCli::SlackError, "No user or channel selected!" else - @selected.post_message(@selected.slack_id, message) + message.strip! + if message.length == 0 + raise SlackCli::SlackError, "Message must cannot be nil or blank..." + else + @selected.post_message(@selected.slack_id, message) + end end end @@ -62,6 +61,6 @@ def list_users @users.each do |user| puts "#{user.real_name} Slack ID: #{user.slack_id}" end - return nil + return nil end -end \ No newline at end of file +end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 978b678d..e40d9c63 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -1,19 +1,53 @@ require_relative "test_helper" # probably don't need any tests for abstract superclass. -# describe "Recipient" do -# describe "initialize" do -# end +describe "Recipient" do + before(:each) do + VCR.insert_cassette("recipient/api_calls") + end + after(:each) do + VCR.eject_cassette + end -# describe "send message" do -# it "can post a message on the everyone slack channel" do -# VCR.use_cassette("message_post") do -# name = "everyone" -# text = "hello world" -# pigeon = SlackCli::Recipient.send_message(name: name, message: text) + describe "self.get" do + describe "cases when our program should raise an exception..." do + it "should raise an exception created by changes to API" do + class Dummy < SlackCli::Recipient + BADTOKEN = "123" -# expect(pigeon["ok"]).must_equal true -# end -# end -# end -# end + def self.list_url + return "http://slack.com/api/users.list" + end + + def self.get + query_params = { + token: BADTOKEN, + } + response = HTTParty.get(list_url, query: query_params) + return response + end + end + + test_dummy = Dummy.get + expect(test_dummy["ok"]).must_equal false + expect(test_dummy["error"]).must_equal "invalid_auth" + end + + it "should raise an exception created by changes to API URL" do + class Dummy < SlackCli::Recipient + def self.list_url + return "http://slack.com/api/users.lis" + end + def self.get + super + query_params = { + token: TOKEN, + } + end + end + + expect { Dummy.get }.must_raise SlackCli::SlackError + end + end + end +end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index ad890d1a..8f6469c9 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -1,3 +1,8 @@ +require "simplecov" +SimpleCov.start do + add_filter %r{^/specs?/} +end + require "minitest" require "minitest/autorun" require "minitest/reporters" diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 1b03e2ea..4383207f 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -57,45 +57,16 @@ end end - describe "cases when our program should raise an exception..." do - it "should raise an exception created by changes to API" do - class Dummy < SlackCli::Recipient - LIST_URL = "http://slack.com/api/users.list" - BADTOKEN = "123" - def self.get - query_params = { - token: BADTOKEN, - } - response = HTTParty.get(self::LIST_URL, query: query_params) - # error_helper(response) - return response - end - end + describe "send message" do + it "can post a message on the 'everyone' slack channel" do + workspace.select_channel("everyone") + text = "hello world" + pigeon = workspace.send_message(text) - test_dummy = Dummy.get - expect(test_dummy["ok"]).must_equal false - expect(test_dummy["error"]).must_equal "invalid_auth" + expect(pigeon["ok"]).must_equal true end - it "should raise an exception created by changes to API URI" do - class Dummy < SlackCli::Recipient - LIST_URL = "http://slack.com/api/users.lis" - def self.get - query_params = { - token: TOKEN, - } - response = HTTParty.get(self::LIST_URL, query: query_params) - # error_helper(response) - return response - end - end - - test_dummy = Dummy.get - expect(test_dummy["ok"]).must_equal false - expect(test_dummy["req_method"]).must_equal "users.lis" - end - - it "raise an exception when a user enters nil in send_message" do + it "raise an exception when a user enters nil in send_message" do message = "" expect { workspace.send_message(message) }.must_raise SlackCli::SlackError end From de4fa527070e27276c513a422d8b754df8e1753a Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Fri, 22 Mar 2019 11:09:05 -0700 Subject: [PATCH 64/69] added missing end workspace.rb --- lib/workspace.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index 4baa8d46..29998639 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -41,7 +41,8 @@ def send_message(message) if message.length == 0 raise SlackCli::SlackError, "Message must cannot be nil or blank..." else - @selected.post_message(@selected.slack_id, message) + @selected.post_message(@selected.slack_id, message) + end end end From bfcc4d57e5dfc2beaf89a12b6419c5c5f50d4bb6 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Fri, 22 Mar 2019 11:11:28 -0700 Subject: [PATCH 65/69] added missing ends in workspace_spec --- specs/workspace_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index efa06e78..3b9aef8d 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -65,8 +65,8 @@ expect(pigeon["ok"]).must_equal true end + end - it "raise an exception when a user enters nil in send_message" do describe "show details method" do it "returns details for a selected user" do workspace.select_user("hanalways") From 1d9024eed9157ba9cb961323119f98366f3bb560 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Fri, 22 Mar 2019 11:20:22 -0700 Subject: [PATCH 66/69] "editing style" --- specs/recipient_spec.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index e40d9c63..7ba6f805 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -8,8 +8,11 @@ after(:each) do VCR.eject_cassette end + let(:workspace) { + workspace = Workspace.new + } - describe "self.get" do + describe "self.get" do describe "cases when our program should raise an exception..." do it "should raise an exception created by changes to API" do class Dummy < SlackCli::Recipient @@ -27,16 +30,16 @@ def self.get return response end end - + test_dummy = Dummy.get expect(test_dummy["ok"]).must_equal false expect(test_dummy["error"]).must_equal "invalid_auth" end - + it "should raise an exception created by changes to API URL" do class Dummy < SlackCli::Recipient def self.list_url - return "http://slack.com/api/users.lis" + return "http://slack.com/api/users.lis" end def self.get super @@ -45,7 +48,7 @@ def self.get } end end - + expect { Dummy.get }.must_raise SlackCli::SlackError end end From df3c9f4dcae8d492938bdc1ce1a6bf000b1aea38 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Fri, 22 Mar 2019 11:43:10 -0700 Subject: [PATCH 67/69] hid view from simplecov, and some methods in Recipient that are only tested in subclasses --- lib/recipient.rb | 7 +++++-- lib/slack.rb | 4 +++- specs/test_helper.rb | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index ee5b1673..27f095ad 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -12,11 +12,12 @@ class Recipient TOKEN = ENV["SLACK_TOKEN"] attr_reader :send_message, :name, :slack_id, :error_helper, :details, :list - + # :nocov: def initialize @slack_id = slack_id @name = name end + # :nocov: def self.list_url raise NotImplementedError, "TODO: implement me in a child class" @@ -45,7 +46,8 @@ def self.get response = HTTParty.get(list_url, query: query_params) return error_helper(response) end - + + # :nocov: def details raise NotImplementedError "TODO: implement me in a child class" end @@ -53,6 +55,7 @@ def details def self.list raise NotImplementedError "TODO: implement me in a child class" end + # :nocov: def self.error_helper(response) unless response.code == 200 && response["ok"] diff --git a/lib/slack.rb b/lib/slack.rb index 33ecf0a7..d0fd7d68 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,6 +1,7 @@ require_relative "workspace" -#driver code + +# :nocov: def main workspace = Workspace.new puts "TatiHana Slack Channels loaded #{SlackCli::Channel.list.length} channels" @@ -60,3 +61,4 @@ def options end main if __FILE__ == $0 +# :nocov: diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 8f6469c9..affb5c80 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -13,7 +13,7 @@ require_relative "../lib/channel" require_relative "../lib/user" require_relative "../lib/workspace" -require_relative "../lib/recipient" +# require_relative "../lib/recipient" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 9097e7537509000d5802258e0e9dda52dbd6506c Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Fri, 22 Mar 2019 14:46:14 -0700 Subject: [PATCH 68/69] added checking for when the select_channel or user does not exist --- lib/slack.rb | 11 ++++++----- lib/workspace.rb | 11 +++++++++++ specs/workspace_spec.rb | 26 ++++++++++++++++---------- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index d0fd7d68..c04260fe 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,6 +1,5 @@ require_relative "workspace" - # :nocov: def main workspace = Workspace.new @@ -43,13 +42,15 @@ def options puts "No user or channel selected, try again." end when "send message" - begin - puts "What would you like to send to #{workspace.selected.name}?" + if workspace.selected == nil + puts "No user or channel selected" + else + # begin message = gets.chomp workspace.send_message(message) - binding.pry - rescue SlackCli::SlackError + # rescue SlackCli::SlackError puts "No user or channel selected, try again" + # end end when "quit" puts "Thanks for checking out TatiHana! Bye bye..." diff --git a/lib/workspace.rb b/lib/workspace.rb index 29998639..f9eec800 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -17,12 +17,23 @@ def select_channel(name) @selected = @channels.find do |channel| channel.name == name || channel.slack_id == name end + if @selected == nil + puts "That channel does not exist" + else + return @selected + end end def select_user(name) @selected = @users.find do |user| user.name == name || user.slack_id == name end + + if @selected == nil + puts "That user does not exist" + else + return @selected + end end def show_details diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 3b9aef8d..df41a5a1 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -67,13 +67,13 @@ end end - describe "show details method" do - it "returns details for a selected user" do + describe "show details method" do + it "returns details for a selected user" do workspace.select_user("hanalways") expect(workspace.show_details).must_be_kind_of String end - it "returns details for a selected channel" do + it "returns details for a selected channel" do workspace.select_channel("everyone") expect(workspace.show_details).must_be_kind_of String end @@ -86,9 +86,15 @@ end end - describe "send_message method" do - it "raise an exception when a user enters nil in send_message" do - message = "" + describe "send_message method" do + it "raise an exception when a trying to send a nil or blank message to a channel or user" do + workspace.select_user("tatsqui") + no_text = "" + expect { workspace.send_message(no_text) }.must_raise SlackCli::SlackError + end + + it "will raise and exception with a nil message" do + message = nil expect { workspace.send_message(message) }.must_raise SlackCli::SlackError end @@ -99,14 +105,14 @@ end end - describe "list_channels method" do - it "returns details of a channel as nil" do + describe "list_channels method" do + it "returns details of a channel as nil" do assert_nil(workspace.list_channels) end end - describe "list_users method" do - it "returns details of a user as nil" do + describe "list_users method" do + it "returns details of a user as nil" do assert_nil(workspace.list_users) end end From 640e673f3885b4e988ccd56cd3d914c53bf95798 Mon Sep 17 00:00:00 2001 From: Tatiana Quintana Date: Fri, 22 Mar 2019 16:00:12 -0700 Subject: [PATCH 69/69] "added one more test for selecting nil user" --- specs/workspace_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index df41a5a1..7e04b536 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -83,6 +83,11 @@ expect { workspace.show_details }.must_raise SlackCli::SlackError + + workspace.select_user("") + expect { + workspace.show_details + }.must_raise SlackCli::SlackError end end