From c5e1f80a6bb2485f3fded7162af35bb010936b94 Mon Sep 17 00:00:00 2001 From: Georgina Sanchez Buenrostro Date: Tue, 10 Sep 2019 14:18:26 -0700 Subject: [PATCH 01/14] set-up --- lib/slack.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/slack.rb b/lib/slack.rb index 960cf2f7..a3f73c60 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,8 +1,24 @@ #!/usr/bin/env ruby +require 'dotenv' +require 'httparty' + +# Tell dotenv to look for the .env file +Dotenv.load + +URL = "https://slack.com/api/channels.list" +KEY = ENV['SLACK_TOKEN'] def main puts "Welcome to the Ada Slack CLI!" + response = HTTParty.get(URL, query: { + token: KEY + }) + + response["channels"].each do |channel| + puts channel["name"] + end + # TODO project puts "Thank you for using the Ada Slack CLI" From 8a61e13953f88023f3d94bfd2b30e290bc009bd0 Mon Sep 17 00:00:00 2001 From: Georgina Sanchez Buenrostro Date: Tue, 10 Sep 2019 16:43:51 -0700 Subject: [PATCH 02/14] Class Instantiations - User/Channel/Recipient --- lib/channel.rb | 12 +++++++++ lib/recipient.rb | 21 +++++++++++++++ lib/user.rb | 10 ++++++++ test/channel_test.rb | 25 ++++++++++++++++++ test/recipient_test.rb | 58 ++++++++++++++++++++++++++++++++++++++++++ test/test_helper.rb | 5 ++++ test/user_test.rb | 20 +++++++++++++++ 7 files changed, 151 insertions(+) create mode 100644 lib/channel.rb create mode 100644 lib/recipient.rb create mode 100644 lib/user.rb create mode 100644 test/channel_test.rb create mode 100644 test/recipient_test.rb create mode 100644 test/user_test.rb diff --git a/lib/channel.rb b/lib/channel.rb new file mode 100644 index 00000000..f91845fc --- /dev/null +++ b/lib/channel.rb @@ -0,0 +1,12 @@ +# channel's name, topic, member count, and Slack ID + +class Channel < Recipient + attr_reader :topic, :member_count + + def initialize(name, topic, member_count, slack_id) + super(name, slack_id) + + @topic = topic + @member_count = member_count + end +end diff --git a/lib/recipient.rb b/lib/recipient.rb new file mode 100644 index 00000000..6622c0c7 --- /dev/null +++ b/lib/recipient.rb @@ -0,0 +1,21 @@ +class Recipient + attr_reader :slack_id, :name + + def initialize(slack_id, name) + @slack_id = slack_id + @name = name + end + + # def self.get_information(url, query) + # response = HTTParty.get(url, query: query) + # return response + # end + + def self.get_information(url, query) + raise NotImplementedError, 'Implement me in a child class!' + end + + def self.get_list + raise NotImplementedError, 'Implement me in a child class!' + end +end \ No newline at end of file diff --git a/lib/user.rb b/lib/user.rb new file mode 100644 index 00000000..a28dfd00 --- /dev/null +++ b/lib/user.rb @@ -0,0 +1,10 @@ +# username, real name, and Slack ID. + +class User < Recipient + attr_reader :real_name + + def initialize(name, real_name, slack_id) + super(name, slack_id) + @real_name = real_name + end +end \ No newline at end of file diff --git a/test/channel_test.rb b/test/channel_test.rb new file mode 100644 index 00000000..da27a6fc --- /dev/null +++ b/test/channel_test.rb @@ -0,0 +1,25 @@ +require_relative "test_helper" +require 'dotenv' +require 'httparty' + +Dotenv.load + +describe "Channel" do + before do + slack_id = "1232452" + name = "Random" + topic = "Ada" + member_count = "3" + + @channel = Channel.new(name, topic, member_count, slack_id) + end + + describe "Channel instantiation" do + it "creates an instance of Channel" do + expect(@channel).must_be_kind_of Channel + end + end +end + + + \ No newline at end of file diff --git a/test/recipient_test.rb b/test/recipient_test.rb new file mode 100644 index 00000000..0a80f66b --- /dev/null +++ b/test/recipient_test.rb @@ -0,0 +1,58 @@ +require_relative "test_helper" +require 'dotenv' +require 'httparty' + +Dotenv.load + +describe "Recipient" do + before do + VCR.use_cassette("location_find") do + slack_id = "1232452" + name = "Dominique" + @recipient = Recipient.new(slack_id, name) + # @response = Recipient.get_information(URL,) + end + end + + describe "Recipient instantiation" do + it "is an instance of Recipient " do + expect(@recipient).must_be_kind_of Recipient + end + end + + describe "get_information" do + it "raises an error if invoked directly (without subclassing)" do + url = "https://slack.com/api/channels.list" + query = {token: 347358792354398} + + expect { + Recipient.get_information(url, query) + }.must_raise NotImplementedError + end + end + + describe "list_information" do + it "raises an error if invoked directly (without subclassing)" do + + expect { + Recipient.get_list + }.must_raise NotImplementedError + end + end + +end + + # describe "get_information" do + # it "gets response from server (JSON)" do + # #Arrange + # url = "https://slack.com/api/channels.list" + # query = {token: ENV['SLACK_TOKEN']} + # #Act + # response = Recipient.get_information(url, query) + + # #Assert + # expect(response).must_be_instance_of HTTParty::Response + # end + # end + +# end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 90aeb408..a49ba802 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -9,9 +9,14 @@ require 'minitest/skip_dsl' require 'vcr' + Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new VCR.configure do |config| config.cassette_library_dir = "test/cassettes" config.hook_into :webmock end + +require_relative '../lib/recipient.rb' +require_relative '../lib/channel.rb' +require_relative '../lib/user.rb' \ No newline at end of file diff --git a/test/user_test.rb b/test/user_test.rb new file mode 100644 index 00000000..3022fd28 --- /dev/null +++ b/test/user_test.rb @@ -0,0 +1,20 @@ +require_relative "test_helper" +require 'dotenv' +require 'httparty' + +Dotenv.load + +describe "User" do + before do + slack_id = "1232452" + name = "Dominique" + real_name = "Dominique Taylor" + @user = User.new(name, real_name, slack_id) + end + + describe "User instantiation" do + it "is an instance of User" do + expect(@user).must_be_kind_of User + end + end +end \ No newline at end of file From 1ad02fda63c0f0da34e395a38ffa7c7153b4138a Mon Sep 17 00:00:00 2001 From: Georgina Sanchez Buenrostro Date: Wed, 11 Sep 2019 13:47:10 -0700 Subject: [PATCH 03/14] abstract methods - recipient --- lib/recipient.rb | 4 ++-- test/recipient_test.rb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 6622c0c7..148005d0 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -11,11 +11,11 @@ def initialize(slack_id, name) # return response # end - def self.get_information(url, query) + def self.details raise NotImplementedError, 'Implement me in a child class!' end - def self.get_list + def self.list raise NotImplementedError, 'Implement me in a child class!' end end \ No newline at end of file diff --git a/test/recipient_test.rb b/test/recipient_test.rb index 0a80f66b..8dbebf53 100644 --- a/test/recipient_test.rb +++ b/test/recipient_test.rb @@ -20,22 +20,22 @@ end end - describe "get_information" do + describe "self.details" do it "raises an error if invoked directly (without subclassing)" do url = "https://slack.com/api/channels.list" query = {token: 347358792354398} expect { - Recipient.get_information(url, query) + Recipient.details }.must_raise NotImplementedError end end - describe "list_information" do + describe "self.list" do it "raises an error if invoked directly (without subclassing)" do expect { - Recipient.get_list + Recipient.list }.must_raise NotImplementedError end end From 5ec793d7bdb89200ac058b20fa584dd6816bbbd5 Mon Sep 17 00:00:00 2001 From: Georgina Sanchez Buenrostro Date: Wed, 11 Sep 2019 14:05:23 -0700 Subject: [PATCH 04/14] user self.get method --- lib/recipient.rb | 8 ++-- lib/user.rb | 8 ++++ test/cassettes/recipient.yml | 83 ++++++++++++++++++++++++++++++++++++ test/cassettes/user.yml | 83 ++++++++++++++++++++++++++++++++++++ test/recipient_test.rb | 31 ++++++-------- test/test_helper.rb | 10 +++++ test/user_test.rb | 15 +++++++ 7 files changed, 217 insertions(+), 21 deletions(-) create mode 100644 test/cassettes/recipient.yml create mode 100644 test/cassettes/user.yml diff --git a/lib/recipient.rb b/lib/recipient.rb index 148005d0..31d728fc 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -6,10 +6,10 @@ def initialize(slack_id, name) @name = name end - # def self.get_information(url, query) - # response = HTTParty.get(url, query: query) - # return response - # end + def self.get(url, query) + response = HTTParty.get(url, query: query) + return response + end def self.details raise NotImplementedError, 'Implement me in a child class!' diff --git a/lib/user.rb b/lib/user.rb index a28dfd00..7c8c9444 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -7,4 +7,12 @@ def initialize(name, real_name, slack_id) super(name, slack_id) @real_name = real_name end + + def self.get(url, query) + url = "https://slack.com/api/users.list" + query = {token: ENV['SLACK_TOKEN']} + + response = HTTParty.get(url, query: query) + return response + end end \ No newline at end of file diff --git a/test/cassettes/recipient.yml b/test/cassettes/recipient.yml new file mode 100644 index 00000000..83f6b68e --- /dev/null +++ b/test/cassettes/recipient.yml @@ -0,0 +1,83 @@ +--- +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: + - '721' + Connection: + - keep-alive + Date: + - Wed, 11 Sep 2019 20:57:23 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - a8ec0837-e49e-4228-ad43-043d8aaaea9a + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - channels:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-q42r + X-Cache: + - Miss from cloudfront + Via: + - 1.1 82ea95080f526df99896343fb7269b07.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C2 + X-Amz-Cf-Id: + - 8-_vQiRQzavf10WF7f06zyW9aO_AMAbRkQwx4a_hFVRDO1u79c9iMQ== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CN5S0B30U","name":"random","is_channel":true,"created":1568073948,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMTGXDXD0","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTGXDXD0","UMUS3K402","UMW5P9DHR","UN8GKRXK8"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UMTGXDXD0","last_set":1568073948},"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":"UMTGXDXD0","last_set":1568073948},"previous_names":[],"num_members":4},{"id":"CN6A8MNHW","name":"general","is_channel":true,"created":1568073948,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UMTGXDXD0","name_normalized":"general","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTGXDXD0","UMUS3K402","UMW5P9DHR","UN8GKRXK8"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UMTGXDXD0","last_set":1568073948},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UMTGXDXD0","last_set":1568073948},"previous_names":[],"num_members":4},{"id":"CN86A001M","name":"slack-cli","is_channel":true,"created":1568073949,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMTGXDXD0","name_normalized":"slack-cli","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTGXDXD0","UMUS3K402","UMW5P9DHR","UN8GKRXK8"],"topic":{"value":"Really + fun topic for testing","creator":"UMW5P9DHR","last_set":1568150556},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":4},{"id":"CN9T10WBG","name":"pets","is_channel":true,"created":1568150583,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMW5P9DHR","name_normalized":"pets","is_shared":false,"is_org_shared":false,"is_member":false,"is_private":false,"is_mpim":false,"members":["UMTGXDXD0","UMW5P9DHR"],"topic":{"value":"for + pets and pet-friendly people","creator":"UMW5P9DHR","last_set":1568150610},"purpose":{"value":"collects + pets","creator":"UMW5P9DHR","last_set":1568150584},"previous_names":[],"num_members":2},{"id":"CNANHC6LF","name":"spaghetti","is_channel":true,"created":1568224227,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMW5P9DHR","name_normalized":"spaghetti","is_shared":false,"is_org_shared":false,"is_member":false,"is_private":false,"is_mpim":false,"members":["UMTGXDXD0","UMUS3K402","UMW5P9DHR"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":3}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 11 Sep 2019 20:57:23 GMT +recorded_with: VCR 5.0.0 diff --git a/test/cassettes/user.yml b/test/cassettes/user.yml new file mode 100644 index 00000000..a055d807 --- /dev/null +++ b/test/cassettes/user.yml @@ -0,0 +1,83 @@ +--- +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: + - '1181' + Connection: + - keep-alive + Date: + - Wed, 11 Sep 2019 21:04:55 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - '09cf6a88-903a-4094-99ba-1bcfee34aa34' + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - users:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-3caj + X-Cache: + - Miss from cloudfront + Via: + - 1.1 331202b5b8aab67acbf389883133f257.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C1 + X-Amz-Cf-Id: + - CwPQv5MucQqETMlrzHiRLYV-92geJQE6olF1USgF3BrJKuQRokU-Zg== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TMZTRGKCZ","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":null,"tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Slackbot","real_name_normalized":"Slackbot","display_name":"Slackbot","display_name_normalized":"Slackbot","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"sv41d8cd98f0","always_active":true,"first_name":"slackbot","last_name":"","image_24":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/80588\/marketing\/img\/avatars\/slackbot\/avatar-slackbot.png","image_512":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":"UMTGXDXD0","team_id":"TMZTRGKCZ","name":"dom_taylor","deleted":false,"color":"9f69e7","real_name":"dom_taylor","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"dom_taylor","real_name_normalized":"dom_taylor","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g1639eaa6e83","image_24":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":1568073948},{"id":"UMUS3K402","team_id":"TMZTRGKCZ","name":"holmstedtk","deleted":false,"color":"3c989f","real_name":"Katie + Kennedy","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Katie + Kennedy","real_name_normalized":"Katie Kennedy","display_name":"Katie Kennedy","display_name_normalized":"Katie + Kennedy","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g4c6094fcae2","image_24":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":1568148491},{"id":"UMW5P9DHR","team_id":"TMZTRGKCZ","name":"nataliemtapias","deleted":false,"color":"e7392d","real_name":"Natalie + Tapias","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Natalie + Tapias","real_name_normalized":"Natalie Tapias","display_name":"Natalie Tapias","display_name_normalized":"Natalie + Tapias","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g84c1455fade","image_24":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":1568148346},{"id":"UN8GKRXK8","team_id":"TMZTRGKCZ","name":"cpgeorgina.sanchez","deleted":false,"color":"4bbe2e","real_name":"Georgina","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Georgina","real_name_normalized":"Georgina","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g23b757c8a5c","image_24":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":1568091134,"has_2fa":false}],"cache_ts":1568235895,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 11 Sep 2019 21:04:55 GMT +recorded_with: VCR 5.0.0 diff --git a/test/recipient_test.rb b/test/recipient_test.rb index 8dbebf53..5345085a 100644 --- a/test/recipient_test.rb +++ b/test/recipient_test.rb @@ -6,12 +6,10 @@ describe "Recipient" do before do - VCR.use_cassette("location_find") do slack_id = "1232452" name = "Dominique" @recipient = Recipient.new(slack_id, name) # @response = Recipient.get_information(URL,) - end end describe "Recipient instantiation" do @@ -40,19 +38,18 @@ end end + describe "self.get" do + it "gets response from server (JSON)" do + VCR.use_cassette("recipient") do + #Arrange + url = "https://slack.com/api/channels.list" + query = {token: ENV['SLACK_TOKEN']} + #Act + response = Recipient.get(url, query) + + #Assert + expect(response).must_be_instance_of HTTParty::Response + end + end + end end - - # describe "get_information" do - # it "gets response from server (JSON)" do - # #Arrange - # url = "https://slack.com/api/channels.list" - # query = {token: ENV['SLACK_TOKEN']} - # #Act - # response = Recipient.get_information(url, query) - - # #Assert - # expect(response).must_be_instance_of HTTParty::Response - # end - # end - -# end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index a49ba802..b9a402da 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -15,8 +15,18 @@ VCR.configure do |config| config.cassette_library_dir = "test/cassettes" config.hook_into :webmock + config.default_cassette_options = { + :record => :new_episodes, # record new data when we don't have it yet + :match_requests_on => [:method, :uri, :body], # The http method, URI and body of a request all need to match + } + # Don't leave our token lying around in a cassette file. + config.filter_sensitive_data("") do + ENV["SLACK_TOKEN"] + end end + + require_relative '../lib/recipient.rb' require_relative '../lib/channel.rb' require_relative '../lib/user.rb' \ No newline at end of file diff --git a/test/user_test.rb b/test/user_test.rb index 3022fd28..32b8679e 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -17,4 +17,19 @@ expect(@user).must_be_kind_of User end end + + describe "self.get" do + it "gets response from server (JSON)" do + VCR.use_cassette("user") do + #Arrange + url = "https://slack.com/api/users.list" + query = {token: ENV['SLACK_TOKEN']} + #Act + response = User.get(url, query) + + #Assert + expect(response).must_be_instance_of HTTParty::Response + end + end + end end \ No newline at end of file From dba3c5c3ff48433e83406596301da64b7325ad60 Mon Sep 17 00:00:00 2001 From: Georgina Sanchez Buenrostro Date: Wed, 11 Sep 2019 15:41:34 -0700 Subject: [PATCH 05/14] Returns accurate information about users and channels --- lib/channel.rb | 23 +++++- lib/user.rb | 17 +++- test/cassettes/channel.yml | 163 +++++++++++++++++++++++++++++++++++++ test/channel_test.rb | 58 +++++++++++++ test/user_test.rb | 34 +++++++- 5 files changed, 288 insertions(+), 7 deletions(-) create mode 100644 test/cassettes/channel.yml diff --git a/lib/channel.rb b/lib/channel.rb index f91845fc..0371ffc9 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -3,10 +3,29 @@ class Channel < Recipient attr_reader :topic, :member_count - def initialize(name, topic, member_count, slack_id) - super(name, slack_id) + def initialize(slack_id, name, topic, member_count) + super(slack_id, name) @topic = topic @member_count = member_count end + + def self.get(url, query) + url = "https://slack.com/api/channels.list" + query = {token: ENV['SLACK_TOKEN']} + + response = HTTParty.get(url, query: query) + return response + end + + def self.list + channels_list = [] + response = Channel.get("https://slack.com/api/channels.list", {token: ENV['SLACK_TOKEN']}) + response["channels"].each do |channel| + new_channel = Channel.new(channel["id"], channel["name"], channel["topic"], channel["members"].length) + # binding.pry + channels_list << new_channel + end + return channels_list + end end diff --git a/lib/user.rb b/lib/user.rb index 7c8c9444..045b6754 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,10 +1,10 @@ # username, real name, and Slack ID. - +require "pry" class User < Recipient attr_reader :real_name - def initialize(name, real_name, slack_id) - super(name, slack_id) + def initialize(slack_id, name, real_name) + super(slack_id, name) @real_name = real_name end @@ -15,4 +15,15 @@ def self.get(url, query) response = HTTParty.get(url, query: query) return response end + + def self.list + users_list = [] + response = User.get("https://slack.com/api/users.list", {token: ENV['SLACK_TOKEN']}) + response["members"].each do |member| + new_user = User.new(member["id"], member["name"], member["real_name"]) + # binding.pry + users_list << new_user + end + return users_list + end end \ No newline at end of file diff --git a/test/cassettes/channel.yml b/test/cassettes/channel.yml new file mode 100644 index 00000000..69f13f86 --- /dev/null +++ b/test/cassettes/channel.yml @@ -0,0 +1,163 @@ +--- +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: + - '1181' + Connection: + - keep-alive + Date: + - Wed, 11 Sep 2019 21:07:09 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 1e290bb7-d0c0-4249-bb0b-1086998d49fc + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - users:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-3m6p + X-Cache: + - Miss from cloudfront + Via: + - 1.1 7022a5bbf9872d4a09d63e6cdb457dfe.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C2 + X-Amz-Cf-Id: + - Clb0oJNzNkMjcy3QRGPXwAbwwz-A-twfezv90ZFQogWj8Fu1FjEQQQ== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TMZTRGKCZ","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":null,"tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Slackbot","real_name_normalized":"Slackbot","display_name":"Slackbot","display_name_normalized":"Slackbot","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"sv41d8cd98f0","always_active":true,"first_name":"slackbot","last_name":"","image_24":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/80588\/marketing\/img\/avatars\/slackbot\/avatar-slackbot.png","image_512":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":"UMTGXDXD0","team_id":"TMZTRGKCZ","name":"dom_taylor","deleted":false,"color":"9f69e7","real_name":"dom_taylor","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"dom_taylor","real_name_normalized":"dom_taylor","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g1639eaa6e83","image_24":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":1568073948},{"id":"UMUS3K402","team_id":"TMZTRGKCZ","name":"holmstedtk","deleted":false,"color":"3c989f","real_name":"Katie + Kennedy","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Katie + Kennedy","real_name_normalized":"Katie Kennedy","display_name":"Katie Kennedy","display_name_normalized":"Katie + Kennedy","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g4c6094fcae2","image_24":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":1568148491},{"id":"UMW5P9DHR","team_id":"TMZTRGKCZ","name":"nataliemtapias","deleted":false,"color":"e7392d","real_name":"Natalie + Tapias","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Natalie + Tapias","real_name_normalized":"Natalie Tapias","display_name":"Natalie Tapias","display_name_normalized":"Natalie + Tapias","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g84c1455fade","image_24":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":1568148346},{"id":"UN8GKRXK8","team_id":"TMZTRGKCZ","name":"cpgeorgina.sanchez","deleted":false,"color":"4bbe2e","real_name":"Georgina","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Georgina","real_name_normalized":"Georgina","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g23b757c8a5c","image_24":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":1568091134,"has_2fa":false}],"cache_ts":1568236029,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 11 Sep 2019 21:07:09 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: + - '721' + Connection: + - keep-alive + Date: + - Wed, 11 Sep 2019 22:36:55 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - c628fbc7-3051-4243-9fea-c1cc9cccf41a + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - channels:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-ntnv + X-Cache: + - Miss from cloudfront + Via: + - 1.1 8ae6af4d17aae7471e5fe2792eb6abcd.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C1 + X-Amz-Cf-Id: + - W_M9STpmdZJ3u92fVDXXHJxMEak1IoBKW2FKOwoTMCI8I1Owqe-BEw== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CN5S0B30U","name":"random","is_channel":true,"created":1568073948,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMTGXDXD0","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTGXDXD0","UMUS3K402","UMW5P9DHR","UN8GKRXK8"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UMTGXDXD0","last_set":1568073948},"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":"UMTGXDXD0","last_set":1568073948},"previous_names":[],"num_members":4},{"id":"CN6A8MNHW","name":"general","is_channel":true,"created":1568073948,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UMTGXDXD0","name_normalized":"general","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTGXDXD0","UMUS3K402","UMW5P9DHR","UN8GKRXK8"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UMTGXDXD0","last_set":1568073948},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UMTGXDXD0","last_set":1568073948},"previous_names":[],"num_members":4},{"id":"CN86A001M","name":"slack-cli","is_channel":true,"created":1568073949,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMTGXDXD0","name_normalized":"slack-cli","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTGXDXD0","UMUS3K402","UMW5P9DHR","UN8GKRXK8"],"topic":{"value":"Really + fun topic for testing","creator":"UMW5P9DHR","last_set":1568150556},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":4},{"id":"CN9T10WBG","name":"pets","is_channel":true,"created":1568150583,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMW5P9DHR","name_normalized":"pets","is_shared":false,"is_org_shared":false,"is_member":false,"is_private":false,"is_mpim":false,"members":["UMTGXDXD0","UMW5P9DHR"],"topic":{"value":"for + pets and pet-friendly people","creator":"UMW5P9DHR","last_set":1568150610},"purpose":{"value":"collects + pets","creator":"UMW5P9DHR","last_set":1568150584},"previous_names":[],"num_members":2},{"id":"CNANHC6LF","name":"spaghetti","is_channel":true,"created":1568224227,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMW5P9DHR","name_normalized":"spaghetti","is_shared":false,"is_org_shared":false,"is_member":false,"is_private":false,"is_mpim":false,"members":["UMTGXDXD0","UMUS3K402","UMW5P9DHR"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":3}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 11 Sep 2019 22:36:55 GMT +recorded_with: VCR 5.0.0 diff --git a/test/channel_test.rb b/test/channel_test.rb index da27a6fc..f4edd633 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -19,6 +19,64 @@ expect(@channel).must_be_kind_of Channel end end + + describe "channel.get" do + it "gets response from server (JSON)" do + VCR.use_cassette("channel") do + #Arrange + url = "https://slack.com/api/channels.list" + query = {token: ENV['SLACK_TOKEN']} + #Act + response = User.get(url, query) + + #Assert + expect(response).must_be_instance_of HTTParty::Response + end + end + end + + + describe "self.list" do + it "returns a new channel's list" do + VCR.use_cassette("channel") do + #Act + list = Channel.list + #Assert + expect(list).must_be_kind_of Array + expect(list.length).must_equal 5 + end + end + + it "Returns accurate information about the first channel" do + VCR.use_cassette("channel") do + topic = { + "value" => "Non-work banter and water cooler conversation", + "creator" => "UMTGXDXD0", + "last_set" => 1568073948 + } + first = Channel.list.first + expect(first.slack_id).must_equal "CN5S0B30U" + expect(first.name).must_equal "random" + expect(first.topic).must_equal topic + expect(first.member_count).must_equal 4 + end + end + + it "Returns accurate information about the last channel" do + VCR.use_cassette("channel") do + topic = { + "value" => "", + "creator" => "", + "last_set" => 0 + } + last = Channel.list.last + expect(last.slack_id).must_equal "CNANHC6LF" + expect(last.name).must_equal "spaghetti" + expect(last.topic).must_equal topic + expect(last.member_count).must_equal 3 + end + end + end end diff --git a/test/user_test.rb b/test/user_test.rb index 32b8679e..beeed0de 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -26,10 +26,40 @@ query = {token: ENV['SLACK_TOKEN']} #Act response = User.get(url, query) - #Assert expect(response).must_be_instance_of HTTParty::Response end end end -end \ No newline at end of file + + describe "self.list" do + it "returns a new user's list" do + VCR.use_cassette("user") do + #Act + list = User.list + #Assert + expect(list).must_be_kind_of Array + expect(list.length).must_equal 5 + end + end + + it "Returns accurate information about the first user" do + VCR.use_cassette("user") do + first = User.list.first + expect(first.slack_id).must_equal "USLACKBOT" + expect(first.real_name).must_equal "Slackbot" + expect(first.name).must_equal "slackbot" + end + end + + it "Returns accurate information about the last user" do + VCR.use_cassette("user") do + last = User.list.last + expect(last.slack_id).must_equal "UN8GKRXK8" + expect(last.real_name).must_equal "Georgina" + expect(last.name).must_equal "cpgeorgina.sanchez" + end + end + end +end + From bfb2cfa456ae5a5cb18a6f506eaf55ae5517aaec Mon Sep 17 00:00:00 2001 From: Georgina Sanchez Buenrostro Date: Wed, 11 Sep 2019 21:06:35 -0700 Subject: [PATCH 06/14] user interface --- lib/slack.rb | 26 ++++++++++++++++++-------- lib/user.rb | 1 - 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index a3f73c60..9b759831 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -2,6 +2,11 @@ require 'dotenv' require 'httparty' + +require_relative 'recipient.rb' +require_relative 'channel.rb' +require_relative 'user.rb' + # Tell dotenv to look for the .env file Dotenv.load @@ -9,17 +14,22 @@ KEY = ENV['SLACK_TOKEN'] def main - puts "Welcome to the Ada Slack CLI!" + while true + puts "Welcome to the Ada Slack CLI!" + puts "Select an option: list users, list channels or quit" + + option = gets.chomp - response = HTTParty.get(URL, query: { - token: KEY - }) + break if option.downcase == 'quit' - response["channels"].each do |channel| - puts channel["name"] - end + if option.downcase == 'list users' + puts User.list - # TODO project + elsif option.downcase == 'list channels' + puts Channel.list + end + + end puts "Thank you for using the Ada Slack CLI" end diff --git a/lib/user.rb b/lib/user.rb index 045b6754..9e411312 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -21,7 +21,6 @@ def self.list response = User.get("https://slack.com/api/users.list", {token: ENV['SLACK_TOKEN']}) response["members"].each do |member| new_user = User.new(member["id"], member["name"], member["real_name"]) - # binding.pry users_list << new_user end return users_list From 63c44fb243b80ef2a9efd395c524d8834351c038 Mon Sep 17 00:00:00 2001 From: Georgina Sanchez Buenrostro Date: Thu, 12 Sep 2019 14:18:30 -0700 Subject: [PATCH 07/14] Select an option: select user, select channel, details --- lib/channel.rb | 11 +++-------- lib/slack.rb | 30 ++++++++++++++++++++---------- lib/user.rb | 12 +++++------- test/recipient_test.rb | 15 --------------- test/user_test.rb | 14 -------------- 5 files changed, 28 insertions(+), 54 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 0371ffc9..bd1a4dc6 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -10,19 +10,14 @@ def initialize(slack_id, name, topic, member_count) @member_count = member_count end - def self.get(url, query) + def self.list url = "https://slack.com/api/channels.list" query = {token: ENV['SLACK_TOKEN']} - response = HTTParty.get(url, query: query) - return response - end - - def self.list channels_list = [] - response = Channel.get("https://slack.com/api/channels.list", {token: ENV['SLACK_TOKEN']}) + response = Recipient.get(url, query) response["channels"].each do |channel| - new_channel = Channel.new(channel["id"], channel["name"], channel["topic"], channel["members"].length) + new_channel = Channel.new(channel["id"], channel["name"], channel["topic"]["value"], channel["members"].length) # binding.pry channels_list << new_channel end diff --git a/lib/slack.rb b/lib/slack.rb index 9b759831..5a52b823 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,34 +1,44 @@ #!/usr/bin/env ruby require 'dotenv' require 'httparty' +require 'table_print' - -require_relative 'recipient.rb' -require_relative 'channel.rb' -require_relative 'user.rb' +require_relative 'recipient' +require_relative 'channel' +require_relative 'user' # Tell dotenv to look for the .env file Dotenv.load -URL = "https://slack.com/api/channels.list" -KEY = ENV['SLACK_TOKEN'] - def main while true puts "Welcome to the Ada Slack CLI!" puts "Select an option: list users, list channels or quit" - option = gets.chomp + until option == "list users" || option == "list channels" || option == "quit" + puts "Select a valid option: list users, list channels or quit" + option = gets.chomp + end + break if option.downcase == 'quit' if option.downcase == 'list users' - puts User.list + tp User.list elsif option.downcase == 'list channels' - puts Channel.list + tp Channel.list end + puts "Select an option: select user, select channel, details" + selection = gets.chomp + + until selection == "select user" || selection == "select channel" || selection == "select details" + puts "Select a valid option: select user, select channel or select details" + selection = gets.chomp + end + + end puts "Thank you for using the Ada Slack CLI" diff --git a/lib/user.rb b/lib/user.rb index 9e411312..cf459151 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,5 +1,8 @@ # username, real name, and Slack ID. require "pry" +require 'dotenv' +Dotenv.load + class User < Recipient attr_reader :real_name @@ -8,17 +11,12 @@ def initialize(slack_id, name, real_name) @real_name = real_name end - def self.get(url, query) + def self.list url = "https://slack.com/api/users.list" query = {token: ENV['SLACK_TOKEN']} - response = HTTParty.get(url, query: query) - return response - end - - def self.list users_list = [] - response = User.get("https://slack.com/api/users.list", {token: ENV['SLACK_TOKEN']}) + response = Recipient.get(url, query) response["members"].each do |member| new_user = User.new(member["id"], member["name"], member["real_name"]) users_list << new_user diff --git a/test/recipient_test.rb b/test/recipient_test.rb index 5345085a..f7ede011 100644 --- a/test/recipient_test.rb +++ b/test/recipient_test.rb @@ -37,19 +37,4 @@ }.must_raise NotImplementedError end end - - describe "self.get" do - it "gets response from server (JSON)" do - VCR.use_cassette("recipient") do - #Arrange - url = "https://slack.com/api/channels.list" - query = {token: ENV['SLACK_TOKEN']} - #Act - response = Recipient.get(url, query) - - #Assert - expect(response).must_be_instance_of HTTParty::Response - end - end - end end diff --git a/test/user_test.rb b/test/user_test.rb index beeed0de..fb904cf6 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -18,20 +18,6 @@ end end - describe "self.get" do - it "gets response from server (JSON)" do - VCR.use_cassette("user") do - #Arrange - url = "https://slack.com/api/users.list" - query = {token: ENV['SLACK_TOKEN']} - #Act - response = User.get(url, query) - #Assert - expect(response).must_be_instance_of HTTParty::Response - end - end - end - describe "self.list" do it "returns a new user's list" do VCR.use_cassette("user") do From 52228bbb937fc2db9a8f26d2d7548cc2d38ba099 Mon Sep 17 00:00:00 2001 From: Georgina Sanchez Buenrostro Date: Thu, 12 Sep 2019 14:45:46 -0700 Subject: [PATCH 08/14] returns a hash of details --- lib/channel.rb | 2 +- lib/user.rb | 4 ++++ test/user_test.rb | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/channel.rb b/lib/channel.rb index bd1a4dc6..e29b139d 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -17,7 +17,7 @@ def self.list channels_list = [] response = Recipient.get(url, query) response["channels"].each do |channel| - new_channel = Channel.new(channel["id"], channel["name"], channel["topic"]["value"], channel["members"].length) + new_channel = Channel.new(channel["id"], channel["name"], channel["topic"], channel["members"].length) # binding.pry channels_list << new_channel end diff --git a/lib/user.rb b/lib/user.rb index cf459151..1e7f8df7 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -23,4 +23,8 @@ def self.list end return users_list end + + def details + return {slack_id: @slack_id, name: @name, real_name: @real_name} + end end \ No newline at end of file diff --git a/test/user_test.rb b/test/user_test.rb index fb904cf6..87fc6d53 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -47,5 +47,14 @@ end end end + + describe "details" do + it "returns a hash of details" do + VCR.use_cassette("user") do + natalie = User.new("UN8GKRXK8", "Natalie Tapias", "natalie") + expect(natalie.details).must_be_kind_of Hash + end + end + end end From 1b21b3f9a15a327970e54f01b25e7b222c8dfeab Mon Sep 17 00:00:00 2001 From: Georgina Sanchez Buenrostro Date: Thu, 12 Sep 2019 14:54:41 -0700 Subject: [PATCH 09/14] returns accurate information --- test/user_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/user_test.rb b/test/user_test.rb index 87fc6d53..f35e1251 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -55,6 +55,16 @@ expect(natalie.details).must_be_kind_of Hash end end + + it "returns accurate information" do + VCR.use_cassette("user") do + natalie = User.new("UN8GKRXK8", "Natalie Tapias", "natalie") + result = natalie.details + expect(result[:slack_id]).must_equal "UN8GKRXK8" + expect(result[:real_name]).must_equal "natalie" + expect(result[:name]).must_equal "Natalie Tapias" + end + end end end From 5d6dc8729665305b3a1b3ecd0d2f37a4f65d543c Mon Sep 17 00:00:00 2001 From: Georgina Sanchez Buenrostro Date: Thu, 12 Sep 2019 15:43:45 -0700 Subject: [PATCH 10/14] is an instance of Workspace --- lib/channel.rb | 5 ++ lib/workspace.rb | 10 +++ test/cassettes/workspace.yml | 164 +++++++++++++++++++++++++++++++++++ test/channel_test.rb | 31 +++++++ test/test_helper.rb | 3 +- test/workspace_test.rb | 22 +++++ 6 files changed, 234 insertions(+), 1 deletion(-) create mode 100644 lib/workspace.rb create mode 100644 test/cassettes/workspace.yml create mode 100644 test/workspace_test.rb diff --git a/lib/channel.rb b/lib/channel.rb index e29b139d..7733dfa8 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -23,4 +23,9 @@ def self.list end return channels_list end + + def details + return {slack_id: @slack_id, name: @name, topic: @topic, member_count: @member_count} + end + end diff --git a/lib/workspace.rb b/lib/workspace.rb new file mode 100644 index 00000000..f527d697 --- /dev/null +++ b/lib/workspace.rb @@ -0,0 +1,10 @@ +require 'dotenv' +Dotenv.load + +class Workspace + def initialize(users, channels, selected: nil) + @users = users + @channels = channels + @selected = selected + end +end \ No newline at end of file diff --git a/test/cassettes/workspace.yml b/test/cassettes/workspace.yml new file mode 100644 index 00000000..2373a340 --- /dev/null +++ b/test/cassettes/workspace.yml @@ -0,0 +1,164 @@ +--- +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: + - '1180' + Connection: + - keep-alive + Date: + - Thu, 12 Sep 2019 22:36:16 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 33bb5983-ca9a-43af-ad7c-06eb13485a3c + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - users:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-xcvc + X-Cache: + - Miss from cloudfront + Via: + - 1.1 34f8ef0e4c880df0650a814412a26ea6.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C1 + X-Amz-Cf-Id: + - 8sScCOJIEKCrqzaRsTdwjEoFL22ErlzyPn2V4UaDSAgoEtvbobb8Ow== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TMZTRGKCZ","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":null,"tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Slackbot","real_name_normalized":"Slackbot","display_name":"Slackbot","display_name_normalized":"Slackbot","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"sv41d8cd98f0","always_active":true,"first_name":"slackbot","last_name":"","image_24":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/80588\/marketing\/img\/avatars\/slackbot\/avatar-slackbot.png","image_512":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":"UMTGXDXD0","team_id":"TMZTRGKCZ","name":"dom_taylor","deleted":false,"color":"9f69e7","real_name":"dom_taylor","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"dom_taylor","real_name_normalized":"dom_taylor","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g1639eaa6e83","image_24":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":1568073948},{"id":"UMUS3K402","team_id":"TMZTRGKCZ","name":"holmstedtk","deleted":false,"color":"3c989f","real_name":"Katie + Kennedy","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Katie + Kennedy","real_name_normalized":"Katie Kennedy","display_name":"Katie Kennedy","display_name_normalized":"Katie + Kennedy","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g4c6094fcae2","image_24":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":1568148491},{"id":"UMW5P9DHR","team_id":"TMZTRGKCZ","name":"nataliemtapias","deleted":false,"color":"e7392d","real_name":"Natalie + Tapias","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Natalie + Tapias","real_name_normalized":"Natalie Tapias","display_name":"Natalie Tapias","display_name_normalized":"Natalie + Tapias","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g84c1455fade","image_24":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":1568148346},{"id":"UN8GKRXK8","team_id":"TMZTRGKCZ","name":"cpgeorgina.sanchez","deleted":false,"color":"4bbe2e","real_name":"Georgina","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Georgina","real_name_normalized":"Georgina","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g23b757c8a5c","image_24":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":1568091134,"has_2fa":false}],"cache_ts":1568327777,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Thu, 12 Sep 2019 22:36:17 GMT +- request: + method: get + uri: https://slack.com/api/channels.list?token= + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '828' + Connection: + - keep-alive + Date: + - Thu, 12 Sep 2019 22:36:17 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 9de0eba7-4ba8-4a7c-b5e6-f341a341fbc5 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - channels:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-w4yr + X-Cache: + - Miss from cloudfront + Via: + - 1.1 174acb08636ac7d9e9a778bbf1bcbc53.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C1 + X-Amz-Cf-Id: + - 7IHp8yGL-qWDltCHIcxx_CWHq0X5EPaEVDXb0QL5o10shGA_j__Uig== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CN5S0B30U","name":"random","is_channel":true,"created":1568073948,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMTGXDXD0","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTGXDXD0","UMUS3K402","UMW5P9DHR","UN8GKRXK8"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UMTGXDXD0","last_set":1568073948},"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":"UMTGXDXD0","last_set":1568073948},"previous_names":[],"num_members":4},{"id":"CN6A8MNHW","name":"general","is_channel":true,"created":1568073948,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UMTGXDXD0","name_normalized":"general","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTGXDXD0","UMUS3K402","UMW5P9DHR","UN8GKRXK8"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UMTGXDXD0","last_set":1568073948},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UMTGXDXD0","last_set":1568073948},"previous_names":[],"num_members":4},{"id":"CN86A001M","name":"slack-cli","is_channel":true,"created":1568073949,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMTGXDXD0","name_normalized":"slack-cli","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UMTGXDXD0","UMUS3K402","UMW5P9DHR","UN8GKRXK8"],"topic":{"value":"Really + fun topic for testing","creator":"UMW5P9DHR","last_set":1568150556},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":4},{"id":"CN9T10WBG","name":"pets","is_channel":true,"created":1568150583,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMW5P9DHR","name_normalized":"pets","is_shared":false,"is_org_shared":false,"is_member":false,"is_private":false,"is_mpim":false,"members":["UMTGXDXD0","UMW5P9DHR"],"topic":{"value":"for + pets and pet-friendly people","creator":"UMW5P9DHR","last_set":1568150610},"purpose":{"value":"collects + pets","creator":"UMW5P9DHR","last_set":1568150584},"previous_names":[],"num_members":2},{"id":"CNANHC6LF","name":"spaghetti","is_channel":true,"created":1568224227,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMW5P9DHR","name_normalized":"spaghetti","is_shared":false,"is_org_shared":false,"is_member":false,"is_private":false,"is_mpim":false,"members":["UMTGXDXD0","UMUS3K402","UMW5P9DHR"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":3},{"id":"CNCQ49V7Y","name":"a-new-channel","is_channel":true,"created":1568320692,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMW5P9DHR","name_normalized":"a-new-channel","is_shared":false,"is_org_shared":false,"is_member":false,"is_private":false,"is_mpim":false,"members":[],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":0},{"id":"CNCQ53EDC","name":"natalie-dinner-plans","is_channel":true,"created":1568320726,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMW5P9DHR","name_normalized":"natalie-dinner-plans","is_shared":false,"is_org_shared":false,"is_member":false,"is_private":false,"is_mpim":false,"members":["UMW5P9DHR"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"what + is natalie eating for dinner","creator":"UMW5P9DHR","last_set":1568320727},"previous_names":[],"num_members":1}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Thu, 12 Sep 2019 22:36:17 GMT +recorded_with: VCR 5.0.0 diff --git a/test/channel_test.rb b/test/channel_test.rb index f4edd633..b94efcb6 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -77,6 +77,37 @@ end end end + + describe "details" do + it "returns a hash of details" do + VCR.use_cassette("channel") do + topic = { + "value" => "", + "creator" => "", + "last_set" => 0 + } + random = Channel.new("UN8GKRXK8", "Random", topic, 3) + expect(random.details).must_be_kind_of Hash + end + end + + it "returns accurate information" do + VCR.use_cassette("channel") do + topic = { + "value" => "", + "creator" => "", + "last_set" => 0 + } + random = Channel.new("UN8GKRXK8", "Random", topic, 3) + + result = random.details + expect(result[:slack_id]).must_equal "UN8GKRXK8" + expect(result[:name]).must_equal "Random" + expect(result[:topic]).must_equal topic + expect(result[:member_count]).must_equal 3 + end + end + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index b9a402da..7a84c7a9 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -29,4 +29,5 @@ require_relative '../lib/recipient.rb' require_relative '../lib/channel.rb' -require_relative '../lib/user.rb' \ No newline at end of file +require_relative '../lib/user.rb' +require_relative '../lib/workspace.rb' \ No newline at end of file diff --git a/test/workspace_test.rb b/test/workspace_test.rb new file mode 100644 index 00000000..18e39d6c --- /dev/null +++ b/test/workspace_test.rb @@ -0,0 +1,22 @@ +require_relative "test_helper" +require 'dotenv' +require 'httparty' + +Dotenv.load + +describe "Workspace" do + before do + VCR.use_cassette("workspace") do + users = User.list + channels = Channel.list + selected = User.new("UN8GKRXK8", "Natalie Tapias", "natalie") + @workspace = Workspace.new(users, channels, selected: selected) + end + end + + describe "Workspace instantiation" do + it "is an instance of Workspace" do + expect(@workspace).must_be_kind_of Workspace + end + end +end \ No newline at end of file From 5c8f70bd207003bcabb5ed6dee72a1df4c9042c9 Mon Sep 17 00:00:00 2001 From: Georgina Sanchez Buenrostro Date: Thu, 12 Sep 2019 16:29:48 -0700 Subject: [PATCH 11/14] raises an argument error for invalid selection --- lib/workspace.rb | 16 ++++++++++++++++ test/workspace_test.rb | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/workspace.rb b/lib/workspace.rb index f527d697..1d4513b1 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,4 +1,5 @@ require 'dotenv' +require "pry" Dotenv.load class Workspace @@ -7,4 +8,19 @@ def initialize(users, channels, selected: nil) @channels = channels @selected = selected end + + def select_channel(selection) + value = 0 + + Channel.list.each do |channel| + if channel.name == selection || channel.slack_id == selection + value = 1 + return channel + end + end + + if value = 0 + raise ArgumentError.new("That is wrong") + end + end end \ No newline at end of file diff --git a/test/workspace_test.rb b/test/workspace_test.rb index 18e39d6c..923f03ab 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -19,4 +19,22 @@ expect(@workspace).must_be_kind_of Workspace end end + + describe "select_channel" do + it "returns a selected channel instance" do + VCR.use_cassette("workspace") do + #Act + selected_channel = @workspace.select_channel("random") + + #Assert + expect(selected_channel).must_be_instance_of Channel + end + end + + it "raises an argument error for invalid selection" do + VCR.use_cassette("workspace") do + expect {(@workspace.select_channel("Pizza"))}.must_raise ArgumentError + end + end + end end \ No newline at end of file From 48a258ef25d21fdba14921f36101a6300cf21d66 Mon Sep 17 00:00:00 2001 From: Georgina Sanchez Buenrostro Date: Thu, 12 Sep 2019 18:03:46 -0700 Subject: [PATCH 12/14] assigns selected object to selected instance variable --- lib/workspace.rb | 21 +++++++++- test/cassettes/workspace.yml | 80 ++++++++++++++++++++++++++++++++++++ test/workspace_test.rb | 52 ++++++++++++++++++++++- 3 files changed, 150 insertions(+), 3 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index 1d4513b1..6fc6b45e 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -3,6 +3,8 @@ Dotenv.load class Workspace + attr_reader :users, :channels + attr_accessor :selected def initialize(users, channels, selected: nil) @users = users @channels = channels @@ -15,12 +17,29 @@ def select_channel(selection) Channel.list.each do |channel| if channel.name == selection || channel.slack_id == selection value = 1 + @selected = channel return channel end end if value = 0 - raise ArgumentError.new("That is wrong") + raise ArgumentError.new("Please provide a valid selection for channel. ") + end + end + + def select_user(selection) + value = 0 + + User.list.each do |user| + if user.name == selection || user.slack_id == selection + value = 1 + @selected = user + return user + end + end + + if value = 0 + raise ArgumentError.new("Please provide a valid selection for user.") end end end \ No newline at end of file diff --git a/test/cassettes/workspace.yml b/test/cassettes/workspace.yml index 2373a340..a527a8ec 100644 --- a/test/cassettes/workspace.yml +++ b/test/cassettes/workspace.yml @@ -161,4 +161,84 @@ http_interactions: is natalie eating for dinner","creator":"UMW5P9DHR","last_set":1568320727},"previous_names":[],"num_members":1}],"response_metadata":{"next_cursor":""}}' http_version: recorded_at: Thu, 12 Sep 2019 22:36:17 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: + - '1181' + Connection: + - keep-alive + Date: + - Thu, 12 Sep 2019 23:47:51 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - f9170734-0bb2-440b-b37c-adc6eb22855f + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - users:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-s1xo + X-Cache: + - Miss from cloudfront + Via: + - 1.1 3cd7af07832481c336aa1c93c9b4a6fe.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C2 + X-Amz-Cf-Id: + - ctEQR5IlmsoGYStHcbumJPuTgkfDXERGP-KvyaSOCupnoXtgCKsX6A== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TMZTRGKCZ","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":null,"tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Slackbot","real_name_normalized":"Slackbot","display_name":"Slackbot","display_name_normalized":"Slackbot","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"sv41d8cd98f0","always_active":true,"first_name":"slackbot","last_name":"","image_24":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/80588\/marketing\/img\/avatars\/slackbot\/avatar-slackbot.png","image_512":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":"UMTGXDXD0","team_id":"TMZTRGKCZ","name":"dom_taylor","deleted":false,"color":"9f69e7","real_name":"dom_taylor","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"dom_taylor","real_name_normalized":"dom_taylor","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g1639eaa6e83","image_24":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/1639eaa6e83ba43b00e58d5f77c257cb.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0024-512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":1568073948},{"id":"UMUS3K402","team_id":"TMZTRGKCZ","name":"holmstedtk","deleted":false,"color":"3c989f","real_name":"Katie + Kennedy","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Katie + Kennedy","real_name_normalized":"Katie Kennedy","display_name":"Katie Kennedy","display_name_normalized":"Katie + Kennedy","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g4c6094fcae2","image_24":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/4c6094fcae2a494baccbd128ef25afd5.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":1568148491},{"id":"UMW5P9DHR","team_id":"TMZTRGKCZ","name":"nataliemtapias","deleted":false,"color":"e7392d","real_name":"Natalie + Tapias","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Natalie + Tapias","real_name_normalized":"Natalie Tapias","display_name":"Natalie Tapias","display_name_normalized":"Natalie + Tapias","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g84c1455fade","image_24":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/84c1455fadee76ee25d39ccb9670b4b4.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0004-512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":1568148346},{"id":"UN8GKRXK8","team_id":"TMZTRGKCZ","name":"cpgeorgina.sanchez","deleted":false,"color":"4bbe2e","real_name":"Georgina","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Georgina","real_name_normalized":"Georgina","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g23b757c8a5c","image_24":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":1568091134,"has_2fa":false}],"cache_ts":1568332071,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Thu, 12 Sep 2019 23:47:51 GMT recorded_with: VCR 5.0.0 diff --git a/test/workspace_test.rb b/test/workspace_test.rb index 923f03ab..698e5040 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -15,9 +15,20 @@ end describe "Workspace instantiation" do - it "is an instance of Workspace" do - expect(@workspace).must_be_kind_of Workspace + it "is an instance of Workspace" do + expect(@workspace).must_be_kind_of Workspace end + + it "gets the selected object from the select_user method" do + VCR.use_cassette("workspace") do + users = User.list + channels = Channel.list + workspace_1 = Workspace.new(users, channels) + workspace_1.select_user("UMUS3K402") + expect(workspace_1.selected).must_be_instance_of User + end + end + end describe "select_channel" do @@ -36,5 +47,42 @@ expect {(@workspace.select_channel("Pizza"))}.must_raise ArgumentError end end + end + + describe "select_user" do + it "returns a selected user instance" do + VCR.use_cassette("workspace") do + #Act + selected_user = @workspace.select_user("UMW5P9DHR") + + #Assert + expect(selected_user).must_be_instance_of User + end + end + + it "raises an argument error for invalid selection" do + VCR.use_cassette("workspace") do + expect {(@workspace.select_user("Pizza"))}.must_raise ArgumentError + end + end + + it "assigns selected object to selected instance variable" do + VCR.use_cassette("workspace") do + # selection = "random" + hello ="world" + hi ="world" + expect(hello).must_equal hi + @workspace.select_channel("random") + + topic = { + "value": "Non-work banter and water cooler conversation", + "creator": "UMTGXDXD0", + "last_set": 1568073948 + } + result = Channel.new("CN5S0B30U", "random", topic, 4) + + expect(@workspace.selected).must_be_instance_of Channel + end + end end end \ No newline at end of file From fc2fe727e05bc0e4bdba8036241cb6d9a58ce683 Mon Sep 17 00:00:00 2001 From: Georgina Sanchez Buenrostro Date: Fri, 13 Sep 2019 13:23:54 -0700 Subject: [PATCH 13/14] returns accurate details --- lib/recipient.rb | 2 +- lib/slack.rb | 42 ++++++++++++++++++++++++++---------------- lib/workspace.rb | 11 +++++++++-- test/recipient_test.rb | 5 ++--- test/workspace_test.rb | 16 +++++++++++++++- 5 files changed, 53 insertions(+), 23 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 31d728fc..f1eacb4f 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -11,7 +11,7 @@ def self.get(url, query) return response end - def self.details + def details raise NotImplementedError, 'Implement me in a child class!' end diff --git a/lib/slack.rb b/lib/slack.rb index 5a52b823..f8fe4686 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -6,38 +6,48 @@ require_relative 'recipient' require_relative 'channel' require_relative 'user' +require_relative 'workspace' # Tell dotenv to look for the .env file Dotenv.load def main + new_workspace = Workspace.new(User.list, Channel.list) + while true puts "Welcome to the Ada Slack CLI!" - puts "Select an option: list users, list channels or quit" + puts "Select an option: list users, list channels, select user, select channel, details or quit" option = gets.chomp - until option == "list users" || option == "list channels" || option == "quit" - puts "Select a valid option: list users, list channels or quit" + until option == "list users" || option == "list channels" || option == "quit" || option == "select user" || option == "select channel" || option == "details" + puts "Select a valid option: list users, list channels, select user, select channel, details or quit" option = gets.chomp end - break if option.downcase == 'quit' + break if option.downcase == "quit" - if option.downcase == 'list users' + if option.downcase == "list users" tp User.list - elsif option.downcase == 'list channels' + elsif option.downcase == "list channels" tp Channel.list - end - - puts "Select an option: select user, select channel, details" - selection = gets.chomp - - until selection == "select user" || selection == "select channel" || selection == "select details" - puts "Select a valid option: select user, select channel or select details" - selection = gets.chomp - end - + + elsif option.downcase == "select user" + puts "Enter the username or Slack ID" + selection = gets.chomp + new_workspace.select_user(selection) + + elsif option.downcase == "select channel" + puts "Enter the channel name or Slack ID" + selection = gets.chomp + new_workspace.select_channel(selection) + + elsif option.downcase == "details" + if new_workspace.show_details == nil + puts "You haven't enter the name or Slack ID" + end + tp [new_workspace.show_details] + end end diff --git a/lib/workspace.rb b/lib/workspace.rb index 6fc6b45e..2686c13d 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -22,7 +22,7 @@ def select_channel(selection) end end - if value = 0 + if value == 0 raise ArgumentError.new("Please provide a valid selection for channel. ") end end @@ -38,8 +38,15 @@ def select_user(selection) end end - if value = 0 + if value == 0 raise ArgumentError.new("Please provide a valid selection for user.") end end + + def show_details + if @selected == nil + return nil + end + return @selected.details + end end \ No newline at end of file diff --git a/test/recipient_test.rb b/test/recipient_test.rb index f7ede011..994a8c6d 100644 --- a/test/recipient_test.rb +++ b/test/recipient_test.rb @@ -9,7 +9,6 @@ slack_id = "1232452" name = "Dominique" @recipient = Recipient.new(slack_id, name) - # @response = Recipient.get_information(URL,) end describe "Recipient instantiation" do @@ -18,13 +17,13 @@ end end - describe "self.details" do + describe "details" do it "raises an error if invoked directly (without subclassing)" do url = "https://slack.com/api/channels.list" query = {token: 347358792354398} expect { - Recipient.details + @recipient.details }.must_raise NotImplementedError end end diff --git a/test/workspace_test.rb b/test/workspace_test.rb index 698e5040..c5f4be0f 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -84,5 +84,19 @@ expect(@workspace.selected).must_be_instance_of Channel end end - end + end + + describe "show_details" do + it "show the details of the selected user or channel" do + VCR.use_cassette("workspace") do + expect(@workspace.show_details).must_be_kind_of Hash + end + end + + it "returns accurate details" do + VCR.use_cassette("workspace") do + expect(@workspace.show_details[:slack_id]).must_equal "UN8GKRXK8" + end + end + end end \ No newline at end of file From 1e9e15e2a12f06ae8be02c477940e99c20bf2d0e Mon Sep 17 00:00:00 2001 From: Georgina Sanchez Buenrostro Date: Fri, 13 Sep 2019 16:02:20 -0700 Subject: [PATCH 14/14] Wave 3 finished --- lib/recipient.rb | 19 ++ lib/slack.rb | 38 ++-- lib/user.rb | 2 + lib/workspace.rb | 2 +- test/cassettes/recipient.yml | 357 +++++++++++++++++++++++++++++++++++ test/cassettes/user.yml | 71 +++++++ test/recipient_test.rb | 20 +- test/user_test.rb | 10 + 8 files changed, 504 insertions(+), 15 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index f1eacb4f..ce44b3f1 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,3 +1,6 @@ +require "pry" +class SlackAPIError < StandardError ; end + class Recipient attr_reader :slack_id, :name @@ -18,4 +21,20 @@ def details def self.list raise NotImplementedError, 'Implement me in a child class!' end + + def send_message(message) + url = "https://slack.com/api/chat.postMessage" + body = {token: ENV['SLACK_TOKEN'], + text: message, + channel: @slack_id} + + message_post = HTTParty.post(url, body: body) + + unless message_post.code == 200 && message_post["ok"] + raise SlackAPIError.new("Error when posting #{message} to #{@slack_id}") + end + + return true + end + end \ No newline at end of file diff --git a/lib/slack.rb b/lib/slack.rb index f8fe4686..4729f337 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -16,41 +16,55 @@ def main while true puts "Welcome to the Ada Slack CLI!" - puts "Select an option: list users, list channels, select user, select channel, details or quit" + puts "Select an option: list users, list channels, select user, select channel, details, send message to channel, send message to user or quit" option = gets.chomp - until option == "list users" || option == "list channels" || option == "quit" || option == "select user" || option == "select channel" || option == "details" - puts "Select a valid option: list users, list channels, select user, select channel, details or quit" - option = gets.chomp + until option == "list users" || option == "list channels" || option == "quit" || option == "select user" || option == "select channel" || option == "details" || option == "send message to channel" || option == "send message to user" + puts "Select a valid option: list users, list channels, select user, select channel, details, send message or quit" + option = gets.chomp.downcase end - break if option.downcase == "quit" + break if option == "quit" - if option.downcase == "list users" + if option == "list users" tp User.list - elsif option.downcase == "list channels" + elsif option == "list channels" tp Channel.list - elsif option.downcase == "select user" + elsif option == "select user" puts "Enter the username or Slack ID" selection = gets.chomp new_workspace.select_user(selection) - elsif option.downcase == "select channel" + elsif option == "select channel" puts "Enter the channel name or Slack ID" selection = gets.chomp new_workspace.select_channel(selection) - elsif option.downcase == "details" + elsif option == "details" if new_workspace.show_details == nil puts "You haven't enter the name or Slack ID" end tp [new_workspace.show_details] - end + + elsif option == "send message to channel" + puts "Please enter the channel name or Slack ID" + selection = gets.chomp + channel = new_workspace.select_channel(selection) + puts "Please enter the message:" + message = gets.chomp + channel.send_message(message) + elsif option == "send message to user" + puts "Please enter the user name or Slack ID" + selection = gets.chomp + user = new_workspace.select_user(selection) + puts "Please enter the message:" + message = gets.chomp + user.send_message(message) + end end - puts "Thank you for using the Ada Slack CLI" end diff --git a/lib/user.rb b/lib/user.rb index 1e7f8df7..53559410 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -3,6 +3,7 @@ require 'dotenv' Dotenv.load + class User < Recipient attr_reader :real_name @@ -27,4 +28,5 @@ def self.list def details return {slack_id: @slack_id, name: @name, real_name: @real_name} end + end \ No newline at end of file diff --git a/lib/workspace.rb b/lib/workspace.rb index 2686c13d..29700bce 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -48,5 +48,5 @@ def show_details return nil end return @selected.details - end + end end \ No newline at end of file diff --git a/test/cassettes/recipient.yml b/test/cassettes/recipient.yml index 83f6b68e..24ae60c1 100644 --- a/test/cassettes/recipient.yml +++ b/test/cassettes/recipient.yml @@ -80,4 +80,361 @@ http_interactions: pets","creator":"UMW5P9DHR","last_set":1568150584},"previous_names":[],"num_members":2},{"id":"CNANHC6LF","name":"spaghetti","is_channel":true,"created":1568224227,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UMW5P9DHR","name_normalized":"spaghetti","is_shared":false,"is_org_shared":false,"is_member":false,"is_private":false,"is_mpim":false,"members":["UMTGXDXD0","UMUS3K402","UMW5P9DHR"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":3}],"response_metadata":{"next_cursor":""}}' http_version: recorded_at: Wed, 11 Sep 2019 20:57:23 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&text=hello&channel=Dominique + 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: + - '60' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 21:45:54 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 53cdc5af-05c1-406d-9d9d-51cc10664feb + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:bot + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-xtep + X-Cache: + - Miss from cloudfront + Via: + - 1.1 4db3f26ee4fd9a14a343fada3315105f.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - HIO51-C1 + X-Amz-Cf-Id: + - 6JxaubZ5TCd6eVVSPhOa0Qw10Gbme_xmCSCqR1Jrgu32-4FV6v2z5g== + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"channel_not_found"}' + http_version: + recorded_at: Fri, 13 Sep 2019 21:45:54 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&text=hello&channel=1232452 + 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: + - '60' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 21:46:49 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - aa15c413-577d-45f7-b845-9b0be86a1147 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:bot + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-61a2 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 e8276e704fe9ab202d1f5aa2709d2f93.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - HIO51-C1 + X-Amz-Cf-Id: + - F_AW1THCmnNEcLMwjrjqzxjMJAI2NwtoSjn4lgoP4Wx_GCzKN0PWdQ== + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"channel_not_found"}' + http_version: + recorded_at: Fri, 13 Sep 2019 21:46:49 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&text=hello&channel=UMUS3K402 + 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: + - '171' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 21:53:19 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - e9c8655f-8adf-4915-8986-a3a16aa49a9d + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:bot + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-g1op + X-Cache: + - Miss from cloudfront + Via: + - 1.1 a65ed239b1dc93560d93932663ec96bd.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - HIO51-C1 + X-Amz-Cf-Id: + - qdwb5sTEzMAOaTM0QZZacnEVaLUvNLtsoSNhi8_5uUH8yHEam05AXg== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channel":"DN9FGBEDV","ts":"1568411599.000100","message":{"type":"message","subtype":"bot_message","text":"hello","ts":"1568411599.000100","username":"Leaves + Georgina API Project","bot_id":"BN8SHMAC8"}}' + http_version: + recorded_at: Fri, 13 Sep 2019 21:53:19 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&text=hello&channel=UMTGXDXD0 + 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: + - '171' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 21:55:28 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 3b44b494-9051-4b96-a976-4feb81742207 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:bot + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-x0x4 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 f90d3247f95b3d929916918b14de82bc.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - HIO51-C1 + X-Amz-Cf-Id: + - dWxDbuvrBsZq1P3YgYPtrbdUkenSiNQgvItbdt3KjHpeMsFh4RrwKA== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channel":"DN5S0B0KW","ts":"1568411728.000100","message":{"type":"message","subtype":"bot_message","text":"hello","ts":"1568411728.000100","username":"Leaves + Georgina API Project","bot_id":"BN8SHMAC8"}}' + http_version: + recorded_at: Fri, 13 Sep 2019 21:55:28 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&text=hello&channel=234245t56356 + 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: + - '60' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 22:01:22 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 938b4bea-41e7-4e83-b6df-11e99ddfbf24 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:bot + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-vdna + X-Cache: + - Miss from cloudfront + Via: + - 1.1 cf334f8d204150d702090aa22e0fab56.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - HIO51-C1 + X-Amz-Cf-Id: + - fJ4HrgitPectW9Zg1dCu-LHEucDLXtt_H6ghtj0RMXwtna1gfCxYyA== + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"channel_not_found"}' + http_version: + recorded_at: Fri, 13 Sep 2019 22:01:22 GMT recorded_with: VCR 5.0.0 diff --git a/test/cassettes/user.yml b/test/cassettes/user.yml index a055d807..5a38ea0d 100644 --- a/test/cassettes/user.yml +++ b/test/cassettes/user.yml @@ -80,4 +80,75 @@ http_interactions: Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Georgina","real_name_normalized":"Georgina","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g23b757c8a5c","image_24":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/23b757c8a5ce554904d7122dabceba36.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0023-512.png","status_text_canonical":"","team":"TMZTRGKCZ"},"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":1568091134,"has_2fa":false}],"cache_ts":1568235895,"response_metadata":{"next_cursor":""}}' http_version: recorded_at: Wed, 11 Sep 2019 21:04:55 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&text=It%20works%21&channel=Ada-Cohort-12 + 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: + - '60' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 21:27:03 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 83f283c7-891d-4b92-8149-4753e86e9246 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:bot + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-rg8i + X-Cache: + - Miss from cloudfront + Via: + - 1.1 0732be5515ffeda639cfe5f22fb04df6.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C2 + X-Amz-Cf-Id: + - b76xClcmMWDwijftgXyip97c6xDStcS5N9sOaSHCalsXSlrgFZ0NHQ== + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"channel_not_found"}' + http_version: + recorded_at: Fri, 13 Sep 2019 21:27:04 GMT recorded_with: VCR 5.0.0 diff --git a/test/recipient_test.rb b/test/recipient_test.rb index 994a8c6d..75cecb7e 100644 --- a/test/recipient_test.rb +++ b/test/recipient_test.rb @@ -6,8 +6,8 @@ describe "Recipient" do before do - slack_id = "1232452" - name = "Dominique" + slack_id = "UMTGXDXD0" + name = "dom_taylor" @recipient = Recipient.new(slack_id, name) end @@ -36,4 +36,20 @@ }.must_raise NotImplementedError end end + + describe "send message" do + it "returns true if a message is sent" do + VCR.use_cassette("recipient") do + expect(@recipient.send_message("hello")).must_equal true + end + end + + it "raises an error when message isn't posted" do + new_recipient = Recipient.new("234245t56356", "fgererg") + + VCR.use_cassette("recipient") do + expect{new_recipient.send_message("hello")}.must_raise SlackAPIError + end + end + end end diff --git a/test/user_test.rb b/test/user_test.rb index f35e1251..963c2f3a 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -66,5 +66,15 @@ end end end + + # describe "send_message" do + # it "sends a message to the selected recipient" do + # VCR.use_cassette("user") do + # natalie = User.new("UN8GKRXK8", "Natalie Tapias", "natalie") + # expect(natalie.send_message("It works!", "Ada-Cohort-12")).must_equal true + # end + # end + # end + end