From ebfcdff66c20805352a445bf960fbc3fed4be8b0 Mon Sep 17 00:00:00 2001 From: Shamira Date: Tue, 19 Mar 2019 11:26:31 -0700 Subject: [PATCH 01/27] Class setup --- lib/channel.rb | 1 + lib/recipient.rb | 0 lib/slack.rb | 14 +++++++++++--- lib/user.rb | 0 lib/workspace.rb | 22 ++++++++++++++++++++++ specs/channel_spec.rb | 0 specs/recipient_spec.rb | 0 specs/test_helper.rb | 36 +++++++++++++++++++++++++++--------- specs/user_spec.rb | 0 specs/workspace_spec.rb | 0 10 files changed, 61 insertions(+), 12 deletions(-) create mode 100644 lib/channel.rb create mode 100644 lib/recipient.rb create mode 100644 lib/user.rb create mode 100644 lib/workspace.rb create mode 100644 specs/channel_spec.rb create mode 100644 specs/recipient_spec.rb create mode 100644 specs/user_spec.rb create mode 100644 specs/workspace_spec.rb diff --git a/lib/channel.rb b/lib/channel.rb new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/lib/channel.rb @@ -0,0 +1 @@ + diff --git a/lib/recipient.rb b/lib/recipient.rb new file mode 100644 index 00000000..e69de29b diff --git a/lib/slack.rb b/lib/slack.rb index 960cf2f7..e8e24327 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,11 +1,19 @@ -#!/usr/bin/env ruby - +#!/usr/bin/env rub +require "dotenv" def main +BASE_URL = 'https://slack.com/api/channels.list' + SLACK_TOKEN = ENV["SLACK_TOKEN"] + + puts "Welcome to the Ada Slack CLI!" + + # TODO project puts "Thank you for using the Ada Slack CLI" end -main if __FILE__ == $PROGRAM_NAME \ No newline at end of file +main if __FILE__ == $PROGRAM_NAME + + diff --git a/lib/user.rb b/lib/user.rb new file mode 100644 index 00000000..e69de29b diff --git a/lib/workspace.rb b/lib/workspace.rb new file mode 100644 index 00000000..9b74aaf7 --- /dev/null +++ b/lib/workspace.rb @@ -0,0 +1,22 @@ +class Workspace + attr_reader :user, :channel + attr_accessor :selected + + def initialize + @user = user + @channel = channel + @selected = selected + end + + def select_channel + end + + def select_user + end + + def show_details + end + + def send_message + end +end diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 81ccd06b..18866811 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -1,15 +1,33 @@ -require 'simplecov' +require "simplecov" SimpleCov.start -require 'minitest' -require 'minitest/autorun' -require 'minitest/reporters' -require 'minitest/skip_dsl' -require 'vcr' +require "minitest" +require "minitest/autorun" +require "minitest/reporters" +require "webmock/minitest" +require "minitest/skip_dsl" +require "vcr" +require "dotenv" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new +Dotenv.load + VCR.configure do |config| - config.cassette_library_dir = "specs/cassettes" - config.hook_into :webmock -end \ No newline at end of file + config.cassette_library_dir = "test/cassettes" # folder where casettes will be located + config.hook_into :webmock # tie into this other tool called webmock + config.default_cassette_options = { + :record => :new_episodes, # record new data when we don't have it yet + :match_requests_on => [:method, :uri, :body], # The http method, URI and body of a request all need to match + } + # Don't leave our Slack token lying around in a cassette file. + config.filter_sensitive_data("") do + ENV["SLACK_TOKEN"] + end +end + +# What would you like to test +# test for 200 status and message - different +# length of members +# id +# raise error if channel or user doesn't exist diff --git a/specs/user_spec.rb b/specs/user_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb new file mode 100644 index 00000000..e69de29b From c8a83ffc88220d32c786509f4b5cbfa841547f4b Mon Sep 17 00:00:00 2001 From: Angela Date: Tue, 19 Mar 2019 11:31:42 -0700 Subject: [PATCH 02/27] set up Channel class --- lib/channel.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/channel.rb b/lib/channel.rb index 8b137891..4666a422 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1 +1,20 @@ +require "httparty" +require "env" +Dotenv.load +class Channel + attr_reader :name, :topic, :member_count, :id + + def initialize + @name = name + @topic = topic + @member_count = member_count #some code that counts users. + @id = id + end + + def details(name, topic, member_count, id) + end + + def self.list + end +end From 7fbfc4e9d415f5da035680eff8ba4a042931373f Mon Sep 17 00:00:00 2001 From: Shamira Date: Tue, 19 Mar 2019 11:35:45 -0700 Subject: [PATCH 03/27] added structure for recipient and workspace classes --- lib/recipient.rb | 22 ++++++++++++++++++++++ lib/workspace.rb | 2 ++ 2 files changed, 24 insertions(+) diff --git a/lib/recipient.rb b/lib/recipient.rb index e69de29b..ca6b55d2 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -0,0 +1,22 @@ +class Recipient + attr_reader :slack_id, :name + + def initialize + @slack_id = slack_id + @name = name + end + + def send_message(message) + end + + def self.get(url, params) + end + + private + + def details + end + + def self.list + end +end diff --git a/lib/workspace.rb b/lib/workspace.rb index 9b74aaf7..46b36e50 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -8,6 +8,8 @@ def initialize @selected = selected end + class SlackApiError < StandardError; end + def select_channel end From 62d357d14183a3a71944e923e1a38ad40d67a072 Mon Sep 17 00:00:00 2001 From: Shamira Date: Tue, 19 Mar 2019 11:40:45 -0700 Subject: [PATCH 04/27] finializing class structure --- lib/recipient.rb | 4 ++++ lib/user.rb | 19 +++++++++++++++++++ lib/workspace.rb | 4 ++++ 3 files changed, 27 insertions(+) diff --git a/lib/recipient.rb b/lib/recipient.rb index ca6b55d2..5268b350 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,3 +1,7 @@ +require "httparty" +require "env" +Dotenv.load + class Recipient attr_reader :slack_id, :name diff --git a/lib/user.rb b/lib/user.rb index e69de29b..64420a1e 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -0,0 +1,19 @@ +require "httparty" +require "env" +Dotenv.load + +class User + attr_reader :user_name, :real_name, :slack_id + + def initialize + @user_name = user_name + @real_name = real_name + @slack_id = slack_id + end + + def details + end + + def self.list + end +end diff --git a/lib/workspace.rb b/lib/workspace.rb index 46b36e50..279c5ced 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,3 +1,7 @@ +require "httparty" +require "env" +Dotenv.load + class Workspace attr_reader :user, :channel attr_accessor :selected From f319692589cd21b5d3351aae6a839548d72fbed3 Mon Sep 17 00:00:00 2001 From: Angela Date: Tue, 19 Mar 2019 13:53:56 -0700 Subject: [PATCH 05/27] created self.list method in User class and corresponding passed tests. --- lib/user.rb | 37 +++++++- specs/test_helper.rb | 2 + specs/user_spec.rb | 31 +++++++ test/cassettes/slack_users.yml | 151 +++++++++++++++++++++++++++++++++ 4 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 test/cassettes/slack_users.yml diff --git a/lib/user.rb b/lib/user.rb index 64420a1e..3cb96e75 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,19 +1,54 @@ require "httparty" -require "env" +require "dotenv" Dotenv.load class User attr_reader :user_name, :real_name, :slack_id + BASE_URL = "https://slack.com/api/users.list" + SLACK_TOKEN = ENV["SLACK_TOKEN"] + # query_param = { + # token: SLACK_TOKEN, + # } + # response = httparty.get(BASE_URL, query: query_param) + def initialize @user_name = user_name @real_name = real_name @slack_id = slack_id end + # def get_user + # query_param = { + # token: SLACK_TOKEN, + # } + # response = httparty.get(BASE_URL, query: query_param) + # return response + # end + def details end def self.list + #access the response/API above + # look inside response["members"] + # return username, real name, and slack ID + + query_param = { + token: SLACK_TOKEN, + } + response = HTTParty.get(BASE_URL, query: query_param) + + list = [] + response["members"].each do |member| + member_info = [] + member_info << member["name"] + member_info << member["real_name"] + member_info << member["id"] + + list << member_info + end + + return list end end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 18866811..583ec5ac 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -26,6 +26,8 @@ end end +require_relative "../lib/user" + # What would you like to test # test for 200 status and message - different # length of members diff --git a/specs/user_spec.rb b/specs/user_spec.rb index e69de29b..dc2ca982 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -0,0 +1,31 @@ +require_relative "test_helper" + +describe "returning user lists" do + it "API returns as a hash and its members return as an array" do + VCR.use_cassette("slack_users") do + test_user = User.new + # response = test_user.get_user + + expect(User.list).must_be_kind_of Array + expect(User.list.first).must_be_kind_of Array + end + end + + it "make sure there are 3 members in the list" do + VCR.use_cassette("slack_users") do + test_user = User.new + # response = test_user.get_user + + expect(User.list.length).must_equal 3 + end + end + + it "lists correct username" do + VCR.use_cassette("slack_users") do + test_user = User.new + # response = test_user.get_user + print User.list + expect(User.list[0][0]).must_equal "slackbot" + end + end +end diff --git a/test/cassettes/slack_users.yml b/test/cassettes/slack_users.yml new file mode 100644 index 00000000..49e9a0bf --- /dev/null +++ b/test/cassettes/slack_users.yml @@ -0,0 +1,151 @@ +--- +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: + - '891' + Connection: + - keep-alive + Date: + - Tue, 19 Mar 2019 20:45:47 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - d754c042-33d1-4a84-84da-11149ca6a1bf + 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 + 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-4v6y + X-Cache: + - Miss from cloudfront + Via: + - 1.1 64a11a52a1b20918fec274138dd1ba05.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - rsALn42vDvl-6cFExIyK9DiexjwJFbcwAlD0o60y5akANvGi35uoVQ== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH49RSM8W","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\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":"UH2RALWR2","team_id":"TH49RSM8W","name":"marshallscm","deleted":false,"color":"4bbe2e","real_name":"Shamira + Marshall","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Shamira + Marshall","real_name_normalized":"Shamira Marshall","display_name":"Shamira + Marshall","display_name_normalized":"Shamira Marshall","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gb87774d9533","image_24":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552952011,"has_2fa":false},{"id":"UH2S78AHY","team_id":"TH49RSM8W","name":"angela.ohh","deleted":false,"color":"9f69e7","real_name":"angela.ohh","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"angela.ohh","real_name_normalized":"angela.ohh","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"ge9c24d2cfc6","image_24":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0001-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552951939,"has_2fa":false}],"cache_ts":1553028347,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Tue, 19 Mar 2019 20:44:44 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: + - '891' + Connection: + - keep-alive + Date: + - Tue, 19 Mar 2019 20:45:47 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 07acc638-f205-4086-a52a-23965d5fe543 + 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 + 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-t91r + X-Cache: + - Miss from cloudfront + Via: + - 1.1 36cc224d7812baa70145cc1e6b92b8a5.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - I8EaLOVhYhm1MTPnL7J9VBqHfAC17--7uLCum41Qz2IvJAXUQ-vlpQ== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH49RSM8W","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\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":"UH2RALWR2","team_id":"TH49RSM8W","name":"marshallscm","deleted":false,"color":"4bbe2e","real_name":"Shamira + Marshall","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Shamira + Marshall","real_name_normalized":"Shamira Marshall","display_name":"Shamira + Marshall","display_name_normalized":"Shamira Marshall","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gb87774d9533","image_24":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552952011,"has_2fa":false},{"id":"UH2S78AHY","team_id":"TH49RSM8W","name":"angela.ohh","deleted":false,"color":"9f69e7","real_name":"angela.ohh","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"angela.ohh","real_name_normalized":"angela.ohh","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"ge9c24d2cfc6","image_24":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0001-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552951939,"has_2fa":false}],"cache_ts":1553028347,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Tue, 19 Mar 2019 20:44:44 GMT +recorded_with: VCR 4.0.0 From fdc8b535e784d164a1769e49a25cd379d9caa720 Mon Sep 17 00:00:00 2001 From: Angela Date: Tue, 19 Mar 2019 13:55:04 -0700 Subject: [PATCH 06/27] added self.list --- lib/user.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/user.rb b/lib/user.rb index 3cb96e75..09769d4c 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -49,6 +49,7 @@ def self.list list << member_info end + # list is an array of arrays return list end end From b269ec91038f545e194dc9b57f23b1254819bb89 Mon Sep 17 00:00:00 2001 From: Shamira Date: Tue, 19 Mar 2019 14:23:56 -0700 Subject: [PATCH 07/27] added list method for channel class and tests --- lib/channel.rb | 27 ++- specs/channel_spec.rb | 31 +++ specs/test_helper.rb | 1 + test/cassettes/slack_channels.yml | 303 ++++++++++++++++++++++++++++++ 4 files changed, 361 insertions(+), 1 deletion(-) create mode 100644 test/cassettes/slack_channels.yml diff --git a/lib/channel.rb b/lib/channel.rb index 4666a422..629d491f 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,9 +1,12 @@ require "httparty" -require "env" +require "dotenv" +require "pry" Dotenv.load class Channel attr_reader :name, :topic, :member_count, :id + BASE_URL = "https://slack.com/api/channels.list" + SLACK_TOKEN = ENV["SLACK_TOKEN"] def initialize @name = name @@ -16,5 +19,27 @@ def details(name, topic, member_count, id) end def self.list + #access the response/API above + # look inside response["members"] + # return username, real name, and slack ID + + query_param = { + token: SLACK_TOKEN, + } + response = HTTParty.get(BASE_URL, query: query_param) + + list = [] + response["channels"].each do |channel| + channel_info = [] + channel_info << channel["name"] + channel_info << channel["topic"]["value"] + channel_info << channel["num_members"] + channel_info << channel["id"] + + list << channel_info + end + + # list is an array of arrays + return list end end diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index e69de29b..becccd03 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -0,0 +1,31 @@ +require_relative "test_helper" +require "pry" +describe "returning channel lists" do + it "API returns as a hash and its channel returns as an array" do + VCR.use_cassette("slack_channels") do + test_channel = Channel.new + # response = test_channel.get_channel + print Channel.list + expect(Channel.list).must_be_kind_of Array + expect(Channel.list.first).must_be_kind_of Array + end + end + + it "make sure there are 3 member count in the list" do + VCR.use_cassette("slack_channels") do + test_user = Channel.new + # response = test_user.get_user + + expect(Channel.list.length).must_equal 3 + end + end + + it "lists correct Channel name" do + VCR.use_cassette("slack_channels") do + test_user = Channel.new + # response = test_user.get_user + print Channel.list + expect(Channel.list[0][0]).must_equal "everyone" + end + end +end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 583ec5ac..a2966781 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -27,6 +27,7 @@ end require_relative "../lib/user" +require_relative "../lib/channel" # What would you like to test # test for 200 status and message - different diff --git a/test/cassettes/slack_channels.yml b/test/cassettes/slack_channels.yml new file mode 100644 index 00000000..d9cefab0 --- /dev/null +++ b/test/cassettes/slack_channels.yml @@ -0,0 +1,303 @@ +--- +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: + - '549' + Connection: + - keep-alive + Date: + - Tue, 19 Mar 2019 21:13:35 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 42197208-7395-4982-8d7c-b90c6f9322e3 + X-Oauth-Scopes: + - identify,channels: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 + 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-526b + X-Cache: + - Miss from cloudfront + Via: + - 1.1 3236cbfeb05b5e6a80bfe05dfc656559.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - e8cbf_71J1M828BlcnyywB-9bY-oEZSa0vxX9q3uVtWSvr1vp64Ozw== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CH0E8S9UY","name":"everyone","is_channel":true,"created":1552951939,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"everyone","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UH2S78AHY","last_set":1552951939},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH0E8SBA4","name":"random","is_channel":true,"created":1552951939,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UH2S78AHY","last_set":1552951939},"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":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH2R9UGCU","name":"api-slack","is_channel":true,"created":1552951940,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"api-slack","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Tue, 19 Mar 2019 21:13:35 GMT +- request: + method: get + uri: https://slack.com/api/conversations.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: + - '594' + Connection: + - keep-alive + Date: + - Tue, 19 Mar 2019 21:15:40 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 5df02575-a618-4a31-9aa1-1da7a8d58c2b + X-Oauth-Scopes: + - identify,channels: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 + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - channels:read,groups:read,mpim:read,im:read,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-d8v + X-Cache: + - Miss from cloudfront + Via: + - 1.1 c0098ca8d6549ce8db6f28ee0b22a4ce.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - VmOlHEB5Ea8sXlfLS7EyVUYbt0N189ANc-jC3G7Xiwdi_VDi2TFU_Q== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CH0E8S9UY","name":"everyone","is_channel":true,"is_group":false,"is_im":false,"created":1552951939,"is_archived":false,"is_general":true,"unlinked":0,"name_normalized":"everyone","is_shared":false,"parent_conversation":null,"creator":"UH2S78AHY","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["TH49RSM8W"],"pending_shared":[],"is_pending_ext_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UH2S78AHY","last_set":1552951939},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH0E8SBA4","name":"random","is_channel":true,"is_group":false,"is_im":false,"created":1552951939,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"random","is_shared":false,"parent_conversation":null,"creator":"UH2S78AHY","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["TH49RSM8W"],"pending_shared":[],"is_pending_ext_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UH2S78AHY","last_set":1552951939},"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":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH2R9UGCU","name":"api-slack","is_channel":true,"is_group":false,"is_im":false,"created":1552951940,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"api-slack","is_shared":false,"parent_conversation":null,"creator":"UH2S78AHY","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["TH49RSM8W"],"pending_shared":[],"is_pending_ext_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Tue, 19 Mar 2019 21:15:40 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: + - '549' + Connection: + - keep-alive + Date: + - Tue, 19 Mar 2019 21:22:01 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - d06cbad1-2f3c-4955-81e0-2e0309571b41 + X-Oauth-Scopes: + - identify,channels: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 + 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-1mjm + X-Cache: + - Miss from cloudfront + Via: + - 1.1 3e5a2f6c5b1171dae267d5a9344f95e8.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - x-VhMBoqLbIa8m1uBIzF8-1PCgtQZfcx0kvUH5YAGoCGuMs9minyQA== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CH0E8S9UY","name":"everyone","is_channel":true,"created":1552951939,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"everyone","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UH2S78AHY","last_set":1552951939},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH0E8SBA4","name":"random","is_channel":true,"created":1552951939,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UH2S78AHY","last_set":1552951939},"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":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH2R9UGCU","name":"api-slack","is_channel":true,"created":1552951940,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"api-slack","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Tue, 19 Mar 2019 21:22:01 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: + - '549' + Connection: + - keep-alive + Date: + - Tue, 19 Mar 2019 21:22:01 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 7295de91-1596-4fdb-828d-046cfbc529f7 + X-Oauth-Scopes: + - identify,channels: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 + 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-fx2r + X-Cache: + - Miss from cloudfront + Via: + - 1.1 5da5773a6acab8f3aabf385b38683f20.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - 5wtsYhGhCRGUOf7JONBekIGmtDDW0pvNNs2MGN1IxBUejp7D7GnFHw== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CH0E8S9UY","name":"everyone","is_channel":true,"created":1552951939,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"everyone","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UH2S78AHY","last_set":1552951939},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH0E8SBA4","name":"random","is_channel":true,"created":1552951939,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UH2S78AHY","last_set":1552951939},"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":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH2R9UGCU","name":"api-slack","is_channel":true,"created":1552951940,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"api-slack","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Tue, 19 Mar 2019 21:22:01 GMT +recorded_with: VCR 4.0.0 From c9c72427c105b0c6f7a83df6e003795a1d988b3e Mon Sep 17 00:00:00 2001 From: Angela Date: Tue, 19 Mar 2019 14:38:26 -0700 Subject: [PATCH 08/27] created main method in Slack.rb file --- lib/slack.rb | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index e8e24327..8736bb9b 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,19 +1,40 @@ #!/usr/bin/env rub require "dotenv" -def main -BASE_URL = 'https://slack.com/api/channels.list' - SLACK_TOKEN = ENV["SLACK_TOKEN"] - +def main puts "Welcome to the Ada Slack CLI!" - - - + puts "We currently have #{User.list.length} members and #{Channel.list.length} channels." + + puts "" + puts "Please choose one of the the following number options" + puts "1. List Users" + puts "2. List Channels" + puts "3. Quit" + + selection = gets.chomp + + loop do + if selection == "1" + puts "Here is the list of users:" + puts User.list + elsif selection == "2" + puts "Here is the list of channels: " + puts Channel.list + elsif selection == "3" + break + else + puts "Please choose one of the the following number options" + puts "1. List Users" + puts "2. List Channels" + puts "3. Quit" + + selection = gets.chomp + end + end # TODO project puts "Thank you for using the Ada Slack CLI" end main if __FILE__ == $PROGRAM_NAME - - +# main From f1851b1370222f78e167371e8da409a6787dedf2 Mon Sep 17 00:00:00 2001 From: Shamira Date: Tue, 19 Mar 2019 16:02:09 -0700 Subject: [PATCH 09/27] added workspace class and tests --- lib/recipient.rb | 7 ++++++- lib/workspace.rb | 35 ++++++++++++++++++++++++++++------- specs/test_helper.rb | 2 ++ specs/workspace_spec.rb | 15 +++++++++++++++ 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 5268b350..a2284243 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,5 +1,5 @@ require "httparty" -require "env" +require "dotenv" Dotenv.load class Recipient @@ -14,6 +14,11 @@ def send_message(message) end def self.get(url, params) + # SLACK_TOKEN = ENV["SLACK_TOKEN"] + # param = { + # token: SLACK_TOKEN, + # } + # response = HTTParty.get(url, query: param) end private diff --git a/lib/workspace.rb b/lib/workspace.rb index 279c5ced..fe774fc4 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,5 +1,4 @@ -require "httparty" -require "env" +require "dotenv" Dotenv.load class Workspace @@ -7,20 +6,42 @@ class Workspace attr_accessor :selected def initialize - @user = user - @channel = channel + @user = [] + @channel = [] @selected = selected end class SlackApiError < StandardError; end - def select_channel + def select_channel(channel) + #Channel.list + #using param, find specific channel + # returns an instance of channel end - def select_user + def select_user(user) + #User.list + #using param, find specific user + # returns an instance of user end - def show_details + # seperate methods for Channel and User + def show_details_channel(selected) + # something that represents channel + Channel.list.each do |instance| + if selected == instance[0] + return instance + end + end + end + + def show_details_user(selected) + #something users + User.list.each do |instance| + if selected == instance[0] + return instance + end + end end def send_message diff --git a/specs/test_helper.rb b/specs/test_helper.rb index a2966781..f96a93ba 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -28,6 +28,8 @@ require_relative "../lib/user" require_relative "../lib/channel" +require_relative "../lib/workspace" +require_relative "../lib/recipient" # What would you like to test # test for 200 status and message - different diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index e69de29b..c7c4bbd8 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -0,0 +1,15 @@ +require_relative "test_helper" +require "pry" +describe "show details method" do + it "gives details for a specific instance of Channel" do + VCR.use_cassette("slack_channels") do + # response = test_channel.get_channel + list_of_channels = Channel.list + test_workspace = Workspace.new + channel_test_1 = Channel.list[0][0] + + expect(test_workspace.show_details_channel(channel_test_1)).must_equal ["everyone", "Company-wide announcements and work-based matters", 2, "CH0E8S9UY"] + # expect(Channel.list.first).must_be_kind_of Array + end + end +end From 821a74580af871cd95324eb1c1f34278ee1ad807 Mon Sep 17 00:00:00 2001 From: Angela Date: Tue, 19 Mar 2019 16:12:41 -0700 Subject: [PATCH 10/27] added test for show_details_user method --- practice.rb | 18 +++ specs/workspace_spec.rb | 13 +- test/cassettes/slack_channels.yml | 222 ++++++++++++++++++++++++++++++ 3 files changed, 252 insertions(+), 1 deletion(-) create mode 100644 practice.rb diff --git a/practice.rb b/practice.rb new file mode 100644 index 00000000..150485f7 --- /dev/null +++ b/practice.rb @@ -0,0 +1,18 @@ +puts "Please choose one of the the following number options" +puts "1. List Users" +puts "2. List Channels" +puts "3. Quit" + +selection = gets.chomp + +loop do + if selection == "1" + puts "Here is the list of users:" + # puts User.list + elsif selection == "2" + puts "Here is the list of channels: " + # puts Channel.list + else + break + end +end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index c7c4bbd8..59705f00 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -4,7 +4,7 @@ it "gives details for a specific instance of Channel" do VCR.use_cassette("slack_channels") do # response = test_channel.get_channel - list_of_channels = Channel.list + Channel.list test_workspace = Workspace.new channel_test_1 = Channel.list[0][0] @@ -12,4 +12,15 @@ # expect(Channel.list.first).must_be_kind_of Array end end + + it "gives details for a specific instance of User" do + VCR.use_cassette("slack_channels") do + # response = test_channel.get_channel + User.list + test_workspace = Workspace.new + user_test_1 = User.list[0][0] + + expect(test_workspace.show_details_user(user_test_1)).must_equal ["slackbot", "Slackbot", "USLACKBOT"] + end + end end diff --git a/test/cassettes/slack_channels.yml b/test/cassettes/slack_channels.yml index d9cefab0..557885d9 100644 --- a/test/cassettes/slack_channels.yml +++ b/test/cassettes/slack_channels.yml @@ -300,4 +300,226 @@ http_interactions: you''d prefer to keep out of more focused work-related channels.","creator":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH2R9UGCU","name":"api-slack","is_channel":true,"created":1552951940,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"api-slack","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' http_version: recorded_at: Tue, 19 Mar 2019 21:22:01 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: + - '891' + Connection: + - keep-alive + Date: + - Tue, 19 Mar 2019 23:11:30 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 391492ff-529a-45ea-9cce-7b392eb03b11 + 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 + 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-xhix + X-Cache: + - Miss from cloudfront + Via: + - 1.1 b6280aaedffb702d5f35b330c5f557c7.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - u0QkZXD3-GX4ggsVCX5l8RiWlw-qh3VLw70b_7oj2Nze88HDU1XcgA== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH49RSM8W","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\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":"UH2RALWR2","team_id":"TH49RSM8W","name":"marshallscm","deleted":false,"color":"4bbe2e","real_name":"Shamira + Marshall","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Shamira + Marshall","real_name_normalized":"Shamira Marshall","display_name":"Shamira + Marshall","display_name_normalized":"Shamira Marshall","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gb87774d9533","image_24":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552952011,"has_2fa":false},{"id":"UH2S78AHY","team_id":"TH49RSM8W","name":"angela.ohh","deleted":false,"color":"9f69e7","real_name":"angela.ohh","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"angela.ohh","real_name_normalized":"angela.ohh","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"ge9c24d2cfc6","image_24":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0001-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552951939,"has_2fa":false}],"cache_ts":1553037090,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Tue, 19 Mar 2019 23:10:28 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: + - '891' + Connection: + - keep-alive + Date: + - Tue, 19 Mar 2019 23:11:30 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 56c96777-f1e1-465a-b763-f9a8ee0329c8 + 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 + 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-xhix + X-Cache: + - Miss from cloudfront + Via: + - 1.1 ccbc918e3ddfbe40c4d786475a6e7606.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - gWTOQZzWPwY9AMyTehshAxCY96UtPbbdTJOw5quii0T8aIEpQzhriA== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH49RSM8W","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\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":"UH2RALWR2","team_id":"TH49RSM8W","name":"marshallscm","deleted":false,"color":"4bbe2e","real_name":"Shamira + Marshall","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Shamira + Marshall","real_name_normalized":"Shamira Marshall","display_name":"Shamira + Marshall","display_name_normalized":"Shamira Marshall","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gb87774d9533","image_24":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552952011,"has_2fa":false},{"id":"UH2S78AHY","team_id":"TH49RSM8W","name":"angela.ohh","deleted":false,"color":"9f69e7","real_name":"angela.ohh","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"angela.ohh","real_name_normalized":"angela.ohh","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"ge9c24d2cfc6","image_24":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0001-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552951939,"has_2fa":false}],"cache_ts":1553037090,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Tue, 19 Mar 2019 23:10:28 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: + - '891' + Connection: + - keep-alive + Date: + - Tue, 19 Mar 2019 23:11:31 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - cbb8da99-7669-4e40-9674-6916ba6e5b54 + 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 + 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-c3y1 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 9544538048b67636eed3ec04c11d909b.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - X34Qn_Urk6m9eARW2XoEikYanbvbj-tKRdD8LahBJ4AlhB6TNLQYrw== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH49RSM8W","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\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":"UH2RALWR2","team_id":"TH49RSM8W","name":"marshallscm","deleted":false,"color":"4bbe2e","real_name":"Shamira + Marshall","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Shamira + Marshall","real_name_normalized":"Shamira Marshall","display_name":"Shamira + Marshall","display_name_normalized":"Shamira Marshall","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gb87774d9533","image_24":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/b87774d953381c22c0620b06eee32887.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0023-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552952011,"has_2fa":false},{"id":"UH2S78AHY","team_id":"TH49RSM8W","name":"angela.ohh","deleted":false,"color":"9f69e7","real_name":"angela.ohh","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"angela.ohh","real_name_normalized":"angela.ohh","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"ge9c24d2cfc6","image_24":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0001-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552951939,"has_2fa":false}],"cache_ts":1553037091,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Tue, 19 Mar 2019 23:10:28 GMT recorded_with: VCR 4.0.0 From ba5104dae6bf3cb2cb3117c783f5edc77be79bc8 Mon Sep 17 00:00:00 2001 From: Angela Date: Tue, 19 Mar 2019 16:30:34 -0700 Subject: [PATCH 11/27] added driver code to slack.rb --- lib/slack.rb | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 8736bb9b..c90991bf 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -9,29 +9,32 @@ def main puts "Please choose one of the the following number options" puts "1. List Users" puts "2. List Channels" - puts "3. Quit" + puts "3. Select User" + puts "4. Select Channel" + puts "5. Quit" selection = gets.chomp loop do - if selection == "1" + case selection + when "1" puts "Here is the list of users:" puts User.list - elsif selection == "2" + when "2" puts "Here is the list of channels: " puts Channel.list - elsif selection == "3" + when "3" + chose_user = gets.chomp + workspace = Workspace.new + puts workspace.show_details_user(chose_user) + when "4" + chose_channel = gets.chomp + workspace = Workspace.new + puts workspace.show_details_channel(chose_channel) + when "5" break - else - puts "Please choose one of the the following number options" - puts "1. List Users" - puts "2. List Channels" - puts "3. Quit" - - selection = gets.chomp end end - # TODO project puts "Thank you for using the Ada Slack CLI" end From c732249ccac935ed751bb703908c67ee2fafd0f6 Mon Sep 17 00:00:00 2001 From: Shamira Date: Wed, 20 Mar 2019 13:38:53 -0700 Subject: [PATCH 12/27] added slack_api_wrapper class and spec --- lib/recipient.rb | 34 +++++- lib/slack_api_wrapper.rb | 29 +++++ specs/recipient_spec.rb | 23 ++++ specs/slack_api_wrapper_spec.rb | 32 +++++ specs/test_helper.rb | 1 + specs/workspace_spec.rb | 3 + test/cassettes/slack_message.yml | 200 +++++++++++++++++++++++++++++++ 7 files changed, 320 insertions(+), 2 deletions(-) create mode 100644 lib/slack_api_wrapper.rb create mode 100644 specs/slack_api_wrapper_spec.rb create mode 100644 test/cassettes/slack_message.yml diff --git a/lib/recipient.rb b/lib/recipient.rb index a2284243..c8c74171 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -4,13 +4,43 @@ class Recipient attr_reader :slack_id, :name + BASE_URL = "https://slack.com/api/chat.postMessage" + SLACK_TOKEN = ENV["SLACK_TOKEN"] - def initialize + def initialize(slack_id) @slack_id = slack_id @name = name end - def send_message(message) + # class SlackApiError < StandardError + # raise SlackApiError, "This id does not exist" + # end + + def send_message(message, user: true) + # query_param = { + # token: SLACK_TOKEN, + # channel: slack_id, + # text: message, + # as_user: user, + # } + + # response = HTTParty.post( + # "#{BASE_URL}", + # body: { + # token: SLACK_TOKEN, + # text: message, + # channel: slack_id, + # }, + # ) + + # if !response.code == 200 && response.parsed_response["ok"] + # raise SlackApiError, "Oops something went wrong" + # end + + # return response.code == 200 && response.parsed_response["ok"] + + # if response.code != 200 raise SlackApiError, "This user/channel does not exist" + end def self.get(url, params) diff --git a/lib/slack_api_wrapper.rb b/lib/slack_api_wrapper.rb new file mode 100644 index 00000000..c4c38430 --- /dev/null +++ b/lib/slack_api_wrapper.rb @@ -0,0 +1,29 @@ +require "httparty" +require "dotenv" + +Dotenv.load + +module SlackApi + BASE_URL = "https://slack.com/api/chat.postMessage" + SLACK_TOKEN = ENV["SLACK_TOKEN"] + + class SlackApiError < StandardError; end + + def self.send_message(message, user) + response = HTTParty.post( + "#{BASE_URL}", + headers: {"Content-Type" => "application/x-www-form-urlencoded"}, + body: { + token: SLACK_TOKEN, + text: message, + channel: user, + }, + ) + + if response["ok"] + return true + else + raise SlackApi::SlackApiError, "Error when posting #{message} to #{user}, error: #{response["error"]}" + end + end +end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index e69de29b..f7c91f94 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -0,0 +1,23 @@ +require_relative "test_helper" +require "pry" +# describe do +# # it "will raise an error when given an invalid channel" do +# # error = Recipient.new(ES38768) + +# # VCR.use_cassette("slack-posts") do +# # exception = expect { +# # error.send_message("This post should not work", "invalid-channel") +# # }.must_raise SlackApiError + +# # expect(exception.message).must_equal "Oops something went wrong" +# # end +# # end + +# # verify that it sends a message + +# # what happens with invalid text + +# # what happends with invalid token + +# # look at required and option, and how program should respond +# end diff --git a/specs/slack_api_wrapper_spec.rb b/specs/slack_api_wrapper_spec.rb new file mode 100644 index 00000000..ef394cd0 --- /dev/null +++ b/specs/slack_api_wrapper_spec.rb @@ -0,0 +1,32 @@ +require_relative "test_helper" +require "pry" + +describe SlackApi do + it "can send a valid message" do + VCR.use_cassette("slack_message") do + return_value = SlackApi.send_message("It's gonna work!", + "CH0E8S9UY") + expect(return_value).must_equal true + end + end + + it "generates an error if given an invalid channel" do + VCR.use_cassette("slack_message") do + # return_value = SlackApi.send_message("Test message", + # "bogus") + expect { + SlackApi.send_message("Test message", + "bogus") + }.must_raise SlackApi::SlackApiError + end + end + + it "will generate an error if given an invalid key" do + VCR.use_cassette("slack_message") do + end + end + it "will raise an error if given an empty message" do + VCR.use_cassette("slack_message") do + end + end +end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index f96a93ba..a4a42589 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -30,6 +30,7 @@ require_relative "../lib/channel" require_relative "../lib/workspace" require_relative "../lib/recipient" +require_relative "../lib/slack_api_wrapper" # What would you like to test # test for 200 status and message - different diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 59705f00..075610be 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -23,4 +23,7 @@ expect(test_workspace.show_details_user(user_test_1)).must_equal ["slackbot", "Slackbot", "USLACKBOT"] end end + + # edge cases, what if the list is 0? + # argument error, this user/channel does not exist. end diff --git a/test/cassettes/slack_message.yml b/test/cassettes/slack_message.yml new file mode 100644 index 00000000..6e865749 --- /dev/null +++ b/test/cassettes/slack_message.yml @@ -0,0 +1,200 @@ +--- +http_interactions: +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&text=Test%20message&channel=CH0E8S9UY + headers: + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Date: + - Wed, 20 Mar 2019 20:37:03 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 41ad3fb3-177f-49cb-a670-07236f567555 + X-Oauth-Scopes: + - identify,channels:read,im:read,users:read,users.profile:read,chat:write:user,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 + 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-saap + X-Cache: + - Miss from cloudfront + Via: + - 1.1 1c0b9f2790e77d82d7169b1fa7d0f9cc.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - hvpGfu3pzOoWtag7003c5KR9JFarSyOMBIhZBYOCyIyUzGYxtP8pfA== + body: + encoding: UTF-8 + string: '{"ok":true,"channel":"CH0E8S9UY","ts":"1553114223.000100","message":{"type":"message","subtype":"bot_message","text":"Test + message","ts":"1553114223.000100","username":"Ports - Shamira - API Project","bot_id":"BH2RK7F9S"}}' + http_version: + recorded_at: Wed, 20 Mar 2019 20:37:03 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&text=Test%20message&channel=bogus + headers: + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Date: + - Wed, 20 Mar 2019 20:37:03 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - c591a373-2156-428a-aa4c-5b6fe8db61a5 + X-Oauth-Scopes: + - identify,channels:read,im:read,users:read,users.profile:read,chat:write:user,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 + 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-jogu + X-Cache: + - Miss from cloudfront + Via: + - 1.1 ccbc918e3ddfbe40c4d786475a6e7606.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - K2K1uIUC7L6YG1XcqrY8mCPWt5rYpFpE57GqivqB4puqlQR2kSfqKw== + body: + encoding: UTF-8 + string: '{"ok":false,"error":"channel_not_found"}' + http_version: + recorded_at: Wed, 20 Mar 2019 20:37:03 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&text=It%27s%20gonna%20work%21&channel=CH0E8S9UY + headers: + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Date: + - Wed, 20 Mar 2019 20:38:10 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - a652ec9a-0e4d-4d30-94ad-224a0127acc3 + X-Oauth-Scopes: + - identify,channels:read,im:read,users:read,users.profile:read,chat:write:user,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 + 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-risl + X-Cache: + - Miss from cloudfront + Via: + - 1.1 3e5a2f6c5b1171dae267d5a9344f95e8.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - IIjH_Itn-MU-s1jGyqIRosgRlNyKrLhkKR_A_J9BeaCurgMHU77NCA== + body: + encoding: UTF-8 + string: '{"ok":true,"channel":"CH0E8S9UY","ts":"1553114290.000200","message":{"type":"message","subtype":"bot_message","text":"It''s + gonna work!","ts":"1553114290.000200","username":"Ports - Shamira - API Project","bot_id":"BH2RK7F9S"}}' + http_version: + recorded_at: Wed, 20 Mar 2019 20:38:10 GMT +recorded_with: VCR 4.0.0 From c555943a60ef4ede283855435fcb64d4bc7ac9af Mon Sep 17 00:00:00 2001 From: Angela Date: Wed, 20 Mar 2019 13:53:00 -0700 Subject: [PATCH 13/27] deleted extra files and added additional option for main class --- lib/.DS_Store | Bin 0 -> 6148 bytes lib/dont_use_recipient.rb | 62 ++++++++++++++++++++++++++ lib/recipient.rb | 72 +++++++++---------------------- lib/slack.rb | 19 +++++++- lib/slack_api_wrapper.rb | 29 ------------- practice.rb | 23 ++++++++-- specs/dont_use_recipient_spec.rb | 23 ++++++++++ specs/recipient_spec.rb | 45 +++++++++++-------- specs/slack_api_wrapper_spec.rb | 32 -------------- specs/test_helper.rb | 2 +- 10 files changed, 169 insertions(+), 138 deletions(-) create mode 100644 lib/.DS_Store create mode 100644 lib/dont_use_recipient.rb delete mode 100644 lib/slack_api_wrapper.rb create mode 100644 specs/dont_use_recipient_spec.rb delete mode 100644 specs/slack_api_wrapper_spec.rb diff --git a/lib/.DS_Store b/lib/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..082e536270e3ad7afa97eaa0cbe7b0145578b95e GIT binary patch literal 6148 zcmeHKu};H441HHBDA1t`g7HQsBxaVVDg!egP-q(oMAV>^iZu(rg2ean0q|^}Dw?Je z6RMCM`QF8`eYtn1I0qmMm$OS?0H8+|>>RRb5qU1UA)RE|CkD+iM~(s)s4&^^cEc_* zAZvGoDIRc-Ij`0F-4x|?Qk1fevN^7(=U*!90VkNDr2h-XSYpArF;_ijrbj$ebA6^e zp^@pMk*WW?xNzEt>v7bAZ#~76?YQ-E!dt`tAiZbR>iya9?&Fp7tC)Mi`N$}FTb%Op z{(~2$ad8Hm0cT+68DPy8=^Yz->kK#p&cKQR`94IdV3x2p)K3Q+JpvHBG^?;Lzl#zR z6J`l(Lq4Gd3nf};NJord;k3u(mnEzXEgV5dW}Y;1NGFt_qthPM9U(LH)){aH)*0Bd z+kw>o>+R?N^&r1<2AqL^#X#teZbw5-Db?1E$w{q^)H|w(_|=B15O%Z_(^pFI8C8Y$ XC>>&!ur{QH;y(gPgE!8=pEB?bTQy_s literal 0 HcmV?d00001 diff --git a/lib/dont_use_recipient.rb b/lib/dont_use_recipient.rb new file mode 100644 index 00000000..7967400d --- /dev/null +++ b/lib/dont_use_recipient.rb @@ -0,0 +1,62 @@ +require "httparty" +require "dotenv" +Dotenv.load + +class Recipient + attr_reader :slack_id, :name + BASE_URL = "https://slack.com/api/chat.postMessage" + SLACK_TOKEN = ENV["SLACK_TOKEN"] + + def initialize(slack_id) + @slack_id = slack_id + @name = name + end + + # class SlackApiError < StandardError + # raise SlackApiError, "This id does not exist" + # end + + def send_message(message, user: true) + SlackApi::self_message(message, slack_id) + # query_param = { + # token: SLACK_TOKEN, + # channel: slack_id, + # text: message, + # as_user: user, + # } + + # response = HTTParty.post( + # "#{BASE_URL}", + # body: { + # token: SLACK_TOKEN, + # text: message, + # channel: slack_id, + # }, + # ) + + # if !response.code == 200 && response.parsed_response["ok"] + # raise SlackApiError, "Oops something went wrong" + # end + + # return response.code == 200 && response.parsed_response["ok"] + + # if response.code != 200 raise SlackApiError, "This user/channel does not exist" + + end + + def self.get(url, params) + # SLACK_TOKEN = ENV["SLACK_TOKEN"] + # param = { + # token: SLACK_TOKEN, + # } + # response = HTTParty.get(url, query: param) + end + + private + + def details + end + + def self.list + end +end diff --git a/lib/recipient.rb b/lib/recipient.rb index c8c74171..6cecaa48 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,61 +1,29 @@ require "httparty" require "dotenv" + Dotenv.load -class Recipient - attr_reader :slack_id, :name +module SlackApi BASE_URL = "https://slack.com/api/chat.postMessage" SLACK_TOKEN = ENV["SLACK_TOKEN"] - def initialize(slack_id) - @slack_id = slack_id - @name = name - end - - # class SlackApiError < StandardError - # raise SlackApiError, "This id does not exist" - # end - - def send_message(message, user: true) - # query_param = { - # token: SLACK_TOKEN, - # channel: slack_id, - # text: message, - # as_user: user, - # } - - # response = HTTParty.post( - # "#{BASE_URL}", - # body: { - # token: SLACK_TOKEN, - # text: message, - # channel: slack_id, - # }, - # ) - - # if !response.code == 200 && response.parsed_response["ok"] - # raise SlackApiError, "Oops something went wrong" - # end - - # return response.code == 200 && response.parsed_response["ok"] - - # if response.code != 200 raise SlackApiError, "This user/channel does not exist" - - end - - def self.get(url, params) - # SLACK_TOKEN = ENV["SLACK_TOKEN"] - # param = { - # token: SLACK_TOKEN, - # } - # response = HTTParty.get(url, query: param) - end - - private - - def details - end - - def self.list + class SlackApiError < StandardError; end + + def self.send_message(message, user) + response = HTTParty.post( + "#{BASE_URL}", + headers: { "Content-Type" => "application/x-www-form-urlencoded" }, + body: { + token: SLACK_TOKEN, + text: message, + channel: user, + }, + ) + + if response["ok"] + return true + else + raise SlackApi::SlackApiError, "Error when posting #{message} to #{user}, error: #{response["error"]}" + end end end diff --git a/lib/slack.rb b/lib/slack.rb index c90991bf..aedb19ff 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -11,7 +11,8 @@ def main puts "2. List Channels" puts "3. Select User" puts "4. Select Channel" - puts "5. Quit" + puts "5. Send Message" + puts "6. Quit" selection = gets.chomp @@ -31,7 +32,21 @@ def main chose_channel = gets.chomp workspace = Workspace.new puts workspace.show_details_channel(chose_channel) - when "5" + when "6" + channel_name = Channel.list.map do |channel| + channel[0] + end + puts "Here is a list of channels: #{channel_name}" + + user_name = User.list.map do |user| + user[0] + end + puts "Here is a list of Users#{user_name}" + puts "Input the person's or channel's name you'd like to send to: " + recipient = gets.chomp + puts "Please input your message:" + message = gets.chomp + when "6" break end end diff --git a/lib/slack_api_wrapper.rb b/lib/slack_api_wrapper.rb deleted file mode 100644 index c4c38430..00000000 --- a/lib/slack_api_wrapper.rb +++ /dev/null @@ -1,29 +0,0 @@ -require "httparty" -require "dotenv" - -Dotenv.load - -module SlackApi - BASE_URL = "https://slack.com/api/chat.postMessage" - SLACK_TOKEN = ENV["SLACK_TOKEN"] - - class SlackApiError < StandardError; end - - def self.send_message(message, user) - response = HTTParty.post( - "#{BASE_URL}", - headers: {"Content-Type" => "application/x-www-form-urlencoded"}, - body: { - token: SLACK_TOKEN, - text: message, - channel: user, - }, - ) - - if response["ok"] - return true - else - raise SlackApi::SlackApiError, "Error when posting #{message} to #{user}, error: #{response["error"]}" - end - end -end diff --git a/practice.rb b/practice.rb index 150485f7..b03b96c1 100644 --- a/practice.rb +++ b/practice.rb @@ -1,18 +1,33 @@ +# puts "Welcome to the Ada Slack CLI!" +# puts "We currently have #{User.list.length} members and #{Channel.list.length} channels." + +puts "" puts "Please choose one of the the following number options" puts "1. List Users" puts "2. List Channels" -puts "3. Quit" +puts "3. Select User" +puts "4. Select Channel" +puts "5. Quit" selection = gets.chomp loop do - if selection == "1" + case selection + when "1" puts "Here is the list of users:" # puts User.list - elsif selection == "2" + when "2" puts "Here is the list of channels: " # puts Channel.list - else + when "3" + chose_user = gets.chomp + workspace = Workspace.new + # puts workspace.show_details_user(chose_user) + when "4" + chose_channel = gets.chomp + workspace = Workspace.new + # puts workspace.show_details_channel(chose_channel) + when "5" break end end diff --git a/specs/dont_use_recipient_spec.rb b/specs/dont_use_recipient_spec.rb new file mode 100644 index 00000000..f7c91f94 --- /dev/null +++ b/specs/dont_use_recipient_spec.rb @@ -0,0 +1,23 @@ +require_relative "test_helper" +require "pry" +# describe do +# # it "will raise an error when given an invalid channel" do +# # error = Recipient.new(ES38768) + +# # VCR.use_cassette("slack-posts") do +# # exception = expect { +# # error.send_message("This post should not work", "invalid-channel") +# # }.must_raise SlackApiError + +# # expect(exception.message).must_equal "Oops something went wrong" +# # end +# # end + +# # verify that it sends a message + +# # what happens with invalid text + +# # what happends with invalid token + +# # look at required and option, and how program should respond +# end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index f7c91f94..ef394cd0 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -1,23 +1,32 @@ require_relative "test_helper" require "pry" -# describe do -# # it "will raise an error when given an invalid channel" do -# # error = Recipient.new(ES38768) -# # VCR.use_cassette("slack-posts") do -# # exception = expect { -# # error.send_message("This post should not work", "invalid-channel") -# # }.must_raise SlackApiError +describe SlackApi do + it "can send a valid message" do + VCR.use_cassette("slack_message") do + return_value = SlackApi.send_message("It's gonna work!", + "CH0E8S9UY") + expect(return_value).must_equal true + end + end -# # expect(exception.message).must_equal "Oops something went wrong" -# # end -# # end + it "generates an error if given an invalid channel" do + VCR.use_cassette("slack_message") do + # return_value = SlackApi.send_message("Test message", + # "bogus") + expect { + SlackApi.send_message("Test message", + "bogus") + }.must_raise SlackApi::SlackApiError + end + end -# # verify that it sends a message - -# # what happens with invalid text - -# # what happends with invalid token - -# # look at required and option, and how program should respond -# end + it "will generate an error if given an invalid key" do + VCR.use_cassette("slack_message") do + end + end + it "will raise an error if given an empty message" do + VCR.use_cassette("slack_message") do + end + end +end diff --git a/specs/slack_api_wrapper_spec.rb b/specs/slack_api_wrapper_spec.rb deleted file mode 100644 index ef394cd0..00000000 --- a/specs/slack_api_wrapper_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require_relative "test_helper" -require "pry" - -describe SlackApi do - it "can send a valid message" do - VCR.use_cassette("slack_message") do - return_value = SlackApi.send_message("It's gonna work!", - "CH0E8S9UY") - expect(return_value).must_equal true - end - end - - it "generates an error if given an invalid channel" do - VCR.use_cassette("slack_message") do - # return_value = SlackApi.send_message("Test message", - # "bogus") - expect { - SlackApi.send_message("Test message", - "bogus") - }.must_raise SlackApi::SlackApiError - end - end - - it "will generate an error if given an invalid key" do - VCR.use_cassette("slack_message") do - end - end - it "will raise an error if given an empty message" do - VCR.use_cassette("slack_message") do - end - end -end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index a4a42589..74ffa02b 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -30,7 +30,7 @@ require_relative "../lib/channel" require_relative "../lib/workspace" require_relative "../lib/recipient" -require_relative "../lib/slack_api_wrapper" +# require_relative "../lib/slack_api_wrapper" # What would you like to test # test for 200 status and message - different From 6947a93ce7efa6c05987723da3d685ad9df1ea7f Mon Sep 17 00:00:00 2001 From: Angela Date: Wed, 20 Mar 2019 14:12:59 -0700 Subject: [PATCH 14/27] added until loop in slack.rb --- lib/slack.rb | 33 ++++++++++++++++++++++++++------- specs/.DS_Store | Bin 0 -> 6148 bytes 2 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 specs/.DS_Store diff --git a/lib/slack.rb b/lib/slack.rb index aedb19ff..462972dd 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,10 +1,15 @@ -#!/usr/bin/env rub +#!/usr/bin/env ruby require "dotenv" +require_relative "user" +require_relative "channel" +require_relative "workspace" +require_relative "recipient" def main puts "Welcome to the Ada Slack CLI!" puts "We currently have #{User.list.length} members and #{Channel.list.length} channels." + # user_input = true puts "" puts "Please choose one of the the following number options" puts "1. List Users" @@ -13,26 +18,35 @@ def main puts "4. Select Channel" puts "5. Send Message" puts "6. Quit" - selection = gets.chomp - - loop do + until selection == "6" + # # loop d + # break if selection == "6" + # until user_input == false case selection when "1" puts "Here is the list of users:" puts User.list + puts "What would you like to do next? " + selection = gets.chomp when "2" puts "Here is the list of channels: " puts Channel.list + puts "What would you like to do next? " + selection = gets.chomp when "3" chose_user = gets.chomp workspace = Workspace.new puts workspace.show_details_user(chose_user) + puts "What would you like to do next? " + selection = gets.chomp when "4" chose_channel = gets.chomp workspace = Workspace.new puts workspace.show_details_channel(chose_channel) - when "6" + puts "What would you like to do next? " + selection = gets.chomp + when "5" channel_name = Channel.list.map do |channel| channel[0] end @@ -46,9 +60,14 @@ def main recipient = gets.chomp puts "Please input your message:" message = gets.chomp - when "6" - break + + SlackApi.send_message(message, recipient) + puts "What would you like to do next? " + selection = gets.chomp + # when "6" + # user_input = false end + # break end puts "Thank you for using the Ada Slack CLI" diff --git a/specs/.DS_Store b/specs/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..cbe5a12bd0c9d6b99f296570058cd24d01452784 GIT binary patch literal 6148 zcmeHKO-sW-5PegNR1|Gbil-bs37)-#QV*W}0osp1i=mZh@tTW&Mez6e1N6=AP;Jr( zUW&*}n0=esnc3a9OEwEY`pd}$&;`(;Dz^4mY!Gc%tx3x)yF>{&=E#ua7LRzSdAs2+ zGN5aBgfXTVV$SDl{W4n5QDAhPFUF&MF`}n#lS}H^M-bM4Q%ta6)Xrkrn;oW0*>kmE{*LyjloXmnIl*7DGMv1vx~Qi(mVc@(yj8%8bfmAD?B z$wYzsu>Xf-K)Lv7-pb|cH!k_=;tV(g&cGHJ;F+z`*^lU@GvEw311kpf`;br-Q^PW1 z_;j!cR{&z0<{+%=Pol;ohN)p0ku4O7p~M&}cEykwPJ3d0sbLv0hC}S~A=b0l4Mjrl z%%22zNE*>gXTTX)XJ9A3cJ=(fYQF!k2l<;b;0*jL2BbZ>8T2_NJ6mg$)3Y|A-ceQ5 nuZ*|~VI>^J^wp#Igc^kQL@UJ9u#89x#eW0>4PH0{TV>!AIo)v% literal 0 HcmV?d00001 From 112a72fdef235e5dd1c603d92fe3fb804aa7151c Mon Sep 17 00:00:00 2001 From: Angela Date: Wed, 20 Mar 2019 14:28:09 -0700 Subject: [PATCH 15/27] added useful comment --- lib/slack.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/slack.rb b/lib/slack.rb index 462972dd..7e409707 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -23,6 +23,8 @@ def main # # loop d # break if selection == "6" # until user_input == false + + #TODO: add command list every time teh loop repreats case selection when "1" puts "Here is the list of users:" From b8bb13d0cab508f1548718ddf871872730518d5f Mon Sep 17 00:00:00 2001 From: Shamira Date: Wed, 20 Mar 2019 14:51:57 -0700 Subject: [PATCH 16/27] adding details functionality --- lib/slack.rb | 10 ++++++++-- lib/workspace.rb | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 7e409707..6af0102d 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -39,13 +39,19 @@ def main when "3" chose_user = gets.chomp workspace = Workspace.new - puts workspace.show_details_user(chose_user) + details = workspace.select_user(chose_user) + puts details puts "What would you like to do next? " selection = gets.chomp when "4" chose_channel = gets.chomp workspace = Workspace.new - puts workspace.show_details_channel(chose_channel) + details = workspace.select_channel(chose_channel) + puts details + puts "What would you like to do next? " + selection = gets.chomp + when "details" + puts workspace.show_details_channel(details) puts "What would you like to do next? " selection = gets.chomp when "5" diff --git a/lib/workspace.rb b/lib/workspace.rb index fe774fc4..0eed4183 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -13,16 +13,26 @@ def initialize class SlackApiError < StandardError; end - def select_channel(channel) + def select_channel(selected) #Channel.list #using param, find specific channel # returns an instance of channel + Channel.list.each do |instance| + if selected == instance[0] + return instance + end + end end - def select_user(user) + def select_user(selected) #User.list #using param, find specific user # returns an instance of user + User.list.each do |instance| + if selected == instance[0] + return instance + end + end end # seperate methods for Channel and User From 3365cece7d976d3017ddb684825098b682ce94f9 Mon Sep 17 00:00:00 2001 From: Angela Date: Wed, 20 Mar 2019 15:58:01 -0700 Subject: [PATCH 17/27] fixed show_details --- lib/slack.rb | 86 +++++++++++++++++++++++++++--------------------- lib/workspace.rb | 79 +++++++++++++++++++++++++++++++------------- 2 files changed, 106 insertions(+), 59 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 6af0102d..d10e8ddc 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -5,64 +5,79 @@ require_relative "workspace" require_relative "recipient" +### WHAT DID I CHANGE +#1. formatting for outputting List ____ +#2. moved channel_name and user_name to top +#3. added to workspace class - show_details uses channel_name.include? or user_name.include? +#4. added to workspace class - select_user or select_channel returns SELECTED = string + def main + channel_name = Channel.list.map do |channel| + channel[0] + end + user_name = User.list.map do |user| + user[0] + end puts "Welcome to the Ada Slack CLI!" - puts "We currently have #{User.list.length} members and #{Channel.list.length} channels." - - # user_input = true + puts "We currently have '#{User.list.length}' members and '#{Channel.list.length} channels.'" puts "" - puts "Please choose one of the the following number options" - puts "1. List Users" - puts "2. List Channels" - puts "3. Select User" - puts "4. Select Channel" - puts "5. Send Message" - puts "6. Quit" + puts "Please choose one of the the following options" + puts "List Users" + puts "List Channels" + puts "Select User" + puts "Select Channel" + puts "Details" + puts "Send Message" + puts "Quit" selection = gets.chomp - until selection == "6" - # # loop d - # break if selection == "6" - # until user_input == false + until selection == "Quit" #TODO: add command list every time teh loop repreats + # TODO: format output for listing case selection - when "1" - puts "Here is the list of users:" - puts User.list + when "List Users" + puts "Here is the list of users and their details:" + User.list.each do |user| + puts "Username: #{user[0]}" + puts "Real Name: #{user[1]}" + puts "Slack_ID: #{user[2]}" + puts "" + end puts "What would you like to do next? " selection = gets.chomp - when "2" - puts "Here is the list of channels: " - puts Channel.list + when "List Channels" + puts "Here is the list of channels and their details: " + Channel.list.each do |channel| + puts "Name: #{channel[0]}" + puts "Topic: #{channel[1]}" + puts "Member Count: #{channel[2]}" + puts "Slack_ID: #{channel[3]}" + puts "" + end puts "What would you like to do next? " selection = gets.chomp - when "3" + when "Select User" + puts "Here are all the members' user names: #{user_name}" chose_user = gets.chomp workspace = Workspace.new details = workspace.select_user(chose_user) - puts details + puts "You just selected #{details}" puts "What would you like to do next? " selection = gets.chomp - when "4" + when "Select Channel" + puts "Here are all the channels' names: #{channel_name}" chose_channel = gets.chomp workspace = Workspace.new details = workspace.select_channel(chose_channel) - puts details + puts "You just selected #{details}" puts "What would you like to do next? " selection = gets.chomp - when "details" - puts workspace.show_details_channel(details) + when "Details" + puts workspace.show_details(details) puts "What would you like to do next? " selection = gets.chomp - when "5" - channel_name = Channel.list.map do |channel| - channel[0] - end + when "Send Message" puts "Here is a list of channels: #{channel_name}" - - user_name = User.list.map do |user| - user[0] - end puts "Here is a list of Users#{user_name}" puts "Input the person's or channel's name you'd like to send to: " recipient = gets.chomp @@ -72,10 +87,7 @@ def main SlackApi.send_message(message, recipient) puts "What would you like to do next? " selection = gets.chomp - # when "6" - # user_input = false end - # break end puts "Thank you for using the Ada Slack CLI" diff --git a/lib/workspace.rb b/lib/workspace.rb index 0eed4183..d2c55efa 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,10 +1,19 @@ require "dotenv" +require "httparty" +require_relative "user" +require_relative "channel" Dotenv.load class Workspace attr_reader :user, :channel attr_accessor :selected + # USER_URL = "https://slack.com/api/users.list" + # SLACK_TOKEN = ENV["SLACK_TOKEN"] + + # CHANNEL_URL = "https://slack.com/api/channels.list" + # SLACK_TOKEN = ENV["SLACK_TOKEN"] + def initialize @user = [] @channel = [] @@ -17,43 +26,69 @@ def select_channel(selected) #Channel.list #using param, find specific channel # returns an instance of channel - Channel.list.each do |instance| - if selected == instance[0] - return instance - end - end + + # selected = Channel.new + # Channel.list.each do |instance| + # if selected == instance[0] + # return instance + # end + # end + + selected end def select_user(selected) #User.list #using param, find specific user # returns an instance of user - User.list.each do |instance| - if selected == instance[0] - return instance - end - end + # User.list.each do |instance| + # if selected == instance[0] + # return instance + # end + # end + # selected = User.new + + selected end # seperate methods for Channel and User - def show_details_channel(selected) - # something that represents channel - Channel.list.each do |instance| - if selected == instance[0] - return instance + def show_details(selected) + # array of all user names + user_name = User.list.map do |user| + user[0] + end + # array of all channel names + channel_name = Channel.list.map do |channel| + channel[0] + end + if channel_name.include?(selected) + Channel.list.each do |instance| + if selected == instance[0] + return instance + end + end + elsif user_name.include?(selected) + User.list.each do |instance| + if selected == instance[0] + return instance + end end end - end - def show_details_user(selected) - #something users - User.list.each do |instance| - if selected == instance[0] - return instance - end + if selected == "" + raise SlackApiError, "No user of channel was selected!" end end + # def show_details_user(selected) + # #something users + # User.list.each do |instance| + # if selected == instance[0] + # return instance + # end + # end + # end + def send_message end end From 9bc79b575c2962aa5bde185445b56c8c5f02c56d Mon Sep 17 00:00:00 2001 From: Shamira Date: Thu, 21 Mar 2019 11:47:33 -0700 Subject: [PATCH 18/27] notes on how to add select methods to send user method --- lib/recipient.rb | 15 +++++++++++++-- lib/workspace.rb | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 6cecaa48..a72d2854 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -10,13 +10,24 @@ module SlackApi class SlackApiError < StandardError; end def self.send_message(message, user) + # user_id = User.list.each do |id| + # if user == id[0] + # user[2] + # end + # end + + # have two responses if select is a type of user choose 1st response + # else if user input is a type of channel choose 2nd response. the channel can be select_user or select_channel from the main + # we'd have to require workspace + response = HTTParty.post( "#{BASE_URL}", - headers: { "Content-Type" => "application/x-www-form-urlencoded" }, + headers: {"Content-Type" => "application/x-www-form-urlencoded"}, body: { token: SLACK_TOKEN, text: message, - channel: user, + channel: user_id, #.select_user(chose_user) + as_user: true, }, ) diff --git a/lib/workspace.rb b/lib/workspace.rb index d2c55efa..7fd55c97 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -22,6 +22,7 @@ def initialize class SlackApiError < StandardError; end + # make these Class methods def select_channel(selected) #Channel.list #using param, find specific channel From c2551d720a34375c4fcc5bb6c8dc85da74bdddfb Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 21 Mar 2019 13:27:17 -0700 Subject: [PATCH 19/27] fixed sending message to a channel --- lib/recipient.rb | 7 ++++--- lib/slack.rb | 8 ++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index a72d2854..bb99b7f0 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,5 +1,6 @@ require "httparty" require "dotenv" +require_relative "workspace" Dotenv.load @@ -19,14 +20,14 @@ def self.send_message(message, user) # have two responses if select is a type of user choose 1st response # else if user input is a type of channel choose 2nd response. the channel can be select_user or select_channel from the main # we'd have to require workspace - + test_workspace = Workspace.new response = HTTParty.post( "#{BASE_URL}", - headers: {"Content-Type" => "application/x-www-form-urlencoded"}, + headers: { "Content-Type" => "application/x-www-form-urlencoded" }, body: { token: SLACK_TOKEN, text: message, - channel: user_id, #.select_user(chose_user) + channel: test_workspace.select_channel(user), #.select_user(chose_user) as_user: true, }, ) diff --git a/lib/slack.rb b/lib/slack.rb index d10e8ddc..fdafbe74 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -73,18 +73,14 @@ def main puts "What would you like to do next? " selection = gets.chomp when "Details" - puts workspace.show_details(details) + puts Workspace.show_details(details) puts "What would you like to do next? " selection = gets.chomp when "Send Message" - puts "Here is a list of channels: #{channel_name}" - puts "Here is a list of Users#{user_name}" - puts "Input the person's or channel's name you'd like to send to: " - recipient = gets.chomp puts "Please input your message:" message = gets.chomp - SlackApi.send_message(message, recipient) + SlackApi.send_message(message, chose_channel) puts "What would you like to do next? " selection = gets.chomp end From e3c6412e09713ddc4144ceb037e3f5677410062e Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 21 Mar 2019 13:36:03 -0700 Subject: [PATCH 20/27] fixed our ability to send messages to user and aligned with project requirements --- lib/recipient.rb | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index bb99b7f0..bbfcc5b3 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,6 +1,8 @@ require "httparty" require "dotenv" require_relative "workspace" +require_relative "user" +require_relative "channel" Dotenv.load @@ -11,6 +13,13 @@ module SlackApi class SlackApiError < StandardError; end def self.send_message(message, user) + user_name = User.list.map do |user| + user[0] + end + # array of all channel names + channel_name = Channel.list.map do |channel| + channel[0] + end # user_id = User.list.each do |id| # if user == id[0] # user[2] @@ -21,16 +30,29 @@ def self.send_message(message, user) # else if user input is a type of channel choose 2nd response. the channel can be select_user or select_channel from the main # we'd have to require workspace test_workspace = Workspace.new - response = HTTParty.post( - "#{BASE_URL}", - headers: { "Content-Type" => "application/x-www-form-urlencoded" }, - body: { - token: SLACK_TOKEN, - text: message, - channel: test_workspace.select_channel(user), #.select_user(chose_user) - as_user: true, - }, - ) + if channel_name.include?(user) + response = HTTParty.post( + "#{BASE_URL}", + headers: { "Content-Type" => "application/x-www-form-urlencoded" }, + body: { + token: SLACK_TOKEN, + text: message, + channel: test_workspace.select_channel(user), #.select_user(chose_user) + as_user: true, + }, + ) + elsif user_name.include?(user) + response = HTTParty.post( + "#{BASE_URL}", + headers: { "Content-Type" => "application/x-www-form-urlencoded" }, + body: { + token: SLACK_TOKEN, + text: message, + channel: test_workspace.select_user(user), #.select_user(chose_user) + as_user: true, + }, + ) + end if response["ok"] return true From 49c24cd15c8982e67eb61edf12d9c24a9eda25e7 Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 21 Mar 2019 15:01:47 -0700 Subject: [PATCH 21/27] fixed sending message to user --- lib/recipient.rb | 12 +- lib/slack.rb | 16 ++- lib/workspace.rb | 2 +- specs/recipient_spec.rb | 16 ++- specs/workspace_spec.rb | 39 +++--- test/cassettes/slack_channels.yml | 149 ++++++++++++++++++++ test/cassettes/slack_message.yml | 214 +++++++++++++++++++++++++++++ test/cassettes/slack_message2.yml | 217 ++++++++++++++++++++++++++++++ 8 files changed, 631 insertions(+), 34 deletions(-) create mode 100644 test/cassettes/slack_message2.yml diff --git a/lib/recipient.rb b/lib/recipient.rb index bbfcc5b3..171bac03 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -29,6 +29,15 @@ def self.send_message(message, user) # have two responses if select is a type of user choose 1st response # else if user input is a type of channel choose 2nd response. the channel can be select_user or select_channel from the main # we'd have to require workspace + + #### testing user stuff + practice = [] + User.list.each do |user_name| + if user_name[0] == user + practice << user_name[2] + end + end + test_workspace = Workspace.new if channel_name.include?(user) response = HTTParty.post( @@ -48,7 +57,8 @@ def self.send_message(message, user) body: { token: SLACK_TOKEN, text: message, - channel: test_workspace.select_user(user), #.select_user(chose_user) + channel: practice[0], + # test_workspace.select_user(user) #.select_user(chose_user) as_user: true, }, ) diff --git a/lib/slack.rb b/lib/slack.rb index fdafbe74..be10154f 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -58,29 +58,33 @@ def main selection = gets.chomp when "Select User" puts "Here are all the members' user names: #{user_name}" - chose_user = gets.chomp + chose = gets.chomp #chose_user workspace = Workspace.new - details = workspace.select_user(chose_user) + details = workspace.select_user(chose) puts "You just selected #{details}" puts "What would you like to do next? " selection = gets.chomp when "Select Channel" puts "Here are all the channels' names: #{channel_name}" - chose_channel = gets.chomp + chose = gets.chomp #chose_channel workspace = Workspace.new - details = workspace.select_channel(chose_channel) + details = workspace.select_channel(chose) puts "You just selected #{details}" puts "What would you like to do next? " selection = gets.chomp when "Details" - puts Workspace.show_details(details) + ###### JUST CHANGED + puts workspace.show_details(details) puts "What would you like to do next? " selection = gets.chomp when "Send Message" puts "Please input your message:" message = gets.chomp - SlackApi.send_message(message, chose_channel) + ### WE NEED TO ROUTE PATH TO CORRECT LIKE OF SEND MESSAGE + + SlackApi.send_message(message, chose) + # SlackApi.send_message(message, chose_channel) puts "What would you like to do next? " selection = gets.chomp end diff --git a/lib/workspace.rb b/lib/workspace.rb index 7fd55c97..d43ce791 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -17,7 +17,7 @@ class Workspace def initialize @user = [] @channel = [] - @selected = selected + # @selected = selected end class SlackApiError < StandardError; end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index ef394cd0..1d8c5566 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -2,13 +2,15 @@ require "pry" describe SlackApi do - it "can send a valid message" do - VCR.use_cassette("slack_message") do - return_value = SlackApi.send_message("It's gonna work!", - "CH0E8S9UY") - expect(return_value).must_equal true - end - end + # it "can send a valid message" do + # VCR.use_cassette("slack_message2") do + # # test_workspace = SlackApi::Workspace.new + # return_value = SlackApi.send_message("It's gonna work!", + # "marshallscm") + + # expect(return_value).must_equal true + # end + # end it "generates an error if given an invalid channel" do VCR.use_cassette("slack_message") do diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 075610be..d5f01a1d 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -1,28 +1,29 @@ require_relative "test_helper" require "pry" describe "show details method" do - it "gives details for a specific instance of Channel" do - VCR.use_cassette("slack_channels") do - # response = test_channel.get_channel - Channel.list - test_workspace = Workspace.new - channel_test_1 = Channel.list[0][0] + # it "gives details for a specific instance of Channel" do + # VCR.use_cassette("slack_channels") do + # # response = test_channel.get_channel + # test_workspace = Workspace.new + # channel_test_1 = Channel.list[0][0] + # user_test_1 = User.list[0][0] - expect(test_workspace.show_details_channel(channel_test_1)).must_equal ["everyone", "Company-wide announcements and work-based matters", 2, "CH0E8S9UY"] - # expect(Channel.list.first).must_be_kind_of Array - end - end + # expect(test_workspace.show_details(channel_test_1)).must_equal ["everyone", "Company-wide announcements and work-based matters", 2, "CH0E8S9UY"] + # expect(test_workspace.show_details(user_test_1)).must_equal ["slackbot", "Slackbot", "USLACKBOT"] + # # expect(Channel.list.first).must_be_kind_of Array + # end + # end - it "gives details for a specific instance of User" do - VCR.use_cassette("slack_channels") do - # response = test_channel.get_channel - User.list - test_workspace = Workspace.new - user_test_1 = User.list[0][0] + # it "gives details for a specific instance of User" do + # VCR.use_cassette("slack_channels") do + # # response = test_channel.get_channel + # User.list + # test_workspace = Workspace.new + # user_test_1 = User.list[0][0] - expect(test_workspace.show_details_user(user_test_1)).must_equal ["slackbot", "Slackbot", "USLACKBOT"] - end - end + # expect(test_workspace.show_details_user(user_test_1)).must_equal ["slackbot", "Slackbot", "USLACKBOT"] + # end + # end # edge cases, what if the list is 0? # argument error, this user/channel does not exist. diff --git a/test/cassettes/slack_channels.yml b/test/cassettes/slack_channels.yml index 557885d9..fe778a59 100644 --- a/test/cassettes/slack_channels.yml +++ b/test/cassettes/slack_channels.yml @@ -522,4 +522,153 @@ http_interactions: Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"angela.ohh","real_name_normalized":"angela.ohh","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"ge9c24d2cfc6","image_24":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0001-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552951939,"has_2fa":false}],"cache_ts":1553037091,"response_metadata":{"next_cursor":""}}' http_version: recorded_at: Tue, 19 Mar 2019 23:10:28 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: + - '549' + Connection: + - keep-alive + Date: + - Thu, 21 Mar 2019 21:21:29 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 5cfa1401-3f98-4059-b658-a6d8573bc832 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:user,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 + 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-5iyg + X-Cache: + - Miss from cloudfront + Via: + - 1.1 010086e284fd9714db3b3e3d1d295b60.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - 77dEXSc7j1JfrMk1GkN57utb8rXlKq2UswSvB8CudwWFzQIAwgZgFQ== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CH0E8S9UY","name":"everyone","is_channel":true,"created":1552951939,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"everyone","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UH2S78AHY","last_set":1552951939},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH0E8SBA4","name":"random","is_channel":true,"created":1552951939,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UH2S78AHY","last_set":1552951939},"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":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH2R9UGCU","name":"api-slack","is_channel":true,"created":1552951940,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"api-slack","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Thu, 21 Mar 2019 21:20:07 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: + - '964' + Connection: + - keep-alive + Date: + - Thu, 21 Mar 2019 21:21:29 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - eb6c41a6-1e7d-4682-a387-9f41b471e52b + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:user,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 + 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-i1os + X-Cache: + - Miss from cloudfront + Via: + - 1.1 e9a9022a4b078c3e041bab2045f5beef.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - yQlaP1MlZ3CbNDjB5yG1Kdkin9WFKSfXFiVOV_x-P52mhUYTiAGU7w== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH49RSM8W","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\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":"UH2RALWR2","team_id":"TH49RSM8W","name":"marshallscm","deleted":false,"color":"4bbe2e","real_name":"Shamira + Marshall","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Shamira + Marshall","real_name_normalized":"Shamira Marshall","display_name":"Shamira + Marshall","display_name_normalized":"Shamira Marshall","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"7608f9ef4784","image_original":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_original.jpg","first_name":"Shamira","last_name":"Marshall","image_24":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_24.jpg","image_32":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_32.jpg","image_48":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_48.jpg","image_72":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_72.jpg","image_192":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_192.jpg","image_512":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_512.jpg","image_1024":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_1024.jpg","status_text_canonical":"","team":"TH49RSM8W","is_custom_image":true},"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":1553100291,"has_2fa":false},{"id":"UH2S78AHY","team_id":"TH49RSM8W","name":"angela.ohh","deleted":false,"color":"9f69e7","real_name":"angela.ohh","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"angela.ohh","real_name_normalized":"angela.ohh","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"ge9c24d2cfc6","image_24":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0001-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552951939,"has_2fa":false}],"cache_ts":1553203289,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Thu, 21 Mar 2019 21:20:08 GMT recorded_with: VCR 4.0.0 diff --git a/test/cassettes/slack_message.yml b/test/cassettes/slack_message.yml index 6e865749..e6f0a169 100644 --- a/test/cassettes/slack_message.yml +++ b/test/cassettes/slack_message.yml @@ -197,4 +197,218 @@ http_interactions: gonna work!","ts":"1553114290.000200","username":"Ports - Shamira - API Project","bot_id":"BH2RK7F9S"}}' http_version: recorded_at: Wed, 20 Mar 2019 20:38:10 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: + - '964' + Connection: + - keep-alive + Date: + - Thu, 21 Mar 2019 21:16:48 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 9698383c-8c39-4fcc-a2d7-9d18452dcf01 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:user,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 + 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-b5y2 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 44914fa6421b789193cec8998428f8bd.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - LS-HsDokakZUO0INJK5YQEz_IycA3K2kFXBBcY6xGA0HoYVqxbCZ_Q== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH49RSM8W","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\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":"UH2RALWR2","team_id":"TH49RSM8W","name":"marshallscm","deleted":false,"color":"4bbe2e","real_name":"Shamira + Marshall","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Shamira + Marshall","real_name_normalized":"Shamira Marshall","display_name":"Shamira + Marshall","display_name_normalized":"Shamira Marshall","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"7608f9ef4784","image_original":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_original.jpg","first_name":"Shamira","last_name":"Marshall","image_24":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_24.jpg","image_32":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_32.jpg","image_48":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_48.jpg","image_72":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_72.jpg","image_192":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_192.jpg","image_512":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_512.jpg","image_1024":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_1024.jpg","status_text_canonical":"","team":"TH49RSM8W","is_custom_image":true},"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":1553100291,"has_2fa":false},{"id":"UH2S78AHY","team_id":"TH49RSM8W","name":"angela.ohh","deleted":false,"color":"9f69e7","real_name":"angela.ohh","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"angela.ohh","real_name_normalized":"angela.ohh","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"ge9c24d2cfc6","image_24":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0001-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552951939,"has_2fa":false}],"cache_ts":1553203008,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Thu, 21 Mar 2019 21:15:27 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: + - '549' + Connection: + - keep-alive + Date: + - Thu, 21 Mar 2019 21:16:49 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 75de4f25-9391-4fd4-bda7-8ef3c2e03506 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:user,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 + 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-s1yq + X-Cache: + - Miss from cloudfront + Via: + - 1.1 3e5a2f6c5b1171dae267d5a9344f95e8.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - nksaZ46XBGAX0PQkhstWRKypgMt5okH7m3QttCwuNIEa4kEV9GRHlA== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CH0E8S9UY","name":"everyone","is_channel":true,"created":1552951939,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"everyone","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UH2S78AHY","last_set":1552951939},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH0E8SBA4","name":"random","is_channel":true,"created":1552951939,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UH2S78AHY","last_set":1552951939},"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":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH2R9UGCU","name":"api-slack","is_channel":true,"created":1552951940,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"api-slack","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Thu, 21 Mar 2019 21:15:27 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&text=It%27s%20gonna%20work%21&channel=marshallscm&as_user=true + headers: + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Date: + - Thu, 21 Mar 2019 21:22:05 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - b84cbe1b-40d0-4e43-bcaf-acc87bdb6bc9 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:user,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 + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:user + 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-6ur8 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 3a3b6c95360356dea16e73abeac4acfb.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - eP8jG74llIep7XP-Oe9BiC3qtATSNlXMi_DAcGF7t8NuidISThAhoA== + body: + encoding: UTF-8 + string: '{"ok":false,"error":"channel_not_found"}' + http_version: + recorded_at: Thu, 21 Mar 2019 21:20:43 GMT recorded_with: VCR 4.0.0 diff --git a/test/cassettes/slack_message2.yml b/test/cassettes/slack_message2.yml new file mode 100644 index 00000000..90f20742 --- /dev/null +++ b/test/cassettes/slack_message2.yml @@ -0,0 +1,217 @@ +--- +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: + - '964' + Connection: + - keep-alive + Date: + - Thu, 21 Mar 2019 21:31:17 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 653eb101-9438-47df-a891-08dfaf8e2548 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:user,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 + 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-imty + X-Cache: + - Miss from cloudfront + Via: + - 1.1 c0098ca8d6549ce8db6f28ee0b22a4ce.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - K-myWzOG7CHneXnlSeLbiKrHSOOeZyp5HYqgm26s1BWEq2q7ibaNUQ== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH49RSM8W","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\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":"UH2RALWR2","team_id":"TH49RSM8W","name":"marshallscm","deleted":false,"color":"4bbe2e","real_name":"Shamira + Marshall","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Shamira + Marshall","real_name_normalized":"Shamira Marshall","display_name":"Shamira + Marshall","display_name_normalized":"Shamira Marshall","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"7608f9ef4784","image_original":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_original.jpg","first_name":"Shamira","last_name":"Marshall","image_24":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_24.jpg","image_32":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_32.jpg","image_48":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_48.jpg","image_72":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_72.jpg","image_192":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_192.jpg","image_512":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_512.jpg","image_1024":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_1024.jpg","status_text_canonical":"","team":"TH49RSM8W","is_custom_image":true},"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":1553100291,"has_2fa":false},{"id":"UH2S78AHY","team_id":"TH49RSM8W","name":"angela.ohh","deleted":false,"color":"9f69e7","real_name":"angela.ohh","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"angela.ohh","real_name_normalized":"angela.ohh","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"ge9c24d2cfc6","image_24":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0001-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552951939,"has_2fa":false}],"cache_ts":1553203877,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Thu, 21 Mar 2019 21:29:55 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: + - '549' + Connection: + - keep-alive + Date: + - Thu, 21 Mar 2019 21:31:17 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 75efc898-d7ae-41bb-a53a-bb82905ed47d + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:user,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 + 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-tufr + X-Cache: + - Miss from cloudfront + Via: + - 1.1 cb7132faa45d3b1ff4d65185f2d36d27.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - USkiqTfXB_f884bOClkZfJaQWs5SZp20eegiz0HYMiKL6J96yFz-Ww== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CH0E8S9UY","name":"everyone","is_channel":true,"created":1552951939,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"everyone","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UH2S78AHY","last_set":1552951939},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH0E8SBA4","name":"random","is_channel":true,"created":1552951939,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UH2S78AHY","last_set":1552951939},"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":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH2R9UGCU","name":"api-slack","is_channel":true,"created":1552951940,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"api-slack","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Thu, 21 Mar 2019 21:29:56 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&text=It%27s%20gonna%20work%21&channel=marshallscm&as_user=true + headers: + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Date: + - Thu, 21 Mar 2019 21:31:18 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - ffaeb739-cb7c-4765-8e4d-d06c7771f725 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:user,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 + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:user + 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-d8v + X-Cache: + - Miss from cloudfront + Via: + - 1.1 33a89f27becabefce49116de5fab23d8.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - rJchDWBkGxFE7HCAgus8k4GSw6zFgS3CybZwQVaLv-U-NAjvUudvXw== + body: + encoding: UTF-8 + string: '{"ok":false,"error":"channel_not_found"}' + http_version: + recorded_at: Thu, 21 Mar 2019 21:29:56 GMT +recorded_with: VCR 4.0.0 From 4a81dcb79c4d39bf4cac7400c5e3319328cf8fb8 Mon Sep 17 00:00:00 2001 From: Shamira Date: Thu, 21 Mar 2019 15:36:07 -0700 Subject: [PATCH 22/27] Added tests for workspace --- lib/recipient.rb | 8 +- lib/workspace.rb | 4 +- specs/recipient_spec.rb | 20 +- specs/workspace_spec.rb | 38 ++-- test/cassettes/slack_message.yml | 297 ++++++++++++++++++++++++++++++ test/cassettes/slack_message2.yml | 140 ++++++++++++++ 6 files changed, 472 insertions(+), 35 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 171bac03..4729d4ba 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -10,7 +10,7 @@ module SlackApi BASE_URL = "https://slack.com/api/chat.postMessage" SLACK_TOKEN = ENV["SLACK_TOKEN"] - class SlackApiError < StandardError; end + # class SlackApiError < StandardError; end def self.send_message(message, user) user_name = User.list.map do |user| @@ -42,7 +42,7 @@ def self.send_message(message, user) if channel_name.include?(user) response = HTTParty.post( "#{BASE_URL}", - headers: { "Content-Type" => "application/x-www-form-urlencoded" }, + headers: {"Content-Type" => "application/x-www-form-urlencoded"}, body: { token: SLACK_TOKEN, text: message, @@ -53,7 +53,7 @@ def self.send_message(message, user) elsif user_name.include?(user) response = HTTParty.post( "#{BASE_URL}", - headers: { "Content-Type" => "application/x-www-form-urlencoded" }, + headers: {"Content-Type" => "application/x-www-form-urlencoded"}, body: { token: SLACK_TOKEN, text: message, @@ -67,7 +67,7 @@ def self.send_message(message, user) if response["ok"] return true else - raise SlackApi::SlackApiError, "Error when posting #{message} to #{user}, error: #{response["error"]}" + raise SlackApi::ArgumentError, "Error when posting #{message} to #{user}, error: #{response["error"]}" end end end diff --git a/lib/workspace.rb b/lib/workspace.rb index d43ce791..56952427 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -20,7 +20,7 @@ def initialize # @selected = selected end - class SlackApiError < StandardError; end + # class SlackApiError < StandardError; end # make these Class methods def select_channel(selected) @@ -77,7 +77,7 @@ def show_details(selected) end if selected == "" - raise SlackApiError, "No user of channel was selected!" + raise ArgumentError, "No user of channel was selected!" end end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 1d8c5566..13a2e658 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -2,24 +2,26 @@ require "pry" describe SlackApi do - # it "can send a valid message" do - # VCR.use_cassette("slack_message2") do - # # test_workspace = SlackApi::Workspace.new - # return_value = SlackApi.send_message("It's gonna work!", - # "marshallscm") + it "can send a valid message" do + VCR.use_cassette("slack_message2") do + # test_workspace = SlackApi::Workspace.new + return_value = SlackApi.send_message("It's gonna work!", + "marshallscm") - # expect(return_value).must_equal true - # end - # end + expect(return_value).must_equal true + end + end it "generates an error if given an invalid channel" do VCR.use_cassette("slack_message") do # return_value = SlackApi.send_message("Test message", # "bogus") + puts "TESTING SOMETHIND #{SlackApi.send_message("Test message", + "bogus")}" expect { SlackApi.send_message("Test message", "bogus") - }.must_raise SlackApi::SlackApiError + }.must_raise SlackApi::ArgumentError end end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index d5f01a1d..744cb2c2 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -1,29 +1,27 @@ require_relative "test_helper" require "pry" describe "show details method" do - # it "gives details for a specific instance of Channel" do - # VCR.use_cassette("slack_channels") do - # # response = test_channel.get_channel - # test_workspace = Workspace.new - # channel_test_1 = Channel.list[0][0] - # user_test_1 = User.list[0][0] + it "gives details for a specific instance of Channel" do + VCR.use_cassette("slack_channels") do + test_workspace = Workspace.new + channel_test_1 = Channel.list[0][0] + user_test_1 = User.list[0][0] - # expect(test_workspace.show_details(channel_test_1)).must_equal ["everyone", "Company-wide announcements and work-based matters", 2, "CH0E8S9UY"] - # expect(test_workspace.show_details(user_test_1)).must_equal ["slackbot", "Slackbot", "USLACKBOT"] - # # expect(Channel.list.first).must_be_kind_of Array - # end - # end + expect(test_workspace.show_details(channel_test_1)).must_equal ["everyone", "Company-wide announcements and work-based matters", 2, "CH0E8S9UY"] + expect(test_workspace.show_details(user_test_1)).must_equal ["slackbot", "Slackbot", "USLACKBOT"] + end + end - # it "gives details for a specific instance of User" do - # VCR.use_cassette("slack_channels") do - # # response = test_channel.get_channel - # User.list - # test_workspace = Workspace.new - # user_test_1 = User.list[0][0] + it "raises SlackApiError if list is nil" do + VCR.use_cassette("slack_channels") do + # response = test_channel.get_channel + User.list + test_workspace = Workspace.new + test_workspace.select_user("") - # expect(test_workspace.show_details_user(user_test_1)).must_equal ["slackbot", "Slackbot", "USLACKBOT"] - # end - # end + expect { test_workspace.show_details(test_workspace.select_user("")) }.must_raise ArgumentError + end + end # edge cases, what if the list is 0? # argument error, this user/channel does not exist. diff --git a/test/cassettes/slack_message.yml b/test/cassettes/slack_message.yml index e6f0a169..6dbe87c0 100644 --- a/test/cassettes/slack_message.yml +++ b/test/cassettes/slack_message.yml @@ -411,4 +411,301 @@ http_interactions: string: '{"ok":false,"error":"channel_not_found"}' http_version: recorded_at: Thu, 21 Mar 2019 21:20:43 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: + - '962' + Connection: + - keep-alive + Date: + - Thu, 21 Mar 2019 22:06:21 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 69797b0a-3ec7-4f35-b886-943e8a0c6494 + X-Oauth-Scopes: + - identify,channels:read,im:read,users:read,users.profile:read,chat:write:user,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 + 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-7r9s + X-Cache: + - Miss from cloudfront + Via: + - 1.1 e9485f60105658dfd8d6d4dbc070260a.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - oP9dytJ-MPjnBVfXiOFL4zT8MyWFGrVPf0aLSz_SKSHvM0wjKE9GXw== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH49RSM8W","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\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":"UH2RALWR2","team_id":"TH49RSM8W","name":"marshallscm","deleted":false,"color":"4bbe2e","real_name":"Shamira + Marshall","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Shamira + Marshall","real_name_normalized":"Shamira Marshall","display_name":"Shamira + Marshall","display_name_normalized":"Shamira Marshall","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"7608f9ef4784","image_original":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_original.jpg","first_name":"Shamira","last_name":"Marshall","image_24":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_24.jpg","image_32":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_32.jpg","image_48":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_48.jpg","image_72":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_72.jpg","image_192":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_192.jpg","image_512":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_512.jpg","image_1024":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_1024.jpg","status_text_canonical":"","team":"TH49RSM8W","is_custom_image":true},"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":1553100291,"has_2fa":false},{"id":"UH2S78AHY","team_id":"TH49RSM8W","name":"angela.ohh","deleted":false,"color":"9f69e7","real_name":"angela.ohh","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"angela.ohh","real_name_normalized":"angela.ohh","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"ge9c24d2cfc6","image_24":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0001-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552951939}],"cache_ts":1553205981,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Thu, 21 Mar 2019 22:06:21 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: + - '962' + Connection: + - keep-alive + Date: + - Thu, 21 Mar 2019 22:17:32 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 021b80f6-6829-42bd-b77e-a03aae7f17f9 + X-Oauth-Scopes: + - identify,channels:read,im:read,users:read,users.profile:read,chat:write:user,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 + 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-46vh + X-Cache: + - Miss from cloudfront + Via: + - 1.1 7430a54821bbaeddfc77b56ba1b84eae.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - OHvZ5-9ATTIOhZzjeeQYDkFNzcyGvE85zL6QY8Avl6gzIJsjWkIfBA== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH49RSM8W","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\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":"UH2RALWR2","team_id":"TH49RSM8W","name":"marshallscm","deleted":false,"color":"4bbe2e","real_name":"Shamira + Marshall","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Shamira + Marshall","real_name_normalized":"Shamira Marshall","display_name":"Shamira + Marshall","display_name_normalized":"Shamira Marshall","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"7608f9ef4784","image_original":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_original.jpg","first_name":"Shamira","last_name":"Marshall","image_24":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_24.jpg","image_32":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_32.jpg","image_48":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_48.jpg","image_72":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_72.jpg","image_192":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_192.jpg","image_512":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_512.jpg","image_1024":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_1024.jpg","status_text_canonical":"","team":"TH49RSM8W","is_custom_image":true},"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":1553100291,"has_2fa":false},{"id":"UH2S78AHY","team_id":"TH49RSM8W","name":"angela.ohh","deleted":false,"color":"9f69e7","real_name":"angela.ohh","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"angela.ohh","real_name_normalized":"angela.ohh","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"ge9c24d2cfc6","image_24":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0001-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552951939}],"cache_ts":1553206652,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Thu, 21 Mar 2019 22:17:32 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: + - '549' + Connection: + - keep-alive + Date: + - Thu, 21 Mar 2019 22:17:32 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 79468c17-ca1a-4c66-a412-3a2da0421722 + X-Oauth-Scopes: + - identify,channels:read,im:read,users:read,users.profile:read,chat:write:user,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 + 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-1gfy + X-Cache: + - Miss from cloudfront + Via: + - 1.1 7fe3163daf2d65b2899c9b0772889524.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - bIV5lEdaA7fN9c50q9tqyVOJ7O_DJ3yylWgBikmtOiDfHXLwOeNkVg== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CH0E8S9UY","name":"everyone","is_channel":true,"created":1552951939,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"everyone","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UH2S78AHY","last_set":1552951939},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH0E8SBA4","name":"random","is_channel":true,"created":1552951939,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UH2S78AHY","last_set":1552951939},"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":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH2R9UGCU","name":"api-slack","is_channel":true,"created":1552951940,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"api-slack","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Thu, 21 Mar 2019 22:17: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: + - '962' + Connection: + - keep-alive + Date: + - Thu, 21 Mar 2019 22:17:32 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 4d7b6748-abbe-47cf-98fd-9968a5a5b20e + X-Oauth-Scopes: + - identify,channels:read,im:read,users:read,users.profile:read,chat:write:user,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 + 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-yqz7 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 3a3b6c95360356dea16e73abeac4acfb.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - HkEZCJEr8fI2ATq4nyr0adxw93kBmPApwOZO0BmsXILO61MPqECLpA== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH49RSM8W","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\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":"UH2RALWR2","team_id":"TH49RSM8W","name":"marshallscm","deleted":false,"color":"4bbe2e","real_name":"Shamira + Marshall","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Shamira + Marshall","real_name_normalized":"Shamira Marshall","display_name":"Shamira + Marshall","display_name_normalized":"Shamira Marshall","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"7608f9ef4784","image_original":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_original.jpg","first_name":"Shamira","last_name":"Marshall","image_24":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_24.jpg","image_32":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_32.jpg","image_48":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_48.jpg","image_72":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_72.jpg","image_192":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_192.jpg","image_512":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_512.jpg","image_1024":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_1024.jpg","status_text_canonical":"","team":"TH49RSM8W","is_custom_image":true},"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":1553100291,"has_2fa":false},{"id":"UH2S78AHY","team_id":"TH49RSM8W","name":"angela.ohh","deleted":false,"color":"9f69e7","real_name":"angela.ohh","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"angela.ohh","real_name_normalized":"angela.ohh","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"ge9c24d2cfc6","image_24":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0001-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552951939}],"cache_ts":1553206652,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Thu, 21 Mar 2019 22:17:32 GMT recorded_with: VCR 4.0.0 diff --git a/test/cassettes/slack_message2.yml b/test/cassettes/slack_message2.yml index 90f20742..faed1ce1 100644 --- a/test/cassettes/slack_message2.yml +++ b/test/cassettes/slack_message2.yml @@ -214,4 +214,144 @@ http_interactions: string: '{"ok":false,"error":"channel_not_found"}' http_version: recorded_at: Thu, 21 Mar 2019 21:29:56 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: + - '962' + Connection: + - keep-alive + Date: + - Thu, 21 Mar 2019 22:07:28 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - d0fcae61-6ce2-4a8b-86b2-e4b2a064fd21 + X-Oauth-Scopes: + - identify,channels:read,im:read,users:read,users.profile:read,chat:write:user,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 + 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-sqce + X-Cache: + - Miss from cloudfront + Via: + - 1.1 3a3b6c95360356dea16e73abeac4acfb.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - vVhbEkyzBFCGGj7b1424kylOPd78se0a7gVOrbAUq7fwQtmRQwVrOw== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH49RSM8W","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\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":"UH2RALWR2","team_id":"TH49RSM8W","name":"marshallscm","deleted":false,"color":"4bbe2e","real_name":"Shamira + Marshall","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Shamira + Marshall","real_name_normalized":"Shamira Marshall","display_name":"Shamira + Marshall","display_name_normalized":"Shamira Marshall","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"7608f9ef4784","image_original":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_original.jpg","first_name":"Shamira","last_name":"Marshall","image_24":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_24.jpg","image_32":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_32.jpg","image_48":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_48.jpg","image_72":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_72.jpg","image_192":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_192.jpg","image_512":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_512.jpg","image_1024":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_1024.jpg","status_text_canonical":"","team":"TH49RSM8W","is_custom_image":true},"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":1553100291,"has_2fa":false},{"id":"UH2S78AHY","team_id":"TH49RSM8W","name":"angela.ohh","deleted":false,"color":"9f69e7","real_name":"angela.ohh","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"angela.ohh","real_name_normalized":"angela.ohh","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"ge9c24d2cfc6","image_24":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0001-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552951939}],"cache_ts":1553206048,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Thu, 21 Mar 2019 22:07:28 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&text=It%27s%20gonna%20work%21&channel=UH2RALWR2&as_user=true + headers: + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Date: + - Thu, 21 Mar 2019 22:07:28 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 01c96752-e190-441b-8d81-76ab475c7f95 + X-Oauth-Scopes: + - identify,channels:read,im:read,users:read,users.profile:read,chat:write:user,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 + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:user + 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-c1so + X-Cache: + - Miss from cloudfront + Via: + - 1.1 36cc224d7812baa70145cc1e6b92b8a5.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - ndqdveb66Wx16JALVqY7f3oGccUFTvfobuWdIopykvsBi4a4qWG7yw== + body: + encoding: UTF-8 + string: '{"ok":true,"channel":"DH2S81ANN","ts":"1553206048.000100","message":{"bot_id":"BH2RK7F9S","type":"message","text":"It''s + gonna work!","user":"UH2RALWR2","ts":"1553206048.000100"}}' + http_version: + recorded_at: Thu, 21 Mar 2019 22:07:28 GMT recorded_with: VCR 4.0.0 From 955e8b126abd946ed187f71dce1a8d5cff4b60da Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 21 Mar 2019 15:55:26 -0700 Subject: [PATCH 23/27] cleaned up comments --- lib/channel.rb | 15 -------------- lib/recipient.rb | 16 +++------------ lib/slack.rb | 12 +---------- lib/user.rb | 20 ------------------- lib/workspace.rb | 50 +--------------------------------------------- specs/user_spec.rb | 4 +--- 6 files changed, 6 insertions(+), 111 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 629d491f..6f9a7161 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -8,21 +8,7 @@ class Channel BASE_URL = "https://slack.com/api/channels.list" SLACK_TOKEN = ENV["SLACK_TOKEN"] - def initialize - @name = name - @topic = topic - @member_count = member_count #some code that counts users. - @id = id - end - - def details(name, topic, member_count, id) - end - def self.list - #access the response/API above - # look inside response["members"] - # return username, real name, and slack ID - query_param = { token: SLACK_TOKEN, } @@ -39,7 +25,6 @@ def self.list list << channel_info end - # list is an array of arrays return list end end diff --git a/lib/recipient.rb b/lib/recipient.rb index 4729d4ba..884a5c58 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -20,17 +20,8 @@ def self.send_message(message, user) channel_name = Channel.list.map do |channel| channel[0] end - # user_id = User.list.each do |id| - # if user == id[0] - # user[2] - # end - # end - # have two responses if select is a type of user choose 1st response - # else if user input is a type of channel choose 2nd response. the channel can be select_user or select_channel from the main - # we'd have to require workspace - - #### testing user stuff + #### TODO: CHANGE VARIABLE NAME practice = [] User.list.each do |user_name| if user_name[0] == user @@ -42,7 +33,7 @@ def self.send_message(message, user) if channel_name.include?(user) response = HTTParty.post( "#{BASE_URL}", - headers: {"Content-Type" => "application/x-www-form-urlencoded"}, + headers: { "Content-Type" => "application/x-www-form-urlencoded" }, body: { token: SLACK_TOKEN, text: message, @@ -53,12 +44,11 @@ def self.send_message(message, user) elsif user_name.include?(user) response = HTTParty.post( "#{BASE_URL}", - headers: {"Content-Type" => "application/x-www-form-urlencoded"}, + headers: { "Content-Type" => "application/x-www-form-urlencoded" }, body: { token: SLACK_TOKEN, text: message, channel: practice[0], - # test_workspace.select_user(user) #.select_user(chose_user) as_user: true, }, ) diff --git a/lib/slack.rb b/lib/slack.rb index be10154f..fa613fe3 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -5,12 +5,6 @@ require_relative "workspace" require_relative "recipient" -### WHAT DID I CHANGE -#1. formatting for outputting List ____ -#2. moved channel_name and user_name to top -#3. added to workspace class - show_details uses channel_name.include? or user_name.include? -#4. added to workspace class - select_user or select_channel returns SELECTED = string - def main channel_name = Channel.list.map do |channel| channel[0] @@ -32,8 +26,7 @@ def main selection = gets.chomp until selection == "Quit" - #TODO: add command list every time teh loop repreats - # TODO: format output for listing + #TODO: add command list every time teh loop repeats case selection when "List Users" puts "Here is the list of users and their details:" @@ -81,10 +74,7 @@ def main puts "Please input your message:" message = gets.chomp - ### WE NEED TO ROUTE PATH TO CORRECT LIKE OF SEND MESSAGE - SlackApi.send_message(message, chose) - # SlackApi.send_message(message, chose_channel) puts "What would you like to do next? " selection = gets.chomp end diff --git a/lib/user.rb b/lib/user.rb index 09769d4c..31bb193a 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -7,10 +7,6 @@ class User BASE_URL = "https://slack.com/api/users.list" SLACK_TOKEN = ENV["SLACK_TOKEN"] - # query_param = { - # token: SLACK_TOKEN, - # } - # response = httparty.get(BASE_URL, query: query_param) def initialize @user_name = user_name @@ -18,22 +14,7 @@ def initialize @slack_id = slack_id end - # def get_user - # query_param = { - # token: SLACK_TOKEN, - # } - # response = httparty.get(BASE_URL, query: query_param) - # return response - # end - - def details - end - def self.list - #access the response/API above - # look inside response["members"] - # return username, real name, and slack ID - query_param = { token: SLACK_TOKEN, } @@ -49,7 +30,6 @@ def self.list list << member_info end - # list is an array of arrays return list end end diff --git a/lib/workspace.rb b/lib/workspace.rb index 56952427..159c805e 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -8,60 +8,24 @@ class Workspace attr_reader :user, :channel attr_accessor :selected - # USER_URL = "https://slack.com/api/users.list" - # SLACK_TOKEN = ENV["SLACK_TOKEN"] - - # CHANNEL_URL = "https://slack.com/api/channels.list" - # SLACK_TOKEN = ENV["SLACK_TOKEN"] - - def initialize - @user = [] - @channel = [] - # @selected = selected - end - # class SlackApiError < StandardError; end - # make these Class methods def select_channel(selected) - #Channel.list - #using param, find specific channel - # returns an instance of channel - - # selected = Channel.new - # Channel.list.each do |instance| - # if selected == instance[0] - # return instance - # end - # end - selected end def select_user(selected) - #User.list - #using param, find specific user - # returns an instance of user - # User.list.each do |instance| - # if selected == instance[0] - # return instance - # end - # end - # selected = User.new - selected end - # seperate methods for Channel and User def show_details(selected) - # array of all user names user_name = User.list.map do |user| user[0] end - # array of all channel names channel_name = Channel.list.map do |channel| channel[0] end + if channel_name.include?(selected) Channel.list.each do |instance| if selected == instance[0] @@ -80,16 +44,4 @@ def show_details(selected) raise ArgumentError, "No user of channel was selected!" end end - - # def show_details_user(selected) - # #something users - # User.list.each do |instance| - # if selected == instance[0] - # return instance - # end - # end - # end - - def send_message - end end diff --git a/specs/user_spec.rb b/specs/user_spec.rb index dc2ca982..78c07d44 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -4,7 +4,6 @@ it "API returns as a hash and its members return as an array" do VCR.use_cassette("slack_users") do test_user = User.new - # response = test_user.get_user expect(User.list).must_be_kind_of Array expect(User.list.first).must_be_kind_of Array @@ -14,7 +13,6 @@ it "make sure there are 3 members in the list" do VCR.use_cassette("slack_users") do test_user = User.new - # response = test_user.get_user expect(User.list.length).must_equal 3 end @@ -23,7 +21,7 @@ it "lists correct username" do VCR.use_cassette("slack_users") do test_user = User.new - # response = test_user.get_user + print User.list expect(User.list[0][0]).must_equal "slackbot" end From fd84b3ba317e8d5e0bea7e830e078cdc8e0786b1 Mon Sep 17 00:00:00 2001 From: Angela Date: Fri, 22 Mar 2019 09:58:34 -0700 Subject: [PATCH 24/27] added better formatting for options in slack.rb --- lib/slack.rb | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index fa613fe3..d0d4f706 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -5,6 +5,19 @@ require_relative "workspace" require_relative "recipient" +def display_options + options = ["1. List Users", + "2. List Channels", + "3. Select User", + "4. Select Channel", + "5. Details", + "6. Send Message", + "7. Quit"] + options.each do |one_option| + puts one_option + end +end + def main channel_name = Channel.list.map do |channel| channel[0] @@ -16,17 +29,9 @@ def main puts "We currently have '#{User.list.length}' members and '#{Channel.list.length} channels.'" puts "" puts "Please choose one of the the following options" - puts "List Users" - puts "List Channels" - puts "Select User" - puts "Select Channel" - puts "Details" - puts "Send Message" - puts "Quit" + display_options selection = gets.chomp until selection == "Quit" - - #TODO: add command list every time teh loop repeats case selection when "List Users" puts "Here is the list of users and their details:" @@ -37,6 +42,7 @@ def main puts "" end puts "What would you like to do next? " + display_options selection = gets.chomp when "List Channels" puts "Here is the list of channels and their details: " @@ -48,6 +54,7 @@ def main puts "" end puts "What would you like to do next? " + display_options selection = gets.chomp when "Select User" puts "Here are all the members' user names: #{user_name}" @@ -56,6 +63,7 @@ def main details = workspace.select_user(chose) puts "You just selected #{details}" puts "What would you like to do next? " + display_options selection = gets.chomp when "Select Channel" puts "Here are all the channels' names: #{channel_name}" @@ -64,9 +72,9 @@ def main details = workspace.select_channel(chose) puts "You just selected #{details}" puts "What would you like to do next? " + display_options selection = gets.chomp when "Details" - ###### JUST CHANGED puts workspace.show_details(details) puts "What would you like to do next? " selection = gets.chomp @@ -76,6 +84,7 @@ def main SlackApi.send_message(message, chose) puts "What would you like to do next? " + display_options selection = gets.chomp end end From 777140e1ac81dae7898e54ec00a8e394c2339414 Mon Sep 17 00:00:00 2001 From: Angela Date: Fri, 22 Mar 2019 10:31:24 -0700 Subject: [PATCH 25/27] we DRY'd our code and changed Argument Error to custom error --- lib/recipient.rb | 16 ++++---- lib/slack.rb | 48 +++++++++++++---------- lib/workspace.rb | 4 +- specs/channel_spec.rb | 13 +++---- specs/recipient_spec.rb | 14 +++---- specs/user_spec.rb | 7 ++-- specs/workspace_spec.rb | 6 +-- test/cassettes/slack_message.yml | 65 ++++++++++++++++++++++++++++++++ 8 files changed, 118 insertions(+), 55 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 884a5c58..4b3bcaf6 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -10,11 +10,11 @@ module SlackApi BASE_URL = "https://slack.com/api/chat.postMessage" SLACK_TOKEN = ENV["SLACK_TOKEN"] - # class SlackApiError < StandardError; end + class SlackApiError < StandardError; end def self.send_message(message, user) - user_name = User.list.map do |user| - user[0] + user_name = User.list.map do |user_list| + user_list[0] end # array of all channel names channel_name = Channel.list.map do |channel| @@ -23,9 +23,9 @@ def self.send_message(message, user) #### TODO: CHANGE VARIABLE NAME practice = [] - User.list.each do |user_name| - if user_name[0] == user - practice << user_name[2] + User.list.each do |user_name_list| + if user_name_list[0] == user + practice << user_name_list[2] end end @@ -52,12 +52,14 @@ def self.send_message(message, user) as_user: true, }, ) + else + raise ArgumentError, "The input #{user} is not included in our channels." end if response["ok"] return true else - raise SlackApi::ArgumentError, "Error when posting #{message} to #{user}, error: #{response["error"]}" + raise SlackApiError, "Error when posting #{message} to #{user}, error: #{response["error"]}" end end end diff --git a/lib/slack.rb b/lib/slack.rb index d0d4f706..5c32d3bf 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -30,10 +30,10 @@ def main puts "" puts "Please choose one of the the following options" display_options - selection = gets.chomp - until selection == "Quit" + selection = gets.chomp.downcase + until selection == "quit" case selection - when "List Users" + when "list users" puts "Here is the list of users and their details:" User.list.each do |user| puts "Username: #{user[0]}" @@ -43,8 +43,8 @@ def main end puts "What would you like to do next? " display_options - selection = gets.chomp - when "List Channels" + selection = gets.chomp.downcase + when "list channels" puts "Here is the list of channels and their details: " Channel.list.each do |channel| puts "Name: #{channel[0]}" @@ -55,37 +55,45 @@ def main end puts "What would you like to do next? " display_options - selection = gets.chomp - when "Select User" + selection = gets.chomp.downcase + when "select user" puts "Here are all the members' user names: #{user_name}" - chose = gets.chomp #chose_user + chose = gets.chomp.downcase #chose_user workspace = Workspace.new details = workspace.select_user(chose) puts "You just selected #{details}" puts "What would you like to do next? " display_options - selection = gets.chomp - when "Select Channel" + selection = gets.chomp.downcase + when "select channel" puts "Here are all the channels' names: #{channel_name}" - chose = gets.chomp #chose_channel + chose = gets.chomp.downcase #chose_channel workspace = Workspace.new details = workspace.select_channel(chose) puts "You just selected #{details}" puts "What would you like to do next? " display_options - selection = gets.chomp - when "Details" - puts workspace.show_details(details) + selection = gets.chomp.downcase + when "details" + if details == nil + puts "You must select user or channel first." + else + puts workspace.show_details(details) + end puts "What would you like to do next? " - selection = gets.chomp - when "Send Message" - puts "Please input your message:" - message = gets.chomp + selection = gets.chomp.downcase + when "send message" + if details == nil + puts "You must select user or channel first." + else + puts "Please input your message:" + message = gets.chomp.downcase - SlackApi.send_message(message, chose) + SlackApi.send_message(message, chose) + end puts "What would you like to do next? " display_options - selection = gets.chomp + selection = gets.chomp.downcase end end diff --git a/lib/workspace.rb b/lib/workspace.rb index 159c805e..490f3eb3 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -8,7 +8,7 @@ class Workspace attr_reader :user, :channel attr_accessor :selected - # class SlackApiError < StandardError; end + class SlackApiError < StandardError; end def select_channel(selected) selected @@ -41,7 +41,7 @@ def show_details(selected) end if selected == "" - raise ArgumentError, "No user of channel was selected!" + raise SlackApiError, "No user of channel was selected!" end end end diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index becccd03..f9ef9ba1 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -3,9 +3,8 @@ describe "returning channel lists" do it "API returns as a hash and its channel returns as an array" do VCR.use_cassette("slack_channels") do - test_channel = Channel.new - # response = test_channel.get_channel - print Channel.list + Channel.new + expect(Channel.list).must_be_kind_of Array expect(Channel.list.first).must_be_kind_of Array end @@ -13,8 +12,7 @@ it "make sure there are 3 member count in the list" do VCR.use_cassette("slack_channels") do - test_user = Channel.new - # response = test_user.get_user + Channel.new expect(Channel.list.length).must_equal 3 end @@ -22,9 +20,8 @@ it "lists correct Channel name" do VCR.use_cassette("slack_channels") do - test_user = Channel.new - # response = test_user.get_user - print Channel.list + Channel.new + expect(Channel.list[0][0]).must_equal "everyone" end end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 13a2e658..26b0dd42 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -14,23 +14,19 @@ it "generates an error if given an invalid channel" do VCR.use_cassette("slack_message") do - # return_value = SlackApi.send_message("Test message", - # "bogus") - puts "TESTING SOMETHIND #{SlackApi.send_message("Test message", - "bogus")}" expect { SlackApi.send_message("Test message", "bogus") - }.must_raise SlackApi::ArgumentError + }.must_raise ArgumentError end end - it "will generate an error if given an invalid key" do - VCR.use_cassette("slack_message") do - end - end it "will raise an error if given an empty message" do VCR.use_cassette("slack_message") do + expect { + SlackApi.send_message("", + "angela.ohh") + }.must_raise SlackApi::SlackApiError end end end diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 78c07d44..fa93dc67 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -3,7 +3,7 @@ describe "returning user lists" do it "API returns as a hash and its members return as an array" do VCR.use_cassette("slack_users") do - test_user = User.new + User.new expect(User.list).must_be_kind_of Array expect(User.list.first).must_be_kind_of Array @@ -12,7 +12,7 @@ it "make sure there are 3 members in the list" do VCR.use_cassette("slack_users") do - test_user = User.new + User.new expect(User.list.length).must_equal 3 end @@ -20,9 +20,8 @@ it "lists correct username" do VCR.use_cassette("slack_users") do - test_user = User.new + User.new - print User.list expect(User.list[0][0]).must_equal "slackbot" end end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 744cb2c2..07283250 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -14,15 +14,11 @@ it "raises SlackApiError if list is nil" do VCR.use_cassette("slack_channels") do - # response = test_channel.get_channel User.list test_workspace = Workspace.new test_workspace.select_user("") - expect { test_workspace.show_details(test_workspace.select_user("")) }.must_raise ArgumentError + expect { test_workspace.show_details(test_workspace.select_user("")) }.must_raise Workspace::SlackApiError end end - - # edge cases, what if the list is 0? - # argument error, this user/channel does not exist. end diff --git a/test/cassettes/slack_message.yml b/test/cassettes/slack_message.yml index 6dbe87c0..df436d5f 100644 --- a/test/cassettes/slack_message.yml +++ b/test/cassettes/slack_message.yml @@ -708,4 +708,69 @@ http_interactions: Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"angela.ohh","real_name_normalized":"angela.ohh","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"ge9c24d2cfc6","image_24":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0001-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552951939}],"cache_ts":1553206652,"response_metadata":{"next_cursor":""}}' http_version: recorded_at: Thu, 21 Mar 2019 22:17:32 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&text=&channel=UH2S78AHY&as_user=true + headers: + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 17:04:55 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - cfef10d4-0a8b-4706-8767-770f0bef791c + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:user,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 + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:user + 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-ia6a + X-Cache: + - Miss from cloudfront + Via: + - 1.1 e9dbb62af8eec6cb13379a137374c506.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - hddm3i5Us5qaWcVdAd5K8bwM3ZWmbe7eQKzWB9JPVzJvn0tb8bhNtw== + body: + encoding: UTF-8 + string: '{"ok":false,"error":"no_text"}' + http_version: + recorded_at: Fri, 22 Mar 2019 17:03:24 GMT recorded_with: VCR 4.0.0 From dbbfdac39f6dbc3f1ff71d3a518296e1aaf2c3a9 Mon Sep 17 00:00:00 2001 From: Angela Date: Fri, 22 Mar 2019 11:07:28 -0700 Subject: [PATCH 26/27] erase unneccesary constructor and changed ArgumentError to our custom error. --- lib/channel.rb | 2 +- lib/recipient.rb | 2 +- lib/user.rb | 8 -------- specs/recipient_spec.rb | 2 +- 4 files changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 6f9a7161..c2d4ce57 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -4,7 +4,7 @@ Dotenv.load class Channel - attr_reader :name, :topic, :member_count, :id + # attr_reader :name, :topic, :member_count, :id BASE_URL = "https://slack.com/api/channels.list" SLACK_TOKEN = ENV["SLACK_TOKEN"] diff --git a/lib/recipient.rb b/lib/recipient.rb index 4b3bcaf6..caad6195 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -53,7 +53,7 @@ def self.send_message(message, user) }, ) else - raise ArgumentError, "The input #{user} is not included in our channels." + raise SlackApiError, "The input #{user} is not included in our channels." end if response["ok"] diff --git a/lib/user.rb b/lib/user.rb index 31bb193a..d9fbe0cb 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -3,17 +3,9 @@ Dotenv.load class User - attr_reader :user_name, :real_name, :slack_id - BASE_URL = "https://slack.com/api/users.list" SLACK_TOKEN = ENV["SLACK_TOKEN"] - def initialize - @user_name = user_name - @real_name = real_name - @slack_id = slack_id - end - def self.list query_param = { token: SLACK_TOKEN, diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 26b0dd42..355330ca 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -17,7 +17,7 @@ expect { SlackApi.send_message("Test message", "bogus") - }.must_raise ArgumentError + }.must_raise SlackApi::SlackApiError end end From 43a8e26f9b51cf6c2f129af81893451344256ee1 Mon Sep 17 00:00:00 2001 From: Angela Date: Fri, 22 Mar 2019 11:13:00 -0700 Subject: [PATCH 27/27] added tests for recipient-channel and workspace-channel --- specs/recipient_spec.rb | 3 + specs/workspace_spec.rb | 2 + test/cassettes/slack_message2.yml | 289 ++++++++++++++++++++++++++++++ 3 files changed, 294 insertions(+) diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index 355330ca..d8c30034 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -8,7 +8,10 @@ return_value = SlackApi.send_message("It's gonna work!", "marshallscm") + return_value2 = SlackApi.send_message("It's gonna work!", + "everyone") expect(return_value).must_equal true + expect(return_value2).must_equal true end end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 07283250..b600194a 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -17,8 +17,10 @@ User.list test_workspace = Workspace.new test_workspace.select_user("") + test_workspace.select_channel("") expect { test_workspace.show_details(test_workspace.select_user("")) }.must_raise Workspace::SlackApiError + expect { test_workspace.show_details(test_workspace.select_channel("")) }.must_raise Workspace::SlackApiError end end end diff --git a/test/cassettes/slack_message2.yml b/test/cassettes/slack_message2.yml index faed1ce1..71f6859b 100644 --- a/test/cassettes/slack_message2.yml +++ b/test/cassettes/slack_message2.yml @@ -354,4 +354,293 @@ http_interactions: gonna work!","user":"UH2RALWR2","ts":"1553206048.000100"}}' http_version: recorded_at: Thu, 21 Mar 2019 22:07:28 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: + - '965' + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 18:13:38 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 8f851f69-85de-4155-932b-880b90c74664 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:user,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 + 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-myy5 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 3fcd7d0200438e7af0ce180cc71925ad.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - nGF0Ap5q6pp00nOcq37Ucq1QM1o3c9ZU0Iz5M5KSBJ8Oc9T_jwLiHQ== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH49RSM8W","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\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":"UH2RALWR2","team_id":"TH49RSM8W","name":"marshallscm","deleted":false,"color":"4bbe2e","real_name":"Shamira + Marshall","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Shamira + Marshall","real_name_normalized":"Shamira Marshall","display_name":"Shamira + Marshall","display_name_normalized":"Shamira Marshall","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"7608f9ef4784","image_original":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_original.jpg","first_name":"Shamira","last_name":"Marshall","image_24":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_24.jpg","image_32":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_32.jpg","image_48":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_48.jpg","image_72":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_72.jpg","image_192":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_192.jpg","image_512":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_512.jpg","image_1024":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_1024.jpg","status_text_canonical":"","team":"TH49RSM8W","is_custom_image":true},"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":1553100291,"has_2fa":false},{"id":"UH2S78AHY","team_id":"TH49RSM8W","name":"angela.ohh","deleted":false,"color":"9f69e7","real_name":"angela.ohh","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"angela.ohh","real_name_normalized":"angela.ohh","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"ge9c24d2cfc6","image_24":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0001-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552951939,"has_2fa":false}],"cache_ts":1553278418,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Fri, 22 Mar 2019 18:12:07 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: + - '549' + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 18:13:38 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - e5f35bf6-e946-4c31-9a96-b900035d4fe7 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:user,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 + 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-unfa + X-Cache: + - Miss from cloudfront + Via: + - 1.1 ccbc918e3ddfbe40c4d786475a6e7606.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - fnMrpAv39niaM81HMUh-zhLLWHXEETfWh1aYi5cKpT6lFABSAW9KQw== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CH0E8S9UY","name":"everyone","is_channel":true,"created":1552951939,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"everyone","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UH2S78AHY","last_set":1552951939},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH0E8SBA4","name":"random","is_channel":true,"created":1552951939,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UH2S78AHY","last_set":1552951939},"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":"UH2S78AHY","last_set":1552951939},"previous_names":[],"num_members":2},{"id":"CH2R9UGCU","name":"api-slack","is_channel":true,"created":1552951940,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2S78AHY","name_normalized":"api-slack","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2RALWR2","UH2S78AHY"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Fri, 22 Mar 2019 18:12:07 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: + - '965' + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 18:13:38 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - b4c5f10b-118c-4760-9589-3faf8252d7e9 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:user,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 + 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-bjjw + X-Cache: + - Miss from cloudfront + Via: + - 1.1 33a89f27becabefce49116de5fab23d8.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - 9vZKgw7UZm40mXYjAeNC8GWhKofjlpEib2J-qJXt5v6ryWy0zsDIeA== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH49RSM8W","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\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":"UH2RALWR2","team_id":"TH49RSM8W","name":"marshallscm","deleted":false,"color":"4bbe2e","real_name":"Shamira + Marshall","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Shamira + Marshall","real_name_normalized":"Shamira Marshall","display_name":"Shamira + Marshall","display_name_normalized":"Shamira Marshall","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"7608f9ef4784","image_original":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_original.jpg","first_name":"Shamira","last_name":"Marshall","image_24":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_24.jpg","image_32":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_32.jpg","image_48":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_48.jpg","image_72":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_72.jpg","image_192":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_192.jpg","image_512":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_512.jpg","image_1024":"https:\/\/avatars.slack-edge.com\/2019-03-20\/582916660435_7608f9ef47843f20290c_1024.jpg","status_text_canonical":"","team":"TH49RSM8W","is_custom_image":true},"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":1553100291,"has_2fa":false},{"id":"UH2S78AHY","team_id":"TH49RSM8W","name":"angela.ohh","deleted":false,"color":"9f69e7","real_name":"angela.ohh","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"angela.ohh","real_name_normalized":"angela.ohh","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"ge9c24d2cfc6","image_24":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0001-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/e9c24d2cfc6d69108ae65335301d1be8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0026-512.png","status_text_canonical":"","team":"TH49RSM8W"},"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":1552951939,"has_2fa":false}],"cache_ts":1553278418,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Fri, 22 Mar 2019 18:12:07 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&text=It%27s%20gonna%20work%21&channel=everyone&as_user=true + headers: + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 18:13:38 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - a4462ce0-e018-4844-9159-46db6b0b3041 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:user,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 + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:user + 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-shy + X-Cache: + - Miss from cloudfront + Via: + - 1.1 44914fa6421b789193cec8998428f8bd.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - zk19TDO88OKRvjehWhLruIGPt2MHIeF9lpmOYTWsLfQ7IRLES6pi7A== + body: + encoding: UTF-8 + string: '{"ok":true,"channel":"CH0E8S9UY","ts":"1553278418.000100","message":{"bot_id":"BH371BS5T","type":"message","text":"It''s + gonna work!","user":"UH2S78AHY","ts":"1553278418.000100"}}' + http_version: + recorded_at: Fri, 22 Mar 2019 18:12:08 GMT recorded_with: VCR 4.0.0