From 97d7f3dfbe6b1cbba8bb01fa2aa8ceb3154b0c8c Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Tue, 19 Mar 2019 11:28:13 -0700 Subject: [PATCH 01/42] Setup environment --- .gitignore | 4 ++++ specs/test_helper.rb | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/.gitignore b/.gitignore index 8d6a243f..2a35b04d 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,7 @@ build-iPhoneSimulator/ # Ignore cassette files /specs/cassettes/ + +# Ignore test file +test.rb + diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 81ccd06b..5f78ba5f 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -6,10 +6,20 @@ require 'minitest/reporters' require 'minitest/skip_dsl' require 'vcr' +require "webmock/minitest" +require "dotenv" +Dotenv.load Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new VCR.configure do |config| config.cassette_library_dir = "specs/cassettes" config.hook_into :webmock + config.default_cassette_options = { + :record => :new_episodes, + :match_requests_on => [:method, :uri, :body], + } + config.filter_sensitive_data("") do + ENV["SLACK_API_TOKEN"] + end end \ No newline at end of file From 6e0dee743c180f85d684ffc894da243fad2f21e2 Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Tue, 19 Mar 2019 11:40:10 -0700 Subject: [PATCH 02/42] More environment setup --- lib/channel.rb | 3 +++ lib/recipient.rb | 3 +++ lib/user.rb | 3 +++ specs/channel_spec.rb | 1 + specs/recipient_spec.rb | 1 + specs/test_helper.rb | 21 +++++++++++++-------- specs/user_spec.rb | 1 + 7 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 lib/channel.rb create mode 100644 lib/recipient.rb create mode 100644 lib/user.rb create mode 100644 specs/channel_spec.rb create mode 100644 specs/recipient_spec.rb create mode 100644 specs/user_spec.rb diff --git a/lib/channel.rb b/lib/channel.rb new file mode 100644 index 00000000..ea3643ae --- /dev/null +++ b/lib/channel.rb @@ -0,0 +1,3 @@ +class Channel + #code +end diff --git a/lib/recipient.rb b/lib/recipient.rb new file mode 100644 index 00000000..fef59fd5 --- /dev/null +++ b/lib/recipient.rb @@ -0,0 +1,3 @@ +class Recipient + #code +end diff --git a/lib/user.rb b/lib/user.rb new file mode 100644 index 00000000..1fef6b17 --- /dev/null +++ b/lib/user.rb @@ -0,0 +1,3 @@ +class User + #code +end diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb new file mode 100644 index 00000000..b5cae113 --- /dev/null +++ b/specs/channel_spec.rb @@ -0,0 +1 @@ +require_relative "test_helper" diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb new file mode 100644 index 00000000..b5cae113 --- /dev/null +++ b/specs/recipient_spec.rb @@ -0,0 +1 @@ +require_relative "test_helper" diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 5f78ba5f..09fb41b7 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -1,15 +1,20 @@ -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 "webmock/minitest" require "dotenv" Dotenv.load +require_relative "../lib/channel" +require_relative "../lib/user" +require_relative "../lib/recipient" +require_relative "../lib/slack" + Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new VCR.configure do |config| @@ -17,9 +22,9 @@ config.hook_into :webmock config.default_cassette_options = { :record => :new_episodes, - :match_requests_on => [:method, :uri, :body], + :match_requests_on => [:method, :uri, :body], } config.filter_sensitive_data("") do ENV["SLACK_API_TOKEN"] end -end \ No newline at end of file +end diff --git a/specs/user_spec.rb b/specs/user_spec.rb new file mode 100644 index 00000000..b5cae113 --- /dev/null +++ b/specs/user_spec.rb @@ -0,0 +1 @@ +require_relative "test_helper" From 29cfeef6530c811e363b2fe74f83cd339e62ccab Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Tue, 19 Mar 2019 13:56:28 -0700 Subject: [PATCH 03/42] Add SlackCLI module and Recipient constructor test --- lib/channel.rb | 8 +++++--- lib/recipient.rb | 8 +++++--- lib/user.rb | 8 +++++--- lib/workspace.rb | 5 +++++ specs/recipient_spec.rb | 15 +++++++++++++++ specs/workspace_spec.rb | 1 + 6 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 lib/workspace.rb create mode 100644 specs/workspace_spec.rb diff --git a/lib/channel.rb b/lib/channel.rb index ea3643ae..ebf22f10 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,3 +1,5 @@ -class Channel - #code -end +module SlackCLI + class Channel + #code + end +end \ No newline at end of file diff --git a/lib/recipient.rb b/lib/recipient.rb index fef59fd5..1752aac5 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,3 +1,5 @@ -class Recipient - #code -end +module SlackCLI + class Recipient + #code + end +end \ No newline at end of file diff --git a/lib/user.rb b/lib/user.rb index 1fef6b17..7393df56 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,3 +1,5 @@ -class User - #code -end +module SlackCLI + class User + #code + end +end \ No newline at end of file diff --git a/lib/workspace.rb b/lib/workspace.rb new file mode 100644 index 00000000..dabb939d --- /dev/null +++ b/lib/workspace.rb @@ -0,0 +1,5 @@ +module SlackCLI + class Workspace + #code + end +end \ No newline at end of file diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index b5cae113..269917d1 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -1 +1,16 @@ require_relative "test_helper" + +describe SlackCLI::Recipient do + describe 'constructor' do + it 'takes and saves a Slack id and name' do + VCR.use_cassette("recipient") do + slack_id = "CH2SKTDBN" + name = "random" + record = SlackCLI::Recipient.new(slack_id, name) + expect(record.slack_id).must_equal slack_id + expect(record.name).must_equal name + expect(record).must_be_kind_of SlackCLI::Recipient + end + end + end +end \ No newline at end of file diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb new file mode 100644 index 00000000..b5cae113 --- /dev/null +++ b/specs/workspace_spec.rb @@ -0,0 +1 @@ +require_relative "test_helper" From deb36349750e79c1721429503041a0ffbcab7c87 Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Tue, 19 Mar 2019 14:04:36 -0700 Subject: [PATCH 04/42] Wrote constructor for Recepicient, fixed recipient spec --- lib/recipient.rb | 9 +++++++-- specs/recipient_spec.rb | 26 +++++++++++++++----------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 1752aac5..e1e961eb 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,5 +1,10 @@ module SlackCLI class Recipient - #code + attr_reader :slack_id, :name + + def initialize(slack_id, name) + @slack_id = slack_id + @name = name + end end -end \ No newline at end of file +end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 269917d1..801c8f8b 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -1,16 +1,20 @@ require_relative "test_helper" describe SlackCLI::Recipient do - describe 'constructor' do - it 'takes and saves a Slack id and name' do - VCR.use_cassette("recipient") do - slack_id = "CH2SKTDBN" - name = "random" - record = SlackCLI::Recipient.new(slack_id, name) - expect(record.slack_id).must_equal slack_id - expect(record.name).must_equal name - expect(record).must_be_kind_of SlackCLI::Recipient - end + describe "constructor" do + before do + @slack_id = "CH2SKTDBN" + @name = "random" + @record = SlackCLI::Recipient.new(@slack_id, @name) + end + + it "is an instance of Recipient" do + expect(@record).must_be_kind_of SlackCLI::Recipient + end + + it "takes and saves a Slack id and name" do + expect(@record.slack_id).must_equal @slack_id + expect(@record.name).must_equal @name end end -end \ No newline at end of file +end From 58df5a468ab5cef7e5766ecb80ed38038a907ec7 Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Tue, 19 Mar 2019 14:21:44 -0700 Subject: [PATCH 05/42] Added test for self.get to Recipient spec and removed VCR from constructor test --- specs/recipient_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 801c8f8b..ffad2024 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -17,4 +17,18 @@ expect(@record.name).must_equal @name end end + + describe "self.get" do + it "gets a response" do + VCR.use_cassette("recipient find") do + url = "slack.com/api/users.list" + params = {"token": ENV["SLACK_API_TOKEN"]} + + response = self.get(url, params) + expect(response).wont_be_nil + expect(response).must_be_kind_of HTTParty::Response + expect(response.code).wont_equal 401 + end + end + end end From 166fb29d6a7af95db3782d580c562c05811e7a6e Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Tue, 19 Mar 2019 14:29:38 -0700 Subject: [PATCH 06/42] Add recipient self.get method --- lib/recipient.rb | 6 ++++++ specs/recipient_spec.rb | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index e1e961eb..1359b5eb 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,3 +1,5 @@ +require 'httparty' + module SlackCLI class Recipient attr_reader :slack_id, :name @@ -6,5 +8,9 @@ def initialize(slack_id, name) @slack_id = slack_id @name = name end + + def self.get(url, params) + return HTTParty.get(url, query: params) + end end end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index ffad2024..1a3ba961 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -21,10 +21,10 @@ describe "self.get" do it "gets a response" do VCR.use_cassette("recipient find") do - url = "slack.com/api/users.list" + url = "http://slack.com/api/users.list" params = {"token": ENV["SLACK_API_TOKEN"]} - response = self.get(url, params) + response = SlackCLI::Recipient.get(url, params) expect(response).wont_be_nil expect(response).must_be_kind_of HTTParty::Response expect(response.code).wont_equal 401 From 72304f95f7df8a85ee45fc6f8d7741e2f59c6427 Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Tue, 19 Mar 2019 14:33:19 -0700 Subject: [PATCH 07/42] Add recipient self.list --- lib/recipient.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/recipient.rb b/lib/recipient.rb index 1359b5eb..cbb4240a 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -12,5 +12,9 @@ def initialize(slack_id, name) def self.get(url, params) return HTTParty.get(url, query: params) end + + def self.list + raise NotImplementedError, 'Implement me in a child class!' + end end end From c07db087b2385dc780ef5790bce238b08aaa369d Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Tue, 19 Mar 2019 14:43:47 -0700 Subject: [PATCH 08/42] Change recipient to take kwargs and wrote constructor tests for User --- lib/recipient.rb | 2 +- specs/recipient_spec.rb | 2 +- specs/user_spec.rb | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index cbb4240a..1588742d 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -4,7 +4,7 @@ module SlackCLI class Recipient attr_reader :slack_id, :name - def initialize(slack_id, name) + def initialize(slack_id: slack_id, name: name) @slack_id = slack_id @name = name end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 1a3ba961..b3d895be 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -5,7 +5,7 @@ before do @slack_id = "CH2SKTDBN" @name = "random" - @record = SlackCLI::Recipient.new(@slack_id, @name) + @record = SlackCLI::Recipient.new(slack_id: @slack_id, name: @name) end it "is an instance of Recipient" do diff --git a/specs/user_spec.rb b/specs/user_spec.rb index b5cae113..f58c39bb 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -1 +1,23 @@ require_relative "test_helper" + +describe SlackCLI::User do + describe "constructor" do + before do + @slack_id = "CH2SKTDBN" + @name = "FreddyBoi13" + @real_name = "Alfred Molina" + @record = SlackCLI::User.new(slack_id: @slack_id, name: @name, real_name: @real_name) + end + + it "is an instance of Recipient" do + expect(@record).must_be_kind_of SlackCLI::User + end + + it "takes and saves a Slack id, name, and real name" do + expect(@record.slack_id).must_equal @slack_id + expect(@record.name).must_equal @name + expect(@record.real_name).must_equal @real_name + end + end + +end \ No newline at end of file From d9c962eee974f9676a1ea11f796d250b892ff86a Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Tue, 19 Mar 2019 15:03:42 -0700 Subject: [PATCH 09/42] Wrote constructor for User class --- lib/recipient.rb | 6 +++--- lib/user.rb | 14 +++++++++++--- specs/user_spec.rb | 5 ++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 1588742d..2e49fb1f 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,10 +1,10 @@ -require 'httparty' +require "httparty" module SlackCLI class Recipient attr_reader :slack_id, :name - def initialize(slack_id: slack_id, name: name) + def initialize(slack_id:, name:) @slack_id = slack_id @name = name end @@ -14,7 +14,7 @@ def self.get(url, params) end def self.list - raise NotImplementedError, 'Implement me in a child class!' + raise NotImplementedError, "Implement me in a child class!" end end end diff --git a/lib/user.rb b/lib/user.rb index 7393df56..8e39791b 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,5 +1,13 @@ +require_relative "recipient" + module SlackCLI - class User - #code + class User < Recipient + attr_reader :real_name + + def initialize(slack_id:, name:, real_name:) + super(slack_id: slack_id, name: name) + + @real_name = real_name + end end -end \ No newline at end of file +end diff --git a/specs/user_spec.rb b/specs/user_spec.rb index f58c39bb..08a68999 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -9,7 +9,7 @@ @record = SlackCLI::User.new(slack_id: @slack_id, name: @name, real_name: @real_name) end - it "is an instance of Recipient" do + it "is an instance of User" do expect(@record).must_be_kind_of SlackCLI::User end @@ -19,5 +19,4 @@ expect(@record.real_name).must_equal @real_name end end - -end \ No newline at end of file +end From 37e9abba3751c32f9751387153c7a66603a6850d Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Tue, 19 Mar 2019 15:24:52 -0700 Subject: [PATCH 10/42] "Wrote test for self.list for User class" --- specs/user_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 08a68999..7818439e 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -19,4 +19,20 @@ expect(@record.real_name).must_equal @real_name end end + + describe "self.list" do + it "returns an array of users" do + # VCR.use_cassette("users find") do + # url = "http://slack.com/api/users.list" + # params = {"token": ENV["SLACK_API_TOKEN"]} + + # response = SlackCLI::User.get(url, params) + + users_array = SlackCLI::User.list + + expect(users_array).must_be_kind_of array + expect(users_array.first).must_be_kind_of SlackCLI::User + expect(users_array.length).wont_equal 0 + end + end end From 8f16cfcb1645df33d19011254f80c90f8a315e0f Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Tue, 19 Mar 2019 15:37:25 -0700 Subject: [PATCH 11/42] Create user.list method --- lib/user.rb | 17 +++++++++++++++++ specs/user_spec.rb | 16 ++++++---------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index 8e39791b..f24b4c3c 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -9,5 +9,22 @@ def initialize(slack_id:, name:, real_name:) @real_name = real_name end + + def self.list + url = "https://slack.com/api/users.list" + data = { + "token": ENV["SLACK_API_TOKEN"] + } + response = self.get(url, data) + users = [] + response["members"].each do |member| + slack_id = member["id"] + name = member["name"] + real_name = member["real_name"] + user = self.new(slack_id: slack_id, name: name, real_name: real_name) + users << user + end + return users + end end end diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 7818439e..c25c125d 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -22,17 +22,13 @@ describe "self.list" do it "returns an array of users" do - # VCR.use_cassette("users find") do - # url = "http://slack.com/api/users.list" - # params = {"token": ENV["SLACK_API_TOKEN"]} + VCR.use_cassette("users find") do + users_array = SlackCLI::User.list - # response = SlackCLI::User.get(url, params) - - users_array = SlackCLI::User.list - - expect(users_array).must_be_kind_of array - expect(users_array.first).must_be_kind_of SlackCLI::User - expect(users_array.length).wont_equal 0 + expect(users_array).must_be_kind_of Array + expect(users_array.first).must_be_kind_of SlackCLI::User + expect(users_array.length).wont_equal 0 + end end end end From 658fbc85c44942ec00436504d828171dd4b61bdb Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Tue, 19 Mar 2019 15:41:43 -0700 Subject: [PATCH 12/42] Added constructor test for channel class --- specs/channel_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index b5cae113..cd3bd6aa 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -1 +1,24 @@ require_relative "test_helper" + +describe SlackCLI::Channel do + describe "constructor" do + before do + @slack_id = "CH2SKTDBN" + @name = "Catssss" + @topic = "It's about cats, duh" + @member_count = "2,000,000" + @record = SlackCLI::User.new(slack_id: @slack_id, name: @name, topic: @topic, member_count: member_count) + end + + it "is an instance of Channel" do + expect(@record).must_be_kind_of SlackCLI::Channel + end + + it "takes and saves a Slack id, name, topic, and member count" do + expect(@record.slack_id).must_equal @slack_id + expect(@record.name).must_equal @name + expect(@record.topic).must_equal @topic + expect(@record.member_count).must_equal @member_count + end + end +end From c81f7d5888cd5f03dfafbca8693f3ad88e687ee9 Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Tue, 19 Mar 2019 15:46:53 -0700 Subject: [PATCH 13/42] Create Channel constructor --- lib/channel.rb | 13 +++++++++++-- specs/channel_spec.rb | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index ebf22f10..9fe87b74 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,5 +1,14 @@ +require_relative "recipient" + module SlackCLI - class Channel - #code + class Channel < Recipient + attr_reader :topic, :member_count + + def initialize(slack_id:, name:, topic:, member_count:) + super(slack_id: slack_id, name: name) + + @topic = topic + @member_count = member_count + end end end \ No newline at end of file diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index cd3bd6aa..dd407b4d 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -7,7 +7,7 @@ @name = "Catssss" @topic = "It's about cats, duh" @member_count = "2,000,000" - @record = SlackCLI::User.new(slack_id: @slack_id, name: @name, topic: @topic, member_count: member_count) + @record = SlackCLI::Channel.new(slack_id: @slack_id, name: @name, topic: @topic, member_count: @member_count) end it "is an instance of Channel" do From 87c5bd393f0bb81a7f2b856f2da216505f60b4e8 Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Tue, 19 Mar 2019 15:48:55 -0700 Subject: [PATCH 14/42] Create channel.list test --- specs/channel_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index dd407b4d..69dbade2 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -21,4 +21,16 @@ expect(@record.member_count).must_equal @member_count end end + + describe "self.list" do + it "returns an array of channels" do + VCR.use_cassette("channels find") do + channels_array = SlackCLI::Channel.list + + expect(channels_array).must_be_kind_of Array + expect(channels_array.first).must_be_kind_of SlackCLI::Channel + expect(channels_array.length).wont_equal 0 + end + end + end end From 7e66ef94c4878e5bf00299aeaa9d38d86b93efbc Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Tue, 19 Mar 2019 15:53:46 -0700 Subject: [PATCH 15/42] Created self.list for Channel class --- lib/channel.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/channel.rb b/lib/channel.rb index 9fe87b74..80949ccc 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -10,5 +10,23 @@ def initialize(slack_id:, name:, topic:, member_count:) @topic = topic @member_count = member_count end + + def self.list + url = "https://slack.com/api/channels.list" + data = { + "token": ENV["SLACK_API_TOKEN"], + } + response = self.get(url, data) + channels = [] + response["channels"].each do |channel| + slack_id = channel["id"] + name = channel["name"] + topic = channel["topic"]["value"] + member_count = channel["num_members"] + channel = self.new(slack_id: slack_id, name: name, topic: topic, member_count: member_count) + channels << channel + end + return channels + end end -end \ No newline at end of file +end From f43603495835e502d9025c927c13bc3e0c0f3f03 Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Tue, 19 Mar 2019 16:20:52 -0700 Subject: [PATCH 16/42] Add workspace constructor tests --- specs/workspace_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index b5cae113..0eb4846e 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -1 +1,23 @@ require_relative "test_helper" + +describe SlackCLI::Workspace do + describe "constructor" do + before do + VCR.use_cassette("workspace") do + @workspace = Workspace.new + end + end + + it "is an instance of Channel" do + expect(@workspace).must_be_kind_of SlackCLI::Workspace + end + + it "has a collection of users, collection of channels, and a selected recipient is nil" do + expect(@workspace.users).must_be_kind_of Array + expect(@workspace.users.first).must_be_kind_of SlackCLI::User + expect(@workspace.channels).must_be_kind_of Array + expect(@workspace.channels.first).must_be_kind_of SlackCLI::Channel + expect(@workspace.selected).must_be_nil + end + end +end \ No newline at end of file From 85a195d9c3dfc85070aab22b754aeba1f26dbd31 Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Tue, 19 Mar 2019 16:25:54 -0700 Subject: [PATCH 17/42] Wrote constructor for Workspace and updated test helper to include workspace, fixed workspace test --- lib/workspace.rb | 13 +++++++++++-- specs/test_helper.rb | 1 + specs/workspace_spec.rb | 6 +++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index dabb939d..126c5cd2 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,5 +1,14 @@ +require_relative "user" +require_relative "channel" + module SlackCLI class Workspace - #code + attr_reader :users, :channels, :selected + + def initialize + @users = SlackCLI::User.list + @channels = SlackCLI::Channel.list + @selected = nil + end end -end \ No newline at end of file +end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 09fb41b7..05508fe3 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -14,6 +14,7 @@ require_relative "../lib/user" require_relative "../lib/recipient" require_relative "../lib/slack" +require_relative "../lib/workspace" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 0eb4846e..0619559b 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -1,10 +1,10 @@ require_relative "test_helper" -describe SlackCLI::Workspace do +describe "SlackCLI::Workspace" do describe "constructor" do before do VCR.use_cassette("workspace") do - @workspace = Workspace.new + @workspace = SlackCLI::Workspace.new end end @@ -20,4 +20,4 @@ expect(@workspace.selected).must_be_nil end end -end \ No newline at end of file +end From ede491e3bd8792268de8b573a630e6d90467abdd Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Wed, 20 Mar 2019 08:49:25 -0700 Subject: [PATCH 18/42] Display number of users and channels when program is launched --- lib/channel.rb | 2 ++ lib/slack.rb | 9 +++++---- lib/user.rb | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 80949ccc..17c39cd5 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,4 +1,6 @@ require_relative "recipient" +require 'dotenv' +Dotenv.load module SlackCLI class Channel < Recipient diff --git a/lib/slack.rb b/lib/slack.rb index 960cf2f7..41b2a103 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,11 +1,12 @@ #!/usr/bin/env ruby - +require_relative "workspace.rb" def main puts "Welcome to the Ada Slack CLI!" - # TODO project - + workspace = SlackCLI::Workspace.new + puts "There are #{workspace.channels.count} channels in this workspace" + puts "There are #{workspace.users.count} users in this workspace" 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 diff --git a/lib/user.rb b/lib/user.rb index f24b4c3c..2b8e12f6 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,4 +1,6 @@ require_relative "recipient" +require 'dotenv' +Dotenv.load module SlackCLI class User < Recipient From 1a287b7cf8fe59b27bd8b1cc71bf8f00d13d7d35 Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Wed, 20 Mar 2019 12:06:44 -0700 Subject: [PATCH 19/42] Updated Slack.rb to ask user for input and list possible options so far. Need to update output for the options --- lib/slack.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/slack.rb b/lib/slack.rb index 41b2a103..5a975c9b 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,11 +1,29 @@ #!/usr/bin/env ruby require_relative "workspace.rb" + def main puts "Welcome to the Ada Slack CLI!" workspace = SlackCLI::Workspace.new puts "There are #{workspace.channels.count} channels in this workspace" puts "There are #{workspace.users.count} users in this workspace" + + puts "You can: List Users, List Channels, or Quit." + puts "Please enter what option you would like to take. You can exit by entering 'quit'." + response = gets.chomp.downcase + while response != "quit" + if response == "list users" + puts workspace.users + elsif response == "list channels" + planet_choice = solar_system.find_planet_by_name(gets.chomp) + puts workspace.channels + else + puts "Please make sure to select from the choices above. You can quit be entering 'quit'." + end + puts "\nPlease enter what you would like to do: \nList Users \nList Channels" + response = gets.chomp.downcase + end + puts "Thank you for using the Ada Slack CLI" end From 112cd39bba6d3b7fc75c4aef21c4dc08659bd55e Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Wed, 20 Mar 2019 12:31:46 -0700 Subject: [PATCH 20/42] Add functionality to list users and channels --- lib/slack.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 5a975c9b..dcb79e9b 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -9,22 +9,33 @@ def main puts "There are #{workspace.users.count} users in this workspace" puts "You can: List Users, List Channels, or Quit." - puts "Please enter what option you would like to take. You can exit by entering 'quit'." + puts "Please enter what option you would like to take. You can quit by entering 'quit'." response = gets.chomp.downcase while response != "quit" if response == "list users" - puts workspace.users + list_users(workspace) elsif response == "list channels" - planet_choice = solar_system.find_planet_by_name(gets.chomp) - puts workspace.channels + list_channels(workspace) else puts "Please make sure to select from the choices above. You can quit be entering 'quit'." end - puts "\nPlease enter what you would like to do: \nList Users \nList Channels" + puts "\nPlease enter what you would like to do: \nList Users \nList Channels \nQuit" response = gets.chomp.downcase end puts "Thank you for using the Ada Slack CLI" end +def list_users(workspace) + workspace.users.each do |user| + puts "Slack ID: #{user.slack_id}, username: #{user.name}, real name: #{user.real_name}" + end +end + +def list_channels(workspace) + workspace.channels.each do |channel| + puts "Slack ID: #{channel.slack_id}, name: #{channel.name}, topic: #{channel.topic}, member count: #{channel.member_count}" + end +end + main if __FILE__ == $PROGRAM_NAME From a7138ae16e32fe4a2b84bc4c5ef54aea0ad9294d Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Wed, 20 Mar 2019 13:59:17 -0700 Subject: [PATCH 21/42] Write tests for select_user and add additional options to main --- lib/slack.rb | 7 +++++-- specs/workspace_spec.rb | 34 +++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index dcb79e9b..3ccf4738 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -8,7 +8,7 @@ def main puts "There are #{workspace.channels.count} channels in this workspace" puts "There are #{workspace.users.count} users in this workspace" - puts "You can: List Users, List Channels, or Quit." + puts "You can: List Users, List Channels, Select User, Select Channel, Details, or Quit." puts "Please enter what option you would like to take. You can quit by entering 'quit'." response = gets.chomp.downcase while response != "quit" @@ -16,10 +16,13 @@ def main list_users(workspace) elsif response == "list channels" list_channels(workspace) + elsif response == "select user" + elsif response == "select channel" + elsif response == "details" else puts "Please make sure to select from the choices above. You can quit be entering 'quit'." end - puts "\nPlease enter what you would like to do: \nList Users \nList Channels \nQuit" + puts "\nPlease enter what you would like to do: \nList Users \nList Channels \nSelect User \nSelect Channel \nDetails \nQuit" response = gets.chomp.downcase end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 0619559b..30a0cceb 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -1,13 +1,13 @@ require_relative "test_helper" describe "SlackCLI::Workspace" do - describe "constructor" do - before do - VCR.use_cassette("workspace") do - @workspace = SlackCLI::Workspace.new - end + before do + VCR.use_cassette("workspace") do + @workspace = SlackCLI::Workspace.new end + end + describe "constructor" do it "is an instance of Channel" do expect(@workspace).must_be_kind_of SlackCLI::Workspace end @@ -20,4 +20,28 @@ expect(@workspace.selected).must_be_nil end end + + describe "select_user" do + before do + @username = @workspace.users.first.name + end + it "should return an instance of User, given valid input" do + + expect(@workspace.select_user(@username)).must_be_kind_of SlackCLI::User + expect(@workspace.selected).must_be_kind_of SlackCLI::User + expect(@workspace.selected).must_equal @workspace.users.first + end + # add after select_channel is implemented + # it "should update selected when a new user is selected" do + # @workspace.select_channel(channel) + # username2 = @workspace.users[1].name + # expect(@workspace.selected).must_equal @workspace.users[1] + # end + + it "should return nil, given invalid user" do + bad_username = "" + @workspace.select_user(bad_username) + expect(@workspace.selected).must_be_nil + end + end end From b5478f3cc90e4c2d897aca56ba1a6ec27b3713d2 Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Wed, 20 Mar 2019 14:04:57 -0700 Subject: [PATCH 22/42] Created select_user and find_user for workspace class, passed tests --- lib/workspace.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/workspace.rb b/lib/workspace.rb index 126c5cd2..b98483d2 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -10,5 +10,20 @@ def initialize @channels = SlackCLI::Channel.list @selected = nil end + + def select_user(user_info) + @selected = find_user(user_info) + end + + private + + def find_user(user_info) + @users.each do |user| + if user_info == user.slack_id || user_info == user.name + return user + end + end + return nil + end end end From a36f2b733cdf7c77b9f2db0b8bd11733cb969ebb Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Wed, 20 Mar 2019 14:21:34 -0700 Subject: [PATCH 23/42] Added tests for select_channel and updated tests for select_user --- specs/workspace_spec.rb | 73 ++++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 30a0cceb..5368a698 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -22,21 +22,30 @@ end describe "select_user" do - before do - @username = @workspace.users.first.name + it "should return an instance of User, given valid name" do + username = @workspace.users.first.name + expect(@workspace.select_user(username)).must_be_kind_of SlackCLI::User + expect(@workspace.selected).must_be_kind_of SlackCLI::User + expect(@workspace.selected).must_equal @workspace.users.first end - it "should return an instance of User, given valid input" do - - expect(@workspace.select_user(@username)).must_be_kind_of SlackCLI::User + + it "should return an instance of User, given valid slack id" do + slack_id = @workspace.users.first.slack_id + expect(@workspace.select_user(slack_id)).must_be_kind_of SlackCLI::User expect(@workspace.selected).must_be_kind_of SlackCLI::User expect(@workspace.selected).must_equal @workspace.users.first end - # add after select_channel is implemented - # it "should update selected when a new user is selected" do - # @workspace.select_channel(channel) - # username2 = @workspace.users[1].name - # expect(@workspace.selected).must_equal @workspace.users[1] - # end + + it "should update selected when a new user is selected" do + slack_id1 = @workspace.users.first.slack_id + slack_id2 = @workspace.users.last.slack_id + @workspace.select_user(slack_id1) + expect(@workspace.selected).must_equal @workspace.users.first + @workspace.select_user(slack_id2) + if slack_id1 != slack_id2 + expect(@workspace.selected).must_equal @workspace.users.last + end + end it "should return nil, given invalid user" do bad_username = "" @@ -44,4 +53,46 @@ expect(@workspace.selected).must_be_nil end end + + describe "select_channel" do + it "should return an instance of Channel, given valid name" do + name = @workspace.channels.first.name + expect(@workspace.select_channel(name)).must_be_kind_of SlackCLI::Channel + expect(@workspace.selected).must_be_kind_of SlackCLI::Channel + expect(@workspace.selected).must_equal @workspace.channels.first + end + + it "should return an instance of Channel, given valid slack id" do + slack_id = @workspace.channels.first.slack_id + expect(@workspace.select_channel(slack_id)).must_be_kind_of SlackCLI::Channel + expect(@workspace.selected).must_be_kind_of SlackCLI::Channel + expect(@workspace.selected).must_equal @workspace.channels.first + end + + it "should update selected when a new channel is selected" do + slack_id1 = @workspace.channels.first.slack_id + slack_id2 = @workspace.channels.last.slack_id + @workspace.select_channel(slack_id1) + expect(@workspace.selected).must_equal @workspace.channels.first + @workspace.select_channel(slack_id2) + if slack_id1 != slack_id2 + expect(@workspace.selected).must_equal @workspace.channel.last + end + end + + it "should update selected from user to channel when new channel is selected" do + user_slack_id = @workspace.users.first.slack_id + channel_slack_id = @workspace.channels.first.slack_id + @workspace.select_user(user_slack_id) + expect(@workspace.selected).must_equal @workspace.users.first + @workspace.select_channel(channel_slack_id) + expect(@workspace.selected).must_equal @workspace.channel.first + end + + it "should return nil, given invalid channel" do + bad_slack_id = "" + @workspace.select_channel(bad_slack_id) + expect(@workspace.selected).must_be_nil + end + end end From b62b045b615ef53cd78b5cb681e741cd331895d2 Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Wed, 20 Mar 2019 14:25:50 -0700 Subject: [PATCH 24/42] Add select_channel and find_channel methods to workspace --- lib/workspace.rb | 13 +++++++++++++ specs/workspace_spec.rb | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index b98483d2..cab8bea2 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -15,6 +15,9 @@ def select_user(user_info) @selected = find_user(user_info) end + def select_channel(channel_info) + @selected = find_channel(channel_info) + end private def find_user(user_info) @@ -25,5 +28,15 @@ def find_user(user_info) end return nil end + + def find_channel(channel_info) + @channels.each do |channel| + if channel_info == channel.slack_id || channel_info == channel.name + return channel + end + end + return nil + end + end end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 5368a698..2acf8112 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -76,7 +76,7 @@ expect(@workspace.selected).must_equal @workspace.channels.first @workspace.select_channel(slack_id2) if slack_id1 != slack_id2 - expect(@workspace.selected).must_equal @workspace.channel.last + expect(@workspace.selected).must_equal @workspace.channels.last end end @@ -86,7 +86,7 @@ @workspace.select_user(user_slack_id) expect(@workspace.selected).must_equal @workspace.users.first @workspace.select_channel(channel_slack_id) - expect(@workspace.selected).must_equal @workspace.channel.first + expect(@workspace.selected).must_equal @workspace.channels.first end it "should return nil, given invalid channel" do From 4438a244a5153ae0c004ccfb5d71ee8614fe39c6 Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Wed, 20 Mar 2019 14:48:42 -0700 Subject: [PATCH 25/42] Create details method in recipient and details test for user --- lib/recipient.rb | 4 ++++ specs/user_spec.rb | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 2e49fb1f..166fdad1 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -16,5 +16,9 @@ def self.get(url, params) def self.list raise NotImplementedError, "Implement me in a child class!" end + + def details + raise NotImplementedError, "Implement me in a child class!" + end end end diff --git a/specs/user_spec.rb b/specs/user_spec.rb index c25c125d..bba2e1e9 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -1,6 +1,7 @@ require_relative "test_helper" describe SlackCLI::User do + describe "constructor" do before do @slack_id = "CH2SKTDBN" @@ -20,14 +21,36 @@ end end - describe "self.list" do - it "returns an array of users" do - VCR.use_cassette("users find") do - users_array = SlackCLI::User.list + describe "class methods" do + before do + VCR.use_cassette("users") do + @users_array = SlackCLI::User.list + end + end + + describe "self.list" do + it "returns an array of users" do + expect(@users_array).must_be_kind_of Array + expect(@users_array.first).must_be_kind_of SlackCLI::User + expect(@users_array.length).wont_equal 0 + end + end + + describe "details" do + before do + @slack_id = "CH2SKTDBN" + @name = "FreddyBoi13" + @real_name = "Alfred Molina" + @record = SlackCLI::User.new(slack_id: @slack_id, name: @name, real_name: @real_name) + @detail = @record.details + end + + it "returns a string" do + expect(@detail).must_be_kind_of String + end - expect(users_array).must_be_kind_of Array - expect(users_array.first).must_be_kind_of SlackCLI::User - expect(users_array.length).wont_equal 0 + it "returns the correct information" do + expect(@detail).must_equal "Slack ID: #{@slack_id}, username: #{@name}, real name: #{@eal_name}" end end end From adfeb09e79b0852b7279421ceb2a3ddc0d2cabd5 Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Wed, 20 Mar 2019 14:51:21 -0700 Subject: [PATCH 26/42] Created details for user class --- lib/user.rb | 10 +++++++--- specs/user_spec.rb | 3 +-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index 2b8e12f6..16832bc0 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,5 +1,5 @@ require_relative "recipient" -require 'dotenv' +require "dotenv" Dotenv.load module SlackCLI @@ -13,9 +13,9 @@ def initialize(slack_id:, name:, real_name:) end def self.list - url = "https://slack.com/api/users.list" + url = "https://slack.com/api/users.list" data = { - "token": ENV["SLACK_API_TOKEN"] + "token": ENV["SLACK_API_TOKEN"], } response = self.get(url, data) users = [] @@ -28,5 +28,9 @@ def self.list end return users end + + def details + return "Slack ID: #{slack_id}, username: #{name}, real name: #{real_name}" + end end end diff --git a/specs/user_spec.rb b/specs/user_spec.rb index bba2e1e9..f8745183 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -1,7 +1,6 @@ require_relative "test_helper" describe SlackCLI::User do - describe "constructor" do before do @slack_id = "CH2SKTDBN" @@ -50,7 +49,7 @@ end it "returns the correct information" do - expect(@detail).must_equal "Slack ID: #{@slack_id}, username: #{@name}, real name: #{@eal_name}" + expect(@detail).must_equal "Slack ID: #{@slack_id}, username: #{@name}, real name: #{@real_name}" end end end From a688cb8e340353ef8318f5486220c21f6a270856 Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Wed, 20 Mar 2019 14:55:42 -0700 Subject: [PATCH 27/42] Added tests for channel details method --- lib/user.rb | 2 +- specs/channel_spec.rb | 18 ++++++++++++++++++ specs/user_spec.rb | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index 16832bc0..114c00e9 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -30,7 +30,7 @@ def self.list end def details - return "Slack ID: #{slack_id}, username: #{name}, real name: #{real_name}" + return "Slack ID: #{slack_id}, Username: #{name}, Real Name: #{real_name}" end end end diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 69dbade2..13b6f6a2 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -33,4 +33,22 @@ end end end + + describe "details" do + before do + @slack_id = "CH2SKTDBN" + @name = "Catssss" + @topic = "It's about cats, duh" + @member_count = "2,000,000" + @record = SlackCLI::Channel.new(slack_id: @slack_id, name: @name, topic: @topic, member_count: @member_count) + end + + it "returns a string" do + expect(@detail).must_be_kind_of String + end + + it "returns the correct information" do + expect(@detail).must_equal "Slack ID: #{@slack_id}, Name: #{@name}, Topic: #{@topic}, Member count: #{@member_count}" + end + end end diff --git a/specs/user_spec.rb b/specs/user_spec.rb index f8745183..db13c452 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -49,7 +49,7 @@ end it "returns the correct information" do - expect(@detail).must_equal "Slack ID: #{@slack_id}, username: #{@name}, real name: #{@real_name}" + expect(@detail).must_equal "Slack ID: #{@slack_id}, Username: #{@name}, Real Name: #{@real_name}" end end end From 78628bd474edc743d2cc823c6a2b868cb804fd43 Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Wed, 20 Mar 2019 15:11:16 -0700 Subject: [PATCH 28/42] Add details method to channel and added select user and channel functionality to main --- lib/channel.rb | 4 ++++ lib/slack.rb | 24 ++++++++++++++++++++++++ specs/channel_spec.rb | 1 + 3 files changed, 29 insertions(+) diff --git a/lib/channel.rb b/lib/channel.rb index 17c39cd5..709b5afc 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -30,5 +30,9 @@ def self.list end return channels end + + def details + return "Slack ID: #{slack_id}, Name: #{name}, Topic: #{topic}, Member count: #{member_count}" + end end end diff --git a/lib/slack.rb b/lib/slack.rb index 3ccf4738..69f716f1 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -17,7 +17,9 @@ def main elsif response == "list channels" list_channels(workspace) elsif response == "select user" + puts select_user_by_input(workspace) elsif response == "select channel" + puts select_channel_by_input(workspace) elsif response == "details" else puts "Please make sure to select from the choices above. You can quit be entering 'quit'." @@ -41,4 +43,26 @@ def list_channels(workspace) end end +def select_user_by_input(workspace) + puts "What is the Slack ID or username? " + user_info = gets.chomp + user = workspace.select_user(user_info) + if user == nil + puts "We couldn't find that user" + else + puts "User has been selected" + end +end + +def select_channel_by_input(workspace) + puts "What is the Slack ID or name? " + channel_info = gets.chomp + channel = workspace.select_channel(channel_info) + if channel == nil + puts "We couldn't find that channel" + else + puts "Channel has been selected" + end +end + main if __FILE__ == $PROGRAM_NAME diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 13b6f6a2..b369fc13 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -41,6 +41,7 @@ @topic = "It's about cats, duh" @member_count = "2,000,000" @record = SlackCLI::Channel.new(slack_id: @slack_id, name: @name, topic: @topic, member_count: @member_count) + @detail = @record.details end it "returns a string" do From fd5dba17663567604490d3faae6a443f9579ca65 Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Wed, 20 Mar 2019 15:25:14 -0700 Subject: [PATCH 29/42] Added tests for show_details --- specs/workspace_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 2acf8112..3a34bfa3 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -95,4 +95,28 @@ expect(@workspace.selected).must_be_nil end end + + describe "show details" do + it "displays details for user" do + username = @workspace.users.first.name + @workspace.select_user(username) + user_detail = @workspace.show_details + expect(user_detail).must_be_kind_of String + expect(@workspace.users.first.details).must_equal user_detail + end + + it "displays details for channel" do + channel_name = @workspace.channel.first.name + @workspace.select_channel(channel_name) + channel_detail = @workspace.show_details + expect(channel_detail).must_be_kind_of String + expect(@workspace.channels.first.details).must_equal channel_detail + end + + it "returns nil if selected is nil" do + if @workspace.selected == nil + expect(@workspace.details).must_be_nil + end + end + end end From f6ffe2d8e3aceff03ae3791d0de584447d584ef9 Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Wed, 20 Mar 2019 15:34:42 -0700 Subject: [PATCH 30/42] Wrote method for show details and added its functionality into main --- lib/slack.rb | 11 +++++++++++ lib/workspace.rb | 5 +++++ specs/workspace_spec.rb | 4 ++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 69f716f1..efc306f9 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -21,6 +21,8 @@ def main elsif response == "select channel" puts select_channel_by_input(workspace) elsif response == "details" + puts get_details(workspace) + else puts "Please make sure to select from the choices above. You can quit be entering 'quit'." end @@ -65,4 +67,13 @@ def select_channel_by_input(workspace) end end +def get_details(workspace) + detail_info = workspace.show_details + if detail_info == nil + puts "There is nothing selected to show details about. Please select a user or channel." + else + return detail_info + end +end + main if __FILE__ == $PROGRAM_NAME diff --git a/lib/workspace.rb b/lib/workspace.rb index cab8bea2..9dca5a4f 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -18,6 +18,11 @@ def select_user(user_info) def select_channel(channel_info) @selected = find_channel(channel_info) end + + def show_details + return @selected == nil ? nil : @selected.details + end + private def find_user(user_info) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 3a34bfa3..9238572a 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -106,7 +106,7 @@ end it "displays details for channel" do - channel_name = @workspace.channel.first.name + channel_name = @workspace.channels.first.name @workspace.select_channel(channel_name) channel_detail = @workspace.show_details expect(channel_detail).must_be_kind_of String @@ -115,7 +115,7 @@ it "returns nil if selected is nil" do if @workspace.selected == nil - expect(@workspace.details).must_be_nil + expect(@workspace.show_details).must_be_nil end end end From 4180431a3fc5c9deb5fb98a50fc3ab45e96fa31b Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Wed, 20 Mar 2019 15:49:26 -0700 Subject: [PATCH 31/42] Added recipient send message test --- specs/recipient_spec.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index b3d895be..ef043f94 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -20,7 +20,7 @@ describe "self.get" do it "gets a response" do - VCR.use_cassette("recipient find") do + VCR.use_cassette("recipient") do url = "http://slack.com/api/users.list" params = {"token": ENV["SLACK_API_TOKEN"]} @@ -31,4 +31,13 @@ end end end + + describe "send message" do + it "can send a valid message" do + VCR.use_cassette("recipient") do + response = SlackCLI::Recipient.send_message("Hey I can post messages!") + expect(response).must_equal true + end + end + end end From 2ef85bd4f8571b001c546df527046340c26796be Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Thu, 21 Mar 2019 10:17:18 -0700 Subject: [PATCH 32/42] Add send_message to recipient --- lib/recipient.rb | 20 ++++++++++++++++++++ specs/recipient_spec.rb | 15 +++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 166fdad1..401ca37d 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -4,6 +4,9 @@ module SlackCLI class Recipient attr_reader :slack_id, :name + URL = "https://slack.com/api/chat.postMessage" + API_KEY = ENV["SLACK_API_TOKEN"] + def initialize(slack_id:, name:) @slack_id = slack_id @name = name @@ -20,5 +23,22 @@ def self.list def details raise NotImplementedError, "Implement me in a child class!" end + + def send_message(message) + body = { + token: API_KEY, + text: message, + channel: self.slack_id + } + headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } + response = HTTParty.post(URL, body: body, headers: headers) + + unless response.code == 200 && response.parsed_response["ok"] + # raise SlackApiError, "Error when posting #{message} to #{channel}, error: #{response.parsed_response["error"]}" + raise StandardError, "message could not be sent" + end + + return true + end end end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index ef043f94..cfc80291 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -1,13 +1,12 @@ require_relative "test_helper" describe SlackCLI::Recipient do + before do + @slack_id = "CH2SKTDBN" + @name = "random" + @record = SlackCLI::Recipient.new(slack_id: @slack_id, name: @name) + end describe "constructor" do - before do - @slack_id = "CH2SKTDBN" - @name = "random" - @record = SlackCLI::Recipient.new(slack_id: @slack_id, name: @name) - end - it "is an instance of Recipient" do expect(@record).must_be_kind_of SlackCLI::Recipient end @@ -34,8 +33,8 @@ describe "send message" do it "can send a valid message" do - VCR.use_cassette("recipient") do - response = SlackCLI::Recipient.send_message("Hey I can post messages!") + VCR.use_cassette("workspace") do + response = @record.send_message("Hey I can post messages!") expect(response).must_equal true end end From 950412209ed9a4cb8bd967ad2bf5903891680905 Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Thu, 21 Mar 2019 10:25:42 -0700 Subject: [PATCH 33/42] Fix typos --- specs/channel_spec.rb | 2 +- specs/workspace_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index b369fc13..3096fb47 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -24,7 +24,7 @@ describe "self.list" do it "returns an array of channels" do - VCR.use_cassette("channels find") do + VCR.use_cassette("channels") do channels_array = SlackCLI::Channel.list expect(channels_array).must_be_kind_of Array diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 9238572a..572d010e 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -8,7 +8,7 @@ end describe "constructor" do - it "is an instance of Channel" do + it "is an instance of Workspace" do expect(@workspace).must_be_kind_of SlackCLI::Workspace end From 5f8ef781c3f08a98555c37b2b51792bb54bc7dd4 Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Thu, 21 Mar 2019 12:35:38 -0700 Subject: [PATCH 34/42] create SlackApiError class --- lib/recipient.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/recipient.rb b/lib/recipient.rb index 401ca37d..c1b1155a 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,7 +1,11 @@ require "httparty" module SlackCLI + class Recipient + + class SlackApiError < StandardError; end + attr_reader :slack_id, :name URL = "https://slack.com/api/chat.postMessage" From a21aff750d1cae7976efc7e661ced14214745331 Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Thu, 21 Mar 2019 13:55:06 -0700 Subject: [PATCH 35/42] Added send message to Workspace class --- lib/workspace.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index 9dca5a4f..6a6aba69 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -23,6 +23,16 @@ def show_details return @selected == nil ? nil : @selected.details end + def send_message + if @selected != nil + message = gets.chomp + @selected.send_message(message) + return true + else + return false + end + end + private def find_user(user_info) @@ -42,6 +52,5 @@ def find_channel(channel_info) end return nil end - end end From 383341bea98745e6f33e8583ab505e4b7a84ed3c Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Fri, 22 Mar 2019 10:25:30 -0700 Subject: [PATCH 36/42] Update error handling for recipient send_message and add test for it --- lib/recipient.rb | 5 ++--- specs/recipient_spec.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index c1b1155a..00e50382 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -5,7 +5,7 @@ module SlackCLI class Recipient class SlackApiError < StandardError; end - + attr_reader :slack_id, :name URL = "https://slack.com/api/chat.postMessage" @@ -38,8 +38,7 @@ def send_message(message) response = HTTParty.post(URL, body: body, headers: headers) unless response.code == 200 && response.parsed_response["ok"] - # raise SlackApiError, "Error when posting #{message} to #{channel}, error: #{response.parsed_response["error"]}" - raise StandardError, "message could not be sent" + raise SlackApiError, "Error when posting #{message} to #{self.slack_id}, error: #{response.parsed_response["error"]}" end return true diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index cfc80291..ba0ae34e 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -38,5 +38,18 @@ expect(response).must_equal true end end + + it "will raise an error when given an invalid channel" do + VCR.use_cassette("workspace") do + slack_id = "invalid_id" + name = "invalid-channel" + bad_record = SlackCLI::Recipient.new(slack_id: slack_id, name: name) + exception = expect { + bad_record.send_message("This post should not work") + }.must_raise SlackCLI::Recipient::SlackApiError + + expect(exception.message).must_equal "Error when posting This post should not work to invalid_id, error: channel_not_found" + end + end end end From c6c2086c06fdc299bf12b7598d52b50a53343c72 Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Fri, 22 Mar 2019 10:37:36 -0700 Subject: [PATCH 37/42] Added error handling and test for self.get in recipient class --- lib/recipient.rb | 14 ++++++++------ specs/recipient_spec.rb | 13 ++++++++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 00e50382..b7ff0755 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,9 +1,7 @@ require "httparty" module SlackCLI - class Recipient - class SlackApiError < StandardError; end attr_reader :slack_id, :name @@ -17,7 +15,11 @@ def initialize(slack_id:, name:) end def self.get(url, params) - return HTTParty.get(url, query: params) + response = HTTParty.get(url, query: params) + unless response.code == 200 && response.parsed_response["ok"] + raise SlackApiError, "Error when getting response, error: #{response.parsed_response["error"]}" + end + return response end def self.list @@ -32,15 +34,15 @@ def send_message(message) body = { token: API_KEY, text: message, - channel: self.slack_id + channel: self.slack_id, } - headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } + headers = {"Content-Type" => "application/x-www-form-urlencoded"} response = HTTParty.post(URL, body: body, headers: headers) unless response.code == 200 && response.parsed_response["ok"] raise SlackApiError, "Error when posting #{message} to #{self.slack_id}, error: #{response.parsed_response["error"]}" end - + return true end end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index ba0ae34e..7a4aae72 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -29,6 +29,17 @@ expect(response.code).wont_equal 401 end end + + it "raises an error when given bad params" do + VCR.use_cassette("recipient") do + url = "https://slack.com/api/users.list" + data = { + "token": "BAD TOKEN", + } + exception = expect { SlackCLI::Recipient.get(url, data) }.must_raise SlackCLI::Recipient::SlackApiError + expect(exception.message).must_equal "Error when getting response, error: invalid_auth" + end + end end describe "send message" do @@ -47,7 +58,7 @@ exception = expect { bad_record.send_message("This post should not work") }.must_raise SlackCLI::Recipient::SlackApiError - + expect(exception.message).must_equal "Error when posting This post should not work to invalid_id, error: channel_not_found" end end From 0f8aa9e6b6df8e71c063dd52e8a4008742b0a9a0 Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Fri, 22 Mar 2019 10:55:57 -0700 Subject: [PATCH 38/42] Add tests for workspace send_message --- lib/recipient.rb | 18 ++++++++++-------- lib/workspace.rb | 3 +-- specs/recipient_spec.rb | 4 ++-- specs/workspace_spec.rb | 42 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 12 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index b7ff0755..949cbfa4 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -22,14 +22,6 @@ def self.get(url, params) return response end - def self.list - raise NotImplementedError, "Implement me in a child class!" - end - - def details - raise NotImplementedError, "Implement me in a child class!" - end - def send_message(message) body = { token: API_KEY, @@ -45,5 +37,15 @@ def send_message(message) return true end + + private + + def self.list + raise NotImplementedError, "Implement me in a child class!" + end + + def details + raise NotImplementedError, "Implement me in a child class!" + end end end diff --git a/lib/workspace.rb b/lib/workspace.rb index 6a6aba69..ddc6d591 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -23,9 +23,8 @@ def show_details return @selected == nil ? nil : @selected.details end - def send_message + def send_message(message) if @selected != nil - message = gets.chomp @selected.send_message(message) return true else diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 7a4aae72..791869ea 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -44,14 +44,14 @@ describe "send message" do it "can send a valid message" do - VCR.use_cassette("workspace") do + VCR.use_cassette("recipient") do response = @record.send_message("Hey I can post messages!") expect(response).must_equal true end end it "will raise an error when given an invalid channel" do - VCR.use_cassette("workspace") do + VCR.use_cassette("recipient") do slack_id = "invalid_id" name = "invalid-channel" bad_record = SlackCLI::Recipient.new(slack_id: slack_id, name: name) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 572d010e..7f09bab4 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -119,4 +119,46 @@ end end end + + describe "send_message" do + it "returns true if able to send message to user" do + VCR.use_cassette("workspace") do + username = @workspace.users.first.name + @workspace.select_user(username) + response = @workspace.send_message("Hey I can post messages!") + expect(response).must_equal true + end + end + + it "returns true if able to send message to channel" do + VCR.use_cassette("workspace") do + channel = @workspace.channels.first.name + @workspace.select_channel(channel) + response = @workspace.send_message("Hey I can post messages!") + expect(response).must_equal true + end + end + + it "returns false if selected is nil" do + VCR.use_cassette("workspace") do + response = @workspace.send_message("Hey I can post messages!") + expect(response).must_equal false + end + end + end + end + + +# it "will raise an error when given an invalid channel" do +# VCR.use_cassette("workspace") do +# slack_id = "invalid_id" +# name = "invalid-channel" +# bad_record = SlackCLI::Recipient.new(slack_id: slack_id, name: name) +# exception = expect { +# bad_record.send_message("This post should not work") +# }.must_raise SlackCLI::Recipient::SlackApiError + +# expect(exception.message).must_equal "Error when posting This post should not work to invalid_id, error: channel_not_found" +# end +# end \ No newline at end of file From 1b7bbbb8e3053b7b55289d62c31e962d705a3061 Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Fri, 22 Mar 2019 11:16:47 -0700 Subject: [PATCH 39/42] Updated recipient for send message, updated slack to include send message and some refactoring --- lib/recipient.rb | 10 +++++----- lib/slack.rb | 29 ++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 949cbfa4..a0b6c908 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -6,9 +6,6 @@ class SlackApiError < StandardError; end attr_reader :slack_id, :name - URL = "https://slack.com/api/chat.postMessage" - API_KEY = ENV["SLACK_API_TOKEN"] - def initialize(slack_id:, name:) @slack_id = slack_id @name = name @@ -23,13 +20,16 @@ def self.get(url, params) end def send_message(message) + url = "https://slack.com/api/chat.postMessage" + api_key = ENV["SLACK_API_TOKEN"] + body = { - token: API_KEY, + token: api_key, text: message, channel: self.slack_id, } headers = {"Content-Type" => "application/x-www-form-urlencoded"} - response = HTTParty.post(URL, body: body, headers: headers) + response = HTTParty.post(url, body: body, headers: headers) unless response.code == 200 && response.parsed_response["ok"] raise SlackApiError, "Error when posting #{message} to #{self.slack_id}, error: #{response.parsed_response["error"]}" diff --git a/lib/slack.rb b/lib/slack.rb index efc306f9..ab1b369b 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -8,7 +8,7 @@ def main puts "There are #{workspace.channels.count} channels in this workspace" puts "There are #{workspace.users.count} users in this workspace" - puts "You can: List Users, List Channels, Select User, Select Channel, Details, or Quit." + puts "You can: List Users, List Channels, Select User, Select Channel, Details, Send Message, or Quit." puts "Please enter what option you would like to take. You can quit by entering 'quit'." response = gets.chomp.downcase while response != "quit" @@ -17,16 +17,17 @@ def main elsif response == "list channels" list_channels(workspace) elsif response == "select user" - puts select_user_by_input(workspace) + select_user_by_input(workspace) elsif response == "select channel" - puts select_channel_by_input(workspace) + select_channel_by_input(workspace) elsif response == "details" puts get_details(workspace) - + elsif response == "send message" + send_message(workspace) else puts "Please make sure to select from the choices above. You can quit be entering 'quit'." end - puts "\nPlease enter what you would like to do: \nList Users \nList Channels \nSelect User \nSelect Channel \nDetails \nQuit" + puts "\nPlease enter what you would like to do: \nList Users \nList Channels \nSelect User \nSelect Channel \nDetails \nSend Message \nQuit" response = gets.chomp.downcase end @@ -35,13 +36,13 @@ def main def list_users(workspace) workspace.users.each do |user| - puts "Slack ID: #{user.slack_id}, username: #{user.name}, real name: #{user.real_name}" + puts user.details end end def list_channels(workspace) workspace.channels.each do |channel| - puts "Slack ID: #{channel.slack_id}, name: #{channel.name}, topic: #{channel.topic}, member count: #{channel.member_count}" + puts channel.details end end @@ -49,7 +50,7 @@ def select_user_by_input(workspace) puts "What is the Slack ID or username? " user_info = gets.chomp user = workspace.select_user(user_info) - if user == nil + if user == nil puts "We couldn't find that user" else puts "User has been selected" @@ -60,7 +61,7 @@ def select_channel_by_input(workspace) puts "What is the Slack ID or name? " channel_info = gets.chomp channel = workspace.select_channel(channel_info) - if channel == nil + if channel == nil puts "We couldn't find that channel" else puts "Channel has been selected" @@ -76,4 +77,14 @@ def get_details(workspace) end end +def send_message(workspace) + puts "What would you like to send?" + message = gets.chomp + if workspace.send_message(message) + puts "Message successfully sent" + else + puts "Please select a channel or user before sending message." + end +end + main if __FILE__ == $PROGRAM_NAME From d8e88aada16968e9d4667799650a5e6b5f2ea352 Mon Sep 17 00:00:00 2001 From: Erica Norris Date: Fri, 22 Mar 2019 11:23:13 -0700 Subject: [PATCH 40/42] DRYed workspace.rb --- lib/workspace.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index ddc6d591..526926b7 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -24,12 +24,9 @@ def show_details end def send_message(message) - if @selected != nil - @selected.send_message(message) - return true - else - return false - end + return false if @selected != nil + @selected.send_message(message) + return true end private From 32b66ce265df97c85f2159d95a92e7816333a208 Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Fri, 22 Mar 2019 11:36:39 -0700 Subject: [PATCH 41/42] Format output with table_print --- lib/slack.rb | 10 ++++------ lib/workspace.rb | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index ab1b369b..b33052c1 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,5 +1,6 @@ #!/usr/bin/env ruby require_relative "workspace.rb" +require "table_print" def main puts "Welcome to the Ada Slack CLI!" @@ -28,6 +29,7 @@ def main puts "Please make sure to select from the choices above. You can quit be entering 'quit'." end puts "\nPlease enter what you would like to do: \nList Users \nList Channels \nSelect User \nSelect Channel \nDetails \nSend Message \nQuit" + puts response = gets.chomp.downcase end @@ -35,15 +37,11 @@ def main end def list_users(workspace) - workspace.users.each do |user| - puts user.details - end + tp workspace.users, "slack_id", "name", "real_name" end def list_channels(workspace) - workspace.channels.each do |channel| - puts channel.details - end + tp workspace.channels, "slack_id", "name", "topic", "member_count" end def select_user_by_input(workspace) diff --git a/lib/workspace.rb b/lib/workspace.rb index 526926b7..7997c5ff 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -24,7 +24,7 @@ def show_details end def send_message(message) - return false if @selected != nil + return false if @selected == nil @selected.send_message(message) return true end From f7a0ed8223a545a5d4b28889ac676092f6b0c488 Mon Sep 17 00:00:00 2001 From: Kelly Downes Date: Fri, 22 Mar 2019 11:41:53 -0700 Subject: [PATCH 42/42] Hide main code from SimpleCov --- lib/slack.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/slack.rb b/lib/slack.rb index b33052c1..b2ee6878 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -2,6 +2,8 @@ require_relative "workspace.rb" require "table_print" +# :nocov: + def main puts "Welcome to the Ada Slack CLI!" @@ -84,5 +86,5 @@ def send_message(workspace) puts "Please select a channel or user before sending message." end end - +# :nocov: main if __FILE__ == $PROGRAM_NAME