diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..d55d4965 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore index 8d6a243f..9c047fc2 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /test/tmp/ /test/version_tmp/ /tmp/ +/.DS_Store/ # Used by dotenv library to load environment variables. # .env @@ -53,4 +54,4 @@ build-iPhoneSimulator/ .env # Ignore cassette files -/specs/cassettes/ +# /specs/cassettes/ diff --git a/lib/channel.rb b/lib/channel.rb new file mode 100644 index 00000000..d2b665bd --- /dev/null +++ b/lib/channel.rb @@ -0,0 +1,35 @@ +# require "dotenv" +# require "httparty" +# require "awesome_print" +require "pry" + +require_relative "recipient" + +module Slack + class Channel < Recipient + attr_reader :topic, :member_count + + def initialize(slack_id, name, topic, member_count) + super(slack_id, name) + @topic = topic + @member_count = member_count + end + + def self.list + list = [] + + response = self.get("https://slack.com/api/channels.list") + + response["channels"].each do |channel| + slack_id = channel["id"] + name = channel["name"] + topic = channel["topic"]["value"] + member_count = channel["num_members"] + + list << Slack::Channel.new(slack_id, name, topic, member_count) + end + + return list + end + end +end diff --git a/lib/recipient.rb b/lib/recipient.rb new file mode 100644 index 00000000..d2f85f0b --- /dev/null +++ b/lib/recipient.rb @@ -0,0 +1,57 @@ + + +module Slack + class SlackError < StandardError; end + + class Recipient + attr_reader :slack_id, :name + + def initialize(slack_id, name) + @slack_id = slack_id + @name = name + end + + def send_message(message, token: ENV["SLACK_API_TOKEN"]) + response = HTTParty.post( + "https://slack.com/api/chat.postMessage", + headers: {"Content-Type" => "application/x-www-form-urlencoded"}, + body: { + token: token, + channel: self.slack_id, + text: message, + }, + ) + + if response.code == 200 && response["ok"] + return true + else + raise Slack::SlackError, "Error: #{response.parsed_response["error"]}" + end + end + + def self.get(url, token: ENV["SLACK_API_TOKEN"]) + response = HTTParty.get( + url, + query: { + token: token, + }, + ) + + if response.code == 200 && response["ok"] + return response.parsed_response + else + raise Slack::SlackError, "Error: #{response.code} #{response.message}" + end + + # return response.parsed_response + end + + def self.list + raise NotImplementedError, "Implement me in a child class!" + end + + def details + raise NotImplementedError, "Implement me in a child class!" + end + end +end diff --git a/lib/sample.rb b/lib/sample.rb new file mode 100644 index 00000000..899b3248 --- /dev/null +++ b/lib/sample.rb @@ -0,0 +1,19 @@ +require "dotenv" +require "httparty" +require "awesome_print" + +Dotenv.load + +url = "https://slack.com/api/channels.list" + +query_parameters = { + token: ENV["SLACK_API_TOKEN"], +} + +response = HTTParty.get(url, query: query_parameters) + +if response.code == 200 + ap response.parsed_response +else + ap "#{response.code} #{response.message}" +end diff --git a/lib/slack.rb b/lib/slack.rb index 960cf2f7..fea1127c 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,11 +1,54 @@ #!/usr/bin/env ruby +require_relative "workspace" +require_relative "user" +require_relative "channel" + +require "colorize" +require "table_print" +require "httparty" +require "pry" +require "dotenv" +Dotenv.load def main - puts "Welcome to the Ada Slack CLI!" + workspace = Slack::Workspace.new + puts "Welcome to the Ada Slack CLI!" # TODO project + loop do + puts "What would you like to do next?" + puts "[list users] [list channels] [select user] [select channel] [details] [send message] [quit]" + print "> " + + user_input = gets.chomp + + case user_input.downcase + when "list users" + tp workspace.users, workspace.tp_user_options + when "list channels" + tp workspace.channels, workspace.tp_channel_options + when "select user" + print "User ID or Username > " + input = gets.chomp + puts "#{input} does not exist".red unless workspace.select_user(input) + when "select channel" + print "Channel ID or Channel Name > " + input = gets.chomp + puts "#{input} does not exist".red unless workspace.select_channel(input) + when "details" + puts "No recipient selected".red unless workspace.selected + tp workspace.selected, workspace.tp_details_options if workspace.selected + when "send message" + print "Message > " + input = gets.chomp + puts "No message entered".red if input == "" + workspace.send_message(input) unless input == "" + end + + break if user_input == "quit" + end puts "Thank you for using the Ada Slack CLI" end -main if __FILE__ == $PROGRAM_NAME \ No newline at end of file +main if __FILE__ == $PROGRAM_NAME diff --git a/lib/user.rb b/lib/user.rb new file mode 100644 index 00000000..1eed4474 --- /dev/null +++ b/lib/user.rb @@ -0,0 +1,32 @@ +require_relative "recipient" + +module Slack + class User < Recipient + attr_reader :real_name, :status_text, :status_emoji + + def initialize(slack_id, name, real_name, status_text, status_emoji) + super(slack_id, name) + @real_name = real_name + @status_text = status_text + @status_emoji = status_emoji + end + + def self.list + list = [] + + response = self.get("https://slack.com/api/users.list") + + response["members"].each do |member| + slack_id = member["id"] + name = member["name"] + real_name = member["real_name"] + status_text = member["profile"]["status_text"] + status_emoji = member["status_emoji"] + + list << Slack::User.new(slack_id, name, real_name, status_text, status_emoji) + end + + return list + end + end +end diff --git a/lib/workspace.rb b/lib/workspace.rb new file mode 100644 index 00000000..f729da54 --- /dev/null +++ b/lib/workspace.rb @@ -0,0 +1,51 @@ +module Slack + class Workspace + attr_reader :users, :channels, :selected + + def initialize + @users = User.list + @channels = Channel.list + @selected = nil + end + + def select_channel(input) + select(input, channels) + end + + def select_user(input) + select(input, users) + end + + def send_message(message) + selected.send_message(message) + end + + def tp_details_options + if selected.class == Slack::User + return tp_user_options + elsif selected.class == Slack::Channel + return tp_channel_options + end + end + + def tp_user_options + return :name, :real_name, :slack_id + end + + def tp_channel_options + return :name, :topic, :member_count, :slack_id + end + + private + + def select(input, recipients) + recipients.each do |recipient| + if input == recipient.slack_id || input == recipient.name + @selected = recipient + return @selected + end + end + return false + end + end +end diff --git a/specs/cassettes/no_token.yml b/specs/cassettes/no_token.yml new file mode 100644 index 00000000..c9077997 --- /dev/null +++ b/specs/cassettes/no_token.yml @@ -0,0 +1,62 @@ +--- +http_interactions: +- request: + method: get + uri: https://slack.com/api/channels.list?token=this_is_wrong + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '55' + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 17:21:35 GMT + Server: + - Apache + Access-Control-Expose-Headers: + - x-slack-req-id + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 911bb648-8fa3-4227-8150-f1406d3bff0e + X-Xss-Protection: + - '0' + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-ax66 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 9cd19437b0d776b24c104d0c56377ca8.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - lNMuZGnvFzuw5SdOrcTyJo2zALGhEwImjCw-_yFSPmLSN_MpqN9SvQ== + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"invalid_auth"}' + http_version: + recorded_at: Fri, 22 Mar 2019 17:21:35 GMT +recorded_with: VCR 4.0.0 diff --git a/specs/cassettes/no_users.yml b/specs/cassettes/no_users.yml new file mode 100644 index 00000000..764d7876 --- /dev/null +++ b/specs/cassettes/no_users.yml @@ -0,0 +1,72 @@ +--- +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: + - '912' + Connection: + - keep-alive + Date: + - Wed, 20 Mar 2019 20:38:14 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 59127942-e278-465b-9cbf-1fd5e5b56b3c + 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-5baq + X-Cache: + - Miss from cloudfront + Via: + - 1.1 010086e284fd9714db3b3e3d1d295b60.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - d_-gcMclsWiu9OptE-SF6PqQ_Ab3_eFk0XGaFNfjZmWSNxZxdmTYZw== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[],"cache_ts":1553114294,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 20 Mar 2019 20:38:14 GMT +recorded_with: VCR 4.0.0 diff --git a/specs/cassettes/recipient.yml b/specs/cassettes/recipient.yml new file mode 100644 index 00000000..7148d714 --- /dev/null +++ b/specs/cassettes/recipient.yml @@ -0,0 +1,267 @@ +--- +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: + - '554' + Connection: + - keep-alive + Date: + - Wed, 20 Mar 2019 20:56:10 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - fb8ab65c-afab-4d83-93ef-31b2daaf44e1 + 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: + - 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-xhix + X-Cache: + - Miss from cloudfront + Via: + - 1.1 a077f80f2fe737f90e09bad4a75fa2bc.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - 8bdvYbzthGc4hM0vhdCjp5L5jqsXuvAdsXA0sZf9xw1UcovSSrs7RA== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CH0EFGJHE","name":"everyone","is_channel":true,"created":1552952596,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UH2RGJ36Y","name_normalized":"everyone","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH0EG0QHE","UH2RGJ36Y"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UH2RGJ36Y","last_set":1552952596},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UH2RGJ36Y","last_set":1552952596},"previous_names":[],"num_members":2},{"id":"CH0EFGQ72","name":"slack-api","is_channel":true,"created":1552952597,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2RGJ36Y","name_normalized":"slack-api","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH0EG0QHE","UH2RGJ36Y"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2},{"id":"CH2P330M9","name":"random","is_channel":true,"created":1552952596,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2RGJ36Y","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH0EG0QHE","UH2RGJ36Y"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UH2RGJ36Y","last_set":1552952596},"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":"UH2RGJ36Y","last_set":1552952596},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 20 Mar 2019 20:56: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: + - '912' + Connection: + - keep-alive + Date: + - Wed, 20 Mar 2019 21:08:27 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 5de30e3d-5529-4f45-9f75-14dbf601d157 + 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-8twt + X-Cache: + - Miss from cloudfront + Via: + - 1.1 7430a54821bbaeddfc77b56ba1b84eae.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - lL0UPoDcXLYHyBBdcgq5eIoJy8bGabylKcT020GitjgsvbKpSVdSYg== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH2P32R19","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":"TH2P32R19"},"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":"UH0EG0QHE","team_id":"TH2P32R19","name":"sopheary.chiv","deleted":false,"color":"4bbe2e","real_name":"Sopheary + Chiv","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Sopheary + Chiv","real_name_normalized":"Sopheary Chiv","display_name":"Sopheary Chiv","display_name_normalized":"Sopheary + Chiv","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g3fc544bd693","image_24":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-512.png","status_text_canonical":"","team":"TH2P32R19"},"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":1552952644,"has_2fa":false},{"id":"UH2RGJ36Y","team_id":"TH2P32R19","name":"jessica.homet","deleted":false,"color":"9f69e7","real_name":"Jessica + Homet","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Jessica + Homet","real_name_normalized":"Jessica Homet","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gf6a25943381","first_name":"Jessica","last_name":"Homet","image_24":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-512.png","status_text_canonical":"","team":"TH2P32R19"},"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":1552952990}],"cache_ts":1553116107,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 20 Mar 2019 21:08:27 GMT +- request: + method: get + uri: https://slack.com/api/channels.list?token=this_is_wrong + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '55' + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 17:22:18 GMT + Server: + - Apache + Access-Control-Expose-Headers: + - x-slack-req-id + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - df883bb9-f145-4654-9aed-d14f342aefd5 + X-Xss-Protection: + - '0' + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-26um + X-Cache: + - Miss from cloudfront + Via: + - 1.1 44914fa6421b789193cec8998428f8bd.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - "-jNduFJ-VXScFe4-M8RUqBwQaNZvaMrVuKDPO4zyQy0Nx7Kzl0wNXQ==" + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"invalid_auth"}' + http_version: + recorded_at: Fri, 22 Mar 2019 17:22:18 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=This-is-wrong&channel=USLACKBOT&text=hi + 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 22:24:55 GMT + Server: + - Apache + Access-Control-Expose-Headers: + - x-slack-req-id + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 937a1c33-d890-410b-9dc0-ebf9c951e38b + X-Xss-Protection: + - '0' + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-fvbn + X-Cache: + - Miss from cloudfront + Via: + - 1.1 5da5773a6acab8f3aabf385b38683f20.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - FPoN-I7YURWQbiGw7fgX5uHF56QbvgLjbJKbOSZhOXML_Q1vylrYrw== + body: + encoding: UTF-8 + string: '{"ok":false,"error":"invalid_auth"}' + http_version: + recorded_at: Fri, 22 Mar 2019 22:24:55 GMT +recorded_with: VCR 4.0.0 diff --git a/specs/cassettes/slack_message.yml b/specs/cassettes/slack_message.yml new file mode 100644 index 00000000..ac9c7511 --- /dev/null +++ b/specs/cassettes/slack_message.yml @@ -0,0 +1,351 @@ +--- +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: + - '911' + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 21:17:30 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 7791f565-813c-413f-8b9e-2718f4ac597c + 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-wm3w + X-Cache: + - Miss from cloudfront + Via: + - 1.1 c9bb13136100bc969a43d76962ec0705.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - yaAV8n2wjixsmVPRbGYV9ECOq1QLrIJDPY5Mdy1sEo4AX__8dX4I7A== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH2P32R19","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":"TH2P32R19"},"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":"UH0EG0QHE","team_id":"TH2P32R19","name":"sopheary.chiv","deleted":false,"color":"4bbe2e","real_name":"Sopheary + Chiv","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Sopheary + Chiv","real_name_normalized":"Sopheary Chiv","display_name":"Sopheary Chiv","display_name_normalized":"Sopheary + Chiv","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g3fc544bd693","image_24":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-512.png","status_text_canonical":"","team":"TH2P32R19"},"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":1552952644,"has_2fa":false},{"id":"UH2RGJ36Y","team_id":"TH2P32R19","name":"jessica.homet","deleted":false,"color":"9f69e7","real_name":"Jessica + Homet","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Jessica + Homet","real_name_normalized":"Jessica Homet","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gf6a25943381","first_name":"Jessica","last_name":"Homet","image_24":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-512.png","status_text_canonical":"","team":"TH2P32R19"},"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":1552952990}],"cache_ts":1553289450,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Fri, 22 Mar 2019 21:17:30 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: + - '554' + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 21:17:31 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 9d42d672-07f9-446b-ba72-d7b08fb16e9a + 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: + - 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-6bmk + X-Cache: + - Miss from cloudfront + Via: + - 1.1 5da5773a6acab8f3aabf385b38683f20.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - ibxRZhWPGblTBoHknKXZH33jwGMopPPuMzfTNQNlMntH4-Me1S_f1Q== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CH0EFGJHE","name":"everyone","is_channel":true,"created":1552952596,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UH2RGJ36Y","name_normalized":"everyone","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH0EG0QHE","UH2RGJ36Y"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UH2RGJ36Y","last_set":1552952596},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UH2RGJ36Y","last_set":1552952596},"previous_names":[],"num_members":2},{"id":"CH0EFGQ72","name":"slack-api","is_channel":true,"created":1552952597,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2RGJ36Y","name_normalized":"slack-api","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH0EG0QHE","UH2RGJ36Y"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2},{"id":"CH2P330M9","name":"random","is_channel":true,"created":1552952596,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2RGJ36Y","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH0EG0QHE","UH2RGJ36Y"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UH2RGJ36Y","last_set":1552952596},"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":"UH2RGJ36Y","last_set":1552952596},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Fri, 22 Mar 2019 21:17:31 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=UH0EG0QHE&text=hi + 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 21:27:52 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 7c263187-3e45-43a8-9892-82e48fddba1c + 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: + - 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-1836 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 ccbc918e3ddfbe40c4d786475a6e7606.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - G6fwFeeBBs45xuED8LwCEKDyhFQ4e8UAY_BaNGAoAU7fXn9XI6gviw== + body: + encoding: UTF-8 + string: '{"ok":true,"channel":"DH36UDYP7","ts":"1553290072.000600","message":{"type":"message","subtype":"bot_message","text":"hi","ts":"1553290072.000600","username":"Ports + - SophearyChiv - API Project","bot_id":"BH4A4C4EA"}}' + http_version: + recorded_at: Fri, 22 Mar 2019 21:27:52 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=USLACKBOT&text=hi + 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 21:36:51 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 59ae8ce6-1a52-4cbe-a429-da07595cc466 + 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: + - 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-uyrj + X-Cache: + - Miss from cloudfront + Via: + - 1.1 7a5c063eecab094c6dee10829ad7c521.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - dYRF6BTa8g4jjCw9H4LPS_RJA8rufgSgRMZ0SdYqED7qWcf9hsKeYA== + body: + encoding: UTF-8 + string: '{"ok":true,"channel":"DH36UE98D","ts":"1553290611.000100","message":{"type":"message","subtype":"bot_message","text":"hi","ts":"1553290611.000100","username":"Ports + - SophearyChiv - API Project","bot_id":"BH4A4C4EA"}}' + http_version: + recorded_at: Fri, 22 Mar 2019 21:36:51 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=UH0EG0QHE&text=test + 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 22:37:04 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - '09c03a68-6ec2-4462-9f6d-03a7d3075d6b' + 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: + - 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-glin + X-Cache: + - Miss from cloudfront + Via: + - 1.1 5971d213ff39e16c310a05523f08e121.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - W_SAGwqX5q57vFIVkLscmaBjQf6dty2v5WhZD9uIZ0I51rBo_-BKVQ== + body: + encoding: UTF-8 + string: '{"ok":true,"channel":"DH36UDYP7","ts":"1553294224.000700","message":{"type":"message","subtype":"bot_message","text":"test","ts":"1553294224.000700","username":"Ports + - SophearyChiv - API Project","bot_id":"BH4A4C4EA"}}' + http_version: + recorded_at: Fri, 22 Mar 2019 22:37:04 GMT +recorded_with: VCR 4.0.0 diff --git a/specs/cassettes/users_found.yml b/specs/cassettes/users_found.yml new file mode 100644 index 00000000..6e3818c8 --- /dev/null +++ b/specs/cassettes/users_found.yml @@ -0,0 +1,78 @@ +--- +http_interactions: +- request: + method: get + uri: https://slack.com/api/users.list?token= + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '912' + Connection: + - keep-alive + Date: + - Wed, 20 Mar 2019 20:38:14 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 59127942-e278-465b-9cbf-1fd5e5b56b3c + 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-5baq + X-Cache: + - Miss from cloudfront + Via: + - 1.1 010086e284fd9714db3b3e3d1d295b60.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - d_-gcMclsWiu9OptE-SF6PqQ_Ab3_eFk0XGaFNfjZmWSNxZxdmTYZw== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH2P32R19","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":"TH2P32R19"},"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":"UH0EG0QHE","team_id":"TH2P32R19","name":"sopheary.chiv","deleted":false,"color":"4bbe2e","real_name":"Sopheary + Chiv","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Sopheary + Chiv","real_name_normalized":"Sopheary Chiv","display_name":"Sopheary Chiv","display_name_normalized":"Sopheary + Chiv","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g3fc544bd693","image_24":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-512.png","status_text_canonical":"","team":"TH2P32R19"},"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":1552952644,"has_2fa":false},{"id":"UH2RGJ36Y","team_id":"TH2P32R19","name":"jessica.homet","deleted":false,"color":"9f69e7","real_name":"Jessica + Homet","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Jessica + Homet","real_name_normalized":"Jessica Homet","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gf6a25943381","first_name":"Jessica","last_name":"Homet","image_24":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-512.png","status_text_canonical":"","team":"TH2P32R19"},"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":1552952990,"has_2fa":false}],"cache_ts":1553114294,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 20 Mar 2019 20:38:14 GMT +recorded_with: VCR 4.0.0 diff --git a/specs/cassettes/workspace.yml b/specs/cassettes/workspace.yml new file mode 100644 index 00000000..6d96c34b --- /dev/null +++ b/specs/cassettes/workspace.yml @@ -0,0 +1,228 @@ +--- +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: + - '912' + Connection: + - keep-alive + Date: + - Wed, 20 Mar 2019 20:38:13 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - df63ca1d-1097-499d-be79-e01d54e8e400 + 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-524t + X-Cache: + - Miss from cloudfront + Via: + - 1.1 feeead777aa6b11f4775062f1953fdc4.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - vMdNBZLcTzm4lljZJqWNQHY_LaMQMcb1EJGVtQS1E6knOL2PaFzoyQ== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH2P32R19","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":"TH2P32R19"},"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":"UH0EG0QHE","team_id":"TH2P32R19","name":"sopheary.chiv","deleted":false,"color":"4bbe2e","real_name":"Sopheary + Chiv","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Sopheary + Chiv","real_name_normalized":"Sopheary Chiv","display_name":"Sopheary Chiv","display_name_normalized":"Sopheary + Chiv","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g3fc544bd693","image_24":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/3fc544bd693b9af7dcfb713f1cb65dc1.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0022-512.png","status_text_canonical":"","team":"TH2P32R19"},"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":1552952644,"has_2fa":false},{"id":"UH2RGJ36Y","team_id":"TH2P32R19","name":"jessica.homet","deleted":false,"color":"9f69e7","real_name":"Jessica + Homet","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Jessica + Homet","real_name_normalized":"Jessica Homet","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gf6a25943381","first_name":"Jessica","last_name":"Homet","image_24":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/f6a259433810cefa3237505b0b21fb51.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0014-512.png","status_text_canonical":"","team":"TH2P32R19"},"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":1552952990,"has_2fa":false}],"cache_ts":1553114293,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 20 Mar 2019 20:38:13 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: + - '554' + Connection: + - keep-alive + Date: + - Wed, 20 Mar 2019 20:38:14 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - fc83d2de-cc61-4e93-8318-a42adbd122a3 + 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: + - 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-imty + X-Cache: + - Miss from cloudfront + Via: + - 1.1 4f81f573d1d8e804c79450e430cd47be.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - AyY7VVidP4X7OCxVg6qdYaeygM_SOb-ipTZl2k9sE5XTsWAu6boqSQ== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CH0EFGJHE","name":"everyone","is_channel":true,"created":1552952596,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UH2RGJ36Y","name_normalized":"everyone","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH0EG0QHE","UH2RGJ36Y"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UH2RGJ36Y","last_set":1552952596},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UH2RGJ36Y","last_set":1552952596},"previous_names":[],"num_members":2},{"id":"CH0EFGQ72","name":"slack-api","is_channel":true,"created":1552952597,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2RGJ36Y","name_normalized":"slack-api","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH0EG0QHE","UH2RGJ36Y"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2},{"id":"CH2P330M9","name":"random","is_channel":true,"created":1552952596,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2RGJ36Y","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH0EG0QHE","UH2RGJ36Y"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UH2RGJ36Y","last_set":1552952596},"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":"UH2RGJ36Y","last_set":1552952596},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 20 Mar 2019 20:38:14 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: + - '554' + Connection: + - keep-alive + Date: + - Wed, 20 Mar 2019 20:57:43 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 37c512df-2b36-43dd-ae24-2fcbdd2d6c4d + 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: + - 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-rxp9 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 64a11a52a1b20918fec274138dd1ba05.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - XtGSRIeQY9jrWnOkt41YcD76pnaRDzqB-9kcn8SSnoLj4S3wLXoByA== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CH0EFGJHE","name":"everyone","is_channel":true,"created":1552952596,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UH2RGJ36Y","name_normalized":"everyone","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH0EG0QHE","UH2RGJ36Y"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UH2RGJ36Y","last_set":1552952596},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UH2RGJ36Y","last_set":1552952596},"previous_names":[],"num_members":2},{"id":"CH0EFGQ72","name":"slack-api","is_channel":true,"created":1552952597,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2RGJ36Y","name_normalized":"slack-api","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH0EG0QHE","UH2RGJ36Y"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2},{"id":"CH2P330M9","name":"random","is_channel":true,"created":1552952596,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2RGJ36Y","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH0EG0QHE","UH2RGJ36Y"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UH2RGJ36Y","last_set":1552952596},"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":"UH2RGJ36Y","last_set":1552952596},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 20 Mar 2019 20:57:43 GMT +recorded_with: VCR 4.0.0 diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb new file mode 100644 index 00000000..6e7a91a8 --- /dev/null +++ b/specs/channel_spec.rb @@ -0,0 +1,21 @@ +require_relative "test_helper" + +describe "Channel" do + describe "Initialization" do + let(:slack_id) { 20 } + let(:channelname) { "everyone" } + let(:topic) { "Slack API" } + let(:member_count) { 2 } + + it "can be instantiated" do + VCR.use_cassette("channel") do + channel = Slack::Channel.new(slack_id, channelname, topic, member_count) + expect(channel).must_be_instance_of Slack::Channel + expect(channel.slack_id).must_equal 20 + expect(channel.name).must_equal "everyone" + expect(channel.topic).must_equal "Slack API" + expect(channel.member_count).must_equal 2 + end + end + end +end diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb new file mode 100644 index 00000000..586395e4 --- /dev/null +++ b/specs/recipient_spec.rb @@ -0,0 +1,72 @@ +require_relative "test_helper" +# THIS IS MY COMMENT - Jessica + +describe "Recipient" do + let(:slack_id) { 20 } + let(:username) { "Sopheary" } + let(:recipient) { Slack::Recipient.new(slack_id, username) } + + describe "Initialization" do + it "can be instantiated" do + expect(recipient).must_be_instance_of Slack::Recipient + expect(recipient.slack_id).must_equal 20 + expect(recipient.name).must_equal "Sopheary" + end + end + + describe "send message" do + it "sends a valid message" do + VCR.use_cassette("slack_message") do + users = Slack::User.list + return_value = users[0].send_message("hi") + expect(return_value).must_equal true + end + end + + it "raises an error if api sends back not okay" do + VCR.use_cassette("recipient") do + users = Slack::User.list + expect { users[0].send_message("hi", token: "This-is-wrong") }.must_raise Slack::SlackError + end + end + end + + describe "self.get" do + it "can get valid user data from the API" do + VCR.use_cassette("recipient") do + url = "https://slack.com/api/users.list" + + return_value = Slack::Recipient.get(url) + expect(return_value["ok"]).must_equal true + end + end + # sopheary + + it "can get valid channel data from the API" do + VCR.use_cassette("recipient") do + url = "https://slack.com/api/channels.list" + return_value = Slack::Recipient.get(url) + expect(return_value["ok"]).must_equal true + end + end + + it "raises a SlackError if invalid queries are provided" do + VCR.use_cassette("recipient") do + url = "https://slack.com/api/channels.list" + expect { Slack::Recipient.get(url, token: "this_is_wrong") }.must_raise Slack::SlackError + end + end + end + + describe "self.list" do + it "raises error if attempted" do + expect { Slack::Recipient.list }.must_raise NotImplementedError + end + end + + describe "details" do + it "raises error if attempted" do + expect { recipient.details }.must_raise NotImplementedError + end + end +end diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 81ccd06b..44c536fe 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -1,15 +1,38 @@ -require 'simplecov' -SimpleCov.start +require "simplecov" +SimpleCov.start do + add_filter %r{^/specs/} +end -require 'minitest' -require 'minitest/autorun' -require 'minitest/reporters' -require 'minitest/skip_dsl' -require 'vcr' +require "minitest" +require "minitest/autorun" +require "minitest/reporters" +require "minitest/skip_dsl" +require "vcr" +require "webmock/minitest" +require "dotenv" +require "httparty" +require "awesome_print" +require "table_print" + +Dotenv.load Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new +require_relative "../lib/channel" +require_relative "../lib/user" +require_relative "../lib/recipient" +require_relative "../lib/workspace" +# require_relative "../lib/slack" # Do we need this? Don't think so. + 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 = "specs/cassettes" # folder where casettes will be + config.hook_into :webmock # tie into this other rool 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], + } + # Don't leave our token lying around in cassette file. + config.filter_sensitive_data("") do + ENV["SLACK_API_TOKEN"] + end +end diff --git a/specs/user_spec.rb b/specs/user_spec.rb new file mode 100644 index 00000000..566373a9 --- /dev/null +++ b/specs/user_spec.rb @@ -0,0 +1,48 @@ +require_relative "test_helper" + +describe "User" do + describe "Initialization" do + let(:slack_id) { 20 } + let(:username) { "soph" } + let(:real_name) { "Sopheary" } + let(:status_text) { "Good to go" } + let(:status_emoji) { ":)" } + + it "can be instantiated" do + user = Slack::User.new(slack_id, username, real_name, status_text, status_emoji) + expect(user).must_be_instance_of Slack::User + expect(user.slack_id).must_equal 20 + expect(user.name).must_equal "soph" + expect(user.real_name).must_equal "Sopheary" + expect(user.status_text).must_equal "Good to go" + expect(user.status_emoji).must_equal ":)" + end + + describe "List" do + it "can list itself" do + VCR.use_cassette("users_found") do + response = Slack::User.list + + expect(response[0].name).must_equal "slackbot" + expect(response[1].name).must_equal "sopheary.chiv" + end + end + + it "returns the right data types" do + VCR.use_cassette("users_found") do + response = Slack::User.list + + expect(response).must_be_kind_of Array + expect(response[0]).must_be_instance_of Slack::User + expect(response.last).must_be_instance_of Slack::User + end + end + + # it "raise an error if no users found" do + # VCR.use_cassette("no_users") do + # expect { Slack::User.list }.must_equal [] + # end + # end + end + end +end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb new file mode 100644 index 00000000..da564414 --- /dev/null +++ b/specs/workspace_spec.rb @@ -0,0 +1,99 @@ +require_relative "test_helper" + +describe "Workspace" do + before do + VCR.use_cassette("workspace") do + @workspace = Slack::Workspace.new + end + end + describe "Initialization" do + it "can be instantiated" do + VCR.use_cassette("workspace") do + @workspace = Slack::Workspace.new + expect(@workspace).must_be_instance_of Slack::Workspace + end + end + + it "establishes the base structures when instantiated" do + [:users, :channels, :selected].each do |prop| + expect(@workspace).must_respond_to prop + end + + expect(@workspace.users).must_be_kind_of Array + expect(@workspace.channels).must_be_kind_of Array + assert_nil(@workspace.selected) # Changed based on CL feedback... does this make sense? + # end + end + end + + describe "select_user" do + it "returns the right selected user" do + input = "sopheary.chiv" + expect(@workspace.select_user(input).name).must_equal "sopheary.chiv" + end + + it "stores the right user in the selected variable" do + before_selecting_user = @workspace.selected + expect(before_selecting_user).must_be_nil + @workspace.select_user("sopheary.chiv") + after_selecting_user = @workspace.selected + expect(after_selecting_user.name).must_equal "sopheary.chiv" + end + + it "@selected must be an instance of the user" do + @workspace.select_user("sopheary.chiv") + expect(@workspace.selected).must_be_instance_of Slack::User + end + + it "handles the non-existing user" do + non_exiting_user = @workspace.select_user("jennifer.chiv") + expect(non_exiting_user).must_equal false + end + end + + describe "select_channel" do + it "returns the right selected channel" do + input = "slack-api" + expect(@workspace.select_channel(input).name).must_equal "slack-api" + end + + it "stores the right channel in the selected variable" do + before_selecting_user = @workspace.selected + expect(before_selecting_user).must_be_nil + @workspace.select_channel("slack-api") + after_selecting_user = @workspace.selected + expect(after_selecting_user.name).must_equal "slack-api" + end + + it "@selected must be an instance of the channel" do + @workspace.select_channel("slack-api") + expect(@workspace.selected).must_be_instance_of Slack::Channel + end + + it "handles the non-existing channel" do + non_exiting_user = @workspace.select_channel("my-channel") + expect(non_exiting_user).must_equal false + end + end + + describe "tp_details_options, tp_user_options, tp_channel_options" do + it "returns user options if selected class is a user" do + @workspace.select_user("jessica.homet") + expect(@workspace.tp_details_options).must_equal [:name, :real_name, :slack_id] + end + + it "returns channel options if selected class is a user" do + @workspace.select_channel("slack-api") + expect(@workspace.tp_details_options).must_equal [:name, :topic, :member_count, :slack_id] + end + end + + describe "send_message" do + it "sends a valid message" do + VCR.use_cassette("slack_message") do + @workspace.select_user("sopheary.chiv") + expect(@workspace.send_message("test")).must_equal true + end + end + end +end