From 904bd3fbe0e072ba30050c9a6e2004bb8ecce310 Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Mon, 18 Mar 2019 16:58:52 -0700 Subject: [PATCH 01/35] testing slack --- lib/slack.rb | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 960cf2f7..4ce32b85 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,11 +1,31 @@ -#!/usr/bin/env ruby +# #!/usr/bin/env ruby -def main - puts "Welcome to the Ada Slack CLI!" +# def main +# puts "Welcome to the Ada Slack CLI!" - # TODO project +# # TODO project - puts "Thank you for using the Ada Slack CLI" -end +# puts "Thank you for using the Ada Slack CLI" +# end + +# main if __FILE__ == $PROGRAM_NAME + +require "dotenv" +require "httparty" + +# Tell dotenv to look for the .env file +Dotenv.load -main if __FILE__ == $PROGRAM_NAME \ No newline at end of file +url = "https://slack.com/api/channels.list" + +query = { + token: ENV["KEY"], +} + +response = HTTParty.get(url, query: query) + +if response.message != 200 + raise ArgumentError, "Request is unsuccessful" +else + puts "#{response}" +end From 0afb27b43d92c0e46f479398ac6b7a11925c2963 Mon Sep 17 00:00:00 2001 From: Heather Izumi Date: Mon, 18 Mar 2019 17:01:29 -0700 Subject: [PATCH 02/35] Updated Slack API test --- lib/slack.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/slack.rb b/lib/slack.rb index 4ce32b85..685dad93 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -24,7 +24,7 @@ response = HTTParty.get(url, query: query) -if response.message != 200 +if response.code != 200 raise ArgumentError, "Request is unsuccessful" else puts "#{response}" From 49e3afaa54c699b8e358a947bd362e763e328a6e Mon Sep 17 00:00:00 2001 From: Heather Izumi Date: Tue, 19 Mar 2019 14:13:33 -0700 Subject: [PATCH 03/35] Updated test_helper file for VCR --- lib/slack.rb | 43 ++++++++++++++++++++++--------------------- specs/test_helper.rb | 30 +++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 685dad93..c501ff18 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,31 +1,32 @@ -# #!/usr/bin/env ruby +#!/usr/bin/env ruby -# def main -# puts "Welcome to the Ada Slack CLI!" - -# # TODO project +require "dotenv" +require "httparty" +Dotenv.load -# puts "Thank you for using the Ada Slack CLI" -# end +def main + puts "Welcome to the Ada Slack CLI!" -# main if __FILE__ == $PROGRAM_NAME + puts "to be filled in here" -require "dotenv" -require "httparty" + url = "https://slack.com/api/channels.list" -# Tell dotenv to look for the .env file -Dotenv.load + query = { + token: ENV["KEY"], + } -url = "https://slack.com/api/channels.list" + response = HTTParty.get(url, query: query) -query = { - token: ENV["KEY"], -} + if response.code != 200 + raise ArgumentError, "Request is unsuccessful" + elsif list_channel = response["channels"].map do |channel| + channel["name"] + end + end -response = HTTParty.get(url, query: query) + puts list_channel -if response.code != 200 - raise ArgumentError, "Request is unsuccessful" -else - puts "#{response}" + puts "Thank you for using the Ada Slack CLI" end + +main if __FILE__ == $PROGRAM_NAME diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 81ccd06b..fa132758 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -1,15 +1,27 @@ -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" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new +# VCR.configure do |config| +# config.cassette_library_dir = "specs/cassettes" +# config.hook_into :webmock + VCR.configure do |config| - config.cassette_library_dir = "specs/cassettes" - config.hook_into :webmock -end \ No newline at end of file + config.cassette_library_dir = "specs/cassettes" # folder where casettes will be located + config.hook_into :webmock # tie into this other tool called webmock + config.default_cassette_options = { + :record => :new_episodes, # record new data when we don't have it yet + :match_requests_on => [:method, :uri, :body], # The http method, URI and body of a request all need to match + } + # Don't leave our token lying around in a cassette file. + config.filter_sensitive_data("KEY") do + ENV["KEY"] + end +end From f6b7471ed16151646de2013a827ad1fbe9b5b904 Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Tue, 19 Mar 2019 14:43:19 -0700 Subject: [PATCH 04/35] added Recipient parent class and initialized --- .DS_Store | Bin 0 -> 6148 bytes lib/channel.rb | 1 + lib/recipient.rb | 14 ++++++++++++++ specs/recipient_spec.rb | 8 ++++++++ specs/slack_spec.rb | 1 + specs/test_helper.rb | 2 ++ 6 files changed, 26 insertions(+) create mode 100644 .DS_Store create mode 100644 lib/channel.rb create mode 100644 lib/recipient.rb create mode 100644 specs/recipient_spec.rb create mode 100644 specs/slack_spec.rb diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..e81aaea8bf29982243158f811a5c8777227d6d80 GIT binary patch literal 6148 zcmeHK%Wl&^6ur}=?Icx2M3LI1H%Kfhl$44tDx?rnp)QaRL9hUn+OeBhb?hj%8?9ju;*yIr96zC}e%hu`2YGQuvR-JI81Nd5hz)-5g^BUPCbY z;uq(9KjnN&i06}&^ZHrrvcum50crSkg5Cg)XN-LAgt45CRVv6D1z z+2c2&_S{YejxN89qTp}Yc3%13q+7f5BnlJT552J@`>qF8K9Q zE4Dln={q)1^;}=W?#&GybyQT3D zd__TvaM>A$K@|4UBD^`hfQT0mu~2royr1Wmw*vnYdQ5G41}xeTVrl0YJJ?Wx-U{MM zNU@a$xEx}PnV>c*iXxYLKFT`$M_}{{7yBB|Rb9$CF>=cZ?QdXu+wiR$a1F&MU=&zw z1;qJaAqi}1%oNI_1DSjR0Ly5WhO+p3AUKxBrp8PmdSFaZfr`rX6N4!_+AZzZ)R-w$ zbYlAP!Su*XzfhPQ9q}#cPOPcWrRjrBp|K$4j|02oMi~>f1l~RC}+nsg` zQ_^?q(&WTlYayK>2@`&qLP4JOlB1LrwaTA D<(3Vn literal 0 HcmV?d00001 diff --git a/lib/channel.rb b/lib/channel.rb new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/lib/channel.rb @@ -0,0 +1 @@ + diff --git a/lib/recipient.rb b/lib/recipient.rb new file mode 100644 index 00000000..cd8083ca --- /dev/null +++ b/lib/recipient.rb @@ -0,0 +1,14 @@ +module Slack + class Recipient + attr_reader :slack_id, :name + + def initialize(slack_id, name) + @slack_id = slack_id + @name = name + end + + def self.list_all(slack_id) + raise NotImplementedError, "Please implement in my child." + end + end +end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb new file mode 100644 index 00000000..64979a01 --- /dev/null +++ b/specs/recipient_spec.rb @@ -0,0 +1,8 @@ +require "test_helper.rb" + +describe "Recipient class" do + it "creates an instance of Recipient class" do + receiver = Slack::Recipient.new("slack_id", "name") + expect(receiver).must_be_instance_of Slack::Recipient + end +end diff --git a/specs/slack_spec.rb b/specs/slack_spec.rb new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/specs/slack_spec.rb @@ -0,0 +1 @@ + diff --git a/specs/test_helper.rb b/specs/test_helper.rb index fa132758..c86cf08c 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -7,6 +7,8 @@ require "minitest/skip_dsl" require "vcr" +require_relative "../lib/recipient.rb" + Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new # VCR.configure do |config| From 7c9d55b240f50e9f2f6dd2ff16422df37dc79e4d Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Tue, 19 Mar 2019 14:49:41 -0700 Subject: [PATCH 05/35] changed git file --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 8d6a243f..cdf7f804 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,5 @@ build-iPhoneSimulator/ # Ignore cassette files /specs/cassettes/ + +.DS_Store From 37897a0d785d1108c85fc1b4542657e124883dbc Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Tue, 19 Mar 2019 14:57:53 -0700 Subject: [PATCH 06/35] made some changes to initialize --- lib/recipient.rb | 2 +- specs/recipient_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index cd8083ca..09d9c5bd 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -2,7 +2,7 @@ module Slack class Recipient attr_reader :slack_id, :name - def initialize(slack_id, name) + def initialize @slack_id = slack_id @name = name end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 64979a01..89bcd8a9 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -2,7 +2,7 @@ describe "Recipient class" do it "creates an instance of Recipient class" do - receiver = Slack::Recipient.new("slack_id", "name") + receiver = Slack::Recipient expect(receiver).must_be_instance_of Slack::Recipient end end From b8a1fa8738548baf49a4931e02ba5e574cb472dc Mon Sep 17 00:00:00 2001 From: Heather Izumi Date: Tue, 19 Mar 2019 16:29:30 -0700 Subject: [PATCH 07/35] Channel class self.get method --- lib/channel.rb | 23 +++++++++++++++++++++++ lib/recipient.rb | 10 ++++++++-- specs/channel_spec.rb | 19 +++++++++++++++++++ specs/recipient_spec.rb | 2 +- specs/test_helper.rb | 7 +++++++ 5 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 specs/channel_spec.rb diff --git a/lib/channel.rb b/lib/channel.rb index 8b137891..c383476d 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1 +1,24 @@ +module Slack + class Channel < Recipient + attr_reader :slack_id, :name, :url + + def initialize(slack_id, name) + super(slack_id, name) + end + + def self.get + url = "https://slack.com/api/channels.list" + params = { + token: ENV["KEY"], + } + + response_from_get = HTTParty.get(url, query: params) + + return response_from_get + end + + # def self.list_all + + end +end diff --git a/lib/recipient.rb b/lib/recipient.rb index 09d9c5bd..386355ed 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -2,12 +2,18 @@ module Slack class Recipient attr_reader :slack_id, :name - def initialize + def initialize(slack_id, name) @slack_id = slack_id @name = name end - def self.list_all(slack_id) + # def self.get + # puts "Every subclass of Recipient will get here when you call the get method" + # HTTParty.GET(url, query: params) + # return "Dee is writing something specific >:)" + # end + + def self.list_all raise NotImplementedError, "Please implement in my child." end end diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb new file mode 100644 index 00000000..2ba95e13 --- /dev/null +++ b/specs/channel_spec.rb @@ -0,0 +1,19 @@ +require_relative "test_helper.rb" +require "pry" + +describe "Channel class" do + it "Creates an instance of the Channel class" do + new_channel = Slack::Channel.new("id", "name") + expect(new_channel).must_be_instance_of Slack::Channel + end +end + +describe "List_all method" do + it "Successfully GETs response from Slack API" do + VCR.use_cassette("location_find") do + response = Slack::Channel.get + + expect(response["ok"]).must_equal true + end + end +end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 89bcd8a9..bad7e41c 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -2,7 +2,7 @@ describe "Recipient class" do it "creates an instance of Recipient class" do - receiver = Slack::Recipient + receiver = Slack::Recipient.new("id", "name") expect(receiver).must_be_instance_of Slack::Recipient end end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index c86cf08c..52096ea2 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -6,8 +6,15 @@ require "minitest/reporters" require "minitest/skip_dsl" require "vcr" +require "httparty" +require "dotenv" + +Dotenv.load require_relative "../lib/recipient.rb" +require_relative "../lib/channel.rb" +# require_relative "../lib/user.rb" +# require_relative "../lib/message.rb" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 8115f600bb7ba8a16b6a331dcbec3ed72f7837e3 Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Tue, 19 Mar 2019 17:25:35 -0700 Subject: [PATCH 08/35] added User class and initial tests --- lib/channel.rb | 1 - lib/user.rb | 23 +++++++++++++++++++++++ specs/test_helper.rb | 2 +- specs/user_spec.rb | 19 +++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 lib/user.rb create mode 100644 specs/user_spec.rb diff --git a/lib/channel.rb b/lib/channel.rb index c383476d..04c48d3b 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,4 +1,3 @@ - module Slack class Channel < Recipient attr_reader :slack_id, :name, :url diff --git a/lib/user.rb b/lib/user.rb new file mode 100644 index 00000000..6c93ee80 --- /dev/null +++ b/lib/user.rb @@ -0,0 +1,23 @@ +module Slack + class User < Recipient + attr_reader :slack_id, :name, :url + + def initialize(slack_id, name) + super(slack_id, name) + end + + def self.get + url = "https://slack.com/api/users.list" + params = { + token: ENV["KEY"], + } + + response_from_get = HTTParty.get(url, query: params) + + return response_from_get + end + + # def self.list_all + + end +end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 52096ea2..6693e338 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -13,7 +13,7 @@ require_relative "../lib/recipient.rb" require_relative "../lib/channel.rb" -# require_relative "../lib/user.rb" +require_relative "../lib/user.rb" # require_relative "../lib/message.rb" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new diff --git a/specs/user_spec.rb b/specs/user_spec.rb new file mode 100644 index 00000000..0c289343 --- /dev/null +++ b/specs/user_spec.rb @@ -0,0 +1,19 @@ +require_relative "test_helper.rb" +require "pry" + +describe "Channel class" do + it "Creates an instance of the Channel class" do + new_user = Slack::User.new("id", "name") + expect(new_user).must_be_instance_of Slack::User + end +end + +describe "List_all method" do + it "Successfully GETs response from Slack API" do + VCR.use_cassette("location_find") do + response = Slack::User.get + + expect(response["ok"]).must_equal true + end + end +end From 8e47965c1e0ec6245dd71ef6316bc93f7c164bcb Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Tue, 19 Mar 2019 21:17:21 -0700 Subject: [PATCH 09/35] created self.list_all method in user class --- lib/channel.rb | 5 +++-- lib/recipient.rb | 6 +++--- lib/user.rb | 13 +++++++++---- specs/channel_spec.rb | 2 +- specs/user_spec.rb | 14 ++++++++++++-- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 04c48d3b..473961b0 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,6 +1,6 @@ module Slack class Channel < Recipient - attr_reader :slack_id, :name, :url + attr_reader :slack_id, :name def initialize(slack_id, name) super(slack_id, name) @@ -18,6 +18,7 @@ def self.get end # def self.list_all - + # self.get + # end end end diff --git a/lib/recipient.rb b/lib/recipient.rb index 386355ed..5cb66b73 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -13,8 +13,8 @@ def initialize(slack_id, name) # return "Dee is writing something specific >:)" # end - def self.list_all - raise NotImplementedError, "Please implement in my child." - end + # def self.list_all + # raise NotImplementedError, "Please implement in my child." + # end end end diff --git a/lib/user.rb b/lib/user.rb index 6c93ee80..72f3cca1 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,9 +1,10 @@ module Slack class User < Recipient - attr_reader :slack_id, :name, :url + attr_reader :slack_id, :name - def initialize(slack_id, name) + def initialize(slack_id, name, real_name) super(slack_id, name) + @real_name = real_name end def self.get @@ -17,7 +18,11 @@ def self.get return response_from_get end - # def self.list_all - + def self.list_all + users = User.get["members"].map do |user| + self.new(user["id"], user["real_name"], user["profile"]["real_name"]) + end + return users + end end end diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 2ba95e13..07ed4190 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -8,7 +8,7 @@ end end -describe "List_all method" do +describe "Get method" do it "Successfully GETs response from Slack API" do VCR.use_cassette("location_find") do response = Slack::Channel.get diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 0c289343..a055649d 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -3,12 +3,12 @@ describe "Channel class" do it "Creates an instance of the Channel class" do - new_user = Slack::User.new("id", "name") + new_user = Slack::User.new("id", "name", "real name") expect(new_user).must_be_instance_of Slack::User end end -describe "List_all method" do +describe "get method" do it "Successfully GETs response from Slack API" do VCR.use_cassette("location_find") do response = Slack::User.get @@ -17,3 +17,13 @@ end end end + +# unsure what this test should result in. also, not sure calling the correct test +describe "list_all method" do + it "gives a list of all user information from the API" do + VCR.use_cassette("location_find") do + list_response = Slack::User.list_all + expect(list_response.first).must_equal "USLACKBOT" + end + end +end From 7e223d5989797eba666c5bb3831b8938ca44d3b7 Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Wed, 20 Mar 2019 10:13:27 -0700 Subject: [PATCH 10/35] made minor name changes --- .DS_Store | Bin 6148 -> 6148 bytes lib/recipient.rb | 4 +--- specs/channel_spec.rb | 2 +- specs/user_spec.rb | 4 ++-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.DS_Store b/.DS_Store index e81aaea8bf29982243158f811a5c8777227d6d80..d3fd264b4f23d6b98cc84023b6f49c15699819a2 100644 GIT binary patch delta 124 zcmZoMXfc@JFUrTjz`)4BAi%&-#E{64&XDSvlb^gnIqR8gE|BdKkf*yqeW<@^*HG&Fmb1`2iy` BAjkj! delta 79 zcmZoMXfc@JFUrfnz`)4BAi%(o&XC6t&ydKF%uupfkYhPBBkyJ#mg$TfCPs!j3MPg| bn{TroM(`%zW_6tWoLymJmBD6qj=%f>q$v}x diff --git a/lib/recipient.rb b/lib/recipient.rb index 5cb66b73..f1e9fed7 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -7,10 +7,8 @@ def initialize(slack_id, name) @name = name end - # def self.get - # puts "Every subclass of Recipient will get here when you call the get method" + # def self.get(url, params) # HTTParty.GET(url, query: params) - # return "Dee is writing something specific >:)" # end # def self.list_all diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 07ed4190..a63b52f9 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -10,7 +10,7 @@ describe "Get method" do it "Successfully GETs response from Slack API" do - VCR.use_cassette("location_find") do + VCR.use_cassette("channel_find") do response = Slack::Channel.get expect(response["ok"]).must_equal true diff --git a/specs/user_spec.rb b/specs/user_spec.rb index a055649d..abd11381 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -10,7 +10,7 @@ describe "get method" do it "Successfully GETs response from Slack API" do - VCR.use_cassette("location_find") do + VCR.use_cassette("user_find") do response = Slack::User.get expect(response["ok"]).must_equal true @@ -21,7 +21,7 @@ # unsure what this test should result in. also, not sure calling the correct test describe "list_all method" do it "gives a list of all user information from the API" do - VCR.use_cassette("location_find") do + VCR.use_cassette("user_find") do list_response = Slack::User.list_all expect(list_response.first).must_equal "USLACKBOT" end From da766d539ba3867b37c1272a7ba39c9fe6128485 Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Wed, 20 Mar 2019 10:38:39 -0700 Subject: [PATCH 11/35] channel list_all method and test --- lib/channel.rb | 10 +++++++--- specs/channel_spec.rb | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 473961b0..92114fef 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -17,8 +17,12 @@ def self.get return response_from_get end - # def self.list_all - # self.get - # end + def self.list_all + if Channel.get.code != 200 + raise ArgumentError, "Request is unsuccessful" + else all_channels = Channel.get["channels"].map do |channel| + channel["name"] + end end + end end end diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index a63b52f9..f822439a 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -17,3 +17,14 @@ end end end + +describe "list_all method" do + it "gives a list of all user information from the API and returns a value of a 'general' channel name" do + VCR.use_cassette("channel_find") do + list_response = Slack::Channel.list_all + + expect(list_response.length).must_equal 3 + expect(list_response).must_include "general" + end + end +end From e611d21997220e8780527042b6c567169d0ea43e Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Wed, 20 Mar 2019 13:37:43 -0700 Subject: [PATCH 12/35] changes in recipient file --- lib/recipient.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/recipient.rb b/lib/recipient.rb index f1e9fed7..e11aca40 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -7,6 +7,7 @@ def initialize(slack_id, name) @name = name end + # def self.get(url, params) # HTTParty.GET(url, query: params) # end From 573b950382cac00e8da6c08fb9fc63d463399a73 Mon Sep 17 00:00:00 2001 From: Heather Izumi Date: Wed, 20 Mar 2019 14:39:43 -0700 Subject: [PATCH 13/35] channel list method in progress --- .DS_Store | Bin 6148 -> 8196 bytes .vscode/launch.json | 15 +++++++++++++++ lib/channel.rb | 18 ++++++++++++------ specs/channel_spec.rb | 1 + specs/user_spec.rb | 16 ++++++++-------- 5 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.DS_Store b/.DS_Store index d3fd264b4f23d6b98cc84023b6f49c15699819a2..02ab62e7222f58d6e6a8964c31dc700341115734 100644 GIT binary patch delta 264 zcmZoMXmOBWU|?W$DortDU;r^WfEYvza8E20o2aMA$iFdQH}hr%jz7$c**Q2SHn1@A zPv&7!Vq;hd)W9GtwIlhav~1wqVs0g38rBU4iy1tT-_ z$+ua{C%3Q(Oip4`oP3f^aPky3v&moBq(wY)@{^Nt@{>T;0x{4upuy+a#3u8z%Mvot zQG}JDn4y3nl_8m-IHfo_Cn-NahjH=~cIC}-JRg|3B)EYlx`O<(S&-v9^JIPz&&mEg Q92|@guQF_o=b6I{0HUloy#N3J delta 222 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{Mvv5r;6q~50$jG-bU^g=(-((&EB{s&-K$#hn zO$2^Gm>QFf1ohcCxH!0YxhAIzCJS Date: Wed, 20 Mar 2019 14:58:39 -0700 Subject: [PATCH 14/35] added channel info to list_all method --- lib/channel.rb | 7 +++---- specs/channel_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 06840099..e76ba70a 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -4,6 +4,8 @@ class Channel < Recipient def initialize(slack_id, name) super(slack_id, name) + # @members = members + # @topic = topic end def self.get @@ -23,10 +25,7 @@ def self.get def self.list_all all_channels = Channel.get["channels"].map do |channel| - channel["id"] - # channel["name"] - # channel["members"] - # channel["topic"] + "Channel #{channel["id"]} name is: #{channel["name"]}. Number of members: #{channel["num_members"]}. Topic of the channel: #{channel["topic"]["value"]}." end return all_channels end diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 620fa402..c89da926 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -23,9 +23,9 @@ VCR.use_cassette("channel_find") do list_response = Slack::Channel.list_all + puts list_response + expect(list_response.length).must_equal 3 - expect(list_response).must_include "general" - expect(list_response).wont_include "test_channel" end end end From 389301d9a5ad694ce0992568b33847cfdd40d8c6 Mon Sep 17 00:00:00 2001 From: Heather Izumi Date: Wed, 20 Mar 2019 15:49:13 -0700 Subject: [PATCH 15/35] updated list_all methods --- lib/channel.rb | 8 ++++---- lib/slack.rb | 23 +++++------------------ lib/user.rb | 2 +- specs/channel_spec.rb | 2 +- specs/test_helper.rb | 2 +- specs/user_spec.rb | 18 +++++++++--------- 6 files changed, 21 insertions(+), 34 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index e76ba70a..9d093c8a 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -2,10 +2,10 @@ module Slack class Channel < Recipient attr_reader :slack_id, :name - def initialize(slack_id, name) + def initialize(slack_id, name, num_members, topic) super(slack_id, name) - # @members = members - # @topic = topic + @num_members = num_members + @topic = topic end def self.get @@ -25,7 +25,7 @@ def self.get def self.list_all all_channels = Channel.get["channels"].map do |channel| - "Channel #{channel["id"]} name is: #{channel["name"]}. Number of members: #{channel["num_members"]}. Topic of the channel: #{channel["topic"]["value"]}." + self.new(channel["id"], channel["name"], channel["num_members"], channel["topic"]["value"]) end return all_channels end diff --git a/lib/slack.rb b/lib/slack.rb index c501ff18..5be7e37e 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,5 +1,7 @@ #!/usr/bin/env ruby - +# require_relative "../spec/test_helper" +require_relative "channel" +require_relative "recipient" require "dotenv" require "httparty" Dotenv.load @@ -7,24 +9,9 @@ def main puts "Welcome to the Ada Slack CLI!" - puts "to be filled in here" - - url = "https://slack.com/api/channels.list" - - query = { - token: ENV["KEY"], - } - - response = HTTParty.get(url, query: query) - - if response.code != 200 - raise ArgumentError, "Request is unsuccessful" - elsif list_channel = response["channels"].map do |channel| - channel["name"] - end - end + channels = Slack::Channel.list_all.name - puts list_channel + puts channels puts "Thank you for using the Ada Slack CLI" end diff --git a/lib/user.rb b/lib/user.rb index 72f3cca1..57419f14 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -20,7 +20,7 @@ def self.get def self.list_all users = User.get["members"].map do |user| - self.new(user["id"], user["real_name"], user["profile"]["real_name"]) + self.new(user["name"], user["profile"]["real_name"], user["id"]) end return users end diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index c89da926..e213c0a8 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -3,7 +3,7 @@ describe "Channel class" do it "Creates an instance of the Channel class" do - new_channel = Slack::Channel.new("id", "name") + new_channel = Slack::Channel.new("id", "name", 3, "topic") expect(new_channel).must_be_instance_of Slack::Channel end end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 6693e338..a9501ab6 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -14,7 +14,7 @@ require_relative "../lib/recipient.rb" require_relative "../lib/channel.rb" require_relative "../lib/user.rb" -# require_relative "../lib/message.rb" +require_relative "../lib/slack.rb" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new diff --git a/specs/user_spec.rb b/specs/user_spec.rb index dc198d33..3b01787b 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -18,12 +18,12 @@ end end -# unsure what this test should result in. also, not sure calling the correct test -# describe "list_all method" do -# it "gives a list of all user information from the API" do -# VCR.use_cassette("user_find") do -# list_response = Slack::User.list_all -# expect(list_response.first).must_equal "USLACKBOT" -# end -# end -# end +describe "list_all method" do + it "gives a list of all user information from the API" do + VCR.use_cassette("user_find") do + list_response = Slack::User.list_all + puts list_response + expect(list_response.length).must_equal 3 + end + end +end From 2096753d552abbbe8fab4c1d2c559da2210f4e28 Mon Sep 17 00:00:00 2001 From: Heather Izumi Date: Wed, 20 Mar 2019 20:08:57 -0700 Subject: [PATCH 16/35] Accessedlist_all methods via Slack.rb file --- lib/channel.rb | 2 ++ lib/slack.rb | 21 +++++++++++++++++++-- lib/user.rb | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 9d093c8a..8a655f88 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,3 +1,5 @@ +require_relative "recipient" + module Slack class Channel < Recipient attr_reader :slack_id, :name diff --git a/lib/slack.rb b/lib/slack.rb index 5be7e37e..cad4bd8b 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,6 +1,7 @@ #!/usr/bin/env ruby # require_relative "../spec/test_helper" require_relative "channel" +require_relative "user" require_relative "recipient" require "dotenv" require "httparty" @@ -9,9 +10,25 @@ def main puts "Welcome to the Ada Slack CLI!" - channels = Slack::Channel.list_all.name + channels = Slack::Channel.list_all + name_channels = channels.map do |channel| + channel.name + end - puts channels + # puts name_channels + puts "Channels loaded: ", channels.length + + users = Slack::User.list_all + name_users = users.map do |user| + user.name + end + + # puts name_users + puts "Users loaded: ", users.length + + puts "Please select from the following options: list_users, list_channels, or quit" + + # Should we use a case statement here for the 3 options? puts "Thank you for using the Ada Slack CLI" end diff --git a/lib/user.rb b/lib/user.rb index 57419f14..2a01c73a 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,3 +1,5 @@ +require_relative "recipient" + module Slack class User < Recipient attr_reader :slack_id, :name From 0be22803b88317313e279c04f9fe287dc4bc8ec0 Mon Sep 17 00:00:00 2001 From: Heather Izumi Date: Thu, 21 Mar 2019 13:23:31 -0700 Subject: [PATCH 17/35] Added workspace class --- lib/slack.rb | 19 ++++--------------- lib/workspace.rb | 29 +++++++++++++++++++++++++++++ specs/test_helper.rb | 1 + 3 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 lib/workspace.rb diff --git a/lib/slack.rb b/lib/slack.rb index cad4bd8b..07069bb6 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -3,6 +3,7 @@ require_relative "channel" require_relative "user" require_relative "recipient" +require_relative "workspace" require "dotenv" require "httparty" Dotenv.load @@ -10,23 +11,11 @@ def main puts "Welcome to the Ada Slack CLI!" - channels = Slack::Channel.list_all - name_channels = channels.map do |channel| - channel.name - end + puts "Channels loaded: ", Slack::Workspace.channel_list_all.length - # puts name_channels - puts "Channels loaded: ", channels.length + puts "Users loaded: ", Slack::Workspace.user_list_all.length - users = Slack::User.list_all - name_users = users.map do |user| - user.name - end - - # puts name_users - puts "Users loaded: ", users.length - - puts "Please select from the following options: list_users, list_channels, or quit" + puts "Please select from the following options: list_users, list_channels, or quit\n" # Should we use a case statement here for the 3 options? diff --git a/lib/workspace.rb b/lib/workspace.rb new file mode 100644 index 00000000..f62be256 --- /dev/null +++ b/lib/workspace.rb @@ -0,0 +1,29 @@ +require_relative "channel" +require_relative "user" +require_relative "recipient" +require "dotenv" +require "httparty" +Dotenv.load + +module Slack + class Workspace + def self.channel_list_all + channels = Slack::Channel.list_all + name_channels = channels.map do |channel| + channel.name + end + return name_channels + end + + def self.user_list_all + users = Slack::User.list_all + name_users = users.map do |user| + user.name + end + return name_users + end + end +end + +# test = Slack::Workspace.new.user_list_all +# puts test diff --git a/specs/test_helper.rb b/specs/test_helper.rb index a9501ab6..f0782732 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -15,6 +15,7 @@ require_relative "../lib/channel.rb" require_relative "../lib/user.rb" require_relative "../lib/slack.rb" +require_relative "../lib/workspace.rb" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From e8ed772e9c7587c31130c15def51e10acf8afa57 Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Thu, 21 Mar 2019 14:01:19 -0700 Subject: [PATCH 18/35] added methods to Workspace for details about selected classes --- .DS_Store | Bin 8196 -> 6148 bytes lib/channel.rb | 2 +- lib/recipient.rb | 1 - lib/user.rb | 4 ++-- lib/workspace.rb | 17 +++++++++++++++-- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.DS_Store b/.DS_Store index 02ab62e7222f58d6e6a8964c31dc700341115734..6dcdae3bec1b05d4bc5b397db34ae3ed258f3ff4 100644 GIT binary patch delta 222 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{Mvv5r;6q~50$jG-bU^g=(-((&EB{s&-K$#hn zO$2^Gm>QFf1ohcCxH!0YxhAIzCJS9GtwIlhav~1wqVs0g38rBU4iy1tT-_ z$+ua{C%3Q(Oip4`oP3f^aPky3v&moBq(wY)@{^Nt@{>T;0x{4upuy+a#3u8z%Mvot zQG}JDn4y3nl_8m-IHfo_Cn-NahjH=~cIC}-JRg|3B)EYlx`O<(S&-v9^JIPz&&mEg Q92|@guQF_o=b6I{0HUloy#N3J diff --git a/lib/channel.rb b/lib/channel.rb index 8a655f88..3dc4b7bd 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -2,7 +2,7 @@ module Slack class Channel < Recipient - attr_reader :slack_id, :name + attr_reader :slack_id, :name, :num_members, :topic def initialize(slack_id, name, num_members, topic) super(slack_id, name) diff --git a/lib/recipient.rb b/lib/recipient.rb index e11aca40..f1e9fed7 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -7,7 +7,6 @@ def initialize(slack_id, name) @name = name end - # def self.get(url, params) # HTTParty.GET(url, query: params) # end diff --git a/lib/user.rb b/lib/user.rb index 2a01c73a..da45977c 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -2,7 +2,7 @@ module Slack class User < Recipient - attr_reader :slack_id, :name + attr_reader :slack_id, :name, :real_name def initialize(slack_id, name, real_name) super(slack_id, name) @@ -22,7 +22,7 @@ def self.get def self.list_all users = User.get["members"].map do |user| - self.new(user["name"], user["profile"]["real_name"], user["id"]) + self.new(user["id"], user["name"], user["profile"]["real_name"]) end return users end diff --git a/lib/workspace.rb b/lib/workspace.rb index f62be256..0f0b5c5f 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -15,6 +15,13 @@ def self.channel_list_all return name_channels end + def self.selected_all_channels + channels = Slack::Channel.list_all.map do |channel| + "Channel ID #{channel.slack_id}'s name is #{channel.name}. \nIt has #{channel.num_members} members. \nThe topic for this channel is: #{channel.topic}." + end + return channels + end + def self.user_list_all users = Slack::User.list_all name_users = users.map do |user| @@ -22,8 +29,14 @@ def self.user_list_all end return name_users end + + def self.selected_all_users + users = Slack::User.list_all.map do |user| + "User ID: #{user.slack_id}'s real name is #{user.real_name} and displace name is #{user.name}." + end + return users + end end end -# test = Slack::Workspace.new.user_list_all -# puts test +# Slack::Workspace.selected_all_users From 8cbafb27041f81df4ba60f8ac9d5f7b4fd3abfb5 Mon Sep 17 00:00:00 2001 From: Heather Izumi Date: Thu, 21 Mar 2019 15:35:48 -0700 Subject: [PATCH 19/35] Added select_channel and select_user methods to workspace class with tests --- .vscode/launch.json | 1 + lib/slack.rb | 16 +++++++++++++++- lib/workspace.rb | 29 ++++++++++++++++++++++++++--- specs/workspace_spec.rb | 28 ++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 specs/workspace_spec.rb diff --git a/.vscode/launch.json b/.vscode/launch.json index 5444d0fa..5b9ee7b3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,3 +13,4 @@ } ] } + diff --git a/lib/slack.rb b/lib/slack.rb index 07069bb6..8f6b60d7 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -15,7 +15,21 @@ def main puts "Users loaded: ", Slack::Workspace.user_list_all.length - puts "Please select from the following options: list_users, list_channels, or quit\n" + puts "Please select from the following options: list users, list channels, or quit" + + selection = gets.chomp.downcase + + until selection == "quit" + if selection == "list channels" + puts Slack::Workspace.all_channels_details + elsif selection == "list users" + puts Slack::Workspace.all_users_details + else + puts "Please enter a valid selection." + end + puts "What would you like to do next? (list users, list channels, or quit)" + selection = gets.chomp.downcase + end # Should we use a case statement here for the 3 options? diff --git a/lib/workspace.rb b/lib/workspace.rb index 0f0b5c5f..e20a6383 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -15,13 +15,26 @@ def self.channel_list_all return name_channels end - def self.selected_all_channels + def self.all_channels_details channels = Slack::Channel.list_all.map do |channel| "Channel ID #{channel.slack_id}'s name is #{channel.name}. \nIt has #{channel.num_members} members. \nThe topic for this channel is: #{channel.topic}." end return channels end + def self.select_channel(channel_identifier) + find_channel = Slack::Channel.list_all.find { + |channel| + channel.name == channel_identifier || + channel.slack_id == channel_identifier + } + + return find_channel + end + + def self.selected_channel_details + end + def self.user_list_all users = Slack::User.list_all name_users = users.map do |user| @@ -30,12 +43,22 @@ def self.user_list_all return name_users end - def self.selected_all_users + def self.all_users_details users = Slack::User.list_all.map do |user| - "User ID: #{user.slack_id}'s real name is #{user.real_name} and displace name is #{user.name}." + "User ID: #{user.slack_id}'s real name is #{user.real_name} and display name is #{user.name}." end return users end + + def self.select_user(user_identifier) + find_user = Slack::User.list_all.find { + |user| + user.name == user_identifier || + user.slack_id == user_identifier + } + + return find_user + end end end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb new file mode 100644 index 00000000..af3872c7 --- /dev/null +++ b/specs/workspace_spec.rb @@ -0,0 +1,28 @@ +require_relative "test_helper.rb" + +describe "self.select_channel" do + it "can select a channel and return it" do + VCR.use_cassette("channel_find") do + selected_channel = Slack::Workspace.select_channel("general") + + expect(selected_channel.name).must_equal "general" + expect(selected_channel.slack_id).must_equal "CH2NW42JF" + + selected_channel = Slack::Workspace.select_channel("CH2NW42JF") + + expect(selected_channel.name).must_equal "general" + expect(selected_channel.slack_id).must_equal "CH2NW42JF" + end + end +end + +describe "self.select_user" do + it "can select a user and return it" do + VCR.use_cassette("user_find") do + selected_user = Slack::Workspace.select_user("hkizumi") + # puts selected_user + + expect(selected_user.name).must_equal "hkizumi" + end + end +end From a9aaaa6b822fa164f9279b99fe586c2a7124b026 Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Thu, 21 Mar 2019 16:08:02 -0700 Subject: [PATCH 20/35] added UI to slack.rb --- lib/slack.rb | 16 ++++++++++++++-- specs/workspace_spec.rb | 11 ++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 8f6b60d7..e79756b1 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -15,19 +15,31 @@ def main puts "Users loaded: ", Slack::Workspace.user_list_all.length - puts "Please select from the following options: list users, list channels, or quit" + puts "Please select from the following options: list users, select user, list channels, select channel, or quit" selection = gets.chomp.downcase until selection == "quit" if selection == "list channels" puts Slack::Workspace.all_channels_details + elsif selection == "select channel" + puts "Which channel would you like to select?" + channel_identifier = gets.chomp.to_s + selected_channel = Slack::Workspace.select_channel(channel_identifier) + puts "Please type 'details' if you would like to see complete details." + answer = gets.chomp.downcase elsif selection == "list users" puts Slack::Workspace.all_users_details + elsif selection == "select user" + puts "Which user would you like to select?" + channel_identifier = gets.chomp.to_s + selected_user = Slack::Workspace.select_user(channel_identifier) + puts "Please type 'details' if you would like to see complete details." + answer = gets.chomp.downcase else puts "Please enter a valid selection." end - puts "What would you like to do next? (list users, list channels, or quit)" + puts "What would you like to do next? (list users, select user, list channels, select channel, or quit)" selection = gets.chomp.downcase end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index af3872c7..6893036c 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -19,10 +19,15 @@ describe "self.select_user" do it "can select a user and return it" do VCR.use_cassette("user_find") do - selected_user = Slack::Workspace.select_user("hkizumi") - # puts selected_user + selected_user = Slack::Workspace.select_user("slackbot") - expect(selected_user.name).must_equal "hkizumi" + expect(selected_user.name).must_equal "slackbot" + expect(selected_user.slack_id).must_equal "USLACKBOT" + + selected_user = Slack::Workspace.select_user("USLACKBOT") + + expect(selected_user.name).must_equal "slackbot" + expect(selected_user.slack_id).must_equal "USLACKBOT" end end end From 41c015d4da7c9ef9249198e6751069f7bef7ba5d Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Thu, 21 Mar 2019 21:01:14 -0700 Subject: [PATCH 21/35] refactored some of CLI and workspace chanels output --- lib/slack.rb | 58 +++++++++++++++++++++++++++++++++++------------- lib/workspace.rb | 2 +- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index e79756b1..6a87f0ef 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -11,31 +11,36 @@ def main puts "Welcome to the Ada Slack CLI!" - puts "Channels loaded: ", Slack::Workspace.channel_list_all.length + print "Channels loaded: ", Slack::Workspace.channel_list_all.length - puts "Users loaded: ", Slack::Workspace.user_list_all.length - - puts "Please select from the following options: list users, select user, list channels, select channel, or quit" + print "\nUsers loaded: ", Slack::Workspace.user_list_all.length + puts "\nPlease select from the following options: \n list channels, select channel, list users, select user, details, or quit" selection = gets.chomp.downcase until selection == "quit" - if selection == "list channels" + case selection + when "list channels" puts Slack::Workspace.all_channels_details - elsif selection == "select channel" - puts "Which channel would you like to select?" - channel_identifier = gets.chomp.to_s - selected_channel = Slack::Workspace.select_channel(channel_identifier) - puts "Please type 'details' if you would like to see complete details." + when "select channel" + puts "Which user would you like to select?" + user_identifier = gets.chomp.downcase.to_s + selected_channel = Slack::Workspace.select_user(user_identifier) + puts "You have selected #{selected_channel.name}. Please type 'details' for more info!" answer = gets.chomp.downcase - elsif selection == "list users" + if answer == "details" + "#{selected_channel.name}'s detail: \nID - #{selected_channel.slack_id}\n'" + puts "Please type 'details' if you would like to see complete details." + end + # if answers + when "list users" puts Slack::Workspace.all_users_details - elsif selection == "select user" + when "select user" puts "Which user would you like to select?" - channel_identifier = gets.chomp.to_s - selected_user = Slack::Workspace.select_user(channel_identifier) - puts "Please type 'details' if you would like to see complete details." - answer = gets.chomp.downcase + user_identifier = gets.chomp.downcase.to_s + selected_user = Slack::Workspace.select_channel(user_identifier) + # puts selected_channel + when "quit" else puts "Please enter a valid selection." end @@ -43,6 +48,27 @@ def main selection = gets.chomp.downcase end + # if selection == "list channels" + + # elsif selection == "select channel" + + # puts "Please type 'details' if you would like to see complete details." + # answer = gets.chomp.downcase + # elsif selection == "list users" + # puts Slack::Workspace.all_users_details + # elsif selection == "select user" + # puts "Which user would you like to select?" + # channel_identifier = gets.chomp.to_s + # selected_user = Slack::Workspace.select_user(channel_identifier) + # puts "Please type 'details' if you would like to see complete details." + # answer = gets.chomp.downcase + # else + + # end + # puts "What would you like to do next? (list users, select user, list channels, select channel, or quit)" + # selection = gets.chomp.downcase + # end + # Should we use a case statement here for the 3 options? puts "Thank you for using the Ada Slack CLI" diff --git a/lib/workspace.rb b/lib/workspace.rb index e20a6383..af7c9120 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -17,7 +17,7 @@ def self.channel_list_all def self.all_channels_details channels = Slack::Channel.list_all.map do |channel| - "Channel ID #{channel.slack_id}'s name is #{channel.name}. \nIt has #{channel.num_members} members. \nThe topic for this channel is: #{channel.topic}." + "Channel ID: #{channel.slack_id}\nChannel name: #{channel.name} \nMembers: #{channel.num_members} \nChannel Topic: #{channel.topic}" end return channels end From 7c511173cbdc6ed039e844d120eba9ed7f7f6c32 Mon Sep 17 00:00:00 2001 From: Heather Izumi Date: Thu, 21 Mar 2019 21:03:19 -0700 Subject: [PATCH 22/35] updated tests for list_all methods for channel and user classes --- specs/channel_spec.rb | 5 +++-- specs/test_helper.rb | 1 + specs/user_spec.rb | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index e213c0a8..94aa9836 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -1,4 +1,5 @@ require_relative "test_helper.rb" + require "pry" describe "Channel class" do @@ -22,10 +23,10 @@ it "gives a list of all user information from the API and returns a value of a 'general' channel name" do VCR.use_cassette("channel_find") do list_response = Slack::Channel.list_all - - puts list_response + ap list_response expect(list_response.length).must_equal 3 + expect(list_response[0].name).must_equal "general" end end end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index f0782732..f9fe7c33 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -8,6 +8,7 @@ require "vcr" require "httparty" require "dotenv" +require "awesome_print" Dotenv.load diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 3b01787b..c01382c2 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -12,7 +12,6 @@ it "Successfully GETs response from Slack API" do VCR.use_cassette("user_find") do response = Slack::User.get - expect(response["ok"]).must_equal true end end @@ -22,8 +21,9 @@ it "gives a list of all user information from the API" do VCR.use_cassette("user_find") do list_response = Slack::User.list_all - puts list_response + ap list_response expect(list_response.length).must_equal 3 + expect(list_response[0].name).must_equal "slackbot" end end end From a7a0cc60cfb599825e15e360bae36366d7bddfc2 Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Thu, 21 Mar 2019 22:18:38 -0700 Subject: [PATCH 23/35] added message methods to slack.rb for now --- lib/slack.rb | 78 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 6a87f0ef..9f124806 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -26,19 +26,22 @@ def main puts "Which user would you like to select?" user_identifier = gets.chomp.downcase.to_s selected_channel = Slack::Workspace.select_user(user_identifier) - puts "You have selected #{selected_channel.name}. Please type 'details' for more info!" - answer = gets.chomp.downcase - if answer == "details" - "#{selected_channel.name}'s detail: \nID - #{selected_channel.slack_id}\n'" - puts "Please type 'details' if you would like to see complete details." - end + # if selected_channel == nil + # puts "This channel doesn't exist. Exiting to main menu" + # else + # puts "You have selected #{selected_channel.name}. Please type 'details' for more info!" + # answer = gets.chomp.downcase + # if answer == "details" + # puts selected_channel + + # end # if answers when "list users" puts Slack::Workspace.all_users_details - when "select user" - puts "Which user would you like to select?" - user_identifier = gets.chomp.downcase.to_s - selected_user = Slack::Workspace.select_channel(user_identifier) + # when "select user" + # puts "Which user would you like to select?" + # user_identifier = gets.chomp.downcase.to_s + # selected_user = Slack::Workspace.select_channel(user_identifier) # puts selected_channel when "quit" else @@ -48,30 +51,43 @@ def main selection = gets.chomp.downcase end - # if selection == "list channels" - - # elsif selection == "select channel" - - # puts "Please type 'details' if you would like to see complete details." - # answer = gets.chomp.downcase - # elsif selection == "list users" - # puts Slack::Workspace.all_users_details - # elsif selection == "select user" - # puts "Which user would you like to select?" - # channel_identifier = gets.chomp.to_s - # selected_user = Slack::Workspace.select_user(channel_identifier) - # puts "Please type 'details' if you would like to see complete details." - # answer = gets.chomp.downcase - # else - - # end - # puts "What would you like to do next? (list users, select user, list channels, select channel, or quit)" - # selection = gets.chomp.downcase - # end - # Should we use a case statement here for the 3 options? puts "Thank you for using the Ada Slack CLI" end main if __FILE__ == $PROGRAM_NAME + +def send_message(user, message) + url = "https://slack.com/api/chat.postMessage" + params = { + token: ENV["KEY"], + channel: user_identifier, + text: message, + } + + message_request = HTTParty.post(URL, query: params) + if message_request["ok"] == false + raise ArgumentError, "Request is unsuccessful" + else + return message_request + end + end +end + +def send_message(channel, message) + url = "https://slack.com/api/chat.postMessage" + params = { + token: ENV["KEY"], + channel: channel_identifier, + text: message, + } + + message_request = HTTParty.post(URL, query: params) + if message_request["ok"] == false + raise ArgumentError, "Request is unsuccessful" + else + return message_request + end + end +end From b63fb6c54d2a1c5d2563b52c311978887e1a8446 Mon Sep 17 00:00:00 2001 From: Heather Izumi Date: Thu, 21 Mar 2019 22:53:29 -0700 Subject: [PATCH 24/35] Added tests for workspace, working on method to list channel details --- lib/workspace.rb | 14 +++++++++-- specs/workspace_spec.rb | 54 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index af7c9120..52f3fc9a 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -32,7 +32,17 @@ def self.select_channel(channel_identifier) return find_channel end - def self.selected_channel_details + def self.selected_channel_details(channel_identifier) + chosen_channel = self.select_channel(channel_identifier) + + details = "Channel ID: #{chosen_channel.slack_id}\nChannel name: #{chosen_channel.name} \nMembers: #{chosen_channel.num_members} \nChannel Topic: #{chosen_channel.topic}" + + return details + + # chosen_channel = self.select_channel(channel_identifier) + + # details = chosen_channel.self.all_channels_details + # return details end def self.user_list_all @@ -62,4 +72,4 @@ def self.select_user(user_identifier) end end -# Slack::Workspace.selected_all_users +# put Slack::Workspace.selected_channel_details("CH2NW42JF") diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 6893036c..459542d6 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -1,5 +1,27 @@ require_relative "test_helper.rb" +describe "self.channel_list_all" do + it "returns an array of channel names" do + VCR.use_cassette("channel_find") do + list = Slack::Workspace.channel_list_all + + expect(list.length).must_equal 3 + expect(list).must_include "random" + expect(list).wont_include "test" + end + end +end + +describe "self.all_channels_details" do + it "returns an array of channel details" do + VCR.use_cassette("channel_find") do + details = Slack::Workspace.all_channels_details + + expect(details.length).must_equal 3 + end + end +end + describe "self.select_channel" do it "can select a channel and return it" do VCR.use_cassette("channel_find") do @@ -16,6 +38,38 @@ end end +describe "self.selected_channel_details" do + it "returns the details for the selected channel" do + VCR.use_cassette("channel_find") do + channel_details = Slack::Workspace.selected_channel_details("CH2NW42JF") + ap channel_details + # expect(channel_details.length).must_equal 1 + end + end +end + +describe "self.user_list_all" do + it "returns an array of user names" do + VCR.use_cassette("user_find") do + list = Slack::Workspace.user_list_all + ap list + expect(list.length).must_equal 3 + expect(list).must_include "slackbot" + expect(list).wont_include "test" + end + end +end + +describe "self.all_users_details" do + it "returns an array of users details" do + VCR.use_cassette("user_find") do + details = Slack::Workspace.all_users_details + + expect(details.length).must_equal 3 + end + end +end + describe "self.select_user" do it "can select a user and return it" do VCR.use_cassette("user_find") do From 9039c1ec8093a6f0846210e7e65ef42defa744db Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Fri, 22 Mar 2019 08:58:53 -0700 Subject: [PATCH 25/35] working on selected channel details --- lib/channel.rb | 16 ++++++++++++ lib/slack.rb | 67 ++++++++++++------------------------------------ lib/user.rb | 16 ++++++++++++ lib/workspace.rb | 4 +-- 4 files changed, 50 insertions(+), 53 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 3dc4b7bd..ff46dffb 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -31,5 +31,21 @@ def self.list_all end return all_channels end + + def send_message(channel, message) + url = "https://slack.com/api/chat.postMessage" + params = { + token: ENV["KEY"], + channel: channel_identifier, + text: message, + } + + message_request = HTTParty.post(URL, query: params) + if message_request["ok"] == false + raise ArgumentError, "Request is unsuccessful" + else + return message_request + end + end end end diff --git a/lib/slack.rb b/lib/slack.rb index 9f124806..a069cb20 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -23,25 +23,24 @@ def main when "list channels" puts Slack::Workspace.all_channels_details when "select channel" - puts "Which user would you like to select?" - user_identifier = gets.chomp.downcase.to_s - selected_channel = Slack::Workspace.select_user(user_identifier) - # if selected_channel == nil - # puts "This channel doesn't exist. Exiting to main menu" - # else - # puts "You have selected #{selected_channel.name}. Please type 'details' for more info!" - # answer = gets.chomp.downcase - # if answer == "details" - # puts selected_channel - - # end - # if answers + puts "Which channel would you like to select?" + channel_identifier = gets.chomp.downcase.to_s + selected_channel = Slack::Workspace.select_channel(channel_identifier) + if selected_channel == nil + puts "This channel doesn't exist. Exiting to main menu" + else + puts "You have selected #{selected_channel.name}. Please type 'details' for more info!" + answer = gets.chomp.downcase + if answer == "details" + puts Slack::Workspace.selected_channel_details(selected_channel) + end + end when "list users" puts Slack::Workspace.all_users_details - # when "select user" - # puts "Which user would you like to select?" - # user_identifier = gets.chomp.downcase.to_s - # selected_user = Slack::Workspace.select_channel(user_identifier) + when "select user" + puts "Which user would you like to select?" + user_identifier = gets.chomp.downcase.to_s + selected_user = Slack::Workspace.select_channel(user_identifier) # puts selected_channel when "quit" else @@ -57,37 +56,3 @@ def main end main if __FILE__ == $PROGRAM_NAME - -def send_message(user, message) - url = "https://slack.com/api/chat.postMessage" - params = { - token: ENV["KEY"], - channel: user_identifier, - text: message, - } - - message_request = HTTParty.post(URL, query: params) - if message_request["ok"] == false - raise ArgumentError, "Request is unsuccessful" - else - return message_request - end - end -end - -def send_message(channel, message) - url = "https://slack.com/api/chat.postMessage" - params = { - token: ENV["KEY"], - channel: channel_identifier, - text: message, - } - - message_request = HTTParty.post(URL, query: params) - if message_request["ok"] == false - raise ArgumentError, "Request is unsuccessful" - else - return message_request - end - end -end diff --git a/lib/user.rb b/lib/user.rb index da45977c..1a1c432f 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -26,5 +26,21 @@ def self.list_all end return users end + + def send_message(user, message) + url = "https://slack.com/api/chat.postMessage" + params = { + token: ENV["KEY"], + channel: user_identifier, + text: message, + } + + message_request = HTTParty.post(URL, query: params) + if message_request["ok"] == false + raise ArgumentError, "Request is unsuccessful" + else + return message_request + end + end end end diff --git a/lib/workspace.rb b/lib/workspace.rb index 52f3fc9a..37e4eaf1 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -28,7 +28,7 @@ def self.select_channel(channel_identifier) channel.name == channel_identifier || channel.slack_id == channel_identifier } - + # put some sort argument error here? return find_channel end @@ -55,7 +55,7 @@ def self.user_list_all def self.all_users_details users = Slack::User.list_all.map do |user| - "User ID: #{user.slack_id}'s real name is #{user.real_name} and display name is #{user.name}." + "User ID: #{user.slack_id}: \nReal name: #{user.real_name} \nDisplay name: #{user.name}." end return users end From f4ee7236925b28a3f787ebb422d9a603d0eec652 Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Fri, 22 Mar 2019 09:57:51 -0700 Subject: [PATCH 26/35] made minor syntax changes --- lib/slack.rb | 2 +- lib/workspace.rb | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index a069cb20..e2679c92 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -26,7 +26,7 @@ def main puts "Which channel would you like to select?" channel_identifier = gets.chomp.downcase.to_s selected_channel = Slack::Workspace.select_channel(channel_identifier) - if selected_channel == nil + if selected_channel.nil? puts "This channel doesn't exist. Exiting to main menu" else puts "You have selected #{selected_channel.name}. Please type 'details' for more info!" diff --git a/lib/workspace.rb b/lib/workspace.rb index 37e4eaf1..fde17291 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -23,11 +23,10 @@ def self.all_channels_details end def self.select_channel(channel_identifier) - find_channel = Slack::Channel.list_all.find { - |channel| + find_channel = Slack::Channel.list_all.find do |channel| channel.name == channel_identifier || channel.slack_id == channel_identifier - } + end # put some sort argument error here? return find_channel end From 8e924dfef955d0072323157676b8167f39915322 Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Fri, 22 Mar 2019 10:05:09 -0700 Subject: [PATCH 27/35] made changes to selected_channel_details method in workspace --- lib/workspace.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index fde17291..0d6971c4 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -3,6 +3,7 @@ require_relative "recipient" require "dotenv" require "httparty" +require "pry" Dotenv.load module Slack @@ -31,17 +32,10 @@ def self.select_channel(channel_identifier) return find_channel end - def self.selected_channel_details(channel_identifier) - chosen_channel = self.select_channel(channel_identifier) - + def self.selected_channel_details(chosen_channel) details = "Channel ID: #{chosen_channel.slack_id}\nChannel name: #{chosen_channel.name} \nMembers: #{chosen_channel.num_members} \nChannel Topic: #{chosen_channel.topic}" return details - - # chosen_channel = self.select_channel(channel_identifier) - - # details = chosen_channel.self.all_channels_details - # return details end def self.user_list_all From 3764283358efd76675a5cfa17264f3e4676b328d Mon Sep 17 00:00:00 2001 From: Heather Izumi Date: Fri, 22 Mar 2019 10:48:23 -0700 Subject: [PATCH 28/35] Finished list channel/user details method and CLI, added test for list channel method --- lib/slack.rb | 16 ++++++++++++---- lib/workspace.rb | 12 ++++++++---- specs/workspace_spec.rb | 12 ++++++++++-- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index e2679c92..b9da0efa 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -24,7 +24,7 @@ def main puts Slack::Workspace.all_channels_details when "select channel" puts "Which channel would you like to select?" - channel_identifier = gets.chomp.downcase.to_s + channel_identifier = gets.chomp.to_s selected_channel = Slack::Workspace.select_channel(channel_identifier) if selected_channel.nil? puts "This channel doesn't exist. Exiting to main menu" @@ -39,9 +39,17 @@ def main puts Slack::Workspace.all_users_details when "select user" puts "Which user would you like to select?" - user_identifier = gets.chomp.downcase.to_s - selected_user = Slack::Workspace.select_channel(user_identifier) - # puts selected_channel + user_identifier = gets.chomp.to_s + selected_user = Slack::Workspace.select_user(user_identifier) + if selected_user.nil? + puts "This user doesn't exist. Exiting to main menu" + else + puts "You have selected #{selected_user.name}. Please type 'details' for more info!" + answer = gets.chomp.downcase + if answer == "details" + puts Slack::Workspace.selected_user_details(selected_user) + end + end when "quit" else puts "Please enter a valid selection." diff --git a/lib/workspace.rb b/lib/workspace.rb index 0d6971c4..257dc314 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -25,8 +25,8 @@ def self.all_channels_details def self.select_channel(channel_identifier) find_channel = Slack::Channel.list_all.find do |channel| - channel.name == channel_identifier || - channel.slack_id == channel_identifier + channel.name.downcase == channel_identifier.downcase || + channel.slack_id.downcase == channel_identifier.downcase end # put some sort argument error here? return find_channel @@ -56,12 +56,16 @@ def self.all_users_details def self.select_user(user_identifier) find_user = Slack::User.list_all.find { |user| - user.name == user_identifier || - user.slack_id == user_identifier + user.name.downcase == user_identifier.downcase || + user.slack_id.downcase == user_identifier.downcase } return find_user end + + def self.selected_user_details(chosen_user) + details = "User ID: #{chosen_user.slack_id}: \nReal name: #{chosen_user.real_name} \nDisplay name: #{chosen_user.name}." + end end end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 459542d6..e5333df9 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -34,6 +34,9 @@ expect(selected_channel.name).must_equal "general" expect(selected_channel.slack_id).must_equal "CH2NW42JF" + + selected_channel = Slack::Workspace.select_channel("geNeral") + expect(selected_channel.name).must_equal "general" end end end @@ -41,9 +44,11 @@ describe "self.selected_channel_details" do it "returns the details for the selected channel" do VCR.use_cassette("channel_find") do - channel_details = Slack::Workspace.selected_channel_details("CH2NW42JF") + channel = Slack::Channel.new("Pfeiffer_id", "Pfeiffer_name", 5, "Pfeiffer_topic") + channel_details = Slack::Workspace.selected_channel_details(channel) ap channel_details - # expect(channel_details.length).must_equal 1 + expect(channel_details).must_match "Pfeiffer_id" + expect(channel_details).must_match "Pfeiffer_topic" end end end @@ -82,6 +87,9 @@ expect(selected_user.name).must_equal "slackbot" expect(selected_user.slack_id).must_equal "USLACKBOT" + + selected_user = Slack::Workspace.select_user("USLACKbOT") + expect(selected_user.name).must_equal "slackbot" end end end From f58feb9e104ca41a5e549b3e5eeb40ca7d6b386b Mon Sep 17 00:00:00 2001 From: Heather Izumi Date: Fri, 22 Mar 2019 11:23:01 -0700 Subject: [PATCH 29/35] added tests for workspace, moved post message method to recipient class --- lib/recipient.rb | 22 +++++++++++++++++++--- lib/user.rb | 2 +- lib/workspace.rb | 2 -- specs/workspace_spec.rb | 12 ++++++++++++ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index f1e9fed7..567659a7 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -7,12 +7,28 @@ def initialize(slack_id, name) @name = name end + def send_message(message) + url = "https://slack.com/api/chat.postMessage" + params = { + token: ENV["KEY"], + channel: recipient_identifier, + text: message, + } + + message_request = HTTParty.post(URL, query: params) + if message_request["ok"] == false + raise ArgumentError, "Request is unsuccessful" + else + return message_request + end + end + # def self.get(url, params) # HTTParty.GET(url, query: params) # end - # def self.list_all - # raise NotImplementedError, "Please implement in my child." - # end + def self.list_all + raise NotImplementedError, "Please implement in my child." + end end end diff --git a/lib/user.rb b/lib/user.rb index 1a1c432f..25369cb2 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -27,7 +27,7 @@ def self.list_all return users end - def send_message(user, message) + def send_message(message) url = "https://slack.com/api/chat.postMessage" params = { token: ENV["KEY"], diff --git a/lib/workspace.rb b/lib/workspace.rb index 257dc314..3f0d1991 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -68,5 +68,3 @@ def self.selected_user_details(chosen_user) end end end - -# put Slack::Workspace.selected_channel_details("CH2NW42JF") diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index e5333df9..a7290a7d 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -93,3 +93,15 @@ end end end + +describe "self.selected_user_details" do + it "returns the details for the selected user" do + VCR.use_cassette("user_find") do + user = Slack::User.new("RS100", "Robot", "Robot Smith") + user_details = Slack::Workspace.selected_user_details(user) + + expect(user_details).must_match "RS100" + expect(user_details).must_match "Robot Smith" + end + end +end From acd65e2190e2ca836b8661362aeae834d344fd82 Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Fri, 22 Mar 2019 11:25:37 -0700 Subject: [PATCH 30/35] completed slack prompt for details --- .DS_Store | Bin 6148 -> 6148 bytes lib/slack.rb | 20 ++++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.DS_Store b/.DS_Store index 6dcdae3bec1b05d4bc5b397db34ae3ed258f3ff4..6a43182e04412977c34814a208309a8f64d1649d 100644 GIT binary patch delta 16 XcmZoMXffC@kA3oGR?p4P*<}R)IW7i3 delta 25 gcmZoMXffC@kDbHR#9T+g$kcf9ZC1z4&)H=K0B0Wu&Hw-a diff --git a/lib/slack.rb b/lib/slack.rb index b9da0efa..d5c6b6ba 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -15,7 +15,7 @@ def main print "\nUsers loaded: ", Slack::Workspace.user_list_all.length - puts "\nPlease select from the following options: \n list channels, select channel, list users, select user, details, or quit" + puts "\nPlease select from the following options: \n list channels, select channel, list users, select user, or quit" selection = gets.chomp.downcase until selection == "quit" @@ -29,10 +29,14 @@ def main if selected_channel.nil? puts "This channel doesn't exist. Exiting to main menu" else - puts "You have selected #{selected_channel.name}. Please type 'details' for more info!" + puts "You have selected #{selected_channel.name}. Please type 'details' for more info or quit!" answer = gets.chomp.downcase - if answer == "details" + case answer + when "details" puts Slack::Workspace.selected_channel_details(selected_channel) + when "quit" + else + puts "Please select a valid input. Returning to main!" end end when "list users" @@ -44,10 +48,14 @@ def main if selected_user.nil? puts "This user doesn't exist. Exiting to main menu" else - puts "You have selected #{selected_user.name}. Please type 'details' for more info!" + puts "You have selected #{selected_user.name}. Please type 'details' for more info or quit!" answer = gets.chomp.downcase - if answer == "details" - puts Slack::Workspace.selected_user_details(selected_user) + case answer + when "details" + puts puts Slack::Workspace.selected_user_details(selected_user) + when "quit" + else + puts "Please select a valid input. Returning to main!" end end when "quit" From 8249ccdc73f14df9dd2751c5fdb9e5a4fe39d942 Mon Sep 17 00:00:00 2001 From: Heather Izumi Date: Fri, 22 Mar 2019 13:02:39 -0700 Subject: [PATCH 31/35] Started message method in workspace --- lib/channel.rb | 16 ---------------- lib/user.rb | 16 ---------------- lib/workspace.rb | 3 +++ 3 files changed, 3 insertions(+), 32 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index ff46dffb..3dc4b7bd 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -31,21 +31,5 @@ def self.list_all end return all_channels end - - def send_message(channel, message) - url = "https://slack.com/api/chat.postMessage" - params = { - token: ENV["KEY"], - channel: channel_identifier, - text: message, - } - - message_request = HTTParty.post(URL, query: params) - if message_request["ok"] == false - raise ArgumentError, "Request is unsuccessful" - else - return message_request - end - end end end diff --git a/lib/user.rb b/lib/user.rb index 25369cb2..da45977c 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -26,21 +26,5 @@ def self.list_all end return users end - - def send_message(message) - url = "https://slack.com/api/chat.postMessage" - params = { - token: ENV["KEY"], - channel: user_identifier, - text: message, - } - - message_request = HTTParty.post(URL, query: params) - if message_request["ok"] == false - raise ArgumentError, "Request is unsuccessful" - else - return message_request - end - end end end diff --git a/lib/workspace.rb b/lib/workspace.rb index 3f0d1991..f8a702ab 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -66,5 +66,8 @@ def self.select_user(user_identifier) def self.selected_user_details(chosen_user) details = "User ID: #{chosen_user.slack_id}: \nReal name: #{chosen_user.real_name} \nDisplay name: #{chosen_user.name}." end + + def post_message_to(recipient_id) + end end end From ad6efe695c0f6c8add8e7f357b7fa73da32a5a6c Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Fri, 22 Mar 2019 14:25:59 -0700 Subject: [PATCH 32/35] added send message feature in slack.rb --- lib/recipient.rb | 6 +++--- lib/slack.rb | 24 +++++++++++++++++++++--- lib/workspace.rb | 3 --- specs/recipient_spec.rb | 18 +++++++++++++++++- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 567659a7..0e951a1e 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -7,15 +7,15 @@ def initialize(slack_id, name) @name = name end - def send_message(message) + def post_message(message) url = "https://slack.com/api/chat.postMessage" params = { token: ENV["KEY"], - channel: recipient_identifier, + channel: @slack_id || @name, text: message, } - message_request = HTTParty.post(URL, query: params) + message_request = HTTParty.post(url, query: params) if message_request["ok"] == false raise ArgumentError, "Request is unsuccessful" else diff --git a/lib/slack.rb b/lib/slack.rb index d5c6b6ba..e9add367 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -29,11 +29,20 @@ def main if selected_channel.nil? puts "This channel doesn't exist. Exiting to main menu" else - puts "You have selected #{selected_channel.name}. Please type 'details' for more info or quit!" + puts "You have selected #{selected_channel.name}. What would you like to do: details, send message, or quit" answer = gets.chomp.downcase case answer when "details" puts Slack::Workspace.selected_channel_details(selected_channel) + when "send message" + puts "Type message: " + message = gets.chomp + if message == "" + puts "Can't send a blank message. \nType message :" + message = gets.chomp + else + Slack::Recipient.new(selected_channel.slack_id, selected_channel.name).post_message(message) + end when "quit" else puts "Please select a valid input. Returning to main!" @@ -48,11 +57,20 @@ def main if selected_user.nil? puts "This user doesn't exist. Exiting to main menu" else - puts "You have selected #{selected_user.name}. Please type 'details' for more info or quit!" + puts "You have selected #{selected_user.name}. What would you like to do: details, send message, or quit" answer = gets.chomp.downcase case answer when "details" - puts puts Slack::Workspace.selected_user_details(selected_user) + puts Slack::Workspace.selected_user_details(selected_user) + when "send message" + puts "Type message: " + message = gets.chomp + if message == "" + puts "Can't send a blank message. \nType message :" + message = gets.chomp + else + Slack::Recipient.new(selected_user.slack_id, selected_user.name).post_message(message) + end when "quit" else puts "Please select a valid input. Returning to main!" diff --git a/lib/workspace.rb b/lib/workspace.rb index f8a702ab..3f0d1991 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -66,8 +66,5 @@ def self.select_user(user_identifier) def self.selected_user_details(chosen_user) details = "User ID: #{chosen_user.slack_id}: \nReal name: #{chosen_user.real_name} \nDisplay name: #{chosen_user.name}." end - - def post_message_to(recipient_id) - end end end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index bad7e41c..ce03c7ce 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -1,4 +1,5 @@ -require "test_helper.rb" +require_relative "test_helper.rb" +require "pry" describe "Recipient class" do it "creates an instance of Recipient class" do @@ -6,3 +7,18 @@ expect(receiver).must_be_instance_of Slack::Recipient end end + +describe "Post message method" do + it "will return a true value for 'ok'" do + VCR.use_cassette("message_find") do + recipient_id = "USLACKBOT" + name = "slackbot" + + message = "Hi Slackbot! - Heather and Mina" + + new_message = Slack::Recipient.new(recipient_id, name).post_message(message) + expect(new_message["ok"]).must_equal true + expect(new_message["message"]["text"]).must_match "- Heather and Mina" + end + end +end From 4ecb3fbb6b39fab49ff4eacaf6ab074dd93f7fda Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Fri, 22 Mar 2019 14:32:05 -0700 Subject: [PATCH 33/35] added 2 when to selection case --- lib/slack.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index e9add367..4776ebd4 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -15,7 +15,7 @@ def main print "\nUsers loaded: ", Slack::Workspace.user_list_all.length - puts "\nPlease select from the following options: \n list channels, select channel, list users, select user, or quit" + puts "\nPlease select from the following options: \n list channels, select channel, list users, select user, details, send message, or quit" selection = gets.chomp.downcase until selection == "quit" @@ -76,11 +76,15 @@ def main puts "Please select a valid input. Returning to main!" end end + when "details" || "send message" + puts "You haven't selected a user or channel. Exiting to main prompt." + when "send message" + puts "You haven't selected a user or channel. Exiting to main prompt." when "quit" else puts "Please enter a valid selection." end - puts "What would you like to do next? (list users, select user, list channels, select channel, or quit)" + puts "What would you like to do next? (list users, select user, list channels, select channel, details, send message, or quit)" selection = gets.chomp.downcase end From b14f42d099c3d94bb7792816d3aa8275aab9b297 Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Fri, 22 Mar 2019 15:35:19 -0700 Subject: [PATCH 34/35] refactor --- lib/slack.rb | 2 +- lib/workspace.rb | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 4776ebd4..eb22f463 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -76,7 +76,7 @@ def main puts "Please select a valid input. Returning to main!" end end - when "details" || "send message" + when "details" puts "You haven't selected a user or channel. Exiting to main prompt." when "send message" puts "You haven't selected a user or channel. Exiting to main prompt." diff --git a/lib/workspace.rb b/lib/workspace.rb index 3f0d1991..0b9cb280 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -17,10 +17,7 @@ def self.channel_list_all end def self.all_channels_details - channels = Slack::Channel.list_all.map do |channel| - "Channel ID: #{channel.slack_id}\nChannel name: #{channel.name} \nMembers: #{channel.num_members} \nChannel Topic: #{channel.topic}" - end - return channels + return Slack::Channel.list_all.map { |channel| channel.convert_to_string } end def self.select_channel(channel_identifier) @@ -28,7 +25,6 @@ def self.select_channel(channel_identifier) channel.name.downcase == channel_identifier.downcase || channel.slack_id.downcase == channel_identifier.downcase end - # put some sort argument error here? return find_channel end From 5a0cd3775f5e446124be25dca9b6b286ff8c2238 Mon Sep 17 00:00:00 2001 From: Mina Shin Date: Mon, 25 Mar 2019 09:40:34 -0700 Subject: [PATCH 35/35] removed ap and re-added method in workspace.rb and spec --- lib/workspace.rb | 5 ++++- specs/workspace_spec.rb | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index 0b9cb280..2b28e406 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -17,7 +17,10 @@ def self.channel_list_all end def self.all_channels_details - return Slack::Channel.list_all.map { |channel| channel.convert_to_string } + channels = Slack::Channel.list_all.map do |channel| + "Channel ID: #{channel.slack_id}\nChannel name: #{channel.name} \nMembers: #{channel.num_members} \nChannel Topic: #{channel.topic}" + end + return channels end def self.select_channel(channel_identifier) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index a7290a7d..c116c265 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -46,7 +46,7 @@ VCR.use_cassette("channel_find") do channel = Slack::Channel.new("Pfeiffer_id", "Pfeiffer_name", 5, "Pfeiffer_topic") channel_details = Slack::Workspace.selected_channel_details(channel) - ap channel_details + expect(channel_details).must_match "Pfeiffer_id" expect(channel_details).must_match "Pfeiffer_topic" end @@ -57,7 +57,6 @@ it "returns an array of user names" do VCR.use_cassette("user_find") do list = Slack::Workspace.user_list_all - ap list expect(list.length).must_equal 3 expect(list).must_include "slackbot" expect(list).wont_include "test"