From 130b7505e0b1a9f211ac6682afbee046946bb45e Mon Sep 17 00:00:00 2001 From: Janice Huang Date: Tue, 10 Sep 2019 14:59:24 -0700 Subject: [PATCH 01/27] set up files and write channel list method --- .gitignore | 2 +- lib/channel.rb | 24 ++++++++++++++++++++++++ lib/recipient.rb | 21 +++++++++++++++++++++ lib/trial_run.rb | 34 ++++++++++++++++++++++++++++++++++ lib/user.rb | 14 ++++++++++++++ lib/workspace.rb | 12 ++++++++++++ test/channel_test.rb | 0 test/recipient_test.rb | 2 ++ test/user_test.rb | 0 test/workspace_test.rb | 0 10 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 lib/channel.rb create mode 100644 lib/recipient.rb create mode 100644 lib/trial_run.rb create mode 100644 lib/user.rb create mode 100644 lib/workspace.rb create mode 100644 test/channel_test.rb create mode 100644 test/recipient_test.rb create mode 100644 test/user_test.rb create mode 100644 test/workspace_test.rb diff --git a/.gitignore b/.gitignore index 8d6a243f..b78e0506 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,7 @@ /tmp/ # Used by dotenv library to load environment variables. -# .env +.env ## Specific to RubyMotion: .dat* diff --git a/lib/channel.rb b/lib/channel.rb new file mode 100644 index 00000000..9a68b68b --- /dev/null +++ b/lib/channel.rb @@ -0,0 +1,24 @@ +require 'httparty' +require 'dotenv' +require_relative 'recipient' + +Dotenv.load + +module SlackCLI + class Channel < Recipient + + def intiialize(slack_id, name, topic, member_count) + super(slack_id, name) + @topic = topic + @member_count = member_count + end + + #factory method for producing individual channels from json + def self.list(json) + channels = [] + json["channels"].each do|channel| + new_ch = Channel.new(channel["id"], channel["name"], channel["topic"], channel["topic"]["value"], channel["num_members"]) + channels << new_ch + end + return channels + end \ No newline at end of file diff --git a/lib/recipient.rb b/lib/recipient.rb new file mode 100644 index 00000000..71957897 --- /dev/null +++ b/lib/recipient.rb @@ -0,0 +1,21 @@ +require 'httparty' +require 'dotenv' + +Dotenv.load + +module SlackCLI + class Recipient + + attr_reader + + def initialize(slack_id, name) + @slack_id = slack_id + @name = name + end + + def send_message + end + + def self.get(URL, query) + response = HTTParty.get(URL, query) + end diff --git a/lib/trial_run.rb b/lib/trial_run.rb new file mode 100644 index 00000000..eba449f0 --- /dev/null +++ b/lib/trial_run.rb @@ -0,0 +1,34 @@ +require 'httparty' +require 'dotenv' + +Dotenv.load + +# https://slack.com/api/conversations.list includes private conversations +CHANNELS_BASE_URL = "https://slack.com/api/channels.list" +query_parameters = { + token: ENV['SLACK_KEY'] +} + +channels_response = HTTParty.get(CHANNELS_BASE_URL, query: query_parameters) +channels_response["channels"].each do |channel| + puts "channel id: #{channel["id"]}" + puts "member: #{channel["members"]}" + puts "name: #{channel["name"]}" + puts "name normalized: #{channel["name_normalized"]}" +end + + +# USERS_BASE_URL = "https://slack.com/api/users.list" +# query_parameters = { +# token: ENV['SLACK_KEY'] +# } + +# users_response = HTTParty.get(USERS_BASE_URL, query: query_parameters) +# puts users_response + +# CHAT_POST_BASE_URL = "https://slack.com/api/chat.postMessage" +# query_parameters = { +# token: ENV['SLACK_KEY'] +# channel: +# text: +# } \ No newline at end of file diff --git a/lib/user.rb b/lib/user.rb new file mode 100644 index 00000000..54a4e27f --- /dev/null +++ b/lib/user.rb @@ -0,0 +1,14 @@ +require 'httparty' +require 'dotenv' +require_relative 'recipient' + +Dotenv.load + +module SlackCLI + class User < Recipient + + def intiialize(slack_id, name, real_name, status_text, status_emoji) + super(slack_id, name) + @status_text = status_text + @status_emoji = status_emoji + end \ No newline at end of file diff --git a/lib/workspace.rb b/lib/workspace.rb new file mode 100644 index 00000000..bdb65d30 --- /dev/null +++ b/lib/workspace.rb @@ -0,0 +1,12 @@ +require 'httparty' +require 'dotenv' +require_relative 'user' +require_relative 'channel' + +Dotenv.load +attr_accessor :users, :channels, :selected +def initialize + @users = [] + @channels = Channel.get(url: ).list + @selected = nil +end diff --git a/test/channel_test.rb b/test/channel_test.rb new file mode 100644 index 00000000..e69de29b diff --git a/test/recipient_test.rb b/test/recipient_test.rb new file mode 100644 index 00000000..a91a6dc3 --- /dev/null +++ b/test/recipient_test.rb @@ -0,0 +1,2 @@ +module SlackCLI + \ No newline at end of file diff --git a/test/user_test.rb b/test/user_test.rb new file mode 100644 index 00000000..e69de29b diff --git a/test/workspace_test.rb b/test/workspace_test.rb new file mode 100644 index 00000000..e69de29b From cf982c8c5790ebbf0e820e35efb023e9e69de93c Mon Sep 17 00:00:00 2001 From: Janice Huang Date: Tue, 10 Sep 2019 16:47:51 -0700 Subject: [PATCH 02/27] write channel tests, all tests passing. --- lib/channel.rb | 19 ++++--- lib/recipient.rb | 6 ++- lib/slack.rb | 17 +++++-- lib/user.rb | 9 ++-- lib/workspace.rb | 20 ++++++-- test/cassettes/channels_list.yml | 85 ++++++++++++++++++++++++++++++++ test/channel_test.rb | 52 +++++++++++++++++++ test/recipient_test.rb | 2 +- test/test_helper.rb | 13 +++++ 9 files changed, 201 insertions(+), 22 deletions(-) create mode 100644 test/cassettes/channels_list.yml diff --git a/lib/channel.rb b/lib/channel.rb index 9a68b68b..c0f1a0db 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -2,23 +2,28 @@ require 'dotenv' require_relative 'recipient' + Dotenv.load module SlackCLI class Channel < Recipient - - def intiialize(slack_id, name, topic, member_count) + attr_reader :slack_id, :name, :topic, :member_count + + def initialize(slack_id, name, topic, member_count) super(slack_id, name) @topic = topic @member_count = member_count end - + #factory method for producing individual channels from json - def self.list(json) + def self.json_parse(json) channels = [] json["channels"].each do|channel| - new_ch = Channel.new(channel["id"], channel["name"], channel["topic"], channel["topic"]["value"], channel["num_members"]) + new_ch = SlackCLI::Channel.new(channel["id"], channel["name"], channel["topic"]["value"], channel["num_members"]) channels << new_ch end - return channels - end \ No newline at end of file + return channels + end + end +end + diff --git a/lib/recipient.rb b/lib/recipient.rb index 71957897..ca00a372 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -16,6 +16,8 @@ def initialize(slack_id, name) def send_message end - def self.get(URL, query) - response = HTTParty.get(URL, query) + def self.get(url, query) + response = HTTParty.get(url, query) end + end +end \ No newline at end of file diff --git a/lib/slack.rb b/lib/slack.rb index 960cf2f7..1a11438c 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,11 +1,20 @@ #!/usr/bin/env ruby +require 'httparty' +require 'dotenv' +require_relative 'user' +require_relative 'channel' +#require_relative 'workspace' +Dotenv.load def main puts "Welcome to the Ada Slack CLI!" - - # TODO project - + + puts SlackCLI::Channel.new(01, "zadie", "cute puppies", 2) + puts SlackCLI::User.new(01, "zadie", "cute puppy", "runnign around") + puts "Thank you for using the Ada Slack CLI" end -main if __FILE__ == $PROGRAM_NAME \ No newline at end of file +main + +#main if __FILE__ == $PROGRAM_NAME \ No newline at end of file diff --git a/lib/user.rb b/lib/user.rb index 54a4e27f..4c776d76 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -6,9 +6,12 @@ module SlackCLI class User < Recipient - - def intiialize(slack_id, name, real_name, status_text, status_emoji) + + def initialize(slack_id, name, real_name, status_text, status_emoji = nil) super(slack_id, name) + @real_name = real_name @status_text = status_text @status_emoji = status_emoji - end \ No newline at end of file + end + end +end \ No newline at end of file diff --git a/lib/workspace.rb b/lib/workspace.rb index bdb65d30..b08d7dc1 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -4,9 +4,19 @@ require_relative 'channel' Dotenv.load -attr_accessor :users, :channels, :selected -def initialize - @users = [] - @channels = Channel.get(url: ).list - @selected = nil + +module SlackCLI + class Workspace + CHANNEL_URL = 'https://slack.com/api/channels.list' + USER_URL = 'https://slack.com/api/users.list' + query_parameters = { + token: ENV['SLACK_KEY'] + } + attr_accessor :users, :channels, :selected + def initialize + @users = [] + @channels = Channel.get(CHANNEL_URL, query_parameters).json_parse + @selected = nil + end + end end diff --git a/test/cassettes/channels_list.yml b/test/cassettes/channels_list.yml new file mode 100644 index 00000000..bc6176de --- /dev/null +++ b/test/cassettes/channels_list.yml @@ -0,0 +1,85 @@ +--- +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: + - '811' + Connection: + - keep-alive + Date: + - Tue, 10 Sep 2019 23:33:17 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - ddbc1025-fad4-4aaf-8ef7-63461b7c3add + 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-rjc8 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 ec2a2c75c16156e4d43504606c118b91.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C1 + X-Amz-Cf-Id: + - spvEv7ZVWKjEgQkcZDbGL20jb808Rfd0SKJaTw2wCG5ZLTE_x5rmCg== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CMTG8GHKL","name":"apis","is_channel":true,"created":1568071960,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN85KFVNK","name_normalized":"apis","is_shared":false,"is_org_shared":false,"is_member":false,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69TR3N1","UN85KFVNK"],"topic":{"value":"Testing + location for APIs.","creator":"UN69TR3N1","last_set":1568151873},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":3},{"id":"CMURA7JFM","name":"random","is_channel":true,"created":1568071832,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN85KFVNK","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69SEW21","UN69SF69K","UN69TR3N1","UN85KFVNK","UN85LNJMV"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UN85KFVNK","last_set":1568071832},"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":"UN85KFVNK","last_set":1568071832},"previous_names":[],"num_members":6},{"id":"CN03170U9","name":"memes","is_channel":true,"created":1568090675,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN85KFVNK","name_normalized":"memes","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69SF69K","UN69TR3N1","UN85KFVNK","UN85LNJMV"],"topic":{"value":"all + the memes","creator":"UN69TR3N1","last_set":1568151900},"purpose":{"value":"we + need them","creator":"UN85KFVNK","last_set":1568090676},"previous_names":[],"num_members":5},{"id":"CN69J7LQG","name":"general","is_channel":true,"created":1568071832,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UN85KFVNK","name_normalized":"general","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69SEW21","UN69SF69K","UN69TR3N1","UN85KFVNK","UN85LNJMV"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UN85KFVNK","last_set":1568071832},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UN85KFVNK","last_set":1568071832},"previous_names":[],"num_members":6},{"id":"CN759T0MA","name":"fuzzy_bunnies","is_channel":true,"created":1568147657,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN69SEW21","name_normalized":"fuzzy_bunnies","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69SEW21","UN69SF69K","UN69TR3N1","UN85KFVNK","UN85LNJMV"],"topic":{"value":"Adorable + rabbits","creator":"UN69TR3N1","last_set":1568151886},"purpose":{"value":"For + photos and conversation about fuzzy bunnies.","creator":"UN69SEW21","last_set":1568147658},"previous_names":[],"num_members":6},{"id":"CN85KGEJ3","name":"slack-cli","is_channel":true,"created":1568071832,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN85KFVNK","name_normalized":"slack-cli","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69SEW21","UN69SF69K","UN69TR3N1","UN85KFVNK","UN85LNJMV"],"topic":{"value":"CLI","creator":"UN69TR3N1","last_set":1568151925},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":6}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Tue, 10 Sep 2019 23:33:17 GMT +recorded_with: VCR 5.0.0 diff --git a/test/channel_test.rb b/test/channel_test.rb index e69de29b..8e261778 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -0,0 +1,52 @@ +require_relative 'test_helper' + +describe 'can create a channel' do + let (:channel) { + SlackCLI::Channel.new(01, "zadie", "cute puppies", 2) + } + it 'creates a channel' do + expect(channel).must_be_instance_of SlackCLI::Channel + expect(channel.topic).must_equal 'cute puppies' + end +end + +describe 'Channel.get' do + + before do + VCR.use_cassette("channels.list") do + query_parameters = { + token: ENV['SLACK_KEY'] + } + @channels_json = SlackCLI::Channel.get('https://slack.com/api/channels.list',query: query_parameters) + end + end + + it 'gets channel list from slack' do + expect(@channels_json.code).must_equal 200 + end + + it "returns an array of channels" do + expect(@channels_json["channels"]).must_be_kind_of Array + end +end + +describe 'json_parse' do + before do + VCR.use_cassette("channels.list") do + query_parameters = { + token: ENV['SLACK_KEY'] + } + @channels_json = SlackCLI::Channel.get('https://slack.com/api/channels.list',query: query_parameters) + end + @channels = SlackCLI::Channel.json_parse(@channels_json) + end + + it 'creates an array' do + expect(@channels).must_be_kind_of Array + end + + it 'creates an array of Channels' do + expect(@channels[0]).must_be_instance_of SlackCLI::Channel + end +end + diff --git a/test/recipient_test.rb b/test/recipient_test.rb index a91a6dc3..bc122f76 100644 --- a/test/recipient_test.rb +++ b/test/recipient_test.rb @@ -1,2 +1,2 @@ module SlackCLI - \ No newline at end of file +end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 90aeb408..a5bc016c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,10 +8,23 @@ require 'minitest/reporters' require 'minitest/skip_dsl' require 'vcr' +require_relative '../lib/channel' +require_relative '../lib/user' +require_relative '../lib/recipient' +require_relative '../lib/workspace' Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new VCR.configure do |config| config.cassette_library_dir = "test/cassettes" config.hook_into :webmock + config.default_cassette_options = { + :record => :new_episodes, # record new data when we don't have it yet + :match_requests_on => [:method, :uri, :body], # The http method, URI and body of a request all need to match + } + # Don't leave our token lying around in a cassette file. + config.filter_sensitive_data("") do + ENV["SLACK_KEY"] + end end + From 83d3e9fb8de274d09fac4022c2af6791015a4e26 Mon Sep 17 00:00:00 2001 From: Emily Vomacka Date: Tue, 10 Sep 2019 21:36:42 -0700 Subject: [PATCH 03/27] added gitignore, setup test --- .gitignore | 2 +- lib/setup_test.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 lib/setup_test.rb diff --git a/.gitignore b/.gitignore index 8d6a243f..b78e0506 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,7 @@ /tmp/ # Used by dotenv library to load environment variables. -# .env +.env ## Specific to RubyMotion: .dat* diff --git a/lib/setup_test.rb b/lib/setup_test.rb new file mode 100644 index 00000000..eccd8d41 --- /dev/null +++ b/lib/setup_test.rb @@ -0,0 +1,16 @@ +require 'httparty' +require 'dotenv' +Dotenv.load + +url = "https://slack.com/api/channels.list?" + +query_parameters = { + token: ENV['SLACK_API_TOKEN'], + pretty: 1 +} + +response = HTTParty.get(url, query: query_parameters) + +response["channels"].each do |channel| + puts "This channel is called #{channel["name"]} and has #{channel["num_members"]} members." +end From 0d491c313da70751234210e85385c05108887f1c Mon Sep 17 00:00:00 2001 From: Emily Vomacka Date: Wed, 11 Sep 2019 12:45:50 -0700 Subject: [PATCH 04/27] set-up actually added --- lib/setup_test.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/setup_test.rb b/lib/setup_test.rb index eccd8d41..351968c4 100644 --- a/lib/setup_test.rb +++ b/lib/setup_test.rb @@ -5,8 +5,7 @@ url = "https://slack.com/api/channels.list?" query_parameters = { - token: ENV['SLACK_API_TOKEN'], - pretty: 1 + token: ENV['SLACK_API_TOKEN'] } response = HTTParty.get(url, query: query_parameters) From 1028f1884bbf4cac673c4dfbdea881bc009254c5 Mon Sep 17 00:00:00 2001 From: Janice Huang Date: Wed, 11 Sep 2019 13:49:40 -0700 Subject: [PATCH 05/27] add parse function to user --- lib/channel.rb | 4 ++-- lib/recipient.rb | 5 ++++- lib/slack.rb | 6 +++--- lib/trial_run.rb | 33 ++++++++++++++++++++------------- lib/user.rb | 13 ++++++++++++- 5 files changed, 41 insertions(+), 20 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index c0f1a0db..0ed3e08b 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -8,13 +8,13 @@ module SlackCLI class Channel < Recipient attr_reader :slack_id, :name, :topic, :member_count - + def initialize(slack_id, name, topic, member_count) super(slack_id, name) @topic = topic @member_count = member_count end - + #factory method for producing individual channels from json def self.json_parse(json) channels = [] diff --git a/lib/recipient.rb b/lib/recipient.rb index ca00a372..8066eb6b 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -20,4 +20,7 @@ def self.get(url, query) response = HTTParty.get(url, query) end end -end \ No newline at end of file +end + +# details and self.list are abstract class methods +# raise NotImplementedError, 'Implement me in a child class!' \ No newline at end of file diff --git a/lib/slack.rb b/lib/slack.rb index 1a11438c..c4b4c307 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -8,10 +8,10 @@ Dotenv.load def main puts "Welcome to the Ada Slack CLI!" - + puts SlackCLI::Channel.new(01, "zadie", "cute puppies", 2) - puts SlackCLI::User.new(01, "zadie", "cute puppy", "runnign around") - + puts SlackCLI::User.new(01, "zadie", "cute puppy", "running around") + puts "Thank you for using the Ada Slack CLI" end diff --git a/lib/trial_run.rb b/lib/trial_run.rb index eba449f0..5af65620 100644 --- a/lib/trial_run.rb +++ b/lib/trial_run.rb @@ -1,30 +1,37 @@ require 'httparty' require 'dotenv' +require 'table_print' Dotenv.load # https://slack.com/api/conversations.list includes private conversations -CHANNELS_BASE_URL = "https://slack.com/api/channels.list" +# CHANNELS_BASE_URL = "https://slack.com/api/channels.list" +# query_parameters = { +# token: ENV['SLACK_KEY'] +# } + +# channels_response = HTTParty.get(CHANNELS_BASE_URL, query: query_parameters) +# channels_selected_info = [] +# channels_response["channels"].each do |channel| +# channels_selected_info << [channel["id"], channel["members"], channel["name"], channel["name_normalized"]] +# end +# tp channels_selected_info, "channels", "members", "name", "name normalized" + +USERS_BASE_URL = "https://slack.com/api/users.list" query_parameters = { token: ENV['SLACK_KEY'] } -channels_response = HTTParty.get(CHANNELS_BASE_URL, query: query_parameters) -channels_response["channels"].each do |channel| - puts "channel id: #{channel["id"]}" - puts "member: #{channel["members"]}" - puts "name: #{channel["name"]}" - puts "name normalized: #{channel["name_normalized"]}" +users_response = HTTParty.get(USERS_BASE_URL, query: query_parameters) +user_array = [] +users_response["members"].each do |user| + user_array << user["profile"]["real_name"] + user_array << user["profile"]["display_name"] end + tp user_array, "real name", "display name" -# USERS_BASE_URL = "https://slack.com/api/users.list" -# query_parameters = { -# token: ENV['SLACK_KEY'] -# } -# users_response = HTTParty.get(USERS_BASE_URL, query: query_parameters) -# puts users_response # CHAT_POST_BASE_URL = "https://slack.com/api/chat.postMessage" # query_parameters = { diff --git a/lib/user.rb b/lib/user.rb index 4c776d76..e73c9b8a 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -6,12 +6,23 @@ module SlackCLI class User < Recipient - + + attr_reader :real_name, :status_text, :status_emoji def initialize(slack_id, name, real_name, status_text, status_emoji = nil) super(slack_id, name) @real_name = real_name @status_text = status_text @status_emoji = status_emoji end + + #factory method for producing individual users from json + def self.json_parse(json) + users = [] + json["users"].each do|users| + new_user = SlackCLI::User.new(user["id"], user["profile"]["display_name"], user["profile"]["real_name"], user["profile"]["status_text"], user["profile"]["status_emoji"]) + users << new_user + end + return users + end end end \ No newline at end of file From 7e51cfd0dc6a560f1941c8c8a8d3ff7952d91e2d Mon Sep 17 00:00:00 2001 From: Emily Vomacka Date: Wed, 11 Sep 2019 13:52:17 -0700 Subject: [PATCH 06/27] added user tests which are failing --- lib/channel.rb | 1 - lib/setup_test.rb | 2 +- test/cassettes/channels_list.yml | 63 +++++++++++ test/cassettes/users_list.yml | 173 +++++++++++++++++++++++++++++++ test/user_test.rb | 51 +++++++++ 5 files changed, 288 insertions(+), 2 deletions(-) create mode 100644 test/cassettes/users_list.yml diff --git a/lib/channel.rb b/lib/channel.rb index c0f1a0db..1a3c0c80 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -2,7 +2,6 @@ require 'dotenv' require_relative 'recipient' - Dotenv.load module SlackCLI diff --git a/lib/setup_test.rb b/lib/setup_test.rb index 351968c4..de1f89b8 100644 --- a/lib/setup_test.rb +++ b/lib/setup_test.rb @@ -5,7 +5,7 @@ url = "https://slack.com/api/channels.list?" query_parameters = { - token: ENV['SLACK_API_TOKEN'] + token: ENV['SLACK_TOKEN'] } response = HTTParty.get(url, query: query_parameters) diff --git a/test/cassettes/channels_list.yml b/test/cassettes/channels_list.yml index bc6176de..663c44cf 100644 --- a/test/cassettes/channels_list.yml +++ b/test/cassettes/channels_list.yml @@ -82,4 +82,67 @@ http_interactions: photos and conversation about fuzzy bunnies.","creator":"UN69SEW21","last_set":1568147658},"previous_names":[],"num_members":6},{"id":"CN85KGEJ3","name":"slack-cli","is_channel":true,"created":1568071832,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN85KFVNK","name_normalized":"slack-cli","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69SEW21","UN69SF69K","UN69TR3N1","UN85KFVNK","UN85LNJMV"],"topic":{"value":"CLI","creator":"UN69TR3N1","last_set":1568151925},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":6}],"response_metadata":{"next_cursor":""}}' http_version: recorded_at: Tue, 10 Sep 2019 23:33:17 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: + - '53' + Connection: + - keep-alive + Date: + - Wed, 11 Sep 2019 19:46:52 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 + X-Accepted-Oauth-Scopes: + - channels:read + Vary: + - Accept-Encoding + X-Slack-Req-Id: + - d3852359-d770-412c-a348-361bd3b73fb5 + X-Xss-Protection: + - '0' + X-Content-Type-Options: + - nosniff + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-j2wg + X-Cache: + - Miss from cloudfront + Via: + - 1.1 2e20768704c71ff3ce2e677251d27f3c.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C1 + X-Amz-Cf-Id: + - "-7P7A0EFK6dXte7jW14jUxqt4sFR9rx8vT8mPmdpkX7Se_JEjnQhrQ==" + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"not_authed"}' + http_version: + recorded_at: Wed, 11 Sep 2019 19:46:52 GMT recorded_with: VCR 5.0.0 diff --git a/test/cassettes/users_list.yml b/test/cassettes/users_list.yml new file mode 100644 index 00000000..be1e09a3 --- /dev/null +++ b/test/cassettes/users_list.yml @@ -0,0 +1,173 @@ +--- +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: + - '958' + Connection: + - keep-alive + Date: + - Wed, 11 Sep 2019 20:47:46 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 685ce7f9-4640-4647-960b-ccd3d86c544a + 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-45gn + X-Cache: + - Miss from cloudfront + Via: + - 1.1 eab8a154a09e69260fbfe4df90182b2f.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C2 + X-Amz-Cf-Id: + - SobqjbL425k_PrkFG9fYLoN1KrSYF4pgPZcJYl4gIRq_WmK9B2Hk-A== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CMTG8GHKL","name":"apis","is_channel":true,"created":1568071960,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN85KFVNK","name_normalized":"apis","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69TR3N1","UN85KFVNK"],"topic":{"value":"Testing + location for APIs.","creator":"UN69TR3N1","last_set":1568151873},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":3},{"id":"CMURA7JFM","name":"random","is_channel":true,"created":1568071832,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN85KFVNK","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69SEW21","UN69SF69K","UN69TR3N1","UN85KFVNK","UN85LNJMV"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UN85KFVNK","last_set":1568071832},"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":"UN85KFVNK","last_set":1568071832},"previous_names":[],"num_members":6},{"id":"CN03170U9","name":"memes","is_channel":true,"created":1568090675,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN85KFVNK","name_normalized":"memes","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69SEW21","UN69SF69K","UN69TR3N1","UN85KFVNK","UN85LNJMV"],"topic":{"value":"all + the memes","creator":"UN69TR3N1","last_set":1568151900},"purpose":{"value":"we + need them","creator":"UN85KFVNK","last_set":1568090676},"previous_names":[],"num_members":6},{"id":"CN1GC7WAD","name":"hallies_secret","is_channel":true,"created":1568172409,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN69SEW21","name_normalized":"hallies_secret","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UN69SEW21","UN85KFVNK"],"topic":{"value":"To + see who reads their API JSON carefully and joins this channel.","creator":"UN69SEW21","last_set":1568172444},"purpose":{"value":"To + see who reads their API JSON carefully and joins this channel.","creator":"UN69SEW21","last_set":1568172409},"previous_names":[],"num_members":2},{"id":"CN69J7LQG","name":"general","is_channel":true,"created":1568071832,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UN85KFVNK","name_normalized":"general","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69SEW21","UN69SF69K","UN69TR3N1","UN85KFVNK","UN85LNJMV"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UN85KFVNK","last_set":1568071832},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UN85KFVNK","last_set":1568071832},"previous_names":[],"num_members":6},{"id":"CN759T0MA","name":"fuzzy_bunnies","is_channel":true,"created":1568147657,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN69SEW21","name_normalized":"fuzzy_bunnies","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69SEW21","UN69SF69K","UN69TR3N1","UN85KFVNK","UN85LNJMV"],"topic":{"value":"Adorable + rabbits","creator":"UN69TR3N1","last_set":1568151886},"purpose":{"value":"For + photos and conversation about fuzzy bunnies.","creator":"UN69SEW21","last_set":1568147658},"previous_names":[],"num_members":6},{"id":"CN7UD5D8Q","name":"dont_fight_bears","is_channel":true,"created":1568172797,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN69SEW21","name_normalized":"dont_fight_bears","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UN69SEW21","UN69SF69K","UN85KFVNK"],"topic":{"value":"A + place for bear safety and tips.","creator":"UN69SEW21","last_set":1568172825},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":3},{"id":"CN85KGEJ3","name":"slack-cli","is_channel":true,"created":1568071832,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN85KFVNK","name_normalized":"slack-cli","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69SEW21","UN69SF69K","UN69TR3N1","UN85KFVNK","UN85LNJMV"],"topic":{"value":"CLI","creator":"UN69TR3N1","last_set":1568151925},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":6}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 11 Sep 2019 20:47:46 GMT +- 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: + - '1588' + Connection: + - keep-alive + Date: + - Wed, 11 Sep 2019 20:47:46 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 50bfe97f-991c-46c9-b9ba-9523aca7c96d + 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-7ksv + X-Cache: + - Miss from cloudfront + Via: + - 1.1 98aedae6661e3904540676966998ed89.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C2 + X-Amz-Cf-Id: + - 23vpBRdmnfkZi6ABxd9qvL4_TBv8Oasq7Dz937Y2wd_GIDw5dsA8SQ== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TMTG7023U","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":"TMTG7023U"},"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":"UMTG87PC2","team_id":"TMTG7023U","name":"nickyjinchoi","deleted":false,"color":"674b1b","real_name":"Nicky + Choi","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Nicky + Choi","real_name_normalized":"Nicky Choi","display_name":"Nicky Choi","display_name_normalized":"Nicky + Choi","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g6e33044e4c8","image_24":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568071993,"has_2fa":false},{"id":"UN69SEW21","team_id":"TMTG7023U","name":"idhallie","deleted":false,"color":"e7392d","real_name":"Hallie + Johnson","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Hallie + Johnson","real_name_normalized":"Hallie Johnson","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g23bc7b83db4","image_24":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568072412,"has_2fa":false},{"id":"UN69SF69K","team_id":"TMTG7023U","name":"yitgop.yyhxox","deleted":false,"color":"3c989f","real_name":"Yitgop + Y.","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Yitgop + Y.","real_name_normalized":"Yitgop Y.","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gb749eeae508","image_24":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568072069,"has_2fa":false},{"id":"UN69TR3N1","team_id":"TMTG7023U","name":"elizabethjnorthrop","deleted":false,"color":"e0a729","real_name":"Elizabeth + Northrop","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Elizabeth + Northrop","real_name_normalized":"Elizabeth Northrop","display_name":"Elizabeth + Northrop","display_name_normalized":"Elizabeth Northrop","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g555bff2ee78","image_24":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568072090,"has_2fa":false},{"id":"UN85KFVNK","team_id":"TMTG7023U","name":"emilyvomacka","deleted":false,"color":"9f69e7","real_name":"Emily + V","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Emily + V","real_name_normalized":"Emily V","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g319432559c3","first_name":"Emily","last_name":"V","image_24":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568090599,"has_2fa":false},{"id":"UN85LNJMV","team_id":"TMTG7023U","name":"janicehuang","deleted":false,"color":"4bbe2e","real_name":"janice","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"janice","real_name_normalized":"janice","display_name":"janice","display_name_normalized":"janice","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g73010028c3d","image_24":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568071984,"has_2fa":false},{"id":"UN85LQ0HM","team_id":"TMTG7023U","name":"elizabethjnorthrup","deleted":true,"profile":{"title":"","phone":"","skype":"","real_name":"elizabethjnorthrup","real_name_normalized":"elizabethjnorthrup","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g0b2f1d21275","first_name":"","last_name":"","image_24":"https:\/\/secure.gravatar.com\/avatar\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-512.png","status_text_canonical":"","team":"TMTG7023U"},"is_bot":false,"is_app_user":false,"updated":1568072109,"is_invited_user":true}],"cache_ts":1568234866,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 11 Sep 2019 20:47:46 GMT +recorded_with: VCR 5.0.0 diff --git a/test/user_test.rb b/test/user_test.rb index e69de29b..5d741ee8 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -0,0 +1,51 @@ +require_relative 'test_helper' + +describe 'can create a user' do + let (:user) { + SlackCLI::User.new(35, "zadie", "Zadie Rose", "napping") + } + it 'creates a user' do + expect(user).must_be_instance_of SlackCLI::User + expect(user.status_text).must_equal 'cute puppies' + end +end + +describe 'User.get' do + + before do + VCR.use_cassette("users.list") do + query_parameters = { + token: ENV['SLACK_KEY'] + } + @users_json = SlackCLI::Channel.get('https://slack.com/api/users.list', query: query_parameters) + end + end + + it 'gets user list from slack' do + expect(@users_json.code).must_equal 200 + end + + it "returns an array of users" do + expect(@users_json["members"]).must_be_kind_of Array + end +end + +describe 'User.json_parse' do + before do + VCR.use_cassette("users.list") do + query_parameters = { + token: ENV['SLACK_KEY'] + } + @users_json = SlackCLI::User.get('https://slack.com/api/users.list',query: query_parameters) + end + @users = SlackCLI::User.json_parse(@users_json) + end + + it 'creates an array' do + expect(@users).must_be_kind_of Array + end + + it 'creates an array of Channels' do + expect(@users[0]).must_be_instance_of SlackCLI::User + end +end From ad40cdc06de1f114123758ef9f604a86febf94f1 Mon Sep 17 00:00:00 2001 From: Emily Vomacka Date: Wed, 11 Sep 2019 14:20:28 -0700 Subject: [PATCH 07/27] added tests for user and workspace --- lib/user.rb | 8 ++++---- test/user_test.rb | 4 ++-- test/workspace_test.rb | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index e73c9b8a..14c3abc6 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -6,7 +6,7 @@ module SlackCLI class User < Recipient - + attr_reader :real_name, :status_text, :status_emoji def initialize(slack_id, name, real_name, status_text, status_emoji = nil) super(slack_id, name) @@ -14,12 +14,12 @@ def initialize(slack_id, name, real_name, status_text, status_emoji = nil) @status_text = status_text @status_emoji = status_emoji end - + #factory method for producing individual users from json def self.json_parse(json) users = [] - json["users"].each do|users| - new_user = SlackCLI::User.new(user["id"], user["profile"]["display_name"], user["profile"]["real_name"], user["profile"]["status_text"], user["profile"]["status_emoji"]) + json["members"].each do |member| + new_user = SlackCLI::User.new(member["id"], member["profile"]["display_name"], member["profile"]["real_name"], member["profile"]["status_text"], member["profile"]["status_emoji"]) users << new_user end return users diff --git a/test/user_test.rb b/test/user_test.rb index 5d741ee8..54417bab 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -6,7 +6,7 @@ } it 'creates a user' do expect(user).must_be_instance_of SlackCLI::User - expect(user.status_text).must_equal 'cute puppies' + expect(user.status_text).must_equal 'napping' end end @@ -45,7 +45,7 @@ expect(@users).must_be_kind_of Array end - it 'creates an array of Channels' do + it 'creates an array of Users' do expect(@users[0]).must_be_instance_of SlackCLI::User end end diff --git a/test/workspace_test.rb b/test/workspace_test.rb index e69de29b..e89bc6a7 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -0,0 +1,24 @@ +require_relative 'test_helper' + +describe 'can create a workspace' do + let (:workspace) { + SlackCLI::Workspace.new + } + + it 'creates a workspace' do + expect(workspace).must_be_instance_of SlackCLI::Workspace + expect(workspace.selected).must_be nil + end + + it 'has an array of channels' do + expect(workspace.channels).must_be_kind_of Array + expect(workspace.channels[0]).must_be_instance_of Channel + end + + it 'has an array of users' do + expect(workspace.users).must_be_kind_of Array + expect(workspace.users[0]).must_be_instance_of User + end +end + + From 3db3b794a5aa2ded676accfdca9a8cc6d14d96af Mon Sep 17 00:00:00 2001 From: Janice Huang Date: Wed, 11 Sep 2019 14:20:45 -0700 Subject: [PATCH 08/27] add user.get in workspace --- lib/user.rb | 2 +- lib/workspace.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index e73c9b8a..4962138f 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -18,7 +18,7 @@ def initialize(slack_id, name, real_name, status_text, status_emoji = nil) #factory method for producing individual users from json def self.json_parse(json) users = [] - json["users"].each do|users| + json["users"].each do|user| new_user = SlackCLI::User.new(user["id"], user["profile"]["display_name"], user["profile"]["real_name"], user["profile"]["status_text"], user["profile"]["status_emoji"]) users << new_user end diff --git a/lib/workspace.rb b/lib/workspace.rb index b08d7dc1..0f21f408 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -14,7 +14,7 @@ class Workspace } attr_accessor :users, :channels, :selected def initialize - @users = [] + @users = User.get(USER_URL, query_parameters).json_parse @channels = Channel.get(CHANNEL_URL, query_parameters).json_parse @selected = nil end From 3e0f1a48000af11244e9130a7c736f5b13a825cc Mon Sep 17 00:00:00 2001 From: Emily Vomacka Date: Wed, 11 Sep 2019 15:48:53 -0700 Subject: [PATCH 09/27] added list_users and list_channels, added command line --- lib/recipient.rb | 9 +- lib/slack.rb | 20 ++- lib/user.rb | 5 - lib/workspace.rb | 45 +++++- test/cassettes/workspace_new.yml | 236 +++++++++++++++++++++++++++++++ test/channel_test.rb | 2 +- test/workspace_test.rb | 13 +- 7 files changed, 304 insertions(+), 26 deletions(-) create mode 100644 test/cassettes/workspace_new.yml diff --git a/lib/recipient.rb b/lib/recipient.rb index 8066eb6b..bdd6fdaa 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -5,17 +5,16 @@ module SlackCLI class Recipient - - attr_reader - + attr_reader :slack_id, :name + def initialize(slack_id, name) @slack_id = slack_id @name = name end - + def send_message end - + def self.get(url, query) response = HTTParty.get(url, query) end diff --git a/lib/slack.rb b/lib/slack.rb index c4b4c307..a57c2dd3 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -3,15 +3,25 @@ require 'dotenv' require_relative 'user' require_relative 'channel' -#require_relative 'workspace' +require_relative 'workspace' Dotenv.load def main puts "Welcome to the Ada Slack CLI!" - - puts SlackCLI::Channel.new(01, "zadie", "cute puppies", 2) - puts SlackCLI::User.new(01, "zadie", "cute puppy", "running around") - + tsu = SlackCLI::Workspace.new + print "Would you like a list of (1) users or (2) channels? " + choice = gets.chomp.to_i + until [1, 2].include?(choice) + print "Sorry. Please enter '1' or '2'!" + choice = gets.chomp + end + + if choice == 1 + tsu.list_users + elsif choice == 2 + tsu.list_channels + end + puts "Thank you for using the Ada Slack CLI" end diff --git a/lib/user.rb b/lib/user.rb index 39f4f4be..14c3abc6 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -18,13 +18,8 @@ def initialize(slack_id, name, real_name, status_text, status_emoji = nil) #factory method for producing individual users from json def self.json_parse(json) users = [] -<<<<<<< HEAD json["members"].each do |member| new_user = SlackCLI::User.new(member["id"], member["profile"]["display_name"], member["profile"]["real_name"], member["profile"]["status_text"], member["profile"]["status_emoji"]) -======= - json["users"].each do|user| - new_user = SlackCLI::User.new(user["id"], user["profile"]["display_name"], user["profile"]["real_name"], user["profile"]["status_text"], user["profile"]["status_emoji"]) ->>>>>>> 3db3b794a5aa2ded676accfdca9a8cc6d14d96af users << new_user end return users diff --git a/lib/workspace.rb b/lib/workspace.rb index 0f21f408..4fb97e22 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,22 +1,57 @@ require 'httparty' require 'dotenv' +require 'table_print' require_relative 'user' require_relative 'channel' +require_relative 'recipient' Dotenv.load module SlackCLI class Workspace + attr_accessor :users, :channels, :selected + CHANNEL_URL = 'https://slack.com/api/channels.list' USER_URL = 'https://slack.com/api/users.list' - query_parameters = { + GET_PARAMETERS = { token: ENV['SLACK_KEY'] } - attr_accessor :users, :channels, :selected + def initialize - @users = User.get(USER_URL, query_parameters).json_parse - @channels = Channel.get(CHANNEL_URL, query_parameters).json_parse + @users = SlackCLI::User.json_parse(SlackCLI::User.get(USER_URL, query: GET_PARAMETERS)) + @channels = SlackCLI::Channel.json_parse(SlackCLI::Channel.get(CHANNEL_URL, query: GET_PARAMETERS)) @selected = nil + + puts "Workspace loaded! #{users.length} users and #{channels.length} channels available." + end + + def list_users + users_hash_array = [] + @users.each do |user| + user_hash = { + "slack_id" => user.slack_id, + "display name" => user.name, + "real name" => user.real_name, + "status text" => user.status_text, + "status emoji" => user.status_emoji + } + users_hash_array << user_hash + end + tp users_hash_array + end + + def list_channels + channels_hash_array = [] + @channels.each do |channel| + channel_hash = { + "slack_id" => channel.slack_id, + "name" => channel.name, + "topic" => channel.topic, + "member_count" => channel.member_count + } + channels_hash_array << channel_hash + end + tp channels_hash_array end - end + end end diff --git a/test/cassettes/workspace_new.yml b/test/cassettes/workspace_new.yml new file mode 100644 index 00000000..57dbcf99 --- /dev/null +++ b/test/cassettes/workspace_new.yml @@ -0,0 +1,236 @@ +--- +http_interactions: +- request: + method: get + uri: https://slack.com/api/users.list + 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: + - '53' + Connection: + - keep-alive + Date: + - Wed, 11 Sep 2019 21:27:32 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 + X-Accepted-Oauth-Scopes: + - users:read + Vary: + - Accept-Encoding + X-Slack-Req-Id: + - 4662a7be-48df-4b4e-ab82-8fd9bebd37b9 + X-Xss-Protection: + - '0' + X-Content-Type-Options: + - nosniff + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-vnia + X-Cache: + - Miss from cloudfront + Via: + - 1.1 64f86ae1c24221f3a2e4d653d6dbc416.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C2 + X-Amz-Cf-Id: + - dazlkxH__yC1yhM5GByruhPRzTvFMiIxcBiGTMN7zZRVYnyJfXkm2w== + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"not_authed"}' + http_version: + recorded_at: Wed, 11 Sep 2019 21:27:32 GMT +- 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: + - '1588' + Connection: + - keep-alive + Date: + - Wed, 11 Sep 2019 21:38:37 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 78277875-b067-402a-88ca-1b15014815ca + 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-asnz + X-Cache: + - Miss from cloudfront + Via: + - 1.1 a3bd0eb50c22e4d5fbda56a30b96002d.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C2 + X-Amz-Cf-Id: + - 2jud0LeB51fTMzobtWXGo9ERpHbU-5mFoEDcbVjN7Kp7iLO6PQFrgQ== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TMTG7023U","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":"TMTG7023U"},"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":"UMTG87PC2","team_id":"TMTG7023U","name":"nickyjinchoi","deleted":false,"color":"674b1b","real_name":"Nicky + Choi","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Nicky + Choi","real_name_normalized":"Nicky Choi","display_name":"Nicky Choi","display_name_normalized":"Nicky + Choi","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g6e33044e4c8","image_24":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568071993,"has_2fa":false},{"id":"UN69SEW21","team_id":"TMTG7023U","name":"idhallie","deleted":false,"color":"e7392d","real_name":"Hallie + Johnson","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Hallie + Johnson","real_name_normalized":"Hallie Johnson","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g23bc7b83db4","image_24":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568072412,"has_2fa":false},{"id":"UN69SF69K","team_id":"TMTG7023U","name":"yitgop.yyhxox","deleted":false,"color":"3c989f","real_name":"Yitgop + Y.","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Yitgop + Y.","real_name_normalized":"Yitgop Y.","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gb749eeae508","image_24":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568072069,"has_2fa":false},{"id":"UN69TR3N1","team_id":"TMTG7023U","name":"elizabethjnorthrop","deleted":false,"color":"e0a729","real_name":"Elizabeth + Northrop","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Elizabeth + Northrop","real_name_normalized":"Elizabeth Northrop","display_name":"Elizabeth + Northrop","display_name_normalized":"Elizabeth Northrop","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g555bff2ee78","image_24":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568072090,"has_2fa":false},{"id":"UN85KFVNK","team_id":"TMTG7023U","name":"emilyvomacka","deleted":false,"color":"9f69e7","real_name":"Emily + V","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Emily + V","real_name_normalized":"Emily V","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g319432559c3","first_name":"Emily","last_name":"V","image_24":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568090599,"has_2fa":false},{"id":"UN85LNJMV","team_id":"TMTG7023U","name":"janicehuang","deleted":false,"color":"4bbe2e","real_name":"janice","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"janice","real_name_normalized":"janice","display_name":"janice","display_name_normalized":"janice","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g73010028c3d","image_24":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568071984,"has_2fa":false},{"id":"UN85LQ0HM","team_id":"TMTG7023U","name":"elizabethjnorthrup","deleted":true,"profile":{"title":"","phone":"","skype":"","real_name":"elizabethjnorthrup","real_name_normalized":"elizabethjnorthrup","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g0b2f1d21275","first_name":"","last_name":"","image_24":"https:\/\/secure.gravatar.com\/avatar\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-512.png","status_text_canonical":"","team":"TMTG7023U"},"is_bot":false,"is_app_user":false,"updated":1568072109,"is_invited_user":true}],"cache_ts":1568237917,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 11 Sep 2019 21:38:37 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: + - '958' + Connection: + - keep-alive + Date: + - Wed, 11 Sep 2019 21:38:37 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - dd1eab44-a827-45e6-8874-fa27555ed573 + 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-wjvt + X-Cache: + - Miss from cloudfront + Via: + - 1.1 e4d3d5aafc7d7d582423c073065ab563.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C2 + X-Amz-Cf-Id: + - ILTb2-uIOaiU23X2bQCVpSbcC6meLZAKZnTyLxu_2Gb_AQBhCM5YZw== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CMTG8GHKL","name":"apis","is_channel":true,"created":1568071960,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN85KFVNK","name_normalized":"apis","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69TR3N1","UN85KFVNK"],"topic":{"value":"Testing + location for APIs.","creator":"UN69TR3N1","last_set":1568151873},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":3},{"id":"CMURA7JFM","name":"random","is_channel":true,"created":1568071832,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN85KFVNK","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69SEW21","UN69SF69K","UN69TR3N1","UN85KFVNK","UN85LNJMV"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UN85KFVNK","last_set":1568071832},"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":"UN85KFVNK","last_set":1568071832},"previous_names":[],"num_members":6},{"id":"CN03170U9","name":"memes","is_channel":true,"created":1568090675,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN85KFVNK","name_normalized":"memes","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69SEW21","UN69SF69K","UN69TR3N1","UN85KFVNK","UN85LNJMV"],"topic":{"value":"all + the memes","creator":"UN69TR3N1","last_set":1568151900},"purpose":{"value":"we + need them","creator":"UN85KFVNK","last_set":1568090676},"previous_names":[],"num_members":6},{"id":"CN1GC7WAD","name":"hallies_secret","is_channel":true,"created":1568172409,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN69SEW21","name_normalized":"hallies_secret","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UN69SEW21","UN85KFVNK"],"topic":{"value":"To + see who reads their API JSON carefully and joins this channel.","creator":"UN69SEW21","last_set":1568172444},"purpose":{"value":"To + see who reads their API JSON carefully and joins this channel.","creator":"UN69SEW21","last_set":1568172409},"previous_names":[],"num_members":2},{"id":"CN69J7LQG","name":"general","is_channel":true,"created":1568071832,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UN85KFVNK","name_normalized":"general","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69SEW21","UN69SF69K","UN69TR3N1","UN85KFVNK","UN85LNJMV"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UN85KFVNK","last_set":1568071832},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UN85KFVNK","last_set":1568071832},"previous_names":[],"num_members":6},{"id":"CN759T0MA","name":"fuzzy_bunnies","is_channel":true,"created":1568147657,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN69SEW21","name_normalized":"fuzzy_bunnies","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69SEW21","UN69SF69K","UN69TR3N1","UN85KFVNK","UN85LNJMV"],"topic":{"value":"Adorable + rabbits","creator":"UN69TR3N1","last_set":1568151886},"purpose":{"value":"For + photos and conversation about fuzzy bunnies.","creator":"UN69SEW21","last_set":1568147658},"previous_names":[],"num_members":6},{"id":"CN7UD5D8Q","name":"dont_fight_bears","is_channel":true,"created":1568172797,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN69SEW21","name_normalized":"dont_fight_bears","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UN69SEW21","UN69SF69K","UN85KFVNK"],"topic":{"value":"A + place for bear safety and tips.","creator":"UN69SEW21","last_set":1568172825},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":3},{"id":"CN85KGEJ3","name":"slack-cli","is_channel":true,"created":1568071832,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN85KFVNK","name_normalized":"slack-cli","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTG87PC2","UN69SEW21","UN69SF69K","UN69TR3N1","UN85KFVNK","UN85LNJMV"],"topic":{"value":"CLI","creator":"UN69TR3N1","last_set":1568151925},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":6}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 11 Sep 2019 21:38:37 GMT +recorded_with: VCR 5.0.0 diff --git a/test/channel_test.rb b/test/channel_test.rb index 8e261778..b8fadc95 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -30,7 +30,7 @@ end end -describe 'json_parse' do +describe 'Channel.json_parse' do before do VCR.use_cassette("channels.list") do query_parameters = { diff --git a/test/workspace_test.rb b/test/workspace_test.rb index e89bc6a7..5ddf0b61 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -1,23 +1,26 @@ require_relative 'test_helper' describe 'can create a workspace' do - let (:workspace) { - SlackCLI::Workspace.new + + let (:workspace) { + VCR.use_cassette("workspace.new") do + SlackCLI::Workspace.new + end } it 'creates a workspace' do expect(workspace).must_be_instance_of SlackCLI::Workspace - expect(workspace.selected).must_be nil + expect(workspace.selected).must_be_nil end it 'has an array of channels' do expect(workspace.channels).must_be_kind_of Array - expect(workspace.channels[0]).must_be_instance_of Channel + expect(workspace.channels[0]).must_be_instance_of SlackCLI::Channel end it 'has an array of users' do expect(workspace.users).must_be_kind_of Array - expect(workspace.users[0]).must_be_instance_of User + expect(workspace.users[0]).must_be_instance_of SlackCLI::User end end From 0d476c0b01b806657acec401a61d7d736256d51f Mon Sep 17 00:00:00 2001 From: Emily Vomacka Date: Wed, 11 Sep 2019 20:48:25 -0700 Subject: [PATCH 10/27] finished command line to complete wave 1 --- lib/slack.rb | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index a57c2dd3..4b93eda0 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -9,20 +9,25 @@ def main puts "Welcome to the Ada Slack CLI!" tsu = SlackCLI::Workspace.new - print "Would you like a list of (1) users or (2) channels? " - choice = gets.chomp.to_i - until [1, 2].include?(choice) - print "Sorry. Please enter '1' or '2'!" - choice = gets.chomp - end - if choice == 1 - tsu.list_users - elsif choice == 2 - tsu.list_channels - end - - puts "Thank you for using the Ada Slack CLI" + loop do + print "Would you like to (1) list users, (2) list channels, or (3) quit? " + choice = gets.chomp.to_i + until [1, 2, 3].include?(choice) + print "Sorry. Please enter '1', '2' or '3'!" + choice = gets.chomp + end + + if choice == 1 + tsu.list_users + elsif choice == 2 + tsu.list_channels + elsif choice == 3 + puts "Thank you for using the Ada Slack CLI" + exit + end + + end end main From ce610fee72695b9a914a33ea4aa85c285754eb38 Mon Sep 17 00:00:00 2001 From: Janice Huang Date: Wed, 11 Sep 2019 22:48:06 -0700 Subject: [PATCH 11/27] add select user and select channel functions --- lib/slack.rb | 27 ++++++++++++++++++++------- lib/workspace.rb | 48 +++++++++++++++++++++++++++++++++++------------- 2 files changed, 55 insertions(+), 20 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 4b93eda0..4ff8ad51 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -9,25 +9,38 @@ def main puts "Welcome to the Ada Slack CLI!" tsu = SlackCLI::Workspace.new - - loop do + + loop do print "Would you like to (1) list users, (2) list channels, or (3) quit? " choice = gets.chomp.to_i until [1, 2, 3].include?(choice) - print "Sorry. Please enter '1', '2' or '3'!" - choice = gets.chomp + print "Sorry. Please enter '1', '2' or '3'! " + choice = gets.chomp.to_i end - + if choice == 1 tsu.list_users + print "Please select a user (by Slack ID or Display Name): " + user_chosen = gets.chomp + if [tsu.user_menu].include?(user_chosen) + tsu.print_details(user_chosen) + else + print "Sorry. Invalid selection." + end elsif choice == 2 tsu.list_channels + print "Please select a channel (by Slack ID or Name): " + channel_chosen = gets.chomp + if [tsu.channel_menu].include?(channel_chosen) + tsu.print_details(channel_chosen) + else + print "Sorry. Invalid selection." + end elsif choice == 3 puts "Thank you for using the Ada Slack CLI" exit end - - end + end end main diff --git a/lib/workspace.rb b/lib/workspace.rb index 4fb97e22..c960f69f 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -10,48 +10,70 @@ module SlackCLI class Workspace attr_accessor :users, :channels, :selected - + CHANNEL_URL = 'https://slack.com/api/channels.list' USER_URL = 'https://slack.com/api/users.list' GET_PARAMETERS = { token: ENV['SLACK_KEY'] } - + def initialize @users = SlackCLI::User.json_parse(SlackCLI::User.get(USER_URL, query: GET_PARAMETERS)) @channels = SlackCLI::Channel.json_parse(SlackCLI::Channel.get(CHANNEL_URL, query: GET_PARAMETERS)) @selected = nil - + puts "Workspace loaded! #{users.length} users and #{channels.length} channels available." end - + def list_users users_hash_array = [] @users.each do |user| user_hash = { "slack_id" => user.slack_id, - "display name" => user.name, - "real name" => user.real_name, + "display name" => user.name, + "real name" => user.real_name, "status text" => user.status_text, "status emoji" => user.status_emoji } users_hash_array << user_hash - end - tp users_hash_array + end + tp users_hash_array + end + + def user_menu + user_menu_array = [] + @users.each do |user| + user_menu_array << user.slack_id + user_menu_array << user.name + end + return user_menu_array end - + def list_channels channels_hash_array = [] @channels.each do |channel| channel_hash = { "slack_id" => channel.slack_id, - "name" => channel.name, + "name" => channel.name, "topic" => channel.topic, "member_count" => channel.member_count } channels_hash_array << channel_hash - end - tp channels_hash_array + end + tp channels_hash_array + end + + def channel_menu + channel_menu_array = [] + @channels.each do |channel| + channel_menu_array << channel.slack_id + channel_menu_array << channel.name + end + return channel_menu_array + end + + def print_details(selected) + end - end + end end From 086ea9ec41da18efe87fa305caa8f469c96dd625 Mon Sep 17 00:00:00 2001 From: Janice Huang Date: Wed, 11 Sep 2019 23:18:32 -0700 Subject: [PATCH 12/27] add functionality --- lib/slack.rb | 36 +++++++++++++++++++++++++----------- lib/workspace.rb | 6 +++++- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 4ff8ad51..10f75c42 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -11,32 +11,46 @@ def main tsu = SlackCLI::Workspace.new loop do - print "Would you like to (1) list users, (2) list channels, or (3) quit? " - choice = gets.chomp.to_i - until [1, 2, 3].include?(choice) - print "Sorry. Please enter '1', '2' or '3'! " - choice = gets.chomp.to_i + print "\nWhat would you like to do? + - list users + - list channels + - select user + - select channel + - show details + - quit + \nYour choice: " + choice = gets.chomp.downcase + until ["list users", "list channels", "select user", "select channel", "show details", "quit"].include?(choice) + print "Sorry. Please enter a valid choice. " + choice = gets.chomp.downcase end - if choice == 1 + if choice == "list users" tsu.list_users + elsif choice == "list channels" + tsu.list_channels + elsif choice == "select user" print "Please select a user (by Slack ID or Display Name): " user_chosen = gets.chomp if [tsu.user_menu].include?(user_chosen) - tsu.print_details(user_chosen) + selected = user_chosen else print "Sorry. Invalid selection." end - elsif choice == 2 - tsu.list_channels + elsif choice == "select channel" print "Please select a channel (by Slack ID or Name): " channel_chosen = gets.chomp if [tsu.channel_menu].include?(channel_chosen) - tsu.print_details(channel_chosen) + selected = user_chosen else print "Sorry. Invalid selection." end - elsif choice == 3 + elsif choice == "show details" + if selected == nil + puts "No user or channel chosen." + end + tsu.print_details(selected) + elsif choice == "quit" puts "Thank you for using the Ada Slack CLI" exit end diff --git a/lib/workspace.rb b/lib/workspace.rb index c960f69f..e863cca0 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -73,7 +73,11 @@ def channel_menu end def print_details(selected) - + if selected.class == User + elsif selected.class == Channel + elsif selected.class == nil + + end end end From f58d9cfe2a1b868755a2da03081be1057e2308e4 Mon Sep 17 00:00:00 2001 From: Janice Huang Date: Wed, 11 Sep 2019 23:31:21 -0700 Subject: [PATCH 13/27] get full menu up, functions mostly working --- lib/slack.rb | 17 +++++++++-------- lib/workspace.rb | 15 ++++++++++----- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 10f75c42..8e9a548d 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -25,19 +25,20 @@ def main choice = gets.chomp.downcase end - if choice == "list users" + case choice + when "list users" tsu.list_users - elsif choice == "list channels" + when "list channels" tsu.list_channels - elsif choice == "select user" + when "select user" print "Please select a user (by Slack ID or Display Name): " user_chosen = gets.chomp if [tsu.user_menu].include?(user_chosen) selected = user_chosen else - print "Sorry. Invalid selection." + print "\nSorry. Invalid selection." end - elsif choice == "select channel" + when "select channel" print "Please select a channel (by Slack ID or Name): " channel_chosen = gets.chomp if [tsu.channel_menu].include?(channel_chosen) @@ -45,12 +46,12 @@ def main else print "Sorry. Invalid selection." end - elsif choice == "show details" + when "show details" if selected == nil - puts "No user or channel chosen." + puts "\nNo user or channel chosen." end tsu.print_details(selected) - elsif choice == "quit" + when "quit" puts "Thank you for using the Ada Slack CLI" exit end diff --git a/lib/workspace.rb b/lib/workspace.rb index e863cca0..c26304fe 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -73,11 +73,16 @@ def channel_menu end def print_details(selected) - if selected.class == User - elsif selected.class == Channel - elsif selected.class == nil - - + @users.each do |user| + if user.slack_id == selected || user.name == selected + return user + end + end + @channels.each do |channel| + if channel.slack_id == selected || channel.name == selected + return channel + end + end end end end From f168335ea06eebcc2b5fba6525be6abbd844cc94 Mon Sep 17 00:00:00 2001 From: Emily Vomacka Date: Thu, 12 Sep 2019 13:05:52 -0700 Subject: [PATCH 14/27] fixed loop in slack.rb --- lib/slack.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 4b93eda0..839f899d 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -17,7 +17,6 @@ def main print "Sorry. Please enter '1', '2' or '3'!" choice = gets.chomp end - if choice == 1 tsu.list_users elsif choice == 2 @@ -26,7 +25,6 @@ def main puts "Thank you for using the Ada Slack CLI" exit end - end end From 85996b05a6fe5a4bd817a86b1d05b537ed7f07c5 Mon Sep 17 00:00:00 2001 From: Emily Vomacka Date: Thu, 12 Sep 2019 14:38:30 -0700 Subject: [PATCH 15/27] wave three done. --- lib/slack.rb | 13 +++++++++++-- lib/workspace.rb | 10 ++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 983b3b8a..d3a2ef69 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -17,10 +17,11 @@ def main - select user - select channel - show details + - send message - quit \nYour choice: " choice = gets.chomp.downcase - until ["list users", "list channels", "select user", "select channel", "show details", "quit"].include?(choice) + until ["list users", "list channels", "select user", "select channel", "show details", "send message", "quit"].include?(choice) print "Sorry. Please enter a valid choice. " choice = gets.chomp.downcase end @@ -49,7 +50,7 @@ def main tsu.selected = channel end end - if tsu.selected == nil || !(tsu.selected.slack_id == user_chosen || tsu.selected.name == user_chosen) + if tsu.selected == nil || !(tsu.selected.slack_id == channel_chosen || tsu.selected.name == channel_chosen) print "\nSorry. Invalid selection." end when "show details" @@ -58,6 +59,14 @@ def main else tsu.print_details(tsu.selected) end + when "send message" + if tsu.selected == nil + puts "\nNo user or channel chosen." + else + print "What is your message? " + msg = gets.chomp + tsu.send_message(tsu.selected, msg) + end when "quit" puts "Thank you for using the Ada Slack CLI" exit diff --git a/lib/workspace.rb b/lib/workspace.rb index 9fbbd1b2..8abac664 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -14,6 +14,7 @@ class Workspace CHANNEL_URL = 'https://slack.com/api/channels.list' USER_URL = 'https://slack.com/api/users.list' + POST_URL = 'https://slack.com/api/chat.postMessage' GET_PARAMETERS = { token: ENV['SLACK_KEY'] } @@ -81,5 +82,14 @@ def print_details(selected) print "Sorry, something went wrong." end end + + def send_message(selected, msg) + post_parameters = { + token: ENV['SLACK_KEY'], + channel: selected.slack_id, + text: msg + } + return HTTParty.post(POST_URL, query: post_parameters) + end end end \ No newline at end of file From 9a88e7951d5b508e9e15293bf71b20bfab7201ef Mon Sep 17 00:00:00 2001 From: Janice Huang Date: Thu, 12 Sep 2019 21:15:30 -0700 Subject: [PATCH 16/27] make select_user and select_channel methods in workspace.rb to move functionality out of slack.rb --- lib/slack.rb | 30 +++++------------- lib/workspace.rb | 38 ++++++++++++++++++----- test/workspace_test.rb | 69 ++++++++++++++++++++++++++++++++++++------ 3 files changed, 97 insertions(+), 40 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index d3a2ef69..7fffd34c 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -28,41 +28,27 @@ def main case choice when "list users" - tsu.list_users + tp tsu.list_users when "list channels" - tsu.list_channels + tp tsu.list_channels when "select user" print "Please select a user (by Slack ID or Display Name): " user_chosen = gets.chomp - tsu.users.each do |user| - if user.slack_id == user_chosen || user.name == user_chosen - tsu.selected = user - end - end - if tsu.selected == nil || !(tsu.selected.slack_id == user_chosen || tsu.selected.name == user_chosen) - print "\nSorry. Invalid selection." - end + puts "\nYou have selected #{tsu.select_user(user_chosen).name}" when "select channel" print "Please select a channel (by Slack ID or Name): " channel_chosen = gets.chomp - tsu.channels.each do |channel| - if channel.slack_id == channel_chosen || channel.name == channel_chosen - tsu.selected = channel - end - end - if tsu.selected == nil || !(tsu.selected.slack_id == channel_chosen || tsu.selected.name == channel_chosen) - print "\nSorry. Invalid selection." - end + puts "\nYou have selected #{tsu.select_channel(channel_chosen).name}" when "show details" if tsu.selected == nil puts "\nNo user or channel chosen." - else - tsu.print_details(tsu.selected) - end + else + tp tsu.print_details(tsu.selected) + end when "send message" if tsu.selected == nil puts "\nNo user or channel chosen." - else + else print "What is your message? " msg = gets.chomp tsu.send_message(tsu.selected, msg) diff --git a/lib/workspace.rb b/lib/workspace.rb index 8abac664..6b0d3a75 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -39,7 +39,7 @@ def list_users } users_hash_array << user_hash end - tp users_hash_array + return users_hash_array end def list_channels @@ -53,7 +53,31 @@ def list_channels } channels_hash_array << channel_hash end - tp channels_hash_array + return channels_hash_array + end + + def select_user(user_chosen) + @users.each do |user| + if user.slack_id == user_chosen || user.name == user_chosen + @selected = user + return @selected + end + end + if @selected == nil || !(@selected.slack_id == user_chosen || @selected.name == user_chosen) + print "\nSorry. Invalid selection." + end + end + + def select_channel(channel_chosen) + @channels.each do |channel| + if channel.slack_id == channel_chosen || channel.name == channel_chosen + @selected = channel + return @selected + end + end + if @selected == nil || !(@selected.slack_id == channel_chosen || @selected.name == channel_chosen) + print "\nSorry. Invalid selection." + end end def print_details(selected) @@ -67,7 +91,7 @@ def print_details(selected) "status emoji" => selected.status_emoji } ] - tp user_hash + return user_hash elsif selected.class == SlackCLI::Channel channel_hash = [ { @@ -77,10 +101,8 @@ def print_details(selected) "member_count" => selected.member_count } ] - tp channel_hash - else - print "Sorry, something went wrong." - end + return channel_hash + end end def send_message(selected, msg) @@ -92,4 +114,4 @@ def send_message(selected, msg) return HTTParty.post(POST_URL, query: post_parameters) end end -end \ No newline at end of file +end \ No newline at end of file diff --git a/test/workspace_test.rb b/test/workspace_test.rb index 5ddf0b61..1c28df93 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -1,27 +1,76 @@ require_relative 'test_helper' describe 'can create a workspace' do - - let (:workspace) { + + let (:workspace) { VCR.use_cassette("workspace.new") do SlackCLI::Workspace.new - end + end } - + it 'creates a workspace' do - expect(workspace).must_be_instance_of SlackCLI::Workspace - expect(workspace.selected).must_be_nil + expect(workspace).must_be_instance_of SlackCLI::Workspace + expect(workspace.selected).must_be_nil end - + it 'has an array of channels' do expect(workspace.channels).must_be_kind_of Array expect(workspace.channels[0]).must_be_instance_of SlackCLI::Channel - end - + end + it 'has an array of users' do expect(workspace.users).must_be_kind_of Array expect(workspace.users[0]).must_be_instance_of SlackCLI::User - end + end +end + +describe 'it can list users by returning an array of hashes to be table_printed' do + let (:workspace) { + VCR.use_cassette("workspace.new") do + SlackCLI::Workspace.new + end + } + it 'returns an array of hashes' do + expect(workspace.list_users).must_be_kind_of Array + end + it 'contains five key-value pairs in each hash' do + expect(workspace.list_users[0].length).must_equal 5 + end + it 'has slack_id as a key' do + expect(workspace.list_users.last).must_include "slack_id" + end end +describe 'it can list channels by returning an array of hashes to be table_printed' do + let (:workspace) { + VCR.use_cassette("workspace.new") do + SlackCLI::Workspace.new + end + } + it 'returns an array of hashes' do + expect(workspace.list_channels).must_be_kind_of Array + end + it 'contains four key-value pairs in each hash' do + expect(workspace.list_channels[0].length).must_equal 4 + end + it 'has slack_id as a key' do + expect(workspace.list_users.last).must_include "slack_id" + end +end +describe 'select user' do +it 'allows user to select user' +end +it ' ' +end + +describe 'prints details about selected user or channel' do + let (:workspace) { + VCR.use_cassette("workspace.new") do + SlackCLI::Workspace.new + end + } +it 'determines if the object selected is a user or a channel' +workspace. +expect +end From e4169c40711ec30ba9e1ea0e4b06894d3966fab3 Mon Sep 17 00:00:00 2001 From: Janice Huang Date: Thu, 12 Sep 2019 22:10:28 -0700 Subject: [PATCH 17/27] refactor methods' responses to invalid input. in the process of refactoring made it so previously passing tests are now failing. need to refactor tests. --- lib/slack.rb | 10 ++++----- lib/workspace.rb | 26 +++++++++++----------- test/workspace_test.rb | 50 +++++++++++++++++++++++++++++++----------- 3 files changed, 55 insertions(+), 31 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 7fffd34c..f97b02bd 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -9,7 +9,7 @@ def main puts "Welcome to the Ada Slack CLI!" tsu = SlackCLI::Workspace.new - + loop do print "\nWhat would you like to do? - list users @@ -25,7 +25,7 @@ def main print "Sorry. Please enter a valid choice. " choice = gets.chomp.downcase end - + case choice when "list users" tp tsu.list_users @@ -34,11 +34,11 @@ def main when "select user" print "Please select a user (by Slack ID or Display Name): " user_chosen = gets.chomp - puts "\nYou have selected #{tsu.select_user(user_chosen).name}" + puts tsu.select_user(user_chosen) when "select channel" print "Please select a channel (by Slack ID or Name): " channel_chosen = gets.chomp - puts "\nYou have selected #{tsu.select_channel(channel_chosen).name}" + puts tsu.select_channel(channel_chosen) when "show details" if tsu.selected == nil puts "\nNo user or channel chosen." @@ -62,4 +62,4 @@ def main main -#main if __FILE__ == $PROGRAM_NAME \ No newline at end of file +#main if __FILE__ == $PROGRAM_NAME diff --git a/lib/workspace.rb b/lib/workspace.rb index 6b0d3a75..5db8d412 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -11,22 +11,22 @@ module SlackCLI class Workspace attr_accessor :users, :channels, :selected - + CHANNEL_URL = 'https://slack.com/api/channels.list' USER_URL = 'https://slack.com/api/users.list' POST_URL = 'https://slack.com/api/chat.postMessage' GET_PARAMETERS = { token: ENV['SLACK_KEY'] } - + def initialize @users = SlackCLI::User.json_parse(SlackCLI::User.get(USER_URL, query: GET_PARAMETERS)) @channels = SlackCLI::Channel.json_parse(SlackCLI::Channel.get(CHANNEL_URL, query: GET_PARAMETERS)) @selected = nil - + puts "Workspace loaded! #{users.length} users and #{channels.length} channels available." end - + def list_users users_hash_array = [] @users.each do |user| @@ -41,7 +41,7 @@ def list_users end return users_hash_array end - + def list_channels channels_hash_array = [] @channels.each do |channel| @@ -55,31 +55,31 @@ def list_channels end return channels_hash_array end - + def select_user(user_chosen) @users.each do |user| if user.slack_id == user_chosen || user.name == user_chosen @selected = user - return @selected end end if @selected == nil || !(@selected.slack_id == user_chosen || @selected.name == user_chosen) - print "\nSorry. Invalid selection." + return "\nSorry. Invalid selection." end + return "\nYou have selected #{@selected.name}." end - + def select_channel(channel_chosen) @channels.each do |channel| if channel.slack_id == channel_chosen || channel.name == channel_chosen @selected = channel - return @selected end end if @selected == nil || !(@selected.slack_id == channel_chosen || @selected.name == channel_chosen) - print "\nSorry. Invalid selection." + return "\nSorry. Invalid selection." end + return "\nYou have selected #{@selected.name}." end - + def print_details(selected) if selected.class == SlackCLI::User user_hash = [ @@ -104,7 +104,7 @@ def print_details(selected) return channel_hash end end - + def send_message(selected, msg) post_parameters = { token: ENV['SLACK_KEY'], diff --git a/test/workspace_test.rb b/test/workspace_test.rb index 1c28df93..23335b8d 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -31,13 +31,13 @@ end } it 'returns an array of hashes' do - expect(workspace.list_users).must_be_kind_of Array + expect(workspace.list_users).must_be_kind_of Array end it 'contains five key-value pairs in each hash' do - expect(workspace.list_users[0].length).must_equal 5 + expect(workspace.list_users[0].length).must_equal 5 end it 'has slack_id as a key' do - expect(workspace.list_users.last).must_include "slack_id" + expect(workspace.list_users.last).must_include "slack_id" end end @@ -48,20 +48,34 @@ end } it 'returns an array of hashes' do - expect(workspace.list_channels).must_be_kind_of Array + expect(workspace.list_channels).must_be_kind_of Array end it 'contains four key-value pairs in each hash' do - expect(workspace.list_channels[0].length).must_equal 4 + expect(workspace.list_channels[0].length).must_equal 4 end it 'has slack_id as a key' do - expect(workspace.list_users.last).must_include "slack_id" + expect(workspace.list_users.last).must_include "slack_id" end end describe 'select user' do -it 'allows user to select user' -end -it ' ' + let (:workspace) { + VCR.use_cassette("workspace.new") do + SlackCLI::Workspace.new + end + } + it 'allows user to select user' do + expect(workspace.select_user("Slackbot")).must_be_instance_of SlackCLI::User + end + it "puts an 'invalid' msg when not a known user" do + expect(workspace.select_user("Mr. T")).must_include "Invalid" + end + it 'allows user to select channel' do + expect(workspace.select_channel("random")).must_be_instance_of SlackCLI::Channel + end + it "puts an 'invalid' msg when not a known channel" do + expect(workspace.select_channel("MTV")).must_include "Invalid" + end end describe 'prints details about selected user or channel' do @@ -70,7 +84,17 @@ SlackCLI::Workspace.new end } -it 'determines if the object selected is a user or a channel' -workspace. -expect -end + it 'determines if the object selected is a user or a channel' do + selected = workspace.select_channel(random) + expect(workspace.print_details(selected)).must_be_kind_of Array + selected = workspace.select_channel(random) + expect(workspace.print_details(selected).length).must_equal 5 + selected = workspace.select_user(Slackbot) + expect(workspace.print_details(selected)).must_be_kind_of Array + selected = workspace.select_user(Slackbot) + expect(workspace.print_details(selected).length).must_equal 4 + end + it 'complains when no user or channel is selected' do + expect(workspace.print_details(@selected)).must_include "Invalid" + end +end \ No newline at end of file From c48294fe9378530d2e9c75156a6eec0232e5d34f Mon Sep 17 00:00:00 2001 From: Janice Huang Date: Thu, 12 Sep 2019 22:54:17 -0700 Subject: [PATCH 18/27] refactor selection methods --- lib/slack.rb | 15 +++++++++++++-- lib/workspace.rb | 28 +++++++++++----------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index f97b02bd..ec1550e4 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -31,14 +31,25 @@ def main tp tsu.list_users when "list channels" tp tsu.list_channels + ## make helper method for validation to DRY up code when "select user" print "Please select a user (by Slack ID or Display Name): " user_chosen = gets.chomp - puts tsu.select_user(user_chosen) + choice = tsu.select_user(user_chosen) + if choice == nil || !(choice.slack_id == user_chosen || choice.name == user_chosen) + puts "\nSorry. Invalid selection." + else + puts "\nYou have selected #{choice.name}" + end when "select channel" print "Please select a channel (by Slack ID or Name): " channel_chosen = gets.chomp - puts tsu.select_channel(channel_chosen) + choice = tsu.select_channel(channel_chosen) + if choice == nil || !(choice.slack_id == channel_chosen || choice.name == channel_chosen) + puts "\nSorry. Invalid selection." + else + puts "\nYou have selected #{choice.name}" + end when "show details" if tsu.selected == nil puts "\nNo user or channel chosen." diff --git a/lib/workspace.rb b/lib/workspace.rb index 5db8d412..df267e67 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -11,22 +11,22 @@ module SlackCLI class Workspace attr_accessor :users, :channels, :selected - + CHANNEL_URL = 'https://slack.com/api/channels.list' USER_URL = 'https://slack.com/api/users.list' POST_URL = 'https://slack.com/api/chat.postMessage' GET_PARAMETERS = { token: ENV['SLACK_KEY'] } - + def initialize @users = SlackCLI::User.json_parse(SlackCLI::User.get(USER_URL, query: GET_PARAMETERS)) @channels = SlackCLI::Channel.json_parse(SlackCLI::Channel.get(CHANNEL_URL, query: GET_PARAMETERS)) @selected = nil - + puts "Workspace loaded! #{users.length} users and #{channels.length} channels available." end - + def list_users users_hash_array = [] @users.each do |user| @@ -41,7 +41,7 @@ def list_users end return users_hash_array end - + def list_channels channels_hash_array = [] @channels.each do |channel| @@ -55,31 +55,25 @@ def list_channels end return channels_hash_array end - + def select_user(user_chosen) @users.each do |user| if user.slack_id == user_chosen || user.name == user_chosen @selected = user end end - if @selected == nil || !(@selected.slack_id == user_chosen || @selected.name == user_chosen) - return "\nSorry. Invalid selection." - end - return "\nYou have selected #{@selected.name}." + return @selected end - + def select_channel(channel_chosen) @channels.each do |channel| if channel.slack_id == channel_chosen || channel.name == channel_chosen @selected = channel end end - if @selected == nil || !(@selected.slack_id == channel_chosen || @selected.name == channel_chosen) - return "\nSorry. Invalid selection." - end - return "\nYou have selected #{@selected.name}." + return @selected end - + def print_details(selected) if selected.class == SlackCLI::User user_hash = [ @@ -104,7 +98,7 @@ def print_details(selected) return channel_hash end end - + def send_message(selected, msg) post_parameters = { token: ENV['SLACK_KEY'], From 81a787c9930828a901784543a7b7b619d0d633cf Mon Sep 17 00:00:00 2001 From: Janice Huang Date: Thu, 12 Sep 2019 22:58:16 -0700 Subject: [PATCH 19/27] add single quotes for parameters --- test/workspace_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/workspace_test.rb b/test/workspace_test.rb index 23335b8d..8ea703e4 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -85,13 +85,13 @@ end } it 'determines if the object selected is a user or a channel' do - selected = workspace.select_channel(random) + selected = workspace.select_channel('random') expect(workspace.print_details(selected)).must_be_kind_of Array - selected = workspace.select_channel(random) + selected = workspace.select_channel('random') expect(workspace.print_details(selected).length).must_equal 5 - selected = workspace.select_user(Slackbot) + selected = workspace.select_user('Slackbot') expect(workspace.print_details(selected)).must_be_kind_of Array - selected = workspace.select_user(Slackbot) + selected = workspace.select_user('Slackbot') expect(workspace.print_details(selected).length).must_equal 4 end it 'complains when no user or channel is selected' do From 1c0620d37d53c335586650324194994341f10045 Mon Sep 17 00:00:00 2001 From: Emily Vomacka Date: Thu, 12 Sep 2019 23:36:16 -0700 Subject: [PATCH 20/27] light refactor --- lib/channel.rb | 8 ++++++-- lib/recipient.rb | 31 +++++++++++++++++++++++++++---- lib/slack.rb | 20 ++++++++------------ lib/workspace.rb | 11 ----------- test/recipient_test.rb | 19 ++++++++++++++++++- 5 files changed, 59 insertions(+), 30 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 3e367153..ef744d87 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -7,13 +7,13 @@ module SlackCLI class Channel < Recipient attr_reader :slack_id, :name, :topic, :member_count - + def initialize(slack_id, name, topic, member_count) super(slack_id, name) @topic = topic @member_count = member_count end - + #factory method for producing individual channels from json def self.json_parse(json) channels = [] @@ -23,6 +23,10 @@ def self.json_parse(json) end return channels end + + def to_s + "#{super}, about #{topic}" + end end end diff --git a/lib/recipient.rb b/lib/recipient.rb index bdd6fdaa..b192adaa 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -7,19 +7,42 @@ module SlackCLI class Recipient attr_reader :slack_id, :name + POST_URL = 'https://slack.com/api/chat.postMessage' + def initialize(slack_id, name) @slack_id = slack_id @name = name end - def send_message - end + def send_message(msg) + post_parameters = { + token: ENV['SLACK_KEY'], + channel: self.slack_id, + text: msg + } + response = HTTParty.post(POST_URL, query: post_parameters) + if response.code == 200 + puts "Message sent successfully." + else + puts "Message not sent, error code #{response.code}." + end + end + + def to_s + "#{name}, #{slack_id}" + end def self.get(url, query) response = HTTParty.get(url, query) end + + def details + raise NotImplementedError, 'Implement me in a child class!' + end + + def self.list + raise NotImplementedError, 'Implement me in a child class!' + end end end -# details and self.list are abstract class methods -# raise NotImplementedError, 'Implement me in a child class!' \ No newline at end of file diff --git a/lib/slack.rb b/lib/slack.rb index d3a2ef69..d74d92ab 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -34,24 +34,20 @@ def main when "select user" print "Please select a user (by Slack ID or Display Name): " user_chosen = gets.chomp - tsu.users.each do |user| - if user.slack_id == user_chosen || user.name == user_chosen - tsu.selected = user - end - end + tsu.selected = tsu.users.find { |user| user.slack_id == user_chosen || user.name == user_chosen } if tsu.selected == nil || !(tsu.selected.slack_id == user_chosen || tsu.selected.name == user_chosen) print "\nSorry. Invalid selection." + else + puts "\n#{tsu.selected.name} has been selected." end when "select channel" print "Please select a channel (by Slack ID or Name): " channel_chosen = gets.chomp - tsu.channels.each do |channel| - if channel.slack_id == channel_chosen || channel.name == channel_chosen - tsu.selected = channel - end - end + tsu.selected = tsu.channels.find { |channel| channel.slack_id == channel_chosen || channel.name == channel_chosen } if tsu.selected == nil || !(tsu.selected.slack_id == channel_chosen || tsu.selected.name == channel_chosen) - print "\nSorry. Invalid selection." + puts "\nSorry. Invalid selection." + else + puts "\n#{tsu.selected.name} has been selected." end when "show details" if tsu.selected == nil @@ -65,7 +61,7 @@ def main else print "What is your message? " msg = gets.chomp - tsu.send_message(tsu.selected, msg) + tsu.selected.send_message(msg) end when "quit" puts "Thank you for using the Ada Slack CLI" diff --git a/lib/workspace.rb b/lib/workspace.rb index 8abac664..3a47eec4 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,7 +1,6 @@ require 'httparty' require 'dotenv' require 'table_print' -require 'awesome_print' require_relative 'user' require_relative 'channel' require_relative 'recipient' @@ -14,7 +13,6 @@ class Workspace CHANNEL_URL = 'https://slack.com/api/channels.list' USER_URL = 'https://slack.com/api/users.list' - POST_URL = 'https://slack.com/api/chat.postMessage' GET_PARAMETERS = { token: ENV['SLACK_KEY'] } @@ -82,14 +80,5 @@ def print_details(selected) print "Sorry, something went wrong." end end - - def send_message(selected, msg) - post_parameters = { - token: ENV['SLACK_KEY'], - channel: selected.slack_id, - text: msg - } - return HTTParty.post(POST_URL, query: post_parameters) - end end end \ No newline at end of file diff --git a/test/recipient_test.rb b/test/recipient_test.rb index bc122f76..aa6d83fe 100644 --- a/test/recipient_test.rb +++ b/test/recipient_test.rb @@ -1,2 +1,19 @@ -module SlackCLI +require_relative 'test_helper' + + + + describe 'send message' do + before do + VCR.use_cassette("recipient.send_message") do + query_parameters = { + token: ENV['SLACK_KEY'] + } + @users_json = SlackCLI::Recipient.get('https://slack.com/api/users.list',query: query_parameters) + end + @users = SlackCLI::User.json_parse(@users_json) + end + + it 'creates an array' do + expect(@users).must_be_kind_of Array + end end \ No newline at end of file From 58805c1c395ebf8e39cea7647bb52c0ca43c228b Mon Sep 17 00:00:00 2001 From: Janice Huang Date: Fri, 13 Sep 2019 08:21:38 -0700 Subject: [PATCH 21/27] change tests to look for nil instead of 'invalid' string because moved puts statements to driver code --- lib/slack.rb | 2 +- test/workspace_test.rb | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index ec1550e4..0579dc41 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -31,7 +31,7 @@ def main tp tsu.list_users when "list channels" tp tsu.list_channels - ## make helper method for validation to DRY up code + ## make helper method for validation to DRY up code, here (select user and channel) and in print details when "select user" print "Please select a user (by Slack ID or Display Name): " user_chosen = gets.chomp diff --git a/test/workspace_test.rb b/test/workspace_test.rb index 8ea703e4..3431b21f 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -67,14 +67,14 @@ it 'allows user to select user' do expect(workspace.select_user("Slackbot")).must_be_instance_of SlackCLI::User end - it "puts an 'invalid' msg when not a known user" do - expect(workspace.select_user("Mr. T")).must_include "Invalid" + it "returns nil when not a known user" do + expect(workspace.select_user("Mr. T")).must_be_nil end it 'allows user to select channel' do expect(workspace.select_channel("random")).must_be_instance_of SlackCLI::Channel end - it "puts an 'invalid' msg when not a known channel" do - expect(workspace.select_channel("MTV")).must_include "Invalid" + it "returns nil when not a known channel" do + expect(workspace.select_channel("MTV")).must_be_nil end end @@ -88,13 +88,13 @@ selected = workspace.select_channel('random') expect(workspace.print_details(selected)).must_be_kind_of Array selected = workspace.select_channel('random') - expect(workspace.print_details(selected).length).must_equal 5 + expect(workspace.print_details(selected)[0].length).must_equal 4 selected = workspace.select_user('Slackbot') expect(workspace.print_details(selected)).must_be_kind_of Array selected = workspace.select_user('Slackbot') - expect(workspace.print_details(selected).length).must_equal 4 + expect(workspace.print_details(selected)[0].length).must_equal 5 end - it 'complains when no user or channel is selected' do - expect(workspace.print_details(@selected)).must_include "Invalid" + it 'returns nil no user or channel is selected' do + expect(workspace.print_details(@selected)).must_be_nil end end \ No newline at end of file From 7c725b64d09daff15b220528c91a39d9fa5a240d Mon Sep 17 00:00:00 2001 From: Emily Vomacka Date: Fri, 13 Sep 2019 09:02:33 -0700 Subject: [PATCH 22/27] added a few tests --- lib/recipient.rb | 4 +- test/cassettes/recipient_send_message.yml | 89 +++++++++++++++++++++++ test/recipient_test.rb | 11 +-- test/user_test.rb | 18 +++++ 4 files changed, 109 insertions(+), 13 deletions(-) create mode 100644 test/cassettes/recipient_send_message.yml diff --git a/lib/recipient.rb b/lib/recipient.rb index b192adaa..f1901ae2 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -7,8 +7,6 @@ module SlackCLI class Recipient attr_reader :slack_id, :name - POST_URL = 'https://slack.com/api/chat.postMessage' - def initialize(slack_id, name) @slack_id = slack_id @name = name @@ -20,7 +18,7 @@ def send_message(msg) channel: self.slack_id, text: msg } - response = HTTParty.post(POST_URL, query: post_parameters) + response = HTTParty.post('https://slack.com/api/chat.postMessage', query: post_parameters) if response.code == 200 puts "Message sent successfully." else diff --git a/test/cassettes/recipient_send_message.yml b/test/cassettes/recipient_send_message.yml new file mode 100644 index 00000000..c70fdafe --- /dev/null +++ b/test/cassettes/recipient_send_message.yml @@ -0,0 +1,89 @@ +--- +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: + - '1633' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 06:39:17 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 855c23ea-0565-4962-a56f-0d36f1a0da8f + 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-qt4f + X-Cache: + - Miss from cloudfront + Via: + - 1.1 5afc8eca980390e71a86518c6f90001a.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19 + X-Amz-Cf-Id: + - ceg79teeofYp6DKrNBfc_Gl_ag6JneU_6VKTlV8dIxBx74KY_9EQLw== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TMTG7023U","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":"TMTG7023U"},"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":"UMTG87PC2","team_id":"TMTG7023U","name":"nickyjinchoi","deleted":false,"color":"674b1b","real_name":"Nicky + Choi","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Nicky + Choi","real_name_normalized":"Nicky Choi","display_name":"Nicky Choi","display_name_normalized":"Nicky + Choi","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g6e33044e4c8","image_24":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568071993,"has_2fa":false},{"id":"UN69SEW21","team_id":"TMTG7023U","name":"idhallie","deleted":false,"color":"e7392d","real_name":"Hallie + Johnson","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Hallie + Johnson","real_name_normalized":"Hallie Johnson","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g23bc7b83db4","image_24":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568072412,"has_2fa":false},{"id":"UN69SF69K","team_id":"TMTG7023U","name":"yitgop.yyhxox","deleted":false,"color":"3c989f","real_name":"Yitgop + Y.","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Yitgop + Y.","real_name_normalized":"Yitgop Y.","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gb749eeae508","image_24":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568072069,"has_2fa":false},{"id":"UN69TR3N1","team_id":"TMTG7023U","name":"elizabethjnorthrop","deleted":false,"color":"e0a729","real_name":"Elizabeth + Northrop","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Elizabeth + Northrop","real_name_normalized":"Elizabeth Northrop","display_name":"Elizabeth + Northrop","display_name_normalized":"Elizabeth Northrop","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g555bff2ee78","image_24":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568072090,"has_2fa":false},{"id":"UN85KFVNK","team_id":"TMTG7023U","name":"emilyvomacka","deleted":false,"color":"9f69e7","real_name":"Emily + Vomacka","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Emily + Vomacka","real_name_normalized":"Emily Vomacka","display_name":"Emily V","display_name_normalized":"Emily + V","status_text":"Vacationing indefinitely","status_emoji":":sunglasses:","status_expiration":0,"avatar_hash":"g319432559c3","first_name":"Emily","last_name":"Vomacka","image_24":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568242889,"has_2fa":false},{"id":"UN85LNJMV","team_id":"TMTG7023U","name":"janicehuang","deleted":false,"color":"4bbe2e","real_name":"janice","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"janice","real_name_normalized":"janice","display_name":"janice","display_name_normalized":"janice","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g73010028c3d","image_24":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568071984,"has_2fa":false},{"id":"UN85LQ0HM","team_id":"TMTG7023U","name":"elizabethjnorthrup","deleted":true,"profile":{"title":"","phone":"","skype":"","real_name":"elizabethjnorthrup","real_name_normalized":"elizabethjnorthrup","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g0b2f1d21275","first_name":"","last_name":"","image_24":"https:\/\/secure.gravatar.com\/avatar\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-512.png","status_text_canonical":"","team":"TMTG7023U"},"is_bot":false,"is_app_user":false,"updated":1568072109,"is_invited_user":true}],"cache_ts":1568356757,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Fri, 13 Sep 2019 06:39:18 GMT +recorded_with: VCR 5.0.0 diff --git a/test/recipient_test.rb b/test/recipient_test.rb index aa6d83fe..4d8cddbf 100644 --- a/test/recipient_test.rb +++ b/test/recipient_test.rb @@ -2,16 +2,7 @@ - describe 'send message' do - before do - VCR.use_cassette("recipient.send_message") do - query_parameters = { - token: ENV['SLACK_KEY'] - } - @users_json = SlackCLI::Recipient.get('https://slack.com/api/users.list',query: query_parameters) - end - @users = SlackCLI::User.json_parse(@users_json) - end + it 'creates an array' do expect(@users).must_be_kind_of Array diff --git a/test/user_test.rb b/test/user_test.rb index 54417bab..5d8d7df0 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -48,4 +48,22 @@ it 'creates an array of Users' do expect(@users[0]).must_be_instance_of SlackCLI::User end + + describe 'User.send_message' do + let (:workspace) { + VCR.use_cassette("workspace.new") do + SlackCLI::Workspace.new + end + } + let (:msg) { + slackbot = workspace.select_user + VCR.use_cassette("send_msg_to_Slackbot") do + + } + + @msg_json = selected.send_message('hot potato') + end + end + + it "tests " end From 56cae3a1e7cc67d2b8bc7a35ee32d60045fabccd Mon Sep 17 00:00:00 2001 From: Emily Vomacka Date: Fri, 13 Sep 2019 13:59:46 -0700 Subject: [PATCH 23/27] add helper method for invalid input --- lib/slack.rb | 16 ++++++++++++---- lib/workspace.rb | 14 ++------------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index f3b49d51..1a826422 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -6,10 +6,18 @@ require_relative 'workspace' Dotenv.load + +def invalid_input(input) + if input == nil + print "\nSorry. Invalid selection." + end +end + + def main puts "Welcome to the Ada Slack CLI!" tsu = SlackCLI::Workspace.new - + loop do print "\nWhat would you like to do? - list users @@ -25,7 +33,7 @@ def main print "Sorry. Please enter a valid choice. " choice = gets.chomp.downcase end - + case choice when "list users" tp tsu.list_users @@ -35,7 +43,7 @@ def main when "select user" print "Please select a user (by Slack ID or Display Name): " user_chosen = gets.chomp - tsu.selected = tsu.users.find { |user| user.slack_id == user_chosen || user.name == user_chosen } + tsu.selected = tsu.select_user(user_chosen) if tsu.selected == nil || !(tsu.selected.slack_id == user_chosen || tsu.selected.name == user_chosen) print "\nSorry. Invalid selection." else @@ -44,7 +52,7 @@ def main when "select channel" print "Please select a channel (by Slack ID or Name): " channel_chosen = gets.chomp - tsu.selected = tsu.channels.find { |channel| channel.slack_id == channel_chosen || channel.name == channel_chosen } + tsu.selected = tsu.select_channel(channel_chosen) if tsu.selected == nil || !(tsu.selected.slack_id == channel_chosen || tsu.selected.name == channel_chosen) puts "\nSorry. Invalid selection." else diff --git a/lib/workspace.rb b/lib/workspace.rb index ab367574..3d5fcaf4 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -55,21 +55,11 @@ def list_channels end def select_user(user_chosen) - @users.each do |user| - if user.slack_id == user_chosen || user.name == user_chosen - @selected = user - end - end - return @selected + return @users.find { |user| user.slack_id == user_chosen || user.name == user_chosen } end def select_channel(channel_chosen) - @channels.each do |channel| - if channel.slack_id == channel_chosen || channel.name == channel_chosen - @selected = channel - end - end - return @selected + return @channels.find { |channel| channel.slack_id == channel_chosen || channel.name == channel_chosen } end def print_details(selected) From 435efba3e709f1077a7fadccf28a32ddb773eb7d Mon Sep 17 00:00:00 2001 From: Emily Vomacka Date: Fri, 13 Sep 2019 14:39:41 -0700 Subject: [PATCH 24/27] 2:39, all tests passing --- lib/recipient.rb | 4 ---- lib/slack.rb | 36 ++++++++++++++++-------------------- lib/workspace.rb | 4 ++-- test/recipient_test.rb | 10 ---------- test/user_test.rb | 9 ++++----- 5 files changed, 22 insertions(+), 41 deletions(-) delete mode 100644 test/recipient_test.rb diff --git a/lib/recipient.rb b/lib/recipient.rb index f1901ae2..a3ffa859 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -37,10 +37,6 @@ def self.get(url, query) def details raise NotImplementedError, 'Implement me in a child class!' end - - def self.list - raise NotImplementedError, 'Implement me in a child class!' - end end end diff --git a/lib/slack.rb b/lib/slack.rb index 1a826422..054b77bb 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -7,12 +7,21 @@ Dotenv.load -def invalid_input(input) +def invalid_input_check(input) if input == nil print "\nSorry. Invalid selection." + return true + else + puts "\n#{input.name} has been selected." end end +def selected_is_nil(selected) + if selected == nil + puts "\nNo user or channel selected." + return true + end +end def main puts "Welcome to the Ada Slack CLI!" @@ -30,7 +39,7 @@ def main \nYour choice: " choice = gets.chomp.downcase until ["list users", "list channels", "select user", "select channel", "show details", "send message", "quit"].include?(choice) - print "Sorry. Please enter a valid choice. " + print "\nSorry. Please enter a valid choice. " choice = gets.chomp.downcase end @@ -39,35 +48,22 @@ def main tp tsu.list_users when "list channels" tp tsu.list_channels - ## make helper method for validation to DRY up code, here (select user and channel) and in print details when "select user" print "Please select a user (by Slack ID or Display Name): " user_chosen = gets.chomp tsu.selected = tsu.select_user(user_chosen) - if tsu.selected == nil || !(tsu.selected.slack_id == user_chosen || tsu.selected.name == user_chosen) - print "\nSorry. Invalid selection." - else - puts "\n#{tsu.selected.name} has been selected." - end + invalid_input_check(tsu.selected) when "select channel" print "Please select a channel (by Slack ID or Name): " channel_chosen = gets.chomp tsu.selected = tsu.select_channel(channel_chosen) - if tsu.selected == nil || !(tsu.selected.slack_id == channel_chosen || tsu.selected.name == channel_chosen) - puts "\nSorry. Invalid selection." - else - puts "\n#{tsu.selected.name} has been selected." - end + invalid_input_check(tsu.selected) when "show details" - if tsu.selected == nil - puts "\nNo user or channel chosen." - else + if !selected_is_nil(tsu.selected) tp tsu.print_details(tsu.selected) - end + end when "send message" - if tsu.selected == nil - puts "\nNo user or channel chosen." - else + if !selected_is_nil(tsu.selected) print "What is your message? " msg = gets.chomp tsu.selected.send_message(msg) diff --git a/lib/workspace.rb b/lib/workspace.rb index 3d5fcaf4..875c1e15 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -55,13 +55,13 @@ def list_channels end def select_user(user_chosen) - return @users.find { |user| user.slack_id == user_chosen || user.name == user_chosen } + selected_user = @users.find { |user| user.slack_id == user_chosen || user.name == user_chosen } end def select_channel(channel_chosen) return @channels.find { |channel| channel.slack_id == channel_chosen || channel.name == channel_chosen } end - + def print_details(selected) if selected.class == SlackCLI::User user_hash = [ diff --git a/test/recipient_test.rb b/test/recipient_test.rb deleted file mode 100644 index 4d8cddbf..00000000 --- a/test/recipient_test.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative 'test_helper' - - - - - - it 'creates an array' do - expect(@users).must_be_kind_of Array - end -end \ No newline at end of file diff --git a/test/user_test.rb b/test/user_test.rb index 5d8d7df0..ee74192d 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -48,7 +48,7 @@ it 'creates an array of Users' do expect(@users[0]).must_be_instance_of SlackCLI::User end - + describe 'User.send_message' do let (:workspace) { VCR.use_cassette("workspace.new") do @@ -58,12 +58,11 @@ let (:msg) { slackbot = workspace.select_user VCR.use_cassette("send_msg_to_Slackbot") do - + } - + @msg_json = selected.send_message('hot potato') end end - - it "tests " + end From 0ca4685ea36ce4ae20d102297dd087ded8401d68 Mon Sep 17 00:00:00 2001 From: Janice Huang Date: Fri, 13 Sep 2019 15:01:15 -0700 Subject: [PATCH 25/27] made finishing touches --- lib/channel.rb | 13 ++++++------- lib/recipient.rb | 23 +++++++++++------------ lib/user.rb | 6 +++--- lib/workspace.rb | 4 ++-- test/workspace_test.rb | 13 +++++++------ 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index ef744d87..50544fe1 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -7,13 +7,13 @@ module SlackCLI class Channel < Recipient attr_reader :slack_id, :name, :topic, :member_count - + def initialize(slack_id, name, topic, member_count) super(slack_id, name) @topic = topic @member_count = member_count end - + #factory method for producing individual channels from json def self.json_parse(json) channels = [] @@ -23,10 +23,9 @@ def self.json_parse(json) end return channels end - - def to_s - "#{super}, about #{topic}" - end + + def to_s + "#{super}, about #{topic}" + end end end - diff --git a/lib/recipient.rb b/lib/recipient.rb index a3ffa859..c0adca8f 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -5,13 +5,13 @@ module SlackCLI class Recipient - attr_reader :slack_id, :name - + attr_reader :slack_id, :name + def initialize(slack_id, name) @slack_id = slack_id @name = name end - + def send_message(msg) post_parameters = { token: ENV['SLACK_KEY'], @@ -21,22 +21,21 @@ def send_message(msg) response = HTTParty.post('https://slack.com/api/chat.postMessage', query: post_parameters) if response.code == 200 puts "Message sent successfully." - else + else puts "Message not sent, error code #{response.code}." end - end - + end + def to_s "#{name}, #{slack_id}" - end - + end + def self.get(url, query) response = HTTParty.get(url, query) end - - def details + + def details raise NotImplementedError, 'Implement me in a child class!' - end + end end end - diff --git a/lib/user.rb b/lib/user.rb index 14c3abc6..60028cfb 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -6,7 +6,7 @@ module SlackCLI class User < Recipient - + attr_reader :real_name, :status_text, :status_emoji def initialize(slack_id, name, real_name, status_text, status_emoji = nil) super(slack_id, name) @@ -14,7 +14,7 @@ def initialize(slack_id, name, real_name, status_text, status_emoji = nil) @status_text = status_text @status_emoji = status_emoji end - + #factory method for producing individual users from json def self.json_parse(json) users = [] @@ -25,4 +25,4 @@ def self.json_parse(json) return users end end -end \ No newline at end of file +end diff --git a/lib/workspace.rb b/lib/workspace.rb index 875c1e15..60a5e28d 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -61,7 +61,7 @@ def select_user(user_chosen) def select_channel(channel_chosen) return @channels.find { |channel| channel.slack_id == channel_chosen || channel.name == channel_chosen } end - + def print_details(selected) if selected.class == SlackCLI::User user_hash = [ @@ -87,4 +87,4 @@ def print_details(selected) end end end -end \ No newline at end of file +end diff --git a/test/workspace_test.rb b/test/workspace_test.rb index 3431b21f..eb6adcbc 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -12,12 +12,10 @@ expect(workspace).must_be_instance_of SlackCLI::Workspace expect(workspace.selected).must_be_nil end - it 'has an array of channels' do expect(workspace.channels).must_be_kind_of Array expect(workspace.channels[0]).must_be_instance_of SlackCLI::Channel end - it 'has an array of users' do expect(workspace.users).must_be_kind_of Array expect(workspace.users[0]).must_be_instance_of SlackCLI::User @@ -64,13 +62,13 @@ SlackCLI::Workspace.new end } - it 'allows user to select user' do + it 'allows user to select user and returns User object' do expect(workspace.select_user("Slackbot")).must_be_instance_of SlackCLI::User end it "returns nil when not a known user" do expect(workspace.select_user("Mr. T")).must_be_nil end - it 'allows user to select channel' do + it 'allows user to select channel and returns Channel object' do expect(workspace.select_channel("random")).must_be_instance_of SlackCLI::Channel end it "returns nil when not a known channel" do @@ -87,14 +85,17 @@ it 'determines if the object selected is a user or a channel' do selected = workspace.select_channel('random') expect(workspace.print_details(selected)).must_be_kind_of Array + selected = workspace.select_channel('random') expect(workspace.print_details(selected)[0].length).must_equal 4 + selected = workspace.select_user('Slackbot') expect(workspace.print_details(selected)).must_be_kind_of Array + selected = workspace.select_user('Slackbot') expect(workspace.print_details(selected)[0].length).must_equal 5 end - it 'returns nil no user or channel is selected' do + it 'returns nil if no user or channel is selected' do expect(workspace.print_details(@selected)).must_be_nil end -end \ No newline at end of file +end From f50072641ccec42de2038ebf9b451aef22d3dee5 Mon Sep 17 00:00:00 2001 From: Emily Vomacka Date: Fri, 13 Sep 2019 15:03:05 -0700 Subject: [PATCH 26/27] final commit, final final: --- lib/channel.rb | 4 - lib/recipient.rb | 12 +-- test/cassettes/recipient_send_message.yml | 89 ----------------------- test/cassettes/send_msg_to_Slackbot.yml | 75 +++++++++++++++++++ test/user_test.rb | 26 ++++--- 5 files changed, 91 insertions(+), 115 deletions(-) delete mode 100644 test/cassettes/recipient_send_message.yml create mode 100644 test/cassettes/send_msg_to_Slackbot.yml diff --git a/lib/channel.rb b/lib/channel.rb index ef744d87..1a3c0c80 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -23,10 +23,6 @@ def self.json_parse(json) end return channels end - - def to_s - "#{super}, about #{topic}" - end end end diff --git a/lib/recipient.rb b/lib/recipient.rb index a3ffa859..96f3ab5b 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -24,19 +24,11 @@ def send_message(msg) else puts "Message not sent, error code #{response.code}." end - end - - def to_s - "#{name}, #{slack_id}" + return response end def self.get(url, query) response = HTTParty.get(url, query) end - - def details - raise NotImplementedError, 'Implement me in a child class!' - end end -end - +end \ No newline at end of file diff --git a/test/cassettes/recipient_send_message.yml b/test/cassettes/recipient_send_message.yml deleted file mode 100644 index c70fdafe..00000000 --- a/test/cassettes/recipient_send_message.yml +++ /dev/null @@ -1,89 +0,0 @@ ---- -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: - - '1633' - Connection: - - keep-alive - Date: - - Fri, 13 Sep 2019 06:39:17 GMT - Server: - - Apache - X-Content-Type-Options: - - nosniff - X-Slack-Req-Id: - - 855c23ea-0565-4962-a56f-0d36f1a0da8f - 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-qt4f - X-Cache: - - Miss from cloudfront - Via: - - 1.1 5afc8eca980390e71a86518c6f90001a.cloudfront.net (CloudFront) - X-Amz-Cf-Pop: - - SEA19 - X-Amz-Cf-Id: - - ceg79teeofYp6DKrNBfc_Gl_ag6JneU_6VKTlV8dIxBx74KY_9EQLw== - body: - encoding: ASCII-8BIT - string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TMTG7023U","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":"TMTG7023U"},"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":"UMTG87PC2","team_id":"TMTG7023U","name":"nickyjinchoi","deleted":false,"color":"674b1b","real_name":"Nicky - Choi","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Nicky - Choi","real_name_normalized":"Nicky Choi","display_name":"Nicky Choi","display_name_normalized":"Nicky - Choi","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g6e33044e4c8","image_24":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/6e33044e4c8b33fd0f9c91d1336ba76e.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568071993,"has_2fa":false},{"id":"UN69SEW21","team_id":"TMTG7023U","name":"idhallie","deleted":false,"color":"e7392d","real_name":"Hallie - Johnson","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Hallie - Johnson","real_name_normalized":"Hallie Johnson","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g23bc7b83db4","image_24":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/23bc7b83db4e9e1b8078233de714be6c.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0008-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568072412,"has_2fa":false},{"id":"UN69SF69K","team_id":"TMTG7023U","name":"yitgop.yyhxox","deleted":false,"color":"3c989f","real_name":"Yitgop - Y.","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Yitgop - Y.","real_name_normalized":"Yitgop Y.","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gb749eeae508","image_24":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/b749eeae50850c3cdee8b13970b317bf.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568072069,"has_2fa":false},{"id":"UN69TR3N1","team_id":"TMTG7023U","name":"elizabethjnorthrop","deleted":false,"color":"e0a729","real_name":"Elizabeth - Northrop","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Elizabeth - Northrop","real_name_normalized":"Elizabeth Northrop","display_name":"Elizabeth - Northrop","display_name_normalized":"Elizabeth Northrop","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g555bff2ee78","image_24":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/555bff2ee78501c207120cb173f73606.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0009-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568072090,"has_2fa":false},{"id":"UN85KFVNK","team_id":"TMTG7023U","name":"emilyvomacka","deleted":false,"color":"9f69e7","real_name":"Emily - Vomacka","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Emily - Vomacka","real_name_normalized":"Emily Vomacka","display_name":"Emily V","display_name_normalized":"Emily - V","status_text":"Vacationing indefinitely","status_emoji":":sunglasses:","status_expiration":0,"avatar_hash":"g319432559c3","first_name":"Emily","last_name":"Vomacka","image_24":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/319432559c3a057a8391e5e08c4dd308.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0010-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568242889,"has_2fa":false},{"id":"UN85LNJMV","team_id":"TMTG7023U","name":"janicehuang","deleted":false,"color":"4bbe2e","real_name":"janice","tz":"America\/Los_Angeles","tz_label":"Pacific - Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"janice","real_name_normalized":"janice","display_name":"janice","display_name_normalized":"janice","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g73010028c3d","image_24":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/73010028c3d67aa8022066545539f519.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-512.png","status_text_canonical":"","team":"TMTG7023U"},"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":1568071984,"has_2fa":false},{"id":"UN85LQ0HM","team_id":"TMTG7023U","name":"elizabethjnorthrup","deleted":true,"profile":{"title":"","phone":"","skype":"","real_name":"elizabethjnorthrup","real_name_normalized":"elizabethjnorthrup","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g0b2f1d21275","first_name":"","last_name":"","image_24":"https:\/\/secure.gravatar.com\/avatar\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.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\/0b2f1d21275ee333b76dd3a485688452.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0011-512.png","status_text_canonical":"","team":"TMTG7023U"},"is_bot":false,"is_app_user":false,"updated":1568072109,"is_invited_user":true}],"cache_ts":1568356757,"response_metadata":{"next_cursor":""}}' - http_version: - recorded_at: Fri, 13 Sep 2019 06:39:18 GMT -recorded_with: VCR 5.0.0 diff --git a/test/cassettes/send_msg_to_Slackbot.yml b/test/cassettes/send_msg_to_Slackbot.yml new file mode 100644 index 00000000..4782f3e9 --- /dev/null +++ b/test/cassettes/send_msg_to_Slackbot.yml @@ -0,0 +1,75 @@ +--- +http_interactions: +- request: + method: post + uri: https://slack.com/api/chat.postMessage?channel=USLACKBOT&text=hot%20potato&token= + body: + encoding: UTF-8 + 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: + - '175' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 21:50:36 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - b739cbdc-c70d-4efc-9e0f-6f3195b19fc5 + 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-sjev + X-Cache: + - Miss from cloudfront + Via: + - 1.1 6af340edf5d0c2e1a2d1773e9c7a6ecc.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - HIO51-C1 + X-Amz-Cf-Id: + - "-nno4TWKNVR6lAICBRHyBpcxLHc_p5DFZq_0P1UxeiMeKgFPhOAHlg==" + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channel":"DNB0NUYR3","ts":"1568411436.000400","message":{"type":"message","subtype":"bot_message","text":"hot + potato","ts":"1568411436.000400","username":"Leaves - Emily - API Project","bot_id":"BMURL2BPD"}}' + http_version: + recorded_at: Fri, 13 Sep 2019 21:50:36 GMT +recorded_with: VCR 5.0.0 diff --git a/test/user_test.rb b/test/user_test.rb index ee74192d..cf81b2e0 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -50,19 +50,21 @@ end describe 'User.send_message' do - let (:workspace) { + before do + @workspace = VCR.use_cassette("workspace.new") do SlackCLI::Workspace.new end - } - let (:msg) { - slackbot = workspace.select_user - VCR.use_cassette("send_msg_to_Slackbot") do - - } - - @msg_json = selected.send_message('hot potato') - end + @slackbot = @workspace.select_user("Slackbot") + @msg = VCR.use_cassette("send_msg_to_Slackbot") do + @slackbot.send_message("hot potato") + end end - -end + + it "sends a message" do + expect(@msg.code).must_equal 200 + end + end +end + + From b414036059468919cf7567b3c58cf47bd89784e7 Mon Sep 17 00:00:00 2001 From: Emily Vomacka Date: Fri, 13 Sep 2019 15:17:04 -0700 Subject: [PATCH 27/27] added recipient get error msg --- lib/recipient.rb | 8 ++++++-- test/workspace_test.rb | 11 ++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 2a3f8a80..bf410015 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -6,12 +6,12 @@ module SlackCLI class Recipient attr_reader :slack_id, :name - + def initialize(slack_id, name) @slack_id = slack_id @name = name end - + def send_message(msg) post_parameters = { token: ENV['SLACK_KEY'], @@ -29,6 +29,10 @@ def send_message(msg) def self.get(url, query) response = HTTParty.get(url, query) + if response.code != 200 + puts "Something went wrong, error code #{response.code}." + end + return response end end end diff --git a/test/workspace_test.rb b/test/workspace_test.rb index eb6adcbc..41c4f7fe 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -1,17 +1,18 @@ require_relative 'test_helper' describe 'can create a workspace' do - + let (:workspace) { VCR.use_cassette("workspace.new") do SlackCLI::Workspace.new end } - + it 'creates a workspace' do expect(workspace).must_be_instance_of SlackCLI::Workspace expect(workspace.selected).must_be_nil end + it 'has an array of channels' do expect(workspace.channels).must_be_kind_of Array expect(workspace.channels[0]).must_be_instance_of SlackCLI::Channel @@ -85,13 +86,13 @@ it 'determines if the object selected is a user or a channel' do selected = workspace.select_channel('random') expect(workspace.print_details(selected)).must_be_kind_of Array - + selected = workspace.select_channel('random') expect(workspace.print_details(selected)[0].length).must_equal 4 - + selected = workspace.select_user('Slackbot') expect(workspace.print_details(selected)).must_be_kind_of Array - + selected = workspace.select_user('Slackbot') expect(workspace.print_details(selected)[0].length).must_equal 5 end