From 1f1590e3a4786c6dd7ea2c8e913ae1359601f0bc Mon Sep 17 00:00:00 2001 From: qqdipps Date: Mon, 18 Mar 2019 22:14:49 -0700 Subject: [PATCH 01/84] setting-up --- lib/slack.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/slack.rb b/lib/slack.rb index 960cf2f7..1ee5a205 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -8,4 +8,4 @@ def main 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 From b973b4f272b204f16c7771ec2b790d0db03c7b9f Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Mon, 18 Mar 2019 22:18:12 -0700 Subject: [PATCH 02/84] successfully verify the HTTP request --- lib/slack.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/slack.rb b/lib/slack.rb index 960cf2f7..9f7a1af0 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,4 +1,22 @@ #!/usr/bin/env ruby +require 'HTTParty' +require 'dotenv' +require 'awesome_print' +Dotenv.load + +url = 'https://slack.com/api/conversations.list' +key = ENV["SLACK_API_KEY"] + +query_params = { + "token": key, +} +response = HTTParty.get(url, query: query_params) + +# ap JSON.parse(response.body) + +response["channels"].each do |channel| + ap channel["name"] +end def main puts "Welcome to the Ada Slack CLI!" From 78009f76de599cccf2cf53cfab0bb785fa427a2a Mon Sep 17 00:00:00 2001 From: qqdipps Date: Mon, 18 Mar 2019 22:37:29 -0700 Subject: [PATCH 03/84] trying to verify token --- lib/slack.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index ccc44447..b0f5acc6 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,14 +1,15 @@ #!/usr/bin/env ruby -require 'HTTParty' -require 'dotenv' -require 'awesome_print' +require "HTTParty" +require "dotenv" +require "awesome_print" Dotenv.load -url = 'https://slack.com/api/conversations.list' +url = "https://slack.com/api/conversations.list" key = ENV["SLACK_API_KEY"] +p key query_params = { - "token": key, + token: key, } response = HTTParty.get(url, query: query_params) From 7bbe35ab855db96044a537f2bbc00cb70ccf2286 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Tue, 19 Mar 2019 16:10:19 -0700 Subject: [PATCH 04/84] VCR configure --- specs/test_helper.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 81ccd06b..3f628a04 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -12,4 +12,12 @@ 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_API_KEY"] + end end \ No newline at end of file From dcf70d730b8aab9be2dbcfbcd13d44f9e35350ae Mon Sep 17 00:00:00 2001 From: qqdipps Date: Tue, 19 Mar 2019 16:12:59 -0700 Subject: [PATCH 05/84] merge conflict --- lib/slack.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/slack.rb b/lib/slack.rb index b0f5acc6..e399c61c 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -6,7 +6,6 @@ url = "https://slack.com/api/conversations.list" key = ENV["SLACK_API_KEY"] -p key query_params = { token: key, From 5eb884b3dc07a89b281ba2ebcd1c2669a1474d90 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Tue, 19 Mar 2019 16:20:37 -0700 Subject: [PATCH 06/84] test Recipient-initialize method --- specs/recipient_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 specs/recipient_spec.rb diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb new file mode 100644 index 00000000..11ac820a --- /dev/null +++ b/specs/recipient_spec.rb @@ -0,0 +1,7 @@ +require 'test_helper.rb' + +describe "Recipient class" do + describe "initialize" do + expect(Slack::Recipient.new(name: "test", id: "abc")).must_be_instance_of Slack::Recipient + end +end \ No newline at end of file From 355aa6f4013d4a0191bdc4e2cbe0bc14877ebbc9 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Tue, 19 Mar 2019 16:30:30 -0700 Subject: [PATCH 07/84] created recipient class and new test for vars --- lib/recipient.rb | 6 ++++++ specs/recipient_spec.rb | 18 +++++++++++++++--- specs/test_helper.rb | 16 +++++++++------- 3 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 lib/recipient.rb diff --git a/lib/recipient.rb b/lib/recipient.rb new file mode 100644 index 00000000..74da7945 --- /dev/null +++ b/lib/recipient.rb @@ -0,0 +1,6 @@ +module Slack + class Recipient + def initialize(name:, id:) + end + end +end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 11ac820a..9ec5343c 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -1,7 +1,19 @@ -require 'test_helper.rb' +require_relative "test_helper.rb" describe "Recipient class" do + let(:r) { + Slack::Recipient.new(name: "test", id: "abc") + } describe "initialize" do - expect(Slack::Recipient.new(name: "test", id: "abc")).must_be_instance_of Slack::Recipient + it "must be a kind of Recipient" do + expect(r).must_be_instance_of Slack::Recipient + end + + it "will respond to instance variable, and equal correct value" do + expect(r).must_respond_to :name + expect(r).must_respond_to :id + expect(r.name).must_equal "test" + expect(r.id).must_equal "abc" + end end -end \ No newline at end of file +end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 3f628a04..7f33c020 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -1,11 +1,13 @@ -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/recipient.rb" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new @@ -20,4 +22,4 @@ config.filter_sensitive_data("") do ENV["SLACK_API_KEY"] end -end \ No newline at end of file +end From 43009428c2069941d03952a6ba4dfb01dcef83d6 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Tue, 19 Mar 2019 16:33:26 -0700 Subject: [PATCH 08/84] passed test 0002 for intialize method --- lib/recipient.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/recipient.rb b/lib/recipient.rb index 74da7945..20a01fb5 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,6 +1,9 @@ module Slack class Recipient + attr_reader :name, :id def initialize(name:, id:) + @name = name + @id = id end end end From 1e9a7da207209a7dea2c806408c2cf74d7dcefa0 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Wed, 20 Mar 2019 09:15:08 -0700 Subject: [PATCH 09/84] added webmock in test_helper --- specs/test_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 7f33c020..771e85e9 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -5,6 +5,7 @@ require "minitest/autorun" require "minitest/reporters" require "minitest/skip_dsl" +require "webmock/minitest" require "vcr" require_relative "../lib/recipient.rb" From fe963c2e199bc553c7ac825c92c5baafa16a6009 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Wed, 20 Mar 2019 09:22:22 -0700 Subject: [PATCH 10/84] added dotenv to test_helper.rb --- specs/test_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 771e85e9..3bfdd792 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -7,6 +7,8 @@ require "minitest/skip_dsl" require "webmock/minitest" require "vcr" +require "dotenv" +Dotenv.load require_relative "../lib/recipient.rb" From 17fbcaec685f1bb83354a531334943ced41c40be Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Wed, 20 Mar 2019 13:35:30 -0700 Subject: [PATCH 11/84] added test for details method in Recipient class --- specs/recipient_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 9ec5343c..403bcc79 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -16,4 +16,14 @@ expect(r.id).must_equal "abc" end end + + # Check details raising NotImplemented Error when being called + + describe "details method" do + it "raises an error when being invoked by an instance of Recipient" do + expect { + r.details + }.must_raise NotImplementedError + end + end end From 43d65a71093e21385990c909e5c1137119f692ef Mon Sep 17 00:00:00 2001 From: qqdipps Date: Wed, 20 Mar 2019 13:37:59 -0700 Subject: [PATCH 12/84] details implemented for reciept class --- lib/recipient.rb | 5 +++++ specs/user_spec.rb | 0 2 files changed, 5 insertions(+) create mode 100644 specs/user_spec.rb diff --git a/lib/recipient.rb b/lib/recipient.rb index 20a01fb5..e008a7f6 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,9 +1,14 @@ module Slack class Recipient attr_reader :name, :id + def initialize(name:, id:) @name = name @id = id end + + def details + raise NotImplementedError.new + end end end diff --git a/specs/user_spec.rb b/specs/user_spec.rb new file mode 100644 index 00000000..e69de29b From ecada61a721419fb3676bde42a1df120c7f9a63e Mon Sep 17 00:00:00 2001 From: qqdipps Date: Wed, 20 Mar 2019 13:41:27 -0700 Subject: [PATCH 13/84] added tests for initialize User class. --- specs/user_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/specs/user_spec.rb b/specs/user_spec.rb index e69de29b..9f0b62a3 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -0,0 +1,13 @@ +require_relative "test_helper" + +describe "User class" do + let(:user) { + Slack::User.new(id: "123", name: "sam", real_name: "sam bones") + } + describe "User#initialize" do + it "Check type is User and type Recipient" do + expect(user).must_be_instance_of Slack::User + expect(user).must_be_kind_of Slack::Recipient + end + end +end From 447dae2b850f728cb9b8ab9949d449accd24a350 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Wed, 20 Mar 2019 13:47:27 -0700 Subject: [PATCH 14/84] completed initialize for user class --- lib/user.rb | 10 ++++++++++ specs/test_helper.rb | 2 ++ 2 files changed, 12 insertions(+) create mode 100644 lib/user.rb diff --git a/lib/user.rb b/lib/user.rb new file mode 100644 index 00000000..c5e629af --- /dev/null +++ b/lib/user.rb @@ -0,0 +1,10 @@ +module Slack + class User < Recipient + attr_reader :real_name + + def initialize(id:, name:, real_name:) + super(id: id, name: name) + @real_name = real_name + end + end +end \ No newline at end of file diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 3bfdd792..60005c6e 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -8,9 +8,11 @@ require "webmock/minitest" require "vcr" require "dotenv" + Dotenv.load require_relative "../lib/recipient.rb" +require_relative "../lib/user.rb" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From deb6d793c9ed1c4e8a73d87ba59db6d5c4ae2faf Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Wed, 20 Mar 2019 13:52:19 -0700 Subject: [PATCH 15/84] added test for details in user class --- specs/user_spec.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 9f0b62a3..8efc1cb9 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -5,9 +5,24 @@ Slack::User.new(id: "123", name: "sam", real_name: "sam bones") } describe "User#initialize" do - it "Check type is User and type Recipient" do + it "Checks type is User and type Recipient" do expect(user).must_be_instance_of Slack::User expect(user).must_be_kind_of Slack::Recipient end + + it "Checks instance variable name, real_name and id: respond & equal to" do + expect(user.name).must_equal "sam" + expect(user.real_name).must_equal "sam bones" + expect(user.id).must_equal "123" + end end + + # Check details method return String type + + describe "User#details" do + it "returns a String" do + expect(user.details).must_be_instance_of String + end + end + end From a8baccb518dd10cd475c7072e28c94d1d39bf6e5 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Wed, 20 Mar 2019 13:57:32 -0700 Subject: [PATCH 16/84] added test for details, passed string type return --- lib/user.rb | 6 +++++- specs/user_spec.rb | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index c5e629af..771500e0 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -6,5 +6,9 @@ def initialize(id:, name:, real_name:) super(id: id, name: name) @real_name = real_name end + + def details + return "" + end end -end \ No newline at end of file +end diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 8efc1cb9..b104171f 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -23,6 +23,10 @@ it "returns a String" do expect(user.details).must_be_instance_of String end - end + it "Checks details return the accurate String: " do + string_format = "Name: #{user.name}, \nReal Name: #{user.real_name}, \nID: #{user.id}" + expect(user.details).must_equal string_format + end + end end From c4d6e1b7156ddff82c2bb9b84458e7442374e938 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Wed, 20 Mar 2019 13:59:06 -0700 Subject: [PATCH 17/84] completed details method, added return string format --- lib/user.rb | 2 +- specs/user_spec.rb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index 771500e0..6a2f0154 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -8,7 +8,7 @@ def initialize(id:, name:, real_name:) end def details - return "" + return "Name: #{name}, \nReal Name: #{real_name}, \nID: #{id}" end end end diff --git a/specs/user_spec.rb b/specs/user_spec.rb index b104171f..1a0598f7 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -17,8 +17,6 @@ end end - # Check details method return String type - describe "User#details" do it "returns a String" do expect(user.details).must_be_instance_of String From 646392edc4d99c73ce7480ddd324141799763b51 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Wed, 20 Mar 2019 14:03:58 -0700 Subject: [PATCH 18/84] added tests for Channel#initialize --- specs/channel_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 specs/channel_spec.rb diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb new file mode 100644 index 00000000..fe92fa86 --- /dev/null +++ b/specs/channel_spec.rb @@ -0,0 +1,13 @@ +require_relative 'test_helper.rb' + +describe "Channel class" do + describe "Channel#initialize" do + let(:channel) { + Slack::Channel.new(id: "CBD", name: "general", topic: "stuff", member_count: "4") + } + it "returns an instance of Channel and a kind of Recipient" do + expect(channel).must_be_instance_of Slack::Channel + expect(channel).must_be_kind_of Slack::Recipient + end + end +end \ No newline at end of file From 1ca7c14172d15835b2d2303b1f87b1371009204f Mon Sep 17 00:00:00 2001 From: qqdipps Date: Wed, 20 Mar 2019 14:06:47 -0700 Subject: [PATCH 19/84] added class name --- lib/channel.rb | 6 ++++++ specs/test_helper.rb | 1 + 2 files changed, 7 insertions(+) create mode 100644 lib/channel.rb diff --git a/lib/channel.rb b/lib/channel.rb new file mode 100644 index 00000000..c79a88c8 --- /dev/null +++ b/lib/channel.rb @@ -0,0 +1,6 @@ +module Slack + class Channel < Recipient + def initialize(id:, name:, member_count:, topic:) + end + end +end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 60005c6e..3e72f648 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -13,6 +13,7 @@ require_relative "../lib/recipient.rb" require_relative "../lib/user.rb" +require_relative "../lib/channel" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From dd88f725c0e12c48d6e5b6aa95a68949f997860a Mon Sep 17 00:00:00 2001 From: qqdipps Date: Wed, 20 Mar 2019 14:10:06 -0700 Subject: [PATCH 20/84] added tests for instance vars --- specs/channel_spec.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index fe92fa86..a356f605 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -1,4 +1,4 @@ -require_relative 'test_helper.rb' +require_relative "test_helper.rb" describe "Channel class" do describe "Channel#initialize" do @@ -9,5 +9,17 @@ expect(channel).must_be_instance_of Slack::Channel expect(channel).must_be_kind_of Slack::Recipient end + + it "Checks instance variable name, id, topic, member_count: respond & equal to" do + expect(channel).must_respond_to :name + expect(channel).must_respond_to :id + expect(channel).must_respond_to :topic + expect(channel).must_respond_to :member_count + + expect(channel.name).must_equal "general" + expect(channel.id).must_equal "CBD" + expect(channel.topic).must_equal "stuff" + expect(channel.member_count).must_equal "4" + end end -end \ No newline at end of file +end From 765c557189b4b32c50b6bb0075d149f191e23341 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Wed, 20 Mar 2019 14:11:39 -0700 Subject: [PATCH 21/84] completed constructor for channel class --- lib/channel.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/channel.rb b/lib/channel.rb index c79a88c8..6cdad6b6 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,6 +1,11 @@ module Slack class Channel < Recipient + attr_reader :member_count, :topic + def initialize(id:, name:, member_count:, topic:) + super(id: id, name: name) + @member_count = member_count + @topic = topic end end end From ea4fe70464dadb135c76859b4231ecb7a1d8647e Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Wed, 20 Mar 2019 14:14:26 -0700 Subject: [PATCH 22/84] added test for Channel#details --- specs/channel_spec.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index a356f605..6a63aa2f 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -1,10 +1,11 @@ require_relative "test_helper.rb" describe "Channel class" do + let(:channel) { + Slack::Channel.new(id: "CBD", name: "general", topic: "stuff", member_count: "4") + } + describe "Channel#initialize" do - let(:channel) { - Slack::Channel.new(id: "CBD", name: "general", topic: "stuff", member_count: "4") - } it "returns an instance of Channel and a kind of Recipient" do expect(channel).must_be_instance_of Slack::Channel expect(channel).must_be_kind_of Slack::Recipient @@ -22,4 +23,10 @@ expect(channel.member_count).must_equal "4" end end + + describe "Channel#details" do + it "returns a String" do + expect(channel.details).must_be_instance_of String + end + end end From 088b575eedf27d650b68f25ef882b04fa44b2d27 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Wed, 20 Mar 2019 14:15:15 -0700 Subject: [PATCH 23/84] added details method signature to channels --- lib/channel.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/channel.rb b/lib/channel.rb index 6cdad6b6..45559c1a 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,11 +1,15 @@ module Slack class Channel < Recipient attr_reader :member_count, :topic - + def initialize(id:, name:, member_count:, topic:) super(id: id, name: name) @member_count = member_count @topic = topic end + + def details + return "" + end end end From 15ff84ca9334ddaecc663e1cd423b8d8917993da Mon Sep 17 00:00:00 2001 From: qqdipps Date: Wed, 20 Mar 2019 14:19:47 -0700 Subject: [PATCH 24/84] added deatails formated expected test --- specs/channel_spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 6a63aa2f..28363f9c 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -4,7 +4,7 @@ let(:channel) { Slack::Channel.new(id: "CBD", name: "general", topic: "stuff", member_count: "4") } - + describe "Channel#initialize" do it "returns an instance of Channel and a kind of Recipient" do expect(channel).must_be_instance_of Slack::Channel @@ -28,5 +28,10 @@ it "returns a String" do expect(channel.details).must_be_instance_of String end + + it "Checks details return the accurate String" do + string_format = "Name: #{channel.name}, \nID: #{channel.id}, \nTopic: #{channel.topic}, \nMember Count: #{channel.member_count}" + expect(channel.details).must_equal string_format + end end end From 6a4e40b95294152c3811a6a9d4a0e4555bdcde2d Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Wed, 20 Mar 2019 14:21:22 -0700 Subject: [PATCH 25/84] complete channel class --- lib/channel.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/channel.rb b/lib/channel.rb index 45559c1a..5e869980 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -9,7 +9,7 @@ def initialize(id:, name:, member_count:, topic:) end def details - return "" + return "Name: #{name}, \nID: #{id}, \nTopic: #{topic}, \nMember Count: #{member_count}" end end end From 4e03f776fb44fc2fe789c5506b4b22ebce8e2c3f Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Wed, 20 Mar 2019 14:31:53 -0700 Subject: [PATCH 26/84] added respond test for api wrapper class --- specs/apiwrapper_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 specs/apiwrapper_spec.rb diff --git a/specs/apiwrapper_spec.rb b/specs/apiwrapper_spec.rb new file mode 100644 index 00000000..e410d6e5 --- /dev/null +++ b/specs/apiwrapper_spec.rb @@ -0,0 +1,9 @@ +require_relative 'test_helper' + +describe "Api Wrapper module" do + it "responds to get_users and get_channels" do + expect(Slack::ApiWrapper).must_respond_to :get_users + expect(Slack::ApiWrapper).must_respond_to :get_channels + end + +end \ No newline at end of file From 28456142736718fbceff3a685b22e1295fa7f22c Mon Sep 17 00:00:00 2001 From: qqdipps Date: Wed, 20 Mar 2019 14:41:04 -0700 Subject: [PATCH 27/84] method signatures for get_channels, get_users --- lib/apiwrapper.rb | 9 +++++++++ specs/apiwrapper_spec.rb | 17 ++++++++++++----- specs/test_helper.rb | 1 + 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 lib/apiwrapper.rb diff --git a/lib/apiwrapper.rb b/lib/apiwrapper.rb new file mode 100644 index 00000000..f1719afe --- /dev/null +++ b/lib/apiwrapper.rb @@ -0,0 +1,9 @@ +module Slack + module ApiWrapper + def self.get_channels + end + + def self.get_users + end + end +end diff --git a/specs/apiwrapper_spec.rb b/specs/apiwrapper_spec.rb index e410d6e5..b3dc0fbd 100644 --- a/specs/apiwrapper_spec.rb +++ b/specs/apiwrapper_spec.rb @@ -1,9 +1,16 @@ -require_relative 'test_helper' +require_relative "test_helper" describe "Api Wrapper module" do - it "responds to get_users and get_channels" do - expect(Slack::ApiWrapper).must_respond_to :get_users - expect(Slack::ApiWrapper).must_respond_to :get_channels + describe "Api Wrapper module" do + it "responds to get_users and get_channels" do + expect(Slack::ApiWrapper).must_respond_to :get_users + expect(Slack::ApiWrapper).must_respond_to :get_channels + end end -end \ No newline at end of file + describe "ApiWrapper.get_users" do + it "will return with array" do + expect(Slack::ApiWrapper.get_users).must_be_instance_of Array + end + end +end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 3e72f648..c9c0618f 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -14,6 +14,7 @@ require_relative "../lib/recipient.rb" require_relative "../lib/user.rb" require_relative "../lib/channel" +require_relative "../lib/apiwrapper" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 4c1de3e00f2ca3e863fdf13cc638160503f4d4e8 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Wed, 20 Mar 2019 14:55:05 -0700 Subject: [PATCH 28/84] added test for get_json method --- lib/apiwrapper.rb | 2 ++ specs/apiwrapper_spec.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/apiwrapper.rb b/lib/apiwrapper.rb index f1719afe..79c5d9da 100644 --- a/lib/apiwrapper.rb +++ b/lib/apiwrapper.rb @@ -4,6 +4,8 @@ def self.get_channels end def self.get_users + users = [] + return users end end end diff --git a/specs/apiwrapper_spec.rb b/specs/apiwrapper_spec.rb index b3dc0fbd..3350dd76 100644 --- a/specs/apiwrapper_spec.rb +++ b/specs/apiwrapper_spec.rb @@ -12,5 +12,20 @@ it "will return with array" do expect(Slack::ApiWrapper.get_users).must_be_instance_of Array end + + # it "will return a " do + # VCR.use_cassette("slack_api") do + # response = get_users + # response["users"].each do |user| + # expect(user["name"]). + # end + # end + # end + end + + describe "ApiWrapper.get_json" do + it "will return a hash" do + expect(Slack::ApiWrapper.get_json).must_be_instance_of Hash + end end end From 07a989f8882db568248660aad2c2ef0597220b80 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Wed, 20 Mar 2019 14:58:13 -0700 Subject: [PATCH 29/84] added get_json method, updated method params --- lib/apiwrapper.rb | 4 ++++ specs/apiwrapper_spec.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/apiwrapper.rb b/lib/apiwrapper.rb index 79c5d9da..b4d41daa 100644 --- a/lib/apiwrapper.rb +++ b/lib/apiwrapper.rb @@ -7,5 +7,9 @@ def self.get_users users = [] return users end + + def self.get_json(url:, query_params:) + return {} + end end end diff --git a/specs/apiwrapper_spec.rb b/specs/apiwrapper_spec.rb index 3350dd76..6ec4d2fc 100644 --- a/specs/apiwrapper_spec.rb +++ b/specs/apiwrapper_spec.rb @@ -25,7 +25,7 @@ describe "ApiWrapper.get_json" do it "will return a hash" do - expect(Slack::ApiWrapper.get_json).must_be_instance_of Hash + expect(Slack::ApiWrapper.get_json(url:"some_url",query_params:{key: "some_key"})).must_be_instance_of Hash end end end From 4021db89bb8e66719f59e2bd1116be788ff66e2e Mon Sep 17 00:00:00 2001 From: qqdipps Date: Wed, 20 Mar 2019 15:09:58 -0700 Subject: [PATCH 30/84] updated test to reflect design change --- specs/apiwrapper_spec.rb | 13 +++++++++++-- specs/test_helper.rb | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/specs/apiwrapper_spec.rb b/specs/apiwrapper_spec.rb index 6ec4d2fc..96995291 100644 --- a/specs/apiwrapper_spec.rb +++ b/specs/apiwrapper_spec.rb @@ -24,8 +24,17 @@ end describe "ApiWrapper.get_json" do - it "will return a hash" do - expect(Slack::ApiWrapper.get_json(url:"some_url",query_params:{key: "some_key"})).must_be_instance_of Hash + VCR.use_cassette("slack_api") do + before do + url = "https://slack.com/api/users.list" + query = { + token: ENV["SLACK_API_KEY"], + } + @response = Slack::ApiWrapper.get_json(url: url, query_params: query) + end + it "will return a Repsonse object" do + expect(@response).must_be_instance_of HTTParty::Response + end end end end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index c9c0618f..563ecbaa 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -8,6 +8,7 @@ require "webmock/minitest" require "vcr" require "dotenv" +require "HTTParty" Dotenv.load From 2bc8f29095ece50764b994dd98a442657e7c11ab Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Wed, 20 Mar 2019 15:26:10 -0700 Subject: [PATCH 31/84] added more tests for get_json --- lib/apiwrapper.rb | 4 +++- specs/apiwrapper_spec.rb | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/apiwrapper.rb b/lib/apiwrapper.rb index b4d41daa..19ba649c 100644 --- a/lib/apiwrapper.rb +++ b/lib/apiwrapper.rb @@ -9,7 +9,9 @@ def self.get_users end def self.get_json(url:, query_params:) - return {} + response = HTTParty.get(url, query: query_params) + + return response end end end diff --git a/specs/apiwrapper_spec.rb b/specs/apiwrapper_spec.rb index 96995291..2a408814 100644 --- a/specs/apiwrapper_spec.rb +++ b/specs/apiwrapper_spec.rb @@ -24,16 +24,27 @@ end describe "ApiWrapper.get_json" do - VCR.use_cassette("slack_api") do - before do + it "will return a Repsonse object" do + VCR.use_cassette("slack_api") do url = "https://slack.com/api/users.list" query = { token: ENV["SLACK_API_KEY"], } - @response = Slack::ApiWrapper.get_json(url: url, query_params: query) + response = Slack::ApiWrapper.get_json(url: url, query_params: query) + expect(response).must_be_instance_of HTTParty::Response end - it "will return a Repsonse object" do - expect(@response).must_be_instance_of HTTParty::Response + end + + it "raises an error when receiving invalid url" do + VCR.use_cassette("slack_api") do + url = "abc" + query = { + token: ENV["SLACK_API_KEY"], + } + + expect { + Slack::ApiWrapper.get_json(url: url, query_params: query) + }.must_raise SlackError end end end From dee69e73424c4286bfdf4fd63c1088abcab8b96f Mon Sep 17 00:00:00 2001 From: qqdipps Date: Wed, 20 Mar 2019 17:34:13 -0700 Subject: [PATCH 32/84] added helper method to build URL for slack api calls, still need regex for testing tail for only alpha and \., tests are green --- lib/apiwrapper.rb | 17 ++++++++++++++--- specs/apiwrapper_spec.rb | 15 +++++++-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/apiwrapper.rb b/lib/apiwrapper.rb index 19ba649c..fb6732d0 100644 --- a/lib/apiwrapper.rb +++ b/lib/apiwrapper.rb @@ -1,17 +1,28 @@ module Slack + class SlackError < Exception; end + module ApiWrapper def self.get_channels end + URL_BASE = "https://slack.com/api/" def self.get_users users = [] return users end - def self.get_json(url:, query_params:) - response = HTTParty.get(url, query: query_params) - + private + + def self.get_json(url_tail:, query_params:) + response = HTTParty.get(make_url(url_tail: url_tail), query: query_params) + if !response["ok"] + raise SlackError.new + end return response end + + def self.make_url(url_tail:) + return URL_BASE + url_tail + end end end diff --git a/specs/apiwrapper_spec.rb b/specs/apiwrapper_spec.rb index 2a408814..f9b8e9f7 100644 --- a/specs/apiwrapper_spec.rb +++ b/specs/apiwrapper_spec.rb @@ -24,27 +24,26 @@ end describe "ApiWrapper.get_json" do - it "will return a Repsonse object" do + it "will return a Response object" do VCR.use_cassette("slack_api") do - url = "https://slack.com/api/users.list" + url = "users.list" query = { token: ENV["SLACK_API_KEY"], } - response = Slack::ApiWrapper.get_json(url: url, query_params: query) + response = Slack::ApiWrapper.get_json(url_tail: url, query_params: query) expect(response).must_be_instance_of HTTParty::Response end end - + it "raises an error when receiving invalid url" do VCR.use_cassette("slack_api") do - url = "abc" + url = "somethin.gelse" query = { token: ENV["SLACK_API_KEY"], } - expect { - Slack::ApiWrapper.get_json(url: url, query_params: query) - }.must_raise SlackError + Slack::ApiWrapper.get_json(url_tail: url, query_params: query) + }.must_raise Slack::SlackError end end end From d7b34636a7ad0c428de25cd62564a3a9fb834f69 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Wed, 20 Mar 2019 17:42:00 -0700 Subject: [PATCH 33/84] reverted back slackerror class to before debugging api exceptions --- lib/apiwrapper.rb | 7 ++++--- specs/apiwrapper_spec.rb | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/apiwrapper.rb b/lib/apiwrapper.rb index fb6732d0..7a37c4e9 100644 --- a/lib/apiwrapper.rb +++ b/lib/apiwrapper.rb @@ -1,10 +1,11 @@ module Slack - class SlackError < Exception; end - module ApiWrapper + class SlackError < StandardError; end + + URL_BASE = "https://slack.com/api/" + def self.get_channels end - URL_BASE = "https://slack.com/api/" def self.get_users users = [] diff --git a/specs/apiwrapper_spec.rb b/specs/apiwrapper_spec.rb index f9b8e9f7..4576c3d9 100644 --- a/specs/apiwrapper_spec.rb +++ b/specs/apiwrapper_spec.rb @@ -43,7 +43,7 @@ } expect { Slack::ApiWrapper.get_json(url_tail: url, query_params: query) - }.must_raise Slack::SlackError + }.must_raise Slack::ApiWrapper::SlackError end end end From d8768849a85fc0f3d34ca81948ae1de8acfc9f3e Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 10:21:45 -0700 Subject: [PATCH 34/84] completed get_channels and get_users in apiwrapper class --- lib/apiwrapper.rb | 25 +++++++++++++------------ specs/apiwrapper_spec.rb | 34 ++++++---------------------------- 2 files changed, 19 insertions(+), 40 deletions(-) diff --git a/lib/apiwrapper.rb b/lib/apiwrapper.rb index 7a37c4e9..e1731335 100644 --- a/lib/apiwrapper.rb +++ b/lib/apiwrapper.rb @@ -3,27 +3,28 @@ module ApiWrapper class SlackError < StandardError; end URL_BASE = "https://slack.com/api/" + TOKEN = ENV["SLACK_API_KEY"] def self.get_channels + query_params = { + "token": TOKEN, + } + response = HTTParty.get("#{URL_BASE}conversations.list", query: query_params) + if !response["ok"] + raise SlackError.new + end + return response end def self.get_users - users = [] - return users - end - - private - - def self.get_json(url_tail:, query_params:) - response = HTTParty.get(make_url(url_tail: url_tail), query: query_params) + query_params = { + "token": TOKEN, + } + response = HTTParty.get("#{URL_BASE}users.list", query: query_params) if !response["ok"] raise SlackError.new end return response end - - def self.make_url(url_tail:) - return URL_BASE + url_tail - end end end diff --git a/specs/apiwrapper_spec.rb b/specs/apiwrapper_spec.rb index 4576c3d9..141bc6cf 100644 --- a/specs/apiwrapper_spec.rb +++ b/specs/apiwrapper_spec.rb @@ -9,41 +9,19 @@ end describe "ApiWrapper.get_users" do - it "will return with array" do - expect(Slack::ApiWrapper.get_users).must_be_instance_of Array - end - - # it "will return a " do - # VCR.use_cassette("slack_api") do - # response = get_users - # response["users"].each do |user| - # expect(user["name"]). - # end - # end - # end - end - - describe "ApiWrapper.get_json" do it "will return a Response object" do VCR.use_cassette("slack_api") do - url = "users.list" - query = { - token: ENV["SLACK_API_KEY"], - } - response = Slack::ApiWrapper.get_json(url_tail: url, query_params: query) + response = Slack::ApiWrapper.get_users expect(response).must_be_instance_of HTTParty::Response end end + end - it "raises an error when receiving invalid url" do + describe "ApiWrapper.get_channels" do + it "will return a Response object" do VCR.use_cassette("slack_api") do - url = "somethin.gelse" - query = { - token: ENV["SLACK_API_KEY"], - } - expect { - Slack::ApiWrapper.get_json(url_tail: url, query_params: query) - }.must_raise Slack::ApiWrapper::SlackError + response = Slack::ApiWrapper.get_channels + expect(response).must_be_instance_of HTTParty::Response end end end From c4304e0d5675ac3456f1f987db22de488707d124 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 10:28:06 -0700 Subject: [PATCH 35/84] added tests for post --- specs/apiwrapper_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/specs/apiwrapper_spec.rb b/specs/apiwrapper_spec.rb index 141bc6cf..03d3c9a6 100644 --- a/specs/apiwrapper_spec.rb +++ b/specs/apiwrapper_spec.rb @@ -25,4 +25,13 @@ end end end + + describe "ApiWrapper.post" do + it "will return a Response object" do + VCR.use_cassette("slack_api") do + response = Slack::ApiWrapper.post(text: "test text", recipient: "random") + expect(response).must_be_instance_of HTTParty::Response + end + end + end end From 58bf152dc7ba0585858e2dd165788ffbc67539cb Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 13:16:43 -0700 Subject: [PATCH 36/84] completed post method in apiwrapper class --- lib/apiwrapper.rb | 34 ++++++++++++++++++++++++++-------- specs/apiwrapper_spec.rb | 29 ++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/lib/apiwrapper.rb b/lib/apiwrapper.rb index e1731335..986ae3e7 100644 --- a/lib/apiwrapper.rb +++ b/lib/apiwrapper.rb @@ -6,25 +6,43 @@ class SlackError < StandardError; end TOKEN = ENV["SLACK_API_KEY"] def self.get_channels - query_params = { - "token": TOKEN, - } - response = HTTParty.get("#{URL_BASE}conversations.list", query: query_params) - if !response["ok"] - raise SlackError.new - end + url_tail = "channels.list" + response = get_json(url_tail: url_tail) return response end def self.get_users + url_tail = "users.list" + response = get_json(url_tail: url_tail) + return response + end + + def self.get_json(url_tail:) query_params = { "token": TOKEN, } - response = HTTParty.get("#{URL_BASE}users.list", query: query_params) + response = HTTParty.get("#{URL_BASE}#{url_tail}", query: query_params) if !response["ok"] raise SlackError.new end return response end + + def self.post(text:, recipient:) + response = HTTParty.post( + "#{URL_BASE}chat.postMessage", + headers: { "Content-Type" => "application/x-www-form-urlencoded" }, + body: { + token: TOKEN, + channel: recipient, + text: text, + }, + ) + if response["ok"] + return true + else + raise ApiWrapper::SlackError, "Error when posting #{text} to #{recipient}, error: #{response.parsed_response["error"]}" + end + end end end diff --git a/specs/apiwrapper_spec.rb b/specs/apiwrapper_spec.rb index 03d3c9a6..d7daac7e 100644 --- a/specs/apiwrapper_spec.rb +++ b/specs/apiwrapper_spec.rb @@ -8,13 +8,24 @@ end end - describe "ApiWrapper.get_users" do - it "will return a Response object" do + describe "ApiWrapper.get_json" do + it "successfully gets a json object" do + url_tail = "users.list" VCR.use_cassette("slack_api") do - response = Slack::ApiWrapper.get_users + response = Slack::ApiWrapper.get_json(url_tail: url_tail) expect(response).must_be_instance_of HTTParty::Response end end + + it "raise an error if an invalid url is used" do + url_tail = "abc" + VCR.use_cassette("slack_api") do + response = + expect { + Slack::ApiWrapper.get_json(url_tail: url_tail) + }.must_raise Slack::ApiWrapper::SlackError + end + end end describe "ApiWrapper.get_channels" do @@ -27,10 +38,18 @@ end describe "ApiWrapper.post" do - it "will return a Response object" do + it "can send a valid message to a channel" do VCR.use_cassette("slack_api") do response = Slack::ApiWrapper.post(text: "test text", recipient: "random") - expect(response).must_be_instance_of HTTParty::Response + expect(response).must_equal true + end + end + + it "can send a valid message to a user" do + VCR.use_cassette("slack_api") do + user_id = "UH2RH81RA" + response = Slack::ApiWrapper.post(text: "test text", recipient: user_id) + expect(response).must_equal true end end end From acbcf99af0b6a2770fcdd6187e28d37f3f3b24d5 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 13:24:53 -0700 Subject: [PATCH 37/84] added tests for checking invalid channel --- specs/apiwrapper_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/specs/apiwrapper_spec.rb b/specs/apiwrapper_spec.rb index d7daac7e..8b2a5b2f 100644 --- a/specs/apiwrapper_spec.rb +++ b/specs/apiwrapper_spec.rb @@ -52,5 +52,14 @@ expect(response).must_equal true end end + + it "will raise exception if invalid channel used" do + VCR.use_cassette("slack_api") do + user_id = "Noarealid234" + expect { + Slack::ApiWrapper.post(text: "test text", recipient: user_id) + }.must_raise Slack::ApiWrapper::SlackError + end + end end end From fc5d71fb48e579aa1a875ba818c3f1040d936285 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 13:27:38 -0700 Subject: [PATCH 38/84] added test for empty string post request --- specs/apiwrapper_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/specs/apiwrapper_spec.rb b/specs/apiwrapper_spec.rb index 8b2a5b2f..16825608 100644 --- a/specs/apiwrapper_spec.rb +++ b/specs/apiwrapper_spec.rb @@ -61,5 +61,14 @@ }.must_raise Slack::ApiWrapper::SlackError end end + + it "will raise exception if no text is provided" do + VCR.use_cassette("slack_api") do + user_id = "UH2RH81RA" + expect { + Slack::ApiWrapper.post(text: "", recipient: user_id) + }.must_raise Slack::ApiWrapper::SlackError + end + end end end From 47c8dc7a08b6d88065106f621eaa5a118089b1ee Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 13:35:57 -0700 Subject: [PATCH 39/84] added test for invalid token --- lib/apiwrapper.rb | 7 ++++--- specs/apiwrapper_spec.rb | 12 ++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/apiwrapper.rb b/lib/apiwrapper.rb index 986ae3e7..d40a090b 100644 --- a/lib/apiwrapper.rb +++ b/lib/apiwrapper.rb @@ -3,7 +3,6 @@ module ApiWrapper class SlackError < StandardError; end URL_BASE = "https://slack.com/api/" - TOKEN = ENV["SLACK_API_KEY"] def self.get_channels url_tail = "channels.list" @@ -18,8 +17,9 @@ def self.get_users end def self.get_json(url_tail:) + token = ENV["SLACK_API_KEY"] query_params = { - "token": TOKEN, + "token": token, } response = HTTParty.get("#{URL_BASE}#{url_tail}", query: query_params) if !response["ok"] @@ -29,11 +29,12 @@ def self.get_json(url_tail:) end def self.post(text:, recipient:) + token = ENV["SLACK_API_KEY"] response = HTTParty.post( "#{URL_BASE}chat.postMessage", headers: { "Content-Type" => "application/x-www-form-urlencoded" }, body: { - token: TOKEN, + token: token, channel: recipient, text: text, }, diff --git a/specs/apiwrapper_spec.rb b/specs/apiwrapper_spec.rb index 16825608..be227884 100644 --- a/specs/apiwrapper_spec.rb +++ b/specs/apiwrapper_spec.rb @@ -26,6 +26,18 @@ }.must_raise Slack::ApiWrapper::SlackError end end + + it "raise an error when an invalid token is used" do + VCR.use_cassette("slack_api") do + real_token = ENV["SLACK_API_KEY"] + ENV["SLACK_API_KEY"] = "NOT_REAL_TOKEN" + error = expect { + Slack::ApiWrapper.post(text: "Test message with invalid key", + recipient: "general") + }.must_raise Slack::ApiWrapper::SlackError + ENV["SLACK_API_KEY"] = real_token + end + end end describe "ApiWrapper.get_channels" do From e3b2bd15b30b7e7eb5f0796d76ec4ed5215c6f35 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 13:50:07 -0700 Subject: [PATCH 40/84] added first test for create users in user --- specs/user_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 1a0598f7..da059359 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -27,4 +27,10 @@ expect(user.details).must_equal string_format end end + + describe "User.create_users" do + it "will return an array" do + expect(Slack::User.create_users).must_be_instance_of Array + end + end end From 93c9b0544e64c765bba641cc4068f1c1ea52530e Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 13:54:29 -0700 Subject: [PATCH 41/84] fix error --- lib/user.rb | 5 +++++ specs/apiwrapper_spec.rb | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index 6a2f0154..a7e16590 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -10,5 +10,10 @@ def initialize(id:, name:, real_name:) def details return "Name: #{name}, \nReal Name: #{real_name}, \nID: #{id}" end + + def self.create_users + users = [] + return users + end end end diff --git a/specs/apiwrapper_spec.rb b/specs/apiwrapper_spec.rb index be227884..1d69d032 100644 --- a/specs/apiwrapper_spec.rb +++ b/specs/apiwrapper_spec.rb @@ -31,9 +31,8 @@ VCR.use_cassette("slack_api") do real_token = ENV["SLACK_API_KEY"] ENV["SLACK_API_KEY"] = "NOT_REAL_TOKEN" - error = expect { - Slack::ApiWrapper.post(text: "Test message with invalid key", - recipient: "general") + expect { + Slack::ApiWrapper.post(text: "Test message with invalid key", recipient: "general") }.must_raise Slack::ApiWrapper::SlackError ENV["SLACK_API_KEY"] = real_token end From 1fc46a089eff0d14634deb613ea30dc380cc31af Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 13:57:52 -0700 Subject: [PATCH 42/84] debugger --- specs/apiwrapper_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/apiwrapper_spec.rb b/specs/apiwrapper_spec.rb index 1d69d032..0840e2c2 100644 --- a/specs/apiwrapper_spec.rb +++ b/specs/apiwrapper_spec.rb @@ -26,7 +26,7 @@ }.must_raise Slack::ApiWrapper::SlackError end end - +#making changes so we can debug it "raise an error when an invalid token is used" do VCR.use_cassette("slack_api") do real_token = ENV["SLACK_API_KEY"] From df97e06f8f65bba7536851d4c9d70fcb5abdecbf Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 14:13:29 -0700 Subject: [PATCH 43/84] added info for later tests --- specs/user_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/specs/user_spec.rb b/specs/user_spec.rb index da059359..383448ef 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -28,6 +28,15 @@ end end + # user 2 - "UH2RH81RA" + # "elise.pham88" + # "elise.pham88" + + # channel 2 = "CH2P3NB0T" + # "general" + # "Company-wide announcements and work-based matters" + # 2 + describe "User.create_users" do it "will return an array" do expect(Slack::User.create_users).must_be_instance_of Array From 53fd69a310251583459074b3d0b3343e1e9ec53f Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 14:20:04 -0700 Subject: [PATCH 44/84] added test for create_users --- specs/user_spec.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 383448ef..348002de 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -38,8 +38,17 @@ # 2 describe "User.create_users" do + let(:users) { + Slack::User.create_users + } it "will return an array" do - expect(Slack::User.create_users).must_be_instance_of Array + expect(users).must_be_instance_of Array + end + + it "returns correct User objects" do + expect(users[1].name).must_equal "elise.pham88" + expect(users[1].id).must_equal "UH2RH81RA" + expect(users[1].real_name).must_equal "elise.pham88" end end end From 34fb6a36aa28a0ce2a981cf8d3c911b0916f7c4c Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 14:25:27 -0700 Subject: [PATCH 45/84] created user objects factory method --- lib/user.rb | 6 ++++++ specs/user_spec.rb | 17 ++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index a7e16590..5d0a131d 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -13,6 +13,12 @@ def details def self.create_users users = [] + response = ApiWrapper::get_users + response["members"].each do |user| + users << self.new(id: user["id"], + name: user["name"], + real_name: user["real_name"]) + end return users end end diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 348002de..e64ae57b 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -38,17 +38,20 @@ # 2 describe "User.create_users" do - let(:users) { - Slack::User.create_users - } + before do + VCR.use_cassette("slack_api") do + @users = Slack::User.create_users + end + end + it "will return an array" do - expect(users).must_be_instance_of Array + expect(@users).must_be_instance_of Array end it "returns correct User objects" do - expect(users[1].name).must_equal "elise.pham88" - expect(users[1].id).must_equal "UH2RH81RA" - expect(users[1].real_name).must_equal "elise.pham88" + expect(@users[1].name).must_equal "elise.pham88" + expect(@users[1].id).must_equal "UH2RH81RA" + expect(@users[1].real_name).must_equal "elise.pham88" end end end From bc97377f6bc26f85f8ac1bfdca3d42b7bf9d6c08 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 14:27:07 -0700 Subject: [PATCH 46/84] finished testing factory method in user --- specs/user_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/specs/user_spec.rb b/specs/user_spec.rb index e64ae57b..4cebaf44 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -53,5 +53,9 @@ expect(@users[1].id).must_equal "UH2RH81RA" expect(@users[1].real_name).must_equal "elise.pham88" end + + it "returns correct number of users in workspace" do + expect(@users.length).must_equal 3 + end end end From 1927a7d249ef4411e03f1d16444cf7df77d7100f Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 14:31:29 -0700 Subject: [PATCH 47/84] added tests for channel --- specs/user_spec.rb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 4cebaf44..30140d71 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -54,8 +54,31 @@ expect(@users[1].real_name).must_equal "elise.pham88" end - it "returns correct number of users in workspace" do + it "returns correct number of users in workspace" do expect(@users.length).must_equal 3 end end + + describe "Channel.create_channels" do + before do + VCR.use_cassette("slack_api") do + @channels = Slack::Channel.create_channels + end + end + + it "will return an array" do + expect(@channels).must_be_instance_of Array + end + + it "returns correct Channel objects" do + expect(@channels[1].name).must_equal "general" + expect(@channels[1].id).must_equal "CH2P3NB0T" + expect(@channels[1].topic).must_equal "Company-wide announcements and work-based matters" + expect(@channels[1].member_count).must_equal 2 + end + + it "returns correct number of channels in workspace" do + expect(@channels.length).must_equal 4 + end + end end From 0101c90c8e2c8a3fb96c7948c92ba334b5b30de6 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 14:34:43 -0700 Subject: [PATCH 48/84] added factory method, testing complete. all good to go --- lib/channel.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/channel.rb b/lib/channel.rb index 5e869980..aa3c30d5 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -11,5 +11,17 @@ def initialize(id:, name:, member_count:, topic:) def details return "Name: #{name}, \nID: #{id}, \nTopic: #{topic}, \nMember Count: #{member_count}" end + + def self.create_channels + channels = [] + response = ApiWrapper::get_channels + response["channels"].each do |channel| + channels << self.new(id: channel["id"], + name: channel["name"], + member_count: channel["num_members"], + topic: channel["topic"]["value"]) + end + return channels + end end end From 61568329179ffbe24099798f5d3f5357f3a0c451 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 14:39:19 -0700 Subject: [PATCH 49/84] added test for Workspace#initialize --- specs/workspace_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 specs/workspace_spec.rb diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb new file mode 100644 index 00000000..4814dce7 --- /dev/null +++ b/specs/workspace_spec.rb @@ -0,0 +1,15 @@ +require_relative "test_helper" + +describe "Workspace class" do + before do + VCR.use_cassette("slack_api") do + @workspace = Slack::Workspace.new + end + end + + describe "Workspace#initialize" do + it "returns a workspace object" do + expect(@workspace).must_be_instance_of Slack::Workspace + end + end +end From 98fb396cc481e19aae05f1941f20a6dfc604a333 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 14:41:07 -0700 Subject: [PATCH 50/84] initialized begining of new class workspace. --- lib/workspace.rb | 6 ++++++ specs/test_helper.rb | 1 + 2 files changed, 7 insertions(+) create mode 100644 lib/workspace.rb diff --git a/lib/workspace.rb b/lib/workspace.rb new file mode 100644 index 00000000..b5081d3b --- /dev/null +++ b/lib/workspace.rb @@ -0,0 +1,6 @@ +module Slack + class Workspace + def initialize + end + end +end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 563ecbaa..c51934a3 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -16,6 +16,7 @@ require_relative "../lib/user.rb" require_relative "../lib/channel" require_relative "../lib/apiwrapper" +require_relative "../lib/workspace.rb" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 43b9e789fce17c395556f8529957d946ce3c2bd9 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 14:44:27 -0700 Subject: [PATCH 51/84] added test for instance vars. --- specs/workspace_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 4814dce7..53b991f9 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -11,5 +11,12 @@ it "returns a workspace object" do expect(@workspace).must_be_instance_of Slack::Workspace end + + it "responds to instance variable and selected is nil" do + expect(@workspace).must_respond_to :channels + expect(@workspace).must_respond_to :users + expect(@workspace).must_respond_to :selected + expect(@workspace.selected).must_be_nil + end end end From 3e0e6f4fe538c0514b72527dcd4e1a392262f28b Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 14:49:00 -0700 Subject: [PATCH 52/84] added more tests for initialize in workspace class --- lib/workspace.rb | 5 +++++ specs/workspace_spec.rb | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/lib/workspace.rb b/lib/workspace.rb index b5081d3b..65b0560b 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,6 +1,11 @@ module Slack class Workspace + attr_reader :users, :channels, :selected + def initialize + @users = User.create_users + @channels = Channel.create_channels + @selected = nil end end end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 53b991f9..a58f324d 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -18,5 +18,10 @@ expect(@workspace).must_respond_to :selected expect(@workspace.selected).must_be_nil end + + it "has correct instance variable types" do + expect(@workspace.channels[1]).must_be_instance_of Slack::Channel + expect(@workspace.users[1]).must_be_instance_of Slack::User + end end end From 561c19aaf54f6cd9d8fa129fa6d415dbaab29c96 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 14:56:35 -0700 Subject: [PATCH 53/84] added tests for select channels --- specs/workspace_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index a58f324d..7220925d 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -24,4 +24,11 @@ expect(@workspace.users[1]).must_be_instance_of Slack::User end end + + describe "Workspace#Select_channel" do + it "will set the selected variable to input channel" do + @workspace.select_channel(channel: @workspace.channels[1]) + expect(@workspace.selected).must_equal @workspace.channels[1] + end + end end From 32126c8c377052ff8df26dcd629bcdb8c1f30e9b Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 15:02:46 -0700 Subject: [PATCH 54/84] added select_channel method --- lib/workspace.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/workspace.rb b/lib/workspace.rb index 65b0560b..98740bea 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -7,5 +7,10 @@ def initialize @channels = Channel.create_channels @selected = nil end + + def select_channel(channel:) + @selected = channel + return true + end end end From 12baef3f25d22f3d815b35ac1313c4eee8d74223 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 15:05:12 -0700 Subject: [PATCH 55/84] added test for select_user --- specs/workspace_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 7220925d..166cc509 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -31,4 +31,11 @@ expect(@workspace.selected).must_equal @workspace.channels[1] end end + + describe "Workspace#Select_user" do + it "will set the selected variable to input user" do + @workspace.select_user(channel: @workspace.users[1]) + expect(@workspace.selected).must_equal @workspace.users[1] + end + end end From d68c46e7edaba7292ccc74f4dca3174ffd91b3f1 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 15:06:34 -0700 Subject: [PATCH 56/84] merge --- specs/workspace_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 7220925d..ba4d7483 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -26,8 +26,8 @@ end describe "Workspace#Select_channel" do - it "will set the selected variable to input channel" do - @workspace.select_channel(channel: @workspace.channels[1]) + it "will set the selected variable to input channel and returns true" do + expect(@workspace.select_channel(channel: @workspace.channels[1])).must_equal true expect(@workspace.selected).must_equal @workspace.channels[1] end end From 5b3a477a8fd4a11acadd703991eac998181d8bc8 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 15:09:42 -0700 Subject: [PATCH 57/84] added test for list all --- lib/workspace.rb | 5 +++++ specs/workspace_spec.rb | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index 98740bea..5a0d0533 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -12,5 +12,10 @@ def select_channel(channel:) @selected = channel return true end + + def select_user(user:) + @selected = user + return true + end end end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index e412ba4a..1a0d9154 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -34,8 +34,14 @@ describe "Workspace#Select_user" do it "will set the selected variable to input user" do - @workspace.select_user(channel: @workspace.users[1]) + @workspace.select_user(user: @workspace.users[1]) expect(@workspace.selected).must_equal @workspace.users[1] end end + + describe "Workspace#list_all" do + it "will return a string" do + expect(@workspace.list_all).must_be_instance_of String + end + end end From 388e58eb455ed01f0975f3e1c1742e80b7000b6e Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 15:12:26 -0700 Subject: [PATCH 58/84] updated tests --- specs/workspace_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 1a0d9154..233dd6e3 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -41,7 +41,8 @@ describe "Workspace#list_all" do it "will return a string" do - expect(@workspace.list_all).must_be_instance_of String + expect(@workspace.list_all(list: @workspace.channels)).must_be_instance_of String + expect(@workspace.list_all(list: @workspace.users)).must_be_instance_of String end end end From e670a1963727849b90d337b019d89a93387d8920 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 15:12:45 -0700 Subject: [PATCH 59/84] merge --- lib/workspace.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index 5a0d0533..98740bea 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -12,10 +12,5 @@ def select_channel(channel:) @selected = channel return true end - - def select_user(user:) - @selected = user - return true - end end end From b48295a5f4a172f2bd81b14ab747a27b710329ee Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 15:15:15 -0700 Subject: [PATCH 60/84] added list_all method --- lib/workspace.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/workspace.rb b/lib/workspace.rb index 98740bea..44fa4b04 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -12,5 +12,15 @@ def select_channel(channel:) @selected = channel return true end + + def select_user(user:) + @selected = user + return true + end + + def list_all(list:) + result = "" + return result + end end end From 774fdc63c8445cccf0b016a4fd4624ebcfb0b525 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 15:21:37 -0700 Subject: [PATCH 61/84] added require message in workspace --- lib/workspace.rb | 3 +++ specs/workspace_spec.rb | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/lib/workspace.rb b/lib/workspace.rb index 44fa4b04..dd62d398 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,3 +1,6 @@ +require_relative "channel" +require_relative "user" + module Slack class Workspace attr_reader :users, :channels, :selected diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 233dd6e3..a3cd5eba 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -44,5 +44,9 @@ expect(@workspace.list_all(list: @workspace.channels)).must_be_instance_of String expect(@workspace.list_all(list: @workspace.users)).must_be_instance_of String end + + it "will return the correct String format" do + test_list = @workspace.list_all(list: @workspace.channels) + end end end From 3e77ac3383f06377ba9a52b2e0b0653ae87c2d96 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 15:23:54 -0700 Subject: [PATCH 62/84] add require message in user and channel --- lib/channel.rb | 2 ++ lib/user.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/channel.rb b/lib/channel.rb index aa3c30d5..6ba74af0 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,3 +1,5 @@ +require_relative "recipient" + module Slack class Channel < Recipient attr_reader :member_count, :topic diff --git a/lib/user.rb b/lib/user.rb index 5d0a131d..2478361d 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,3 +1,5 @@ +require_relative "recipient" + module Slack class User < Recipient attr_reader :real_name From 048e6657e67ea9daf76458b01fd12bf6419b02f2 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 15:25:17 -0700 Subject: [PATCH 63/84] added require message in user and channel --- lib/channel.rb | 1 + lib/user.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/channel.rb b/lib/channel.rb index 6ba74af0..70990d18 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,4 +1,5 @@ require_relative "recipient" +require_relative "apiwrapper" module Slack class Channel < Recipient diff --git a/lib/user.rb b/lib/user.rb index 2478361d..2e2a08ee 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,4 +1,5 @@ require_relative "recipient" +require_relative "apiwrapper" module Slack class User < Recipient From 7de1697b1132a6c11a83fda331dc0b2deb0c8c3d Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 15:27:03 -0700 Subject: [PATCH 64/84] added httpary, dotenv in apiwrapper class --- lib/apiwrapper.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/apiwrapper.rb b/lib/apiwrapper.rb index d40a090b..3cf2bc10 100644 --- a/lib/apiwrapper.rb +++ b/lib/apiwrapper.rb @@ -1,3 +1,7 @@ +require "httparty" +require "dotenv" +Dotenv.load + module Slack module ApiWrapper class SlackError < StandardError; end From 4d29f21da317d8319069317209f74b060337f5b7 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 15:42:20 -0700 Subject: [PATCH 65/84] added tests for list_all in workspace --- specs/workspace_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index a3cd5eba..d929a6e7 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -47,6 +47,26 @@ it "will return the correct String format" do test_list = @workspace.list_all(list: @workspace.channels) + expected_result = "Name: slack-api-project, \nID: CH0EG6M0Q, \nTopic: , \nMember Count: 2\n" + + "-----------------------\n" + + "Name: general, \nID: CH2P3NB0T, \nTopic: Company-wide announcements and work-based matters, \nMember Count: 2\n" + + "-----------------------\n" + + "Name: random, \nID: CH2RH8AMA, \nTopic: Non-work banter and water cooler conversation, \nMember Count: 2\n" + + "-----------------------\n" + + "Name: super-awesome-stuffs, \nID: CH3UNG023, \nTopic: , \nMember Count: 2\n" + + "-----------------------\n" + expect(test_list).must_equal expected_result + end + + it "will return the correct String format" do + test_list = @workspace.list_all(list: @workspace.users) + expected_result = "Name: slackbot, \nReal Name: Slackbot, \nID: USLACKBOT\n" + + "-----------------------\n" + + "Name: elise.pham88, \nReal Name: elise.pham88, \nID: UH2RH81RA\n" + + "-----------------------\n" + + "Name: s.dippolito, \nReal Name: Sav Dippolito, \nID: UH3UN350X\n" + + "-----------------------\n" + expect(test_list).must_equal expected_result end end end From 40a7623fc398c4f7a01552f9f5ca4b182ebbf428 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 15:48:22 -0700 Subject: [PATCH 66/84] added format to list_all(list) --- lib/workspace.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/workspace.rb b/lib/workspace.rb index dd62d398..35a92ff6 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -23,6 +23,10 @@ def select_user(user:) def list_all(list:) result = "" + list.each do |elem| + result << elem.details + result << "\n-----------------------\n" + end return result end end From 51e4fb7423e8f56a6bc40c527d7e12eaad73555f Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 16:16:11 -0700 Subject: [PATCH 67/84] added begin/rescue block --- lib/channel.rb | 15 +++++++++------ lib/user.rb | 13 ++++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 70990d18..737c0cb3 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -17,12 +17,15 @@ def details def self.create_channels channels = [] - response = ApiWrapper::get_channels - response["channels"].each do |channel| - channels << self.new(id: channel["id"], - name: channel["name"], - member_count: channel["num_members"], - topic: channel["topic"]["value"]) + begin + response = ApiWrapper::get_channels + response["channels"].each do |channel| + channels << self.new(id: channel["id"], + name: channel["name"], + member_count: channel["num_members"], + topic: channel["topic"]["value"]) + end + rescue ApiWrapper::SlackError end return channels end diff --git a/lib/user.rb b/lib/user.rb index 2e2a08ee..571df6ad 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -16,11 +16,14 @@ def details def self.create_users users = [] - response = ApiWrapper::get_users - response["members"].each do |user| - users << self.new(id: user["id"], - name: user["name"], - real_name: user["real_name"]) + begin + response = ApiWrapper::get_users + response["members"].each do |user| + users << self.new(id: user["id"], + name: user["name"], + real_name: user["real_name"]) + end + rescue ApiWrapper::SlackError end return users end From 5dc28ba7ae42fc48a01898bf74ded00bb1b64932 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 16:25:07 -0700 Subject: [PATCH 68/84] added tests for sending message, go --- specs/workspace_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index d929a6e7..7409aebe 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -69,4 +69,12 @@ expect(test_list).must_equal expected_result end end + + describe "Workspace#send_message" do + it "will return true if post succesful" do + @workspace.select_channel(channel: @workspace.channels[1]) + expect(@workspace.send_message(text: "Something new to test!", + recipient: @workspace.selected)).must_equal true + end + end end From 73264e8ca18e8ae8723d31735ccdd9f27457c2eb Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 16:40:27 -0700 Subject: [PATCH 69/84] added send_message in workspace --- lib/workspace.rb | 11 +++++++++++ specs/workspace_spec.rb | 15 ++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index 35a92ff6..fe6b48b1 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -29,5 +29,16 @@ def list_all(list:) end return result end + + def send_message(text:) + return false unless selected + status = true + begin + ApiWrapper.post(text: text, recipient: selected.id) + rescue ApiWrapper::SlackError + status = false + end + return status + end end end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 7409aebe..ba85b24f 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -72,9 +72,18 @@ describe "Workspace#send_message" do it "will return true if post succesful" do - @workspace.select_channel(channel: @workspace.channels[1]) - expect(@workspace.send_message(text: "Something new to test!", - recipient: @workspace.selected)).must_equal true + VCR.use_cassette("slack_api") do + @workspace.select_channel(channel: @workspace.channels[1]) + expect(@workspace.send_message(text: "Something new to test!")).must_equal true + end + end + + it "will return false if post is unsuccessful" do + VCR.use_cassette("slack_api") do + expect(@workspace.send_message(text: "Something new to test!")).must_equal false + @workspace.select_channel(channel: @workspace.channels[1]) + expect(@workspace.send_message(text: "")).must_equal false + end end end end From 9e5a2009d51329dccccbc102519eced8d80794db Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 16:46:59 -0700 Subject: [PATCH 70/84] added test for details_for_selected in workspace --- lib/workspace.rb | 5 ++--- specs/workspace_spec.rb | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index fe6b48b1..514f3f77 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -32,13 +32,12 @@ def list_all(list:) def send_message(text:) return false unless selected - status = true begin ApiWrapper.post(text: text, recipient: selected.id) rescue ApiWrapper::SlackError - status = false + return false end - return status + return true end end end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index ba85b24f..ed547719 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -86,4 +86,10 @@ end end end + + describe "Workspace#details for selected" do + it "will return a String" do + expect(@workspace.details_for_selected).must_be_instance_of String + end + end end From 53b7859f753d2e99dfb086af764d8613fe2af814 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 17:16:13 -0700 Subject: [PATCH 71/84] added details_for_selected method. --- lib/workspace.rb | 5 +++++ specs/workspace_spec.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index 514f3f77..30a2c3bb 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -39,5 +39,10 @@ def send_message(text:) end return true end + + def details_for_selected + return "" unless selected + return selected.details + end end end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index ed547719..5435fa77 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -87,7 +87,7 @@ end end - describe "Workspace#details for selected" do + describe "Workspace#details_for_selected" do it "will return a String" do expect(@workspace.details_for_selected).must_be_instance_of String end From 3cd42306f5f82872d586a30606abdc1edf7f1765 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 19:27:07 -0700 Subject: [PATCH 72/84] added test for find_user in workspace class --- lib/apiwrapper.rb | 2 +- specs/apiwrapper_spec.rb | 19 +++++++++---------- specs/workspace_spec.rb | 11 +++++++++++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/apiwrapper.rb b/lib/apiwrapper.rb index 3cf2bc10..3f5b55b4 100644 --- a/lib/apiwrapper.rb +++ b/lib/apiwrapper.rb @@ -1,4 +1,4 @@ -require "httparty" +require "HTTParty" require "dotenv" Dotenv.load diff --git a/specs/apiwrapper_spec.rb b/specs/apiwrapper_spec.rb index 0840e2c2..9cfd2d8b 100644 --- a/specs/apiwrapper_spec.rb +++ b/specs/apiwrapper_spec.rb @@ -17,16 +17,15 @@ end end - it "raise an error if an invalid url is used" do - url_tail = "abc" - VCR.use_cassette("slack_api") do - response = - expect { - Slack::ApiWrapper.get_json(url_tail: url_tail) - }.must_raise Slack::ApiWrapper::SlackError - end - end -#making changes so we can debug + # it "raise an error if an invalid url is used" do + # url_tail = "abc" + # VCR.use_cassette("slack_api") do + # expect { + # Slack::ApiWrapper.get_json(url_tail: url_tail) + # }.must_raise Slack::ApiWrapper::SlackError + # end + # end + it "raise an error when an invalid token is used" do VCR.use_cassette("slack_api") do real_token = ENV["SLACK_API_KEY"] diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 5435fa77..26031782 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -92,4 +92,15 @@ expect(@workspace.details_for_selected).must_be_instance_of String end end + + describe "Workspace#find_user" do + it "will return a user object, given a valid user's name, real_name or id" do + user_name = "elise.pham88" + real_name = "elise.pham88" + user_id = "UH2RH81RA" + expect(@workspace.find_user(user_name)).must_be_instance_of Slack::User + expect(@workspace.find_user(real_name)).must_be_instance_of Slack::User + expect(@workspace.find_user(user_id)).must_be_instance_of Slack::User + end + end end From 4dbdd08ef48260d72d6e12d3e2c564993fcf1d91 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 19:28:04 -0700 Subject: [PATCH 73/84] merge --- specs/workspace_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 5435fa77..f1683e6b 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -92,4 +92,14 @@ expect(@workspace.details_for_selected).must_be_instance_of String end end + + it "will return string details of selected object if valid" do + @workspace.select_channel(channel: @workspace.channels[1]) + expect(@workspace.details_for_selected).must_equal "Name: general, \nID: CH2P3NB0T, \nTopic: Company-wide announcements and work-based matters, \nMember Count: 2" + end + + it "will return empty string if selected object is nil" do + @workspace.select_channel(channel: @workspace.channels[1]) + expect(@workspace.details_for_selected).must_equal "" + end end From 11d85f6a65c2e05cc4022aecae6f3bb31a9cf651 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 19:30:16 -0700 Subject: [PATCH 74/84] uncomment invalid url test --- specs/apiwrapper_spec.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/specs/apiwrapper_spec.rb b/specs/apiwrapper_spec.rb index 9cfd2d8b..aec88e42 100644 --- a/specs/apiwrapper_spec.rb +++ b/specs/apiwrapper_spec.rb @@ -17,14 +17,14 @@ end end - # it "raise an error if an invalid url is used" do - # url_tail = "abc" - # VCR.use_cassette("slack_api") do - # expect { - # Slack::ApiWrapper.get_json(url_tail: url_tail) - # }.must_raise Slack::ApiWrapper::SlackError - # end - # end + it "raise an error if an invalid url is used" do + url_tail = "abc" + VCR.use_cassette("slack_api") do + expect { + Slack::ApiWrapper.get_json(url_tail: url_tail) + }.must_raise Slack::ApiWrapper::SlackError + end + end it "raise an error when an invalid token is used" do VCR.use_cassette("slack_api") do From f6d3580fda80005503f31bdd5e2daf3369e7c290 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Thu, 21 Mar 2019 19:48:09 -0700 Subject: [PATCH 75/84] added logic for find_user and tests for find_channel, --- lib/workspace.rb | 9 +++++++++ specs/workspace_spec.rb | 45 ++++++++++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index 30a2c3bb..765d7f07 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -44,5 +44,14 @@ def details_for_selected return "" unless selected return selected.details end + + def find_user(input:) + users.each do |user| + if input == user.name.upcase || input == user.real_name.upcase || input == user.id.upcase + return user + end + end + return nil + end end end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 1982e17e..565895d1 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -93,25 +93,42 @@ end end -<<<<<<< HEAD - it "will return string details of selected object if valid" do - @workspace.select_channel(channel: @workspace.channels[1]) - expect(@workspace.details_for_selected).must_equal "Name: general, \nID: CH2P3NB0T, \nTopic: Company-wide announcements and work-based matters, \nMember Count: 2" - end - - it "will return empty string if selected object is nil" do - @workspace.select_channel(channel: @workspace.channels[1]) - expect(@workspace.details_for_selected).must_equal "" -======= describe "Workspace#find_user" do it "will return a user object, given a valid user's name, real_name or id" do user_name = "elise.pham88" real_name = "elise.pham88" user_id = "UH2RH81RA" - expect(@workspace.find_user(user_name)).must_be_instance_of Slack::User - expect(@workspace.find_user(real_name)).must_be_instance_of Slack::User - expect(@workspace.find_user(user_id)).must_be_instance_of Slack::User + user = @workspace.find_user(input: user_name.upcase) + expect(user).must_be_instance_of Slack::User + expect(user.name).must_equal "elise.pham88" + user = @workspace.find_user(input: real_name.upcase) + expect(user).must_be_instance_of Slack::User + expect(user.real_name).must_equal "elise.pham88" + user = @workspace.find_user(input: user_id.upcase) + expect(user).must_be_instance_of Slack::User + expect(user.id).must_equal "UH2RH81RA" + end + + it "will return nil if invalid users name, real_name or id" do + user_name = "elissdfsdfe.pham88" + real_name = "elisesdfsdf.pham88" + user_id = "UH2RHsdfsdf81RA" + expect(@workspace.find_user(input: user_name.upcase)).must_be_nil + expect(@workspace.find_user(input: real_name.upcase)).must_be_nil + expect(@workspace.find_user(input: user_id.upcase)).must_be_nil + end + end + + describe "Workspace#find_channel" do + it "will return a user object, given a valid channel's name or id" do + channel_name = "random" + channel_id = "CH2RH8AMA" + channel = @workspace.find_channel(input: channel_name.upcase) + expect(channel).must_be_instance_of Slack::Channel + expect(channel.name).must_equal "random" + channel = @workspace.find_channel(input: channel_id.upcase) + expect(channel).must_be_instance_of Slack::Channel + expect(channel.id).must_equal "CH2RH8AMA" end ->>>>>>> 3cd42306f5f82872d586a30606abdc1edf7f1765 end end From 601c70b3f20ce4258917f5e4c065667baf4d4165 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Thu, 21 Mar 2019 19:54:28 -0700 Subject: [PATCH 76/84] completed find_channel for workspace --- lib/workspace.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/workspace.rb b/lib/workspace.rb index 765d7f07..c4ba5f05 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -53,5 +53,14 @@ def find_user(input:) end return nil end + + def find_channel(input:) + channels.each do |channel| + if input == channel.name.upcase || input == channel.id.upcase + return channel + end + end + return nil + end end end From aeb79d99f336e070b55ae6730848115f26cae631 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Fri, 22 Mar 2019 10:07:37 -0700 Subject: [PATCH 77/84] added back missing test --- specs/workspace_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 565895d1..af6871bd 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -91,6 +91,15 @@ it "will return a String" do expect(@workspace.details_for_selected).must_be_instance_of String end + + it "will return string details of selected object if valid" do + @workspace.select_channel(channel: @workspace.channels[1]) + expect(@workspace.details_for_selected).must_equal "Name: general, \nID: CH2P3NB0T, \nTopic: Company-wide announcements and work-based matters, \nMember Count: 2" + end + + it "will return empty string if selected object is nil" do + expect(@workspace.details_for_selected).must_equal "" + end end describe "Workspace#find_user" do From b97ab695ce8564cee4ba97f04913a80ab237cb34 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Fri, 22 Mar 2019 10:27:19 -0700 Subject: [PATCH 78/84] fixed up main --- lib/slack.rb | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index e399c61c..1ee5a205 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,22 +1,4 @@ #!/usr/bin/env ruby -require "HTTParty" -require "dotenv" -require "awesome_print" -Dotenv.load - -url = "https://slack.com/api/conversations.list" -key = ENV["SLACK_API_KEY"] - -query_params = { - token: key, -} -response = HTTParty.get(url, query: query_params) - -# ap JSON.parse(response.body) - -response["channels"].each do |channel| - ap channel["name"] -end def main puts "Welcome to the Ada Slack CLI!" From 39859fdf4cf73de5bfd1db9e28dcf77a72e42537 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Fri, 22 Mar 2019 10:56:15 -0700 Subject: [PATCH 79/84] working on CLI --- lib/slack.rb | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 1ee5a205..06b6c548 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,9 +1,49 @@ #!/usr/bin/env ruby +require_relative "workspace" def main - puts "Welcome to the Ada Slack CLI!" + workspace = Slack::Workspace.new + puts "\nWelcome to the Ada Slack CLI!" + puts "-------------------------------" + puts "\nWorkspace: Sav-Elise-API Project" + puts "Number of users: #{workspace.users.length}" + puts "Number of channels: #{workspace.channels.length}\n\n" + options = ["List Users", "List Channels", "Select User", "Select Channel", "Details", "Quit"] - # TODO project + while true + puts "--------OPTIONS--------" + puts options + print "\nPlease enter your command: " + input = gets.chomp.upcase + + case input + when "LIST USERS" + list = workspace.list_all(list: workspace.users) + if list.empty? + puts "Unable to access users at this time." + else + puts "\n" + list + "\n" + end + when "LIST CHANNELS" + list = workspace.list_all(list: workspace.channels) + if list.empty? + puts "Unable to access channels at this time." + else + puts "\n" + list + "\n" + end + when "SELECT USER" + print "Please enter user's name, real name or id: " + input = gets.chomp.upcase + if workspace.find_user(input: input) + end + when "SELECT CHANNEL" + when "DETAILS" + when "QUIT" + break + else + puts "Command not recognized. Try again!\n\n" + end + end puts "Thank you for using the Ada Slack CLI" end From 22c4fdb94b70761c79f5be9677d8be0df69adad8 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Fri, 22 Mar 2019 11:06:27 -0700 Subject: [PATCH 80/84] completed select user command in CLI --- lib/slack.rb | 7 ++++++- lib/workspace.rb | 12 ++++++------ specs/workspace_spec.rb | 16 +++++++--------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 06b6c548..e47a12c0 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -34,7 +34,12 @@ def main when "SELECT USER" print "Please enter user's name, real name or id: " input = gets.chomp.upcase - if workspace.find_user(input: input) + user = workspace.find_user(input: input) + if user + workspace.select_recipient(recipient: user) + puts "Currently, selected recipient is #{user.name}.\n\n" + else + puts "#{input.capitalize} is not a valid user.\n\n" end when "SELECT CHANNEL" when "DETAILS" diff --git a/lib/workspace.rb b/lib/workspace.rb index c4ba5f05..d80f3fb6 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -11,15 +11,15 @@ def initialize @selected = nil end - def select_channel(channel:) - @selected = channel + def select_recipient(recipient:) + @selected = recipient return true end - def select_user(user:) - @selected = user - return true - end + # def select_user(user:) + # @selected = user + # return true + # end def list_all(list:) result = "" diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index af6871bd..afd9fa49 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -25,16 +25,14 @@ end end - describe "Workspace#Select_channel" do + describe "Workspace#Select_recipient" do it "will set the selected variable to input channel and returns true" do - expect(@workspace.select_channel(channel: @workspace.channels[1])).must_equal true + expect(@workspace.select_recipient(recipient: @workspace.channels[1])).must_equal true expect(@workspace.selected).must_equal @workspace.channels[1] end - end - describe "Workspace#Select_user" do - it "will set the selected variable to input user" do - @workspace.select_user(user: @workspace.users[1]) + it "will set the selected variable to input user and returns true" do + @workspace.select_recipient(recipient: @workspace.users[1]) expect(@workspace.selected).must_equal @workspace.users[1] end end @@ -73,7 +71,7 @@ describe "Workspace#send_message" do it "will return true if post succesful" do VCR.use_cassette("slack_api") do - @workspace.select_channel(channel: @workspace.channels[1]) + @workspace.select_recipient(recipient: @workspace.channels[1]) expect(@workspace.send_message(text: "Something new to test!")).must_equal true end end @@ -81,7 +79,7 @@ it "will return false if post is unsuccessful" do VCR.use_cassette("slack_api") do expect(@workspace.send_message(text: "Something new to test!")).must_equal false - @workspace.select_channel(channel: @workspace.channels[1]) + @workspace.select_recipient(recipient: @workspace.channels[1]) expect(@workspace.send_message(text: "")).must_equal false end end @@ -93,7 +91,7 @@ end it "will return string details of selected object if valid" do - @workspace.select_channel(channel: @workspace.channels[1]) + @workspace.select_recipient(recipient: @workspace.channels[1]) expect(@workspace.details_for_selected).must_equal "Name: general, \nID: CH2P3NB0T, \nTopic: Company-wide announcements and work-based matters, \nMember Count: 2" end From 46c92187decf2ff7807a561cd537ca4a51be1fdb Mon Sep 17 00:00:00 2001 From: qqdipps Date: Fri, 22 Mar 2019 11:18:31 -0700 Subject: [PATCH 81/84] added details and selected channel --- lib/slack.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/slack.rb b/lib/slack.rb index e47a12c0..487047b7 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -37,12 +37,27 @@ def main user = workspace.find_user(input: input) if user workspace.select_recipient(recipient: user) - puts "Currently, selected recipient is #{user.name}.\n\n" + puts "Successfully upated selected user to #{user.name}.\n\n" else puts "#{input.capitalize} is not a valid user.\n\n" end when "SELECT CHANNEL" + print "Please enter channel's name or id: " + input = gets.chomp.upcase + channel = workspace.find_channel(input: input) + if channel + workspace.select_recipient(recipient: channel) + puts "Successfully upated selected channel to #{channel.name}.\n\n" + else + puts "#{input.capitalize} is not a valid channel.\n\n" + end when "DETAILS" + details = workspace.details_for_selected + if details.empty? + puts "Error: first select channel or user.\n\n" + else + puts "\n" + details + "\n\n" + end when "QUIT" break else From f3c3a1952f076c2820a4ad0a379c4bc95ab4cd39 Mon Sep 17 00:00:00 2001 From: Elise Pham Date: Fri, 22 Mar 2019 11:31:09 -0700 Subject: [PATCH 82/84] completed CLI --- lib/slack.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/slack.rb b/lib/slack.rb index 487047b7..323b4c00 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -8,7 +8,7 @@ def main puts "\nWorkspace: Sav-Elise-API Project" puts "Number of users: #{workspace.users.length}" puts "Number of channels: #{workspace.channels.length}\n\n" - options = ["List Users", "List Channels", "Select User", "Select Channel", "Details", "Quit"] + options = ["List Users", "List Channels", "Select User", "Select Channel", "Details", "Send Message", "Quit"] while true puts "--------OPTIONS--------" @@ -58,6 +58,20 @@ def main else puts "\n" + details + "\n\n" end + when "SEND MESSAGE" + recipient = workspace.selected + if recipient + puts "Please enter the message you want to send:" + message = gets.chomp + if message.empty? + puts "Error: No message to send.\n\n" + else + workspace.send_message(text: message) + puts "Message was sent to #{recipient.name}.\n\n" + end + else + puts "Error: first select channel or user.\n\n" + end when "QUIT" break else From 87b86e48e13257baed775450852408690ba90bb4 Mon Sep 17 00:00:00 2001 From: qqdipps Date: Fri, 22 Mar 2019 13:47:54 -0700 Subject: [PATCH 83/84] modularized main method --- lib/slack.rb | 125 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 74 insertions(+), 51 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 323b4c00..70cd7272 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -18,68 +18,91 @@ def main case input when "LIST USERS" - list = workspace.list_all(list: workspace.users) - if list.empty? - puts "Unable to access users at this time." - else - puts "\n" + list + "\n" - end + list_users workspace when "LIST CHANNELS" - list = workspace.list_all(list: workspace.channels) - if list.empty? - puts "Unable to access channels at this time." - else - puts "\n" + list + "\n" - end + list_channels workspace when "SELECT USER" - print "Please enter user's name, real name or id: " - input = gets.chomp.upcase - user = workspace.find_user(input: input) - if user - workspace.select_recipient(recipient: user) - puts "Successfully upated selected user to #{user.name}.\n\n" - else - puts "#{input.capitalize} is not a valid user.\n\n" - end + select_user workspace when "SELECT CHANNEL" - print "Please enter channel's name or id: " - input = gets.chomp.upcase - channel = workspace.find_channel(input: input) - if channel - workspace.select_recipient(recipient: channel) - puts "Successfully upated selected channel to #{channel.name}.\n\n" - else - puts "#{input.capitalize} is not a valid channel.\n\n" - end - when "DETAILS" - details = workspace.details_for_selected - if details.empty? - puts "Error: first select channel or user.\n\n" - else - puts "\n" + details + "\n\n" - end + select_channel workspace when "SEND MESSAGE" - recipient = workspace.selected - if recipient - puts "Please enter the message you want to send:" - message = gets.chomp - if message.empty? - puts "Error: No message to send.\n\n" - else - workspace.send_message(text: message) - puts "Message was sent to #{recipient.name}.\n\n" - end - else - puts "Error: first select channel or user.\n\n" - end + send_message workspace + when "DETAILS" + details workspace when "QUIT" break else puts "Command not recognized. Try again!\n\n" end end - puts "Thank you for using the Ada Slack CLI" end +def list_users(workspace) + list = workspace.list_all(list: workspace.users) + if list.empty? + puts "Unable to access users at this time." + else + puts "\n" + list + "\n" + end +end + +def list_channels(workspace) + list = workspace.list_all(list: workspace.channels) + if list.empty? + puts "Unable to access channels at this time." + else + puts "\n" + list + "\n" + end +end + +def select_user(workspace) + print "Please enter user's name, real name or id: " + input = gets.chomp.upcase + user = workspace.find_user(input: input) + if user + workspace.select_recipient(recipient: user) + puts "Successfully upated selected user to #{user.name}.\n\n" + else + puts "#{input.capitalize} is not a valid user.\n\n" + end +end + +def select_channel(workspace) + print "Please enter channel's name or id: " + input = gets.chomp.upcase + channel = workspace.find_channel(input: input) + if channel + workspace.select_recipient(recipient: channel) + puts "Successfully upated selected channel to #{channel.name}.\n\n" + else + puts "#{input.capitalize} is not a valid channel.\n\n" + end +end + +def send_message(workspace) + recipient = workspace.selected + if recipient + puts "Please enter the message you want to send:" + message = gets.chomp + if message.empty? + puts "Error: No message to send.\n\n" + else + workspace.send_message(text: message) + puts "Message was sent to #{recipient.name}.\n\n" + end + else + puts "Error: first select channel or user.\n\n" + end +end + +def details(workspace) + details = workspace.details_for_selected + if details.empty? + puts "Error: first select channel or user.\n\n" + else + puts "\n" + details + "\n\n" + end +end + main if __FILE__ == $PROGRAM_NAME From aa01609b67e9780924b26dace1b0e2009e98d4fe Mon Sep 17 00:00:00 2001 From: qqdipps Date: Fri, 22 Mar 2019 15:32:54 -0700 Subject: [PATCH 84/84] removed commented out code --- lib/slack.rb | 2 -- lib/workspace.rb | 5 ----- 2 files changed, 7 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 70cd7272..9bd7949c 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -9,13 +9,11 @@ def main puts "Number of users: #{workspace.users.length}" puts "Number of channels: #{workspace.channels.length}\n\n" options = ["List Users", "List Channels", "Select User", "Select Channel", "Details", "Send Message", "Quit"] - while true puts "--------OPTIONS--------" puts options print "\nPlease enter your command: " input = gets.chomp.upcase - case input when "LIST USERS" list_users workspace diff --git a/lib/workspace.rb b/lib/workspace.rb index d80f3fb6..47daf1d7 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -16,11 +16,6 @@ def select_recipient(recipient:) return true end - # def select_user(user:) - # @selected = user - # return true - # end - def list_all(list:) result = "" list.each do |elem|