From 81a7177105c0f8bfabb81b2a7ced9e3a565fd660 Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Tue, 10 Sep 2019 11:52:08 -0700 Subject: [PATCH 01/25] Configured VCR to filter_sensitive_data for slack token --- test/test_helper.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index 90aeb408..0887ede9 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,10 +8,19 @@ require 'minitest/reporters' require 'minitest/skip_dsl' require 'vcr' +require "dotenv" +Dotenv.load Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new VCR.configure do |config| config.cassette_library_dir = "test/cassettes" config.hook_into :webmock + + # Don't leave our token lying around in a cassette file. + config.filter_sensitive_data("") do + ENV["SLACK_API_TOKEN"] + end end + + From 015d86d89fac0bdeb9885d5370ced1e46a5c302b Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Tue, 10 Sep 2019 16:13:38 -0700 Subject: [PATCH 02/25] Initialized User class. Added list method --- lib/user.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/user.rb diff --git a/lib/user.rb b/lib/user.rb new file mode 100644 index 00000000..c5d277e2 --- /dev/null +++ b/lib/user.rb @@ -0,0 +1,24 @@ + + +class User < Recipient + attr_reader :real_name, :status_text, :status_emoji + + def initialize(real_name:, status_text: nil , status_emoji: nil, slack_id:, name:) + super(slack_id: slack_id, name: name) + @real_name = real_name + @status_text = status_text + @status_emoji = status_emoji + end + + # def details + # end + + def self.list + response = self.get("https://slack.com/api/users.list", ENV["SLACK_TOKEN"]) + + members = response["members"].map do |member| + self.new(slack_id: member["id"], name: member["name"], real_name: member["real_name"] ) + end + return members + end +end From 975cf00ab888a94d67ae1a021bf48b3872c3d7f2 Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Tue, 10 Sep 2019 16:14:24 -0700 Subject: [PATCH 03/25] Initialized Channel class. Added list method --- lib/channel.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/channel.rb diff --git a/lib/channel.rb b/lib/channel.rb new file mode 100644 index 00000000..a2653d7e --- /dev/null +++ b/lib/channel.rb @@ -0,0 +1,24 @@ + + +class Channel < Recipient + attr_reader :topic, :member_count + + def initialize(topic: , member_count: , slack_id: , name: ) + super(slack_id: slack_id, name: name) + @topic = topic + @member_count = member_count + end + + # def details + # end + + def self.list + response = self.get("https://slack.com/api/channels.list", ENV["SLACK_TOKEN"]) + + # ap response + members = response["channels"].map do |channel| + self.new(slack_id: channel["id"], name: channel["name"], topic: channel["topic"]["value"], member_count: channel["members"].length ) + end + return members + end +end From 78996c0fa3136ba914a7b6bc6081a561f5f27cca Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Tue, 10 Sep 2019 16:15:14 -0700 Subject: [PATCH 04/25] Initialized Recipient class. Added get method --- lib/recipient.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/recipient.rb diff --git a/lib/recipient.rb b/lib/recipient.rb new file mode 100644 index 00000000..8a9a0e45 --- /dev/null +++ b/lib/recipient.rb @@ -0,0 +1,35 @@ +class Recipient + attr_reader :slack_id, :name + + def initialize(slack_id: slack_id, name: name) + @slack_id = slack_id + @name = name + end + + # def send_message(message) + # end + + def self.get(url, params) + query = { + token: params + } + + response = HTTParty.get(url, query: query) + + if response["error"] + raise SlackApiError.new "#{response.code}: #{response.message} -- #{response["error"]}" + end + + return response + end + + def details + + end + + def self.list + raise NotImplementedError.new "Implement me in a child class" + end + + +end From 5200a35c643008422ff8da361b3e16d9265e4801 Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Tue, 10 Sep 2019 16:16:49 -0700 Subject: [PATCH 05/25] Implemented SlackApiError --- lib/slack_api_error.rb | 1 + 1 file changed, 1 insertion(+) create mode 100644 lib/slack_api_error.rb diff --git a/lib/slack_api_error.rb b/lib/slack_api_error.rb new file mode 100644 index 00000000..e65f8de8 --- /dev/null +++ b/lib/slack_api_error.rb @@ -0,0 +1 @@ +class SlackApiError < StandardError; end From ad3997a1cf0b10ed33b84ce9d9dfdfcdadd3d4cc Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Tue, 10 Sep 2019 16:17:25 -0700 Subject: [PATCH 06/25] Initialized Workspace class --- lib/workspace.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lib/workspace.rb diff --git a/lib/workspace.rb b/lib/workspace.rb new file mode 100644 index 00000000..559936e3 --- /dev/null +++ b/lib/workspace.rb @@ -0,0 +1,34 @@ +require 'httparty' +require 'awesome_print' +require 'pry' +require 'table_print' +require 'dotenv' +Dotenv.load + +require_relative 'slack_api_error' +require_relative 'recipient' +require_relative 'channel' +require_relative 'user' + +class Workspace + attr_reader :users, :channels, :selected + + def initialize + @users = User.list + @channels = Channel.list + @selected = nil + end + + def select_channel + end + + def select_user + + end + + def show_details + end + + def send_message + end +end From 0255edec8f4fafe0539262375ef86437dd4c397c Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Tue, 10 Sep 2019 16:18:22 -0700 Subject: [PATCH 07/25] Implemented Wave 1 --- lib/slack.rb | 63 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 960cf2f7..c63283b8 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,11 +1,66 @@ #!/usr/bin/env ruby +require_relative 'workspace' def main + workspace = Workspace.new + + puts "Welcome to the Ada Slack CLI!" - - # TODO project - + puts "The number of channels is #{workspace.channels.length}." + puts "The number of users is #{workspace.users.length}" + + puts "Do you want to list users, list channels, or quit?" + search = gets.chomp.downcase + until search == "quit" + + case search + when "quit" + exit + when "list users", "users" + workspace.users.each do |user| + puts + puts "Username: #{user.name}" + puts "Real Name: #{user.real_name}" + puts "Slack ID: #{user.slack_id}" + end + puts + puts "Do you want to list users, list channels, or quit?" + search = gets.chomp.downcase + when "list channels", "channels" + workspace.channels.each do |channel| + puts + puts "Channel name: #{channel.name}" + puts "Topic: #{channel.topic}" + puts "Member count: #{channel.member_count}" + puts "Slack ID: #{channel.slack_id}" + end + puts + puts "Do you want to list users, list channels, or quit?" + search = gets.chomp.downcase + end + end + puts "Thank you for using the Ada Slack CLI" end -main if __FILE__ == $PROGRAM_NAME \ No newline at end of file +main if __FILE__ == $PROGRAM_NAME + + + + +# url = "https://slack.com/api/channels.list" +# key = ENV["SLACK_TOKEN"] + +# query = { +# token: key +# } + +# response = HTTParty.get(url, query: query) + +# if response["error"] +# raise StandardError.new "#{response.code}: #{response.message} -- #{response["error"]}" +# end + +# response["channels"].each_with_index do |channel, index| +# puts "#{index + 1}. #{channel["name"]}" +# end From 8e430782bb363f7f1436dafe0bd946b750ca4abd Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Tue, 10 Sep 2019 17:07:48 -0700 Subject: [PATCH 08/25] Implemented User tests for #initialize and #list_users --- test/user_test.rb | 74 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 test/user_test.rb diff --git a/test/user_test.rb b/test/user_test.rb new file mode 100644 index 00000000..ddd2d6c8 --- /dev/null +++ b/test/user_test.rb @@ -0,0 +1,74 @@ +require_relative "test_helper" + +describe "User" do + describe "initialize" do + before do + @user = User.new(real_name: "Bob", slack_id: "1234", name: "Bobiscool") + end + it "creates instance of User" do + VCR.use_cassette("initialize_user") do + expect(@user).must_be_kind_of User + end + end + + it "responds to variable names" do + VCR.use_cassette("initialize_user") do + [:real_name, :slack_id, :name].each do |variable| + expect(@user).must_respond_to variable + end + end + end + + it "creates accurate attributes" do + VCR.use_cassette("initialize_user") do + expect(@user.real_name).must_be_kind_of String + expect(@user.real_name).must_equal "Bob" + + expect(@user.name).must_be_kind_of String + expect(@user.name).must_equal "Bobiscool" + + expect(@user.slack_id).must_be_kind_of String + expect(@user.slack_id).must_equal "1234" + end + end + end +end + +describe "list method" do + it "self.list returns an array of users" do + VCR.use_cassette("list_users") do + results = User.list + expect(results).must_be_instance_of Array + results.each do |result| + expect(result).must_be_instance_of User + + end + end + end + + it "returns accurate information" do + VCR.use_cassette("list_users") do + results = User.list + p results + + info = [ + {slack_id: "USLACKBOT", name: "slackbot", real_name: "Slackbot"}, + {slack_id: "UMURTAYP5", name:"juliabouv", real_name:"Julia Bouvier"}, + {slack_id:"UN863PN23", name:"amalh.a97", real_name:"Amal"} + ] + + results.each_with_index do |result, index| + expect(result.slack_id).must_be_kind_of String + expect(result.slack_id).must_equal info[index][:slack_id] + + expect(result.name).must_be_kind_of String + expect(result.name).must_equal info[index][:name] + + expect(result.real_name).must_be_kind_of String + expect(result.real_name).must_equal info[index][:real_name] + end + end + end +end + + From cef385ac5885aeafd464335034059ac5b17a30f4 Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Tue, 10 Sep 2019 17:08:23 -0700 Subject: [PATCH 09/25] Updated requires --- test/test_helper.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 0887ede9..43181ae1 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,14 +2,21 @@ SimpleCov.start do add_filter 'test/' end +require "dotenv" +Dotenv.load require 'minitest' require 'minitest/autorun' require 'minitest/reporters' require 'minitest/skip_dsl' require 'vcr' -require "dotenv" -Dotenv.load +require 'webmock/minitest' +require 'httparty' + +require_relative '../lib/slack_api_error' +require_relative '../lib/recipient' +require_relative '../lib/channel' +require_relative '../lib/user' Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new @@ -18,8 +25,8 @@ config.hook_into :webmock # Don't leave our token lying around in a cassette file. - config.filter_sensitive_data("") do - ENV["SLACK_API_TOKEN"] + config.filter_sensitive_data("") do + ENV["SLACK_TOKEN"] end end From 7772e1abd61eb201130b03a61dbd314dac26b06e Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Tue, 10 Sep 2019 17:19:53 -0700 Subject: [PATCH 10/25] Implemented Channel tests for #initialize and #list_users --- test/channel_test.rb | 76 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 test/channel_test.rb diff --git a/test/channel_test.rb b/test/channel_test.rb new file mode 100644 index 00000000..2bab59a9 --- /dev/null +++ b/test/channel_test.rb @@ -0,0 +1,76 @@ +require_relative "test_helper" + +describe "Channel" do + describe "#initialize" do + before do + @channel = Channel.new(topic: "cool_things", member_count: 5, slack_id: "4321", name: "ThisIsAPlace") + end + it "creates instance of Channel" do + VCR.use_cassette("initialize_channel") do + expect(@channel).must_be_kind_of Channel + end + end + + it "responds to variable names" do + VCR.use_cassette("initialize_channel") do + [:topic, :member_count, :slack_id, :name].each do |variable| + expect(@channel).must_respond_to variable + end + end + end + + it "creates accurate attributes" do + VCR.use_cassette("initialize_channel") do + expect(@channel.topic).must_be_kind_of String + expect(@channel.topic).must_equal "cool_things" + + expect(@channel.member_count).must_be_kind_of Integer + expect(@channel.member_count).must_equal 5 + + expect(@channel.slack_id).must_be_kind_of String + expect(@channel.slack_id).must_equal "4321" + + expect(@channel.name).must_be_kind_of String + expect(@channel.name).must_equal "ThisIsAPlace" + end + end + end + + describe "list method" do + it "self.list returns an array of Channels" do + VCR.use_cassette("list_channels") do + results = Channel.list + expect(results).must_be_instance_of Array + results.each do |result| + expect(result).must_be_instance_of Channel + end + end + end + + it "returns accurate information" do + VCR.use_cassette("list_channels") do + results = Channel.list + + info = [ + {slack_id: "CN5RT17J8", name: "random", topic: "Non-work banter and water cooler conversation", member_count: 2}, + {slack_id: "CN862L6AK", name: "general", topic: "Company-wide announcements and work-based matters", member_count: 2}, + {slack_id: "CN862LB8F", name: "awesome-slack-cli-design-activity", topic: "Discussing the amazing things that are happening here.", member_count: 2}, + ] + + results.each_with_index do |result, index| + expect(result.slack_id).must_be_kind_of String + expect(result.slack_id).must_equal info[index][:slack_id] + + expect(result.name).must_be_kind_of String + expect(result.name).must_equal info[index][:name] + + expect(result.topic).must_be_kind_of String + expect(result.topic).must_equal info[index][:topic] + + expect(result.member_count).must_be_kind_of Integer + expect(result.member_count).must_equal info[index][:member_count] + end + end + end + end +end From b1cc13a11af2e9a9cd2e0c531a7def237259d4f2 Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Tue, 10 Sep 2019 17:21:28 -0700 Subject: [PATCH 11/25] Formatting updates --- lib/channel.rb | 2 -- lib/slack.rb | 4 ++++ lib/user.rb | 3 +-- test/user_test.rb | 1 - 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index a2653d7e..be7aa7ae 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,5 +1,3 @@ - - class Channel < Recipient attr_reader :topic, :member_count diff --git a/lib/slack.rb b/lib/slack.rb index c63283b8..b84b2c00 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -17,6 +17,8 @@ def main when "quit" exit when "list users", "users" + puts + puts "Listing Users..." workspace.users.each do |user| puts puts "Username: #{user.name}" @@ -27,6 +29,8 @@ def main puts "Do you want to list users, list channels, or quit?" search = gets.chomp.downcase when "list channels", "channels" + puts + "Listing Channels..." workspace.channels.each do |channel| puts puts "Channel name: #{channel.name}" diff --git a/lib/user.rb b/lib/user.rb index c5d277e2..f604b765 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,5 +1,3 @@ - - class User < Recipient attr_reader :real_name, :status_text, :status_emoji @@ -22,3 +20,4 @@ def self.list return members end end + diff --git a/test/user_test.rb b/test/user_test.rb index ddd2d6c8..a7ebf34d 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -49,7 +49,6 @@ it "returns accurate information" do VCR.use_cassette("list_users") do results = User.list - p results info = [ {slack_id: "USLACKBOT", name: "slackbot", real_name: "Slackbot"}, From ea8f69763b61934b728652ebec784499d0294dc6 Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Tue, 10 Sep 2019 17:21:28 -0700 Subject: [PATCH 12/25] Formatting updates --- lib/channel.rb | 2 -- lib/recipient.rb | 4 ++-- lib/slack.rb | 4 ++++ lib/user.rb | 3 +-- test/user_test.rb | 1 - 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index a2653d7e..be7aa7ae 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,5 +1,3 @@ - - class Channel < Recipient attr_reader :topic, :member_count diff --git a/lib/recipient.rb b/lib/recipient.rb index 8a9a0e45..a4bbb61f 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -24,11 +24,11 @@ def self.get(url, params) end def details - + raise NotImplementedError.new "Implement me in a child class!" end def self.list - raise NotImplementedError.new "Implement me in a child class" + raise NotImplementedError.new "Implement me in a child class!" end diff --git a/lib/slack.rb b/lib/slack.rb index c63283b8..b84b2c00 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -17,6 +17,8 @@ def main when "quit" exit when "list users", "users" + puts + puts "Listing Users..." workspace.users.each do |user| puts puts "Username: #{user.name}" @@ -27,6 +29,8 @@ def main puts "Do you want to list users, list channels, or quit?" search = gets.chomp.downcase when "list channels", "channels" + puts + "Listing Channels..." workspace.channels.each do |channel| puts puts "Channel name: #{channel.name}" diff --git a/lib/user.rb b/lib/user.rb index c5d277e2..f604b765 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,5 +1,3 @@ - - class User < Recipient attr_reader :real_name, :status_text, :status_emoji @@ -22,3 +20,4 @@ def self.list return members end end + diff --git a/test/user_test.rb b/test/user_test.rb index ddd2d6c8..a7ebf34d 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -49,7 +49,6 @@ it "returns accurate information" do VCR.use_cassette("list_users") do results = User.list - p results info = [ {slack_id: "USLACKBOT", name: "slackbot", real_name: "Slackbot"}, From 42d337262ca582ebb36e59a6b7f534cf1c7e57de Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Wed, 11 Sep 2019 13:53:15 -0700 Subject: [PATCH 13/25] Implemented Recipient tests --- test/recipient_test.rb | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 test/recipient_test.rb diff --git a/test/recipient_test.rb b/test/recipient_test.rb new file mode 100644 index 00000000..db3ed97a --- /dev/null +++ b/test/recipient_test.rb @@ -0,0 +1,65 @@ +require_relative "test_helper" + + +describe "Recipient" do + before do + @recipient = Recipient.new(slack_id: "thisisanid", name: "thisisaname") + end + describe "#initialize" do + it "creates instance of Recipient" do + VCR.use_cassette("initialize_recipient") do + expect(@recipient).must_be_kind_of Recipient + end + end + + it "responds to variable names" do + VCR.use_cassette("initialize_recipient") do + [:slack_id, :name].each do |variable| + expect(@recipient).must_respond_to variable + end + end + end + + it "creates accurate attributes" do + VCR.use_cassette("initialize_recipient") do + expect(@recipient.slack_id).must_be_kind_of String + expect(@recipient.slack_id).must_equal "thisisanid" + + expect(@recipient.name).must_be_kind_of String + expect(@recipient.name).must_equal "thisisaname" + + end + end + end + + describe "get" do + it "response is not nil" do + VCR.use_cassette("get_recipient_api") do + response = Recipient.get("https://slack.com/api/users.list", ENV["SLACK_TOKEN"]) + expect(response).wont_be_nil + end + end + + it "raises exception if there is an error in API response" do + VCR.use_cassette("get_recipient_api_error") do + expect { Recipient.get("https://slack.com/api/users.list", "bad_token") }.must_raise SlackApiError + end + end + end + + describe "#details" do + it "raises NotImplementedError" do + VCR.use_cassette("recipient_details_error") do + expect{ @recipient.details }.must_raise NotImplementedError + end + end + end + + describe "list" do + it "raises NotImplementedError" do + VCR.use_cassette("recipient_list_error") do + expect{ Recipient.list }.must_raise NotImplementedError + end + end + end +end From bd41da6260b1bc0b6e1cfaf0bd58aa4436ae7a04 Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Wed, 11 Sep 2019 14:33:16 -0700 Subject: [PATCH 14/25] Implemented Workspace tests --- test/test_helper.rb | 1 + test/workspace_test.rb | 43 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 test/workspace_test.rb diff --git a/test/test_helper.rb b/test/test_helper.rb index 43181ae1..7a9d058c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -17,6 +17,7 @@ require_relative '../lib/recipient' require_relative '../lib/channel' require_relative '../lib/user' +require_relative '../lib/workspace' Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new diff --git a/test/workspace_test.rb b/test/workspace_test.rb new file mode 100644 index 00000000..1a29e882 --- /dev/null +++ b/test/workspace_test.rb @@ -0,0 +1,43 @@ +require_relative "test_helper" +describe "Workspace" do + before do + VCR.use_cassette("construct_workspace") do + @workspace = Workspace.new + end + end + + describe "#initialize" do + it "creates instance of Workspace" do + expect(@workspace).must_be_kind_of Workspace + end + + it "responds to variable names" do + [:users, :channels, :selected].each do |variable| + expect(@workspace).must_respond_to variable + end + end + + it "creates accurate attributes" do + expect(@workspace.users).must_be_kind_of Array + @workspace.users.each do |user| + expect(user).must_be_instance_of User + end + + expect(@workspace.channels).must_be_kind_of Array + @workspace.channels.each do |channel| + expect(channel).must_be_instance_of Channel + end + + expect(@workspace.selected).must_be_nil + end + end + + xdescribe "#send_message" do + it "can send a valid message" do + response = @workspace.send_message("This is a message", "general") + + expect(response).wont_be_nil + expect(response).must_equal true + end + end +end From 16b192e32ee3fb22e22e77e1347ffbc641081c04 Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Wed, 11 Sep 2019 14:49:06 -0700 Subject: [PATCH 15/25] Implemented #details method --- lib/channel.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index be7aa7ae..e7f93247 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -7,8 +7,17 @@ def initialize(topic: , member_count: , slack_id: , name: ) @member_count = member_count end - # def details - # end + def details + details = """ + Channel Details: + Slack ID: #{@slack_id} + Name: #{@name} + Topic: #{@topic} + Member Count: #{@member_count} + """ + + return details + end def self.list response = self.get("https://slack.com/api/channels.list", ENV["SLACK_TOKEN"]) From 7c42a24ee982d0ba21afd90d8d4c4ac47fb163c4 Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Wed, 11 Sep 2019 14:53:38 -0700 Subject: [PATCH 16/25] Implemented #details method --- lib/user.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index f604b765..4eebe708 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -8,8 +8,18 @@ def initialize(real_name:, status_text: nil , status_emoji: nil, slack_id:, name @status_emoji = status_emoji end - # def details - # end + def details + details = """ + User Details: + Slack ID: #{@slack_id} + Username: #{@name} + Real Name: #{@real_name} + Status Text: #{@status_text} + Status Emoji: #{@status_emoji} + """ + + return details + end def self.list response = self.get("https://slack.com/api/users.list", ENV["SLACK_TOKEN"]) From 65a50fe31e29e297ea28b3e33426c92d46a55f25 Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Wed, 11 Sep 2019 15:02:06 -0700 Subject: [PATCH 17/25] Implemented #details tests --- test/user_test.rb | 80 ++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/test/user_test.rb b/test/user_test.rb index a7ebf34d..e8be1b13 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -1,10 +1,10 @@ require_relative "test_helper" describe "User" do + before do + @user = User.new(real_name: "Bob", slack_id: "1234", name: "Bobiscool") + end describe "initialize" do - before do - @user = User.new(real_name: "Bob", slack_id: "1234", name: "Bobiscool") - end it "creates instance of User" do VCR.use_cassette("initialize_user") do expect(@user).must_be_kind_of User @@ -32,42 +32,52 @@ end end end -end + + describe "#details" do + it "must return something" do + expect (@user.details).wont_be_nil + end -describe "list method" do - it "self.list returns an array of users" do - VCR.use_cassette("list_users") do - results = User.list - expect(results).must_be_instance_of Array - results.each do |result| - expect(result).must_be_instance_of User - + it "must return accurate info" do + expect (@user.details).must_include "Bob" + expect (@user.details).must_include "1234" + expect (@user.details).must_include "Bobiscool" + end + end + + describe "list method" do + it "self.list returns an array of users" do + VCR.use_cassette("list_users") do + results = User.list + expect(results).must_be_instance_of Array + results.each do |result| + expect(result).must_be_instance_of User + + end end end - end - - it "returns accurate information" do - VCR.use_cassette("list_users") do - results = User.list - - info = [ - {slack_id: "USLACKBOT", name: "slackbot", real_name: "Slackbot"}, - {slack_id: "UMURTAYP5", name:"juliabouv", real_name:"Julia Bouvier"}, - {slack_id:"UN863PN23", name:"amalh.a97", real_name:"Amal"} - ] - - results.each_with_index do |result, index| - expect(result.slack_id).must_be_kind_of String - expect(result.slack_id).must_equal info[index][:slack_id] + + it "returns accurate information" do + VCR.use_cassette("list_users") do + results = User.list - expect(result.name).must_be_kind_of String - expect(result.name).must_equal info[index][:name] + info = [ + {slack_id: "USLACKBOT", name: "slackbot", real_name: "Slackbot"}, + {slack_id: "UMURTAYP5", name:"juliabouv", real_name:"Julia Bouvier"}, + {slack_id:"UN863PN23", name:"amalh.a97", real_name:"Amal"} + ] - expect(result.real_name).must_be_kind_of String - expect(result.real_name).must_equal info[index][:real_name] + results.each_with_index do |result, index| + expect(result.slack_id).must_be_kind_of String + expect(result.slack_id).must_equal info[index][:slack_id] + + expect(result.name).must_be_kind_of String + expect(result.name).must_equal info[index][:name] + + expect(result.real_name).must_be_kind_of String + expect(result.real_name).must_equal info[index][:real_name] + end end end - end -end - - + end +end From 87bc46adc568b6493c36c87f9bafda57f96a3103 Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Wed, 11 Sep 2019 15:04:13 -0700 Subject: [PATCH 18/25] Implemented #details tests --- test/channel_test.rb | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/test/channel_test.rb b/test/channel_test.rb index 2bab59a9..2cf862a2 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -1,10 +1,10 @@ require_relative "test_helper" describe "Channel" do + before do + @channel = Channel.new(topic: "cool_things", member_count: 5, slack_id: "4321", name: "ThisIsAPlace") + end describe "#initialize" do - before do - @channel = Channel.new(topic: "cool_things", member_count: 5, slack_id: "4321", name: "ThisIsAPlace") - end it "creates instance of Channel" do VCR.use_cassette("initialize_channel") do expect(@channel).must_be_kind_of Channel @@ -36,6 +36,19 @@ end end + describe "#details" do + it "must return something" do + expect (@channel.details).wont_be_nil + end + + it "must return accurate info" do + expect (@channel.details).must_include "cool_things" + expect (@channel.details).must_include "5" + expect (@channel.details).must_include "4321" + expect (@channel.details).must_include "ThisIsAPlace" + end + end + describe "list method" do it "self.list returns an array of Channels" do VCR.use_cassette("list_channels") do @@ -66,7 +79,7 @@ expect(result.topic).must_be_kind_of String expect(result.topic).must_equal info[index][:topic] - + expect(result.member_count).must_be_kind_of Integer expect(result.member_count).must_equal info[index][:member_count] end From 36412bd5e122145a6430aa2df0ec635abb9d2223 Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Wed, 11 Sep 2019 21:57:54 -0700 Subject: [PATCH 19/25] Implemented #select_user and #select_channel methods --- lib/workspace.rb | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index 559936e3..75fa417d 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -19,16 +19,40 @@ def initialize @selected = nil end - def select_channel + def select_channel(input: nil) + channel_names = @channels.map { |channel| channel.name } + channel_ids = @channels.map { |channel| channel.slack_id } + + if channel_names.include?(input) + @selected = @channels.find { |c| input == c.name } + elsif channel_ids.include?(input) + @selected = @channels.find { |c| input == c.slack_id } + else + raise ArgumentError.new "Argument must include valid name or id" + end + return @selected end - def select_user + def select_user(input: nil) + usernames = @users.map { |user| user.name } + user_ids = @users.map { |user| user.slack_id } + if usernames.include?(input) + @selected = @users.find { |u| input == u.name } + elsif user_ids.include?(input) + @selected = @users.find { |u| input == u.slack_id } + else + raise ArgumentError.new "Argument must include name or id" + end + return @selected end def show_details + return @selected.details if @selected end - def send_message + def send_message(message, channel) + + # return response["ok"] end end From 76f7c949ebdb8e1f90e0544d1d2c4b2d3dd7434b Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Wed, 11 Sep 2019 21:59:09 -0700 Subject: [PATCH 20/25] Implemented #select_channel, #select_user and #show_details tests --- test/workspace_test.rb | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/test/workspace_test.rb b/test/workspace_test.rb index 1a29e882..1777b2aa 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -32,6 +32,59 @@ end end + describe "#select_channel" do + it "returns instance of Channel when name is provided" do + expect(@workspace.select_channel(input: "random")).must_be_instance_of Channel + end + + it "returns instance of Channel when id is provided" do + expect(@workspace.select_channel(input: "CN5RT17J8")).must_be_instance_of Channel + end + + it "raises exception if no name or id provided" do + expect{ @workspace.select_channel }.must_raise ArgumentError + end + end + + describe "#select_user" do + it "returns instance of User when name is provided" do + expect(@workspace.select_user(input: "slackbot")).must_be_instance_of User + end + + it "returns instance of User when id is provided" do + expect(@workspace.select_user(input: "USLACKBOT")).must_be_instance_of User + end + + it "raises exception if no name or id provided" do + expect{ @workspace.select_user }.must_raise ArgumentError + end + end + + describe "#show_details" do + it "returns details if @selected is user" do + @workspace.select_user(input: "slackbot") + + expect(@workspace.show_details).wont_be_nil + expect(@workspace.show_details).must_include "slackbot" + expect(@workspace.show_details).must_include "Slackbot" + expect(@workspace.show_details).must_include "USLACKBOT" + end + + it "returns details if @selected is channel" do + expect(@workspace.select_channel(input: "random")) + + expect(@workspace.show_details).wont_be_nil + expect(@workspace.show_details).must_include "random" + expect(@workspace.show_details).must_include "CN5RT17J8" + expect(@workspace.show_details).must_include "2" + expect(@workspace.show_details).must_include "Non-work banter and water cooler conversation" + end + + it "returns nil if nothing is @selected" do + expect(@workspace.show_details).must_be_nil + end + end + xdescribe "#send_message" do it "can send a valid message" do response = @workspace.send_message("This is a message", "general") From 6c789bca15f7b6b379fce64e022bd00b92ca88e6 Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Wed, 11 Sep 2019 21:59:09 -0700 Subject: [PATCH 21/25] Implemented #select_channel, #select_user and #show_details tests --- lib/workspace.rb | 6 ++--- test/workspace_test.rb | 53 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index 75fa417d..67457a42 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -22,7 +22,7 @@ def initialize def select_channel(input: nil) channel_names = @channels.map { |channel| channel.name } channel_ids = @channels.map { |channel| channel.slack_id } - + if channel_names.include?(input) @selected = @channels.find { |c| input == c.name } elsif channel_ids.include?(input) @@ -36,13 +36,13 @@ def select_channel(input: nil) def select_user(input: nil) usernames = @users.map { |user| user.name } user_ids = @users.map { |user| user.slack_id } - + if usernames.include?(input) @selected = @users.find { |u| input == u.name } elsif user_ids.include?(input) @selected = @users.find { |u| input == u.slack_id } else - raise ArgumentError.new "Argument must include name or id" + raise ArgumentError.new "Argument must include valid name or id" end return @selected end diff --git a/test/workspace_test.rb b/test/workspace_test.rb index 1a29e882..1777b2aa 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -32,6 +32,59 @@ end end + describe "#select_channel" do + it "returns instance of Channel when name is provided" do + expect(@workspace.select_channel(input: "random")).must_be_instance_of Channel + end + + it "returns instance of Channel when id is provided" do + expect(@workspace.select_channel(input: "CN5RT17J8")).must_be_instance_of Channel + end + + it "raises exception if no name or id provided" do + expect{ @workspace.select_channel }.must_raise ArgumentError + end + end + + describe "#select_user" do + it "returns instance of User when name is provided" do + expect(@workspace.select_user(input: "slackbot")).must_be_instance_of User + end + + it "returns instance of User when id is provided" do + expect(@workspace.select_user(input: "USLACKBOT")).must_be_instance_of User + end + + it "raises exception if no name or id provided" do + expect{ @workspace.select_user }.must_raise ArgumentError + end + end + + describe "#show_details" do + it "returns details if @selected is user" do + @workspace.select_user(input: "slackbot") + + expect(@workspace.show_details).wont_be_nil + expect(@workspace.show_details).must_include "slackbot" + expect(@workspace.show_details).must_include "Slackbot" + expect(@workspace.show_details).must_include "USLACKBOT" + end + + it "returns details if @selected is channel" do + expect(@workspace.select_channel(input: "random")) + + expect(@workspace.show_details).wont_be_nil + expect(@workspace.show_details).must_include "random" + expect(@workspace.show_details).must_include "CN5RT17J8" + expect(@workspace.show_details).must_include "2" + expect(@workspace.show_details).must_include "Non-work banter and water cooler conversation" + end + + it "returns nil if nothing is @selected" do + expect(@workspace.show_details).must_be_nil + end + end + xdescribe "#send_message" do it "can send a valid message" do response = @workspace.send_message("This is a message", "general") From ca540596d45a3b11aee8ea466cd79e51a38312d8 Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Wed, 11 Sep 2019 22:28:16 -0700 Subject: [PATCH 22/25] Implemented Wave 2 in slack.rb --- lib/slack.rb | 71 +++++++++++++++++++++++++++++++++++++++--- lib/workspace.rb | 4 +-- test/workspace_test.rb | 8 ++--- 3 files changed, 73 insertions(+), 10 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index b84b2c00..9ab77baa 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -3,19 +3,23 @@ def main workspace = Workspace.new + # variable to format command line entry + prompt = "> " puts "Welcome to the Ada Slack CLI!" puts "The number of channels is #{workspace.channels.length}." puts "The number of users is #{workspace.users.length}" - puts "Do you want to list users, list channels, or quit?" + puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + print prompt search = gets.chomp.downcase until search == "quit" case search when "quit" exit + when "list users", "users" puts puts "Listing Users..." @@ -26,11 +30,13 @@ def main puts "Slack ID: #{user.slack_id}" end puts - puts "Do you want to list users, list channels, or quit?" + puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + print prompt search = gets.chomp.downcase + when "list channels", "channels" puts - "Listing Channels..." + puts "Listing Channels..." workspace.channels.each do |channel| puts puts "Channel name: #{channel.name}" @@ -39,7 +45,64 @@ def main puts "Slack ID: #{channel.slack_id}" end puts - puts "Do you want to list users, list channels, or quit?" + puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + print prompt + search = gets.chomp.downcase + + when "select channel", "channel" + puts "Please enter a channel name or slack_id for the channel you would like to select:" + print prompt + input = gets.chomp + + if workspace.select_channel(input: input) + workspace.select_channel(input: input) + puts """ + #{input} is now selected + """ + else + puts "No channel has that name or ID" + end + + puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + print prompt + search = gets.chomp.downcase + + when "select user", "user" + puts "Please enter a username or slack_id for the user you would like to select:" + print prompt + input = gets.chomp + + if workspace.select_user(input: input) + workspace.select_user(input: input) + puts """ + #{input} is now selected + """ + else + puts "No user has that name or ID" + end + + puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + print prompt + search = gets.chomp.downcase + + when "details" + if workspace.show_details + puts "Here are the details for #{workspace.selected.name}:" + puts workspace.show_details + else + puts """ + No recipient is currently selected + """ + end + + puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + print prompt + search = gets.chomp.downcase + + else + puts "Invalid Command" + puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + print prompt search = gets.chomp.downcase end end diff --git a/lib/workspace.rb b/lib/workspace.rb index 67457a42..8966379f 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -28,7 +28,7 @@ def select_channel(input: nil) elsif channel_ids.include?(input) @selected = @channels.find { |c| input == c.slack_id } else - raise ArgumentError.new "Argument must include valid name or id" + return nil end return @selected end @@ -42,7 +42,7 @@ def select_user(input: nil) elsif user_ids.include?(input) @selected = @users.find { |u| input == u.slack_id } else - raise ArgumentError.new "Argument must include valid name or id" + return nil end return @selected end diff --git a/test/workspace_test.rb b/test/workspace_test.rb index 1777b2aa..60f03063 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -41,8 +41,8 @@ expect(@workspace.select_channel(input: "CN5RT17J8")).must_be_instance_of Channel end - it "raises exception if no name or id provided" do - expect{ @workspace.select_channel }.must_raise ArgumentError + it "returns nil if no valid name or id provided" do + expect(@workspace.select_channel).must_be_nil end end @@ -55,8 +55,8 @@ expect(@workspace.select_user(input: "USLACKBOT")).must_be_instance_of User end - it "raises exception if no name or id provided" do - expect{ @workspace.select_user }.must_raise ArgumentError + it "returns nil if no name or id provided" do + expect(@workspace.select_user).must_be_nil end end From aba9fd168892be0e1e37fa313a77213cdf20ca08 Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Fri, 13 Sep 2019 11:27:05 -0700 Subject: [PATCH 23/25] Implemented send_message method: --- lib/recipient.rb | 7 +--- lib/slack.rb | 68 ++++++++++++++++++++------------------ lib/user.rb | 4 +-- lib/workspace.rb | 17 ++++++++-- test/workspace_test.rb | 74 +++++++++++++++++++++++++++++++++--------- 5 files changed, 113 insertions(+), 57 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index a4bbb61f..7419ae44 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,14 +1,11 @@ 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 - # def send_message(message) - # end - def self.get(url, params) query = { token: params @@ -30,6 +27,4 @@ def details def self.list raise NotImplementedError.new "Implement me in a child class!" end - - end diff --git a/lib/slack.rb b/lib/slack.rb index 9ab77baa..449a4bc6 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -11,7 +11,7 @@ def main puts "The number of channels is #{workspace.channels.length}." puts "The number of users is #{workspace.users.length}" - puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + puts "Do you want to list users, list channels, select user, select channel, show details for selected, send message to selected or quit?" print prompt search = gets.chomp.downcase until search == "quit" @@ -30,7 +30,7 @@ def main puts "Slack ID: #{user.slack_id}" end puts - puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + puts "Do you want to list users, list channels, select user, select channel, show details for selected, send message to selected or quit?" print prompt search = gets.chomp.downcase @@ -45,7 +45,7 @@ def main puts "Slack ID: #{channel.slack_id}" end puts - puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + puts "Do you want to list users, list channels, select user, select channel, show details for selected, send message to selected or quit?" print prompt search = gets.chomp.downcase @@ -60,10 +60,12 @@ def main #{input} is now selected """ else - puts "No channel has that name or ID" + puts """ + No channel has that name or ID + """ end - puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + puts "Do you want to list users, list channels, select user, select channel, show details for selected, send message to selected or quit?" print prompt search = gets.chomp.downcase @@ -78,10 +80,12 @@ def main #{input} is now selected """ else - puts "No user has that name or ID" + puts """ + No user has that name or ID + """ end - puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + puts "Do you want to list users, list channels, select user, select channel, show details for selected, send message to selected or quit?" print prompt search = gets.chomp.downcase @@ -95,16 +99,37 @@ def main """ end - puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + puts "Do you want to list users, list channels, select user, select channel, show details for selected, send message to selected or quit?" + print prompt + search = gets.chomp.downcase + + when "send message", "message" + unless workspace.selected.nil? + puts "What message would you like to send to #{workspace.selected.name}?" + message = gets.chomp + + workspace.send_message(message, workspace.selected.slack_id) + + puts """ + Message posted! + """ + else + puts """ + No recipient selected! + """ + end + + puts "Do you want to list users, list channels, select user, select channel, show details for selected, send message to selected or quit?" print prompt search = gets.chomp.downcase - else - puts "Invalid Command" - puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + puts """ + Invalid Command + """ + puts "Do you want to list users, list channels, select user, select channel, show details for selected, send message to selected or quit?" print prompt search = gets.chomp.downcase - end + end end puts "Thank you for using the Ada Slack CLI" @@ -112,22 +137,3 @@ def main main if __FILE__ == $PROGRAM_NAME - - - -# url = "https://slack.com/api/channels.list" -# key = ENV["SLACK_TOKEN"] - -# query = { -# token: key -# } - -# response = HTTParty.get(url, query: query) - -# if response["error"] -# raise StandardError.new "#{response.code}: #{response.message} -- #{response["error"]}" -# end - -# response["channels"].each_with_index do |channel, index| -# puts "#{index + 1}. #{channel["name"]}" -# end diff --git a/lib/user.rb b/lib/user.rb index 4eebe708..5206d055 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,7 +1,7 @@ class User < Recipient attr_reader :real_name, :status_text, :status_emoji - def initialize(real_name:, status_text: nil , status_emoji: nil, slack_id:, name:) + def initialize(real_name:, slack_id:, name:) super(slack_id: slack_id, name: name) @real_name = real_name @status_text = status_text @@ -14,8 +14,6 @@ def details Slack ID: #{@slack_id} Username: #{@name} Real Name: #{@real_name} - Status Text: #{@status_text} - Status Emoji: #{@status_emoji} """ return details diff --git a/lib/workspace.rb b/lib/workspace.rb index 8966379f..f04e2408 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -52,7 +52,20 @@ def show_details end def send_message(message, channel) - - # return response["ok"] + response = HTTParty.post( + "https://slack.com/api/chat.postMessage", + body: { + token: ENV["SLACK_TOKEN"], + channel: channel, + text: message + }, + headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } + ) + + if response["error"] + raise SlackApiError.new "#{response.code}: #{response.message} -- #{response["error"]}" + end + + return response end end diff --git a/test/workspace_test.rb b/test/workspace_test.rb index 60f03063..ebe33d64 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -36,11 +36,22 @@ it "returns instance of Channel when name is provided" do expect(@workspace.select_channel(input: "random")).must_be_instance_of Channel end - + it "returns instance of Channel when id is provided" do expect(@workspace.select_channel(input: "CN5RT17J8")).must_be_instance_of Channel end - + + it "assigns instance of User to @selected" do + expect(@workspace.selected).must_be_nil + @workspace.select_channel(input: "random") + + expect(@workspace.selected).must_be_instance_of Channel + expect(@workspace.selected.name).must_equal "random" + expect(@workspace.selected.topic).must_equal "Non-work banter and water cooler conversation" + expect(@workspace.selected.member_count).must_equal 2 + expect(@workspace.selected.slack_id).must_equal "CN5RT17J8" + end + it "returns nil if no valid name or id provided" do expect(@workspace.select_channel).must_be_nil end @@ -50,47 +61,80 @@ it "returns instance of User when name is provided" do expect(@workspace.select_user(input: "slackbot")).must_be_instance_of User end - + it "returns instance of User when id is provided" do expect(@workspace.select_user(input: "USLACKBOT")).must_be_instance_of User end - + + it "returns instance of User when name is provided" do + expect(@workspace.selected).must_be_nil + @workspace.select_user(input: "slackbot") + + expect(@workspace.selected).must_be_instance_of User + expect(@workspace.selected.name).must_equal "slackbot" + expect(@workspace.selected.real_name).must_equal "Slackbot" + expect(@workspace.selected.slack_id).must_equal "USLACKBOT" + end + it "returns nil if no name or id provided" do expect(@workspace.select_user).must_be_nil end end - + describe "#show_details" do it "returns details if @selected is user" do @workspace.select_user(input: "slackbot") - + + expect(@workspace.show_details).wont_be_nil + expect(@workspace.show_details).must_include "slackbot" + expect(@workspace.show_details).must_include "Slackbot" + expect(@workspace.show_details).must_include "USLACKBOT" + + @workspace.select_user(input: "USLACKBOT") + expect(@workspace.show_details).wont_be_nil expect(@workspace.show_details).must_include "slackbot" expect(@workspace.show_details).must_include "Slackbot" expect(@workspace.show_details).must_include "USLACKBOT" end - + it "returns details if @selected is channel" do - expect(@workspace.select_channel(input: "random")) - + @workspace.select_channel(input: "random") + + expect(@workspace.show_details).wont_be_nil + expect(@workspace.show_details).must_include "random" + expect(@workspace.show_details).must_include "CN5RT17J8" + expect(@workspace.show_details).must_include "2" + expect(@workspace.show_details).must_include "Non-work banter and water cooler conversation" + + @workspace.select_channel(input: "CN5RT17J8") + expect(@workspace.show_details).wont_be_nil expect(@workspace.show_details).must_include "random" expect(@workspace.show_details).must_include "CN5RT17J8" expect(@workspace.show_details).must_include "2" expect(@workspace.show_details).must_include "Non-work banter and water cooler conversation" end - + it "returns nil if nothing is @selected" do expect(@workspace.show_details).must_be_nil end end - xdescribe "#send_message" do + describe "#send_message" do it "can send a valid message" do - response = @workspace.send_message("This is a message", "general") - - expect(response).wont_be_nil - expect(response).must_equal true + VCR.use_cassette("send_slack_message") do + response = @workspace.send_message("This is a message", "general") + + expect(response).wont_be_nil + expect(response["ok"]).must_equal true + end + end + + it "raises exception if there is an error in API response" do + VCR.use_cassette("send_slack_message_error") do + expect { response = @workspace.send_message("", "general") }.must_raise SlackApiError + end end end end From 6087d61c7930fedf8108f21ffeb5869b074da1ae Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Fri, 13 Sep 2019 11:27:05 -0700 Subject: [PATCH 24/25] Implemented send_message method: --- lib/recipient.rb | 7 +--- lib/slack.rb | 69 +++++++++++++++++++++------------------ lib/user.rb | 4 +-- lib/workspace.rb | 17 ++++++++-- test/workspace_test.rb | 74 +++++++++++++++++++++++++++++++++--------- 5 files changed, 113 insertions(+), 58 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index a4bbb61f..7419ae44 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,14 +1,11 @@ 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 - # def send_message(message) - # end - def self.get(url, params) query = { token: params @@ -30,6 +27,4 @@ def details def self.list raise NotImplementedError.new "Implement me in a child class!" end - - end diff --git a/lib/slack.rb b/lib/slack.rb index 9ab77baa..090c7670 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -6,12 +6,11 @@ def main # variable to format command line entry prompt = "> " - puts "Welcome to the Ada Slack CLI!" puts "The number of channels is #{workspace.channels.length}." puts "The number of users is #{workspace.users.length}" - puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + puts "Do you want to list users, list channels, select user, select channel, show details for selected, send message to selected or quit?" print prompt search = gets.chomp.downcase until search == "quit" @@ -30,7 +29,7 @@ def main puts "Slack ID: #{user.slack_id}" end puts - puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + puts "Do you want to list users, list channels, select user, select channel, show details for selected, send message to selected or quit?" print prompt search = gets.chomp.downcase @@ -45,7 +44,7 @@ def main puts "Slack ID: #{channel.slack_id}" end puts - puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + puts "Do you want to list users, list channels, select user, select channel, show details for selected, send message to selected or quit?" print prompt search = gets.chomp.downcase @@ -60,10 +59,12 @@ def main #{input} is now selected """ else - puts "No channel has that name or ID" + puts """ + No channel has that name or ID + """ end - puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + puts "Do you want to list users, list channels, select user, select channel, show details for selected, send message to selected or quit?" print prompt search = gets.chomp.downcase @@ -78,10 +79,12 @@ def main #{input} is now selected """ else - puts "No user has that name or ID" + puts """ + No user has that name or ID + """ end - puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + puts "Do you want to list users, list channels, select user, select channel, show details for selected, send message to selected or quit?" print prompt search = gets.chomp.downcase @@ -95,16 +98,37 @@ def main """ end - puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + puts "Do you want to list users, list channels, select user, select channel, show details for selected, send message to selected or quit?" + print prompt + search = gets.chomp.downcase + + when "send message", "message" + unless workspace.selected.nil? + puts "What message would you like to send to #{workspace.selected.name}?" + message = gets.chomp + + workspace.send_message(message, workspace.selected.slack_id) + + puts """ + Message posted! + """ + else + puts """ + No recipient selected! + """ + end + + puts "Do you want to list users, list channels, select user, select channel, show details for selected, send message to selected or quit?" print prompt search = gets.chomp.downcase - else - puts "Invalid Command" - puts "Do you want to list users, list channels, select user, select channel, show details for selected or quit?" + puts """ + Invalid Command + """ + puts "Do you want to list users, list channels, select user, select channel, show details for selected, send message to selected or quit?" print prompt search = gets.chomp.downcase - end + end end puts "Thank you for using the Ada Slack CLI" @@ -112,22 +136,3 @@ def main main if __FILE__ == $PROGRAM_NAME - - - -# url = "https://slack.com/api/channels.list" -# key = ENV["SLACK_TOKEN"] - -# query = { -# token: key -# } - -# response = HTTParty.get(url, query: query) - -# if response["error"] -# raise StandardError.new "#{response.code}: #{response.message} -- #{response["error"]}" -# end - -# response["channels"].each_with_index do |channel, index| -# puts "#{index + 1}. #{channel["name"]}" -# end diff --git a/lib/user.rb b/lib/user.rb index 4eebe708..5206d055 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,7 +1,7 @@ class User < Recipient attr_reader :real_name, :status_text, :status_emoji - def initialize(real_name:, status_text: nil , status_emoji: nil, slack_id:, name:) + def initialize(real_name:, slack_id:, name:) super(slack_id: slack_id, name: name) @real_name = real_name @status_text = status_text @@ -14,8 +14,6 @@ def details Slack ID: #{@slack_id} Username: #{@name} Real Name: #{@real_name} - Status Text: #{@status_text} - Status Emoji: #{@status_emoji} """ return details diff --git a/lib/workspace.rb b/lib/workspace.rb index 8966379f..f04e2408 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -52,7 +52,20 @@ def show_details end def send_message(message, channel) - - # return response["ok"] + response = HTTParty.post( + "https://slack.com/api/chat.postMessage", + body: { + token: ENV["SLACK_TOKEN"], + channel: channel, + text: message + }, + headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } + ) + + if response["error"] + raise SlackApiError.new "#{response.code}: #{response.message} -- #{response["error"]}" + end + + return response end end diff --git a/test/workspace_test.rb b/test/workspace_test.rb index 60f03063..ebe33d64 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -36,11 +36,22 @@ it "returns instance of Channel when name is provided" do expect(@workspace.select_channel(input: "random")).must_be_instance_of Channel end - + it "returns instance of Channel when id is provided" do expect(@workspace.select_channel(input: "CN5RT17J8")).must_be_instance_of Channel end - + + it "assigns instance of User to @selected" do + expect(@workspace.selected).must_be_nil + @workspace.select_channel(input: "random") + + expect(@workspace.selected).must_be_instance_of Channel + expect(@workspace.selected.name).must_equal "random" + expect(@workspace.selected.topic).must_equal "Non-work banter and water cooler conversation" + expect(@workspace.selected.member_count).must_equal 2 + expect(@workspace.selected.slack_id).must_equal "CN5RT17J8" + end + it "returns nil if no valid name or id provided" do expect(@workspace.select_channel).must_be_nil end @@ -50,47 +61,80 @@ it "returns instance of User when name is provided" do expect(@workspace.select_user(input: "slackbot")).must_be_instance_of User end - + it "returns instance of User when id is provided" do expect(@workspace.select_user(input: "USLACKBOT")).must_be_instance_of User end - + + it "returns instance of User when name is provided" do + expect(@workspace.selected).must_be_nil + @workspace.select_user(input: "slackbot") + + expect(@workspace.selected).must_be_instance_of User + expect(@workspace.selected.name).must_equal "slackbot" + expect(@workspace.selected.real_name).must_equal "Slackbot" + expect(@workspace.selected.slack_id).must_equal "USLACKBOT" + end + it "returns nil if no name or id provided" do expect(@workspace.select_user).must_be_nil end end - + describe "#show_details" do it "returns details if @selected is user" do @workspace.select_user(input: "slackbot") - + + expect(@workspace.show_details).wont_be_nil + expect(@workspace.show_details).must_include "slackbot" + expect(@workspace.show_details).must_include "Slackbot" + expect(@workspace.show_details).must_include "USLACKBOT" + + @workspace.select_user(input: "USLACKBOT") + expect(@workspace.show_details).wont_be_nil expect(@workspace.show_details).must_include "slackbot" expect(@workspace.show_details).must_include "Slackbot" expect(@workspace.show_details).must_include "USLACKBOT" end - + it "returns details if @selected is channel" do - expect(@workspace.select_channel(input: "random")) - + @workspace.select_channel(input: "random") + + expect(@workspace.show_details).wont_be_nil + expect(@workspace.show_details).must_include "random" + expect(@workspace.show_details).must_include "CN5RT17J8" + expect(@workspace.show_details).must_include "2" + expect(@workspace.show_details).must_include "Non-work banter and water cooler conversation" + + @workspace.select_channel(input: "CN5RT17J8") + expect(@workspace.show_details).wont_be_nil expect(@workspace.show_details).must_include "random" expect(@workspace.show_details).must_include "CN5RT17J8" expect(@workspace.show_details).must_include "2" expect(@workspace.show_details).must_include "Non-work banter and water cooler conversation" end - + it "returns nil if nothing is @selected" do expect(@workspace.show_details).must_be_nil end end - xdescribe "#send_message" do + describe "#send_message" do it "can send a valid message" do - response = @workspace.send_message("This is a message", "general") - - expect(response).wont_be_nil - expect(response).must_equal true + VCR.use_cassette("send_slack_message") do + response = @workspace.send_message("This is a message", "general") + + expect(response).wont_be_nil + expect(response["ok"]).must_equal true + end + end + + it "raises exception if there is an error in API response" do + VCR.use_cassette("send_slack_message_error") do + expect { response = @workspace.send_message("", "general") }.must_raise SlackApiError + end end end end From b17dd36deae3313bf10137a7869dc25c892c9589 Mon Sep 17 00:00:00 2001 From: Julia Bouvier Date: Fri, 13 Sep 2019 14:23:59 -0700 Subject: [PATCH 25/25] Formatting and cassettes --- lib/workspace.rb | 1 - test/cassettes/construct_workspace.yml | 156 ++++++++++++++++++++ test/cassettes/get_recipient_api.yml | 78 ++++++++++ test/cassettes/get_recipient_api_error.yml | 64 ++++++++ test/cassettes/list_channels.yml | 81 ++++++++++ test/cassettes/list_users.yml | 78 ++++++++++ test/cassettes/send_slack_message.yml | 72 +++++++++ test/cassettes/send_slack_message_error.yml | 70 +++++++++ test/workspace_test.rb | 2 +- 9 files changed, 600 insertions(+), 2 deletions(-) create mode 100644 test/cassettes/construct_workspace.yml create mode 100644 test/cassettes/get_recipient_api.yml create mode 100644 test/cassettes/get_recipient_api_error.yml create mode 100644 test/cassettes/list_channels.yml create mode 100644 test/cassettes/list_users.yml create mode 100644 test/cassettes/send_slack_message.yml create mode 100644 test/cassettes/send_slack_message_error.yml diff --git a/lib/workspace.rb b/lib/workspace.rb index f04e2408..b465da66 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,7 +1,6 @@ require 'httparty' require 'awesome_print' require 'pry' -require 'table_print' require 'dotenv' Dotenv.load diff --git a/test/cassettes/construct_workspace.yml b/test/cassettes/construct_workspace.yml new file mode 100644 index 00000000..1fb54e6b --- /dev/null +++ b/test/cassettes/construct_workspace.yml @@ -0,0 +1,156 @@ +--- +http_interactions: +- request: + method: get + uri: https://slack.com/api/users.list?token= + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '932' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 21:21:44 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - b1c516f3-eb2e-492e-b35b-55a991e0a73c + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - users:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-2wz3 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 61e75bd33e6585cb966e70a5677b630b.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - BOS50-C1 + X-Amz-Cf-Id: + - gVBYCyM8oNWBXtCd-4-I4SCLXl0I5FlSycaBsCdu0o_hgWFLmgYv0A== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TMURTAYBV","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":null,"tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Slackbot","real_name_normalized":"Slackbot","display_name":"Slackbot","display_name_normalized":"Slackbot","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"sv41d8cd98f0","always_active":true,"first_name":"slackbot","last_name":"","image_24":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/80588\/marketing\/img\/avatars\/slackbot\/avatar-slackbot.png","image_512":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_512.png","status_text_canonical":"","team":"TMURTAYBV"},"is_admin":false,"is_owner":false,"is_primary_owner":false,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":0},{"id":"UMURTAYP5","team_id":"TMURTAYBV","name":"juliabouv","deleted":false,"color":"9f69e7","real_name":"Julia + Bouvier","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Julia + Bouvier","real_name_normalized":"Julia Bouvier","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gd5cb54a2a82","first_name":"Julia","last_name":"Bouvier","image_24":"https:\/\/secure.gravatar.com\/avatar\/d5cb54a2a827985e630c7b1a77aec5bd.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0025-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/d5cb54a2a827985e630c7b1a77aec5bd.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0025-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/d5cb54a2a827985e630c7b1a77aec5bd.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0025-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/d5cb54a2a827985e630c7b1a77aec5bd.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0025-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/d5cb54a2a827985e630c7b1a77aec5bd.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0025-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/d5cb54a2a827985e630c7b1a77aec5bd.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0025-512.png","status_text_canonical":"","team":"TMURTAYBV"},"is_admin":true,"is_owner":true,"is_primary_owner":true,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":1568073742,"has_2fa":false},{"id":"UN863PN23","team_id":"TMURTAYBV","name":"amalh.a97","deleted":false,"color":"4bbe2e","real_name":"Amal","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Amal","real_name_normalized":"Amal","display_name":"Amal","display_name_normalized":"Amal","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g1bf8487fb4a","image_24":"https:\/\/secure.gravatar.com\/avatar\/1bf8487fb4a2755ba217af6ed776cbce.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/1bf8487fb4a2755ba217af6ed776cbce.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/1bf8487fb4a2755ba217af6ed776cbce.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/1bf8487fb4a2755ba217af6ed776cbce.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/1bf8487fb4a2755ba217af6ed776cbce.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/1bf8487fb4a2755ba217af6ed776cbce.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-512.png","status_text_canonical":"","team":"TMURTAYBV"},"is_admin":false,"is_owner":false,"is_primary_owner":false,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":1568073520,"has_2fa":false}],"cache_ts":1568409704,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Fri, 13 Sep 2019 21:21:44 GMT +- request: + method: get + uri: https://slack.com/api/channels.list?token= + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '592' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 21:21:44 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 4574c2b0-9e17-41b9-8471-43ef67541dcd + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - channels:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-ntno + X-Cache: + - Miss from cloudfront + Via: + - 1.1 bae03a76f4f3eb92893beec8dc1a7f7d.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - BOS50-C1 + X-Amz-Cf-Id: + - wZNMOOqmR2WjbeddhBlprimOoqMLjQ7cUN3R6TrzX-iSh-NqPG9QWA== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CN5RT17J8","name":"random","is_channel":true,"created":1568073362,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMURTAYP5","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMURTAYP5","UN863PN23"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UMURTAYP5","last_set":1568073362},"purpose":{"value":"A + place for non-work-related flimflam, faffing, hodge-podge or jibber-jabber + you''d prefer to keep out of more focused work-related channels.","creator":"UMURTAYP5","last_set":1568073362},"previous_names":[],"num_members":2},{"id":"CN862L6AK","name":"general","is_channel":true,"created":1568073362,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UMURTAYP5","name_normalized":"general","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMURTAYP5","UN863PN23"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UMURTAYP5","last_set":1568073362},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UMURTAYP5","last_set":1568073362},"previous_names":[],"num_members":2},{"id":"CN862LB8F","name":"awesome-slack-cli-design-activity","is_channel":true,"created":1568073362,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMURTAYP5","name_normalized":"awesome-slack-cli-design-activity","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMURTAYP5","UN863PN23"],"topic":{"value":"Discussing + the amazing things that are happening here.","creator":"UMURTAYP5","last_set":1568094901},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Fri, 13 Sep 2019 21:21:45 GMT +recorded_with: VCR 5.0.0 diff --git a/test/cassettes/get_recipient_api.yml b/test/cassettes/get_recipient_api.yml new file mode 100644 index 00000000..6981e6b3 --- /dev/null +++ b/test/cassettes/get_recipient_api.yml @@ -0,0 +1,78 @@ +--- +http_interactions: +- request: + method: get + uri: https://slack.com/api/users.list?token= + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '932' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 21:21:46 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 4a1be412-3f1e-4f5b-9f70-cc66d0a1c4a9 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - users:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-lcub + X-Cache: + - Miss from cloudfront + Via: + - 1.1 61e75bd33e6585cb966e70a5677b630b.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - BOS50-C1 + X-Amz-Cf-Id: + - kJ3A1T2YNhGSsxVUvApMUYPBlCSAYqDLDR7XwBVWHYEf8SXOf1Xarw== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TMURTAYBV","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":null,"tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Slackbot","real_name_normalized":"Slackbot","display_name":"Slackbot","display_name_normalized":"Slackbot","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"sv41d8cd98f0","always_active":true,"first_name":"slackbot","last_name":"","image_24":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/80588\/marketing\/img\/avatars\/slackbot\/avatar-slackbot.png","image_512":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_512.png","status_text_canonical":"","team":"TMURTAYBV"},"is_admin":false,"is_owner":false,"is_primary_owner":false,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":0},{"id":"UMURTAYP5","team_id":"TMURTAYBV","name":"juliabouv","deleted":false,"color":"9f69e7","real_name":"Julia + Bouvier","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Julia + Bouvier","real_name_normalized":"Julia Bouvier","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gd5cb54a2a82","first_name":"Julia","last_name":"Bouvier","image_24":"https:\/\/secure.gravatar.com\/avatar\/d5cb54a2a827985e630c7b1a77aec5bd.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0025-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/d5cb54a2a827985e630c7b1a77aec5bd.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0025-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/d5cb54a2a827985e630c7b1a77aec5bd.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0025-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/d5cb54a2a827985e630c7b1a77aec5bd.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0025-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/d5cb54a2a827985e630c7b1a77aec5bd.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0025-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/d5cb54a2a827985e630c7b1a77aec5bd.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0025-512.png","status_text_canonical":"","team":"TMURTAYBV"},"is_admin":true,"is_owner":true,"is_primary_owner":true,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":1568073742,"has_2fa":false},{"id":"UN863PN23","team_id":"TMURTAYBV","name":"amalh.a97","deleted":false,"color":"4bbe2e","real_name":"Amal","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Amal","real_name_normalized":"Amal","display_name":"Amal","display_name_normalized":"Amal","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g1bf8487fb4a","image_24":"https:\/\/secure.gravatar.com\/avatar\/1bf8487fb4a2755ba217af6ed776cbce.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/1bf8487fb4a2755ba217af6ed776cbce.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/1bf8487fb4a2755ba217af6ed776cbce.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/1bf8487fb4a2755ba217af6ed776cbce.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/1bf8487fb4a2755ba217af6ed776cbce.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/1bf8487fb4a2755ba217af6ed776cbce.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-512.png","status_text_canonical":"","team":"TMURTAYBV"},"is_admin":false,"is_owner":false,"is_primary_owner":false,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":1568073520,"has_2fa":false}],"cache_ts":1568409706,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Fri, 13 Sep 2019 21:21:46 GMT +recorded_with: VCR 5.0.0 diff --git a/test/cassettes/get_recipient_api_error.yml b/test/cassettes/get_recipient_api_error.yml new file mode 100644 index 00000000..be7080a1 --- /dev/null +++ b/test/cassettes/get_recipient_api_error.yml @@ -0,0 +1,64 @@ +--- +http_interactions: +- request: + method: get + uri: https://slack.com/api/users.list?token=bad_token + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '55' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 21:21:46 GMT + Server: + - Apache + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - ae030d6e-e3a5-4555-9c2a-a6693b50364c + X-Xss-Protection: + - '0' + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-x0xq + X-Cache: + - Miss from cloudfront + Via: + - 1.1 bae03a76f4f3eb92893beec8dc1a7f7d.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - BOS50-C1 + X-Amz-Cf-Id: + - 2bfTSy4EErfby2rMZlCWwO-LaeK8GYHbJy7z9hV-F-fEsmbfyI1IYg== + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"invalid_auth"}' + http_version: + recorded_at: Fri, 13 Sep 2019 21:21:46 GMT +recorded_with: VCR 5.0.0 diff --git a/test/cassettes/list_channels.yml b/test/cassettes/list_channels.yml new file mode 100644 index 00000000..50921cea --- /dev/null +++ b/test/cassettes/list_channels.yml @@ -0,0 +1,81 @@ +--- +http_interactions: +- request: + method: get + uri: https://slack.com/api/channels.list?token= + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '592' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 21:21:47 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 8a2a8a28-889c-4c6f-a2f5-a1a9daf3d5e8 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - channels:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-neww + X-Cache: + - Miss from cloudfront + Via: + - 1.1 91ba452fa0dd14b0102b6441c9a2d2d4.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - BOS50-C1 + X-Amz-Cf-Id: + - zDLtGX8YJXfKMEWkMAWcYzJ0xi_azXHr3UWgx5hhjFOV7kc0W53zHg== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CN5RT17J8","name":"random","is_channel":true,"created":1568073362,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMURTAYP5","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMURTAYP5","UN863PN23"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UMURTAYP5","last_set":1568073362},"purpose":{"value":"A + place for non-work-related flimflam, faffing, hodge-podge or jibber-jabber + you''d prefer to keep out of more focused work-related channels.","creator":"UMURTAYP5","last_set":1568073362},"previous_names":[],"num_members":2},{"id":"CN862L6AK","name":"general","is_channel":true,"created":1568073362,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UMURTAYP5","name_normalized":"general","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMURTAYP5","UN863PN23"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UMURTAYP5","last_set":1568073362},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UMURTAYP5","last_set":1568073362},"previous_names":[],"num_members":2},{"id":"CN862LB8F","name":"awesome-slack-cli-design-activity","is_channel":true,"created":1568073362,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMURTAYP5","name_normalized":"awesome-slack-cli-design-activity","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMURTAYP5","UN863PN23"],"topic":{"value":"Discussing + the amazing things that are happening here.","creator":"UMURTAYP5","last_set":1568094901},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Fri, 13 Sep 2019 21:21:47 GMT +recorded_with: VCR 5.0.0 diff --git a/test/cassettes/list_users.yml b/test/cassettes/list_users.yml new file mode 100644 index 00000000..9a9ca03f --- /dev/null +++ b/test/cassettes/list_users.yml @@ -0,0 +1,78 @@ +--- +http_interactions: +- request: + method: get + uri: https://slack.com/api/users.list?token= + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '932' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 21:21:45 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - '0785ff3e-c56f-4f9c-ac9a-8306bf035b4c' + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - users:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-tucf + X-Cache: + - Miss from cloudfront + Via: + - 1.1 2efa65d04af0269ba633652ff413a9f3.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - BOS50-C1 + X-Amz-Cf-Id: + - Cpse8ZoelujVTMVUXoiDAGiLJQuMrEnTeJwBSRjNhdiDqGb1ALg65g== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TMURTAYBV","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":null,"tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Slackbot","real_name_normalized":"Slackbot","display_name":"Slackbot","display_name_normalized":"Slackbot","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"sv41d8cd98f0","always_active":true,"first_name":"slackbot","last_name":"","image_24":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/80588\/marketing\/img\/avatars\/slackbot\/avatar-slackbot.png","image_512":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_512.png","status_text_canonical":"","team":"TMURTAYBV"},"is_admin":false,"is_owner":false,"is_primary_owner":false,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":0},{"id":"UMURTAYP5","team_id":"TMURTAYBV","name":"juliabouv","deleted":false,"color":"9f69e7","real_name":"Julia + Bouvier","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Julia + Bouvier","real_name_normalized":"Julia Bouvier","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gd5cb54a2a82","first_name":"Julia","last_name":"Bouvier","image_24":"https:\/\/secure.gravatar.com\/avatar\/d5cb54a2a827985e630c7b1a77aec5bd.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0025-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/d5cb54a2a827985e630c7b1a77aec5bd.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0025-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/d5cb54a2a827985e630c7b1a77aec5bd.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0025-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/d5cb54a2a827985e630c7b1a77aec5bd.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0025-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/d5cb54a2a827985e630c7b1a77aec5bd.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0025-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/d5cb54a2a827985e630c7b1a77aec5bd.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0025-512.png","status_text_canonical":"","team":"TMURTAYBV"},"is_admin":true,"is_owner":true,"is_primary_owner":true,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":1568073742,"has_2fa":false},{"id":"UN863PN23","team_id":"TMURTAYBV","name":"amalh.a97","deleted":false,"color":"4bbe2e","real_name":"Amal","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Amal","real_name_normalized":"Amal","display_name":"Amal","display_name_normalized":"Amal","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g1bf8487fb4a","image_24":"https:\/\/secure.gravatar.com\/avatar\/1bf8487fb4a2755ba217af6ed776cbce.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/1bf8487fb4a2755ba217af6ed776cbce.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/1bf8487fb4a2755ba217af6ed776cbce.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/1bf8487fb4a2755ba217af6ed776cbce.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/1bf8487fb4a2755ba217af6ed776cbce.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/1bf8487fb4a2755ba217af6ed776cbce.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-512.png","status_text_canonical":"","team":"TMURTAYBV"},"is_admin":false,"is_owner":false,"is_primary_owner":false,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":1568073520,"has_2fa":false}],"cache_ts":1568409705,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Fri, 13 Sep 2019 21:21:45 GMT +recorded_with: VCR 5.0.0 diff --git a/test/cassettes/send_slack_message.yml b/test/cassettes/send_slack_message.yml new file mode 100644 index 00000000..64a67936 --- /dev/null +++ b/test/cassettes/send_slack_message.yml @@ -0,0 +1,72 @@ +--- +http_interactions: +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=general&text=This%20is%20a%20message + headers: + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 21:23:18 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 31b4a7ec-cf38-4ae7-ad98-c2ffa27947b4 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:bot + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-z6bk + X-Cache: + - Miss from cloudfront + Via: + - 1.1 08905871043ac5aeb0ec57f59d339cc4.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - BOS50-C1 + X-Amz-Cf-Id: + - YAANzacO1Sg5OE3ZAyH_R4gfwJ3SxJNkqaiVpEWMomdMf4-iSFewNw== + body: + encoding: UTF-8 + string: '{"ok":true,"channel":"CN862L6AK","ts":"1568409798.000200","message":{"type":"message","subtype":"bot_message","text":"This + is a message","ts":"1568409798.000200","username":"Branches - Julia B. - API + Project","bot_id":"BN7EKDCGY"}}' + http_version: + recorded_at: Fri, 13 Sep 2019 21:23:18 GMT +recorded_with: VCR 5.0.0 diff --git a/test/cassettes/send_slack_message_error.yml b/test/cassettes/send_slack_message_error.yml new file mode 100644 index 00000000..61d25a4a --- /dev/null +++ b/test/cassettes/send_slack_message_error.yml @@ -0,0 +1,70 @@ +--- +http_interactions: +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=general&text= + headers: + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 21:23:19 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 2d2f86a8-2fe8-493b-a451-230e296251cd + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:bot + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-fdpw + X-Cache: + - Miss from cloudfront + Via: + - 1.1 5e247ae48d5501e7c1be84d6fd290885.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - BOS50-C1 + X-Amz-Cf-Id: + - a5aNOoeszOcT9rDDxT3YXZBZLq9rM4zIp8jGNm5pOa5fBJkbBW3L-g== + body: + encoding: UTF-8 + string: '{"ok":false,"error":"no_text"}' + http_version: + recorded_at: Fri, 13 Sep 2019 21:23:19 GMT +recorded_with: VCR 5.0.0 diff --git a/test/workspace_test.rb b/test/workspace_test.rb index ebe33d64..dd54b820 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -133,7 +133,7 @@ it "raises exception if there is an error in API response" do VCR.use_cassette("send_slack_message_error") do - expect { response = @workspace.send_message("", "general") }.must_raise SlackApiError + expect { @workspace.send_message("", "general") }.must_raise SlackApiError end end end