From 07fa5f11a1e21623ce80a10b16e63291fb047758 Mon Sep 17 00:00:00 2001 From: Stephanie Garcia Date: Tue, 10 Sep 2019 12:31:08 -0700 Subject: [PATCH 01/26] Copied ENV file to lib: Authenticated Token Works --- lib/.gitignore | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/slack.rb | 17 ++++++++++++--- 2 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 lib/.gitignore diff --git a/lib/.gitignore b/lib/.gitignore new file mode 100644 index 00000000..58e18732 --- /dev/null +++ b/lib/.gitignore @@ -0,0 +1,57 @@ +.env +*.gem +*.rbc +/.config +/coverage/ +/InstalledFiles +/pkg/ +/spec/reports/ +/spec/examples.txt +/test/tmp/ +/test/version_tmp/ +/tmp/ + +# Used by dotenv library to load environment variables. +# .env + +## Specific to RubyMotion: +.dat* +.repl_history +build/ +*.bridgesupport +build-iPhoneOS/ +build-iPhoneSimulator/ + +## Specific to RubyMotion (use of CocoaPods): +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# vendor/Pods/ + +## Documentation cache and generated files: +/.yardoc/ +/_yardoc/ +/doc/ +/rdoc/ + +## Environment normalization: +/.bundle/ +/vendor/bundle +/lib/bundler/man/ + +# for a library or gem, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# Gemfile.lock +# .ruby-version +# .ruby-gemset + +# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: +.rvmrc + +# Ignore environemnt variables +.env + +# Ignore cassette files +/specs/cassettes/ diff --git a/lib/slack.rb b/lib/slack.rb index 960cf2f7..088d1362 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,11 +1,22 @@ #!/usr/bin/env ruby +require "httparty" +require "dotenv" +Dotenv.load +BASE_URL = "https://slack.com/api/channels.list" +KEY = ENV["SLACK_API_TOKEN"] def main - puts "Welcome to the Ada Slack CLI!" + query = { + token: KEY + } + response = HTTParty.get(BASE_URL, query: query) + #puts "Welcome to the Ada Slack CLI!" # TODO project - - puts "Thank you for using the Ada Slack CLI" + return response + #puts "Thank you for using the Ada Slack CLI" end +puts main + main if __FILE__ == $PROGRAM_NAME \ No newline at end of file From 50dd9ac2fe093b07fa70449e9fb4b03bae724935 Mon Sep 17 00:00:00 2001 From: Stephanie Garcia Date: Tue, 10 Sep 2019 14:36:20 -0700 Subject: [PATCH 02/26] Created Recipient Class and test constructor --- .gitignore | 1 + lib/channel.rb | 0 lib/recipient.rb | 18 ++++++++++++++++++ lib/user.rb | 0 lib/workspace.rb | 0 test/channel_test.rb | 0 test/recipient_test.rb | 22 ++++++++++++++++++++++ test/test_helper.rb | 6 ++++++ test/user_test.rb | 0 test/workspace_test.rb | 0 10 files changed, 47 insertions(+) create mode 100644 lib/channel.rb create mode 100644 lib/recipient.rb create mode 100644 lib/user.rb create mode 100644 lib/workspace.rb create mode 100644 test/channel_test.rb create mode 100644 test/recipient_test.rb create mode 100644 test/user_test.rb create mode 100644 test/workspace_test.rb diff --git a/.gitignore b/.gitignore index 8d6a243f..58e18732 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.env *.gem *.rbc /.config diff --git a/lib/channel.rb b/lib/channel.rb new file mode 100644 index 00000000..e69de29b diff --git a/lib/recipient.rb b/lib/recipient.rb new file mode 100644 index 00000000..7e4bc77d --- /dev/null +++ b/lib/recipient.rb @@ -0,0 +1,18 @@ +class Recipient + attr_reader :slack_id, :name + + def initialize(slack_id, name) + @slack_id = slack_id + @name = name + end + + + + + + + + + + +end \ No newline at end of file diff --git a/lib/user.rb b/lib/user.rb new file mode 100644 index 00000000..e69de29b diff --git a/lib/workspace.rb b/lib/workspace.rb new file mode 100644 index 00000000..e69de29b diff --git a/test/channel_test.rb b/test/channel_test.rb new file mode 100644 index 00000000..e69de29b diff --git a/test/recipient_test.rb b/test/recipient_test.rb new file mode 100644 index 00000000..c4343e35 --- /dev/null +++ b/test/recipient_test.rb @@ -0,0 +1,22 @@ +require_relative 'test_helper' + +describe "Recipient Class" do + describe "Constructor" do + it "Should return a recipient class instance" do + #Expect recipient.new + slack_id = 1 + name = "Dom" + slacker = Recipient.new(slack_id, name) + expect(slacker.slack_id).must_equal slack_id + expect(slacker.name).must_equal "Dom" + end + end + xdescribe "send message method" do + it "Should send a message to" + end + + + + + +end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 90aeb408..87d2ced6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -9,6 +9,12 @@ require 'minitest/skip_dsl' require 'vcr' +require_relative '../lib/recipient' +require_relative '../lib/workspace' +require_relative '../lib/user' +require_relative '../lib/channel' + + Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new VCR.configure do |config| diff --git a/test/user_test.rb b/test/user_test.rb new file mode 100644 index 00000000..e69de29b diff --git a/test/workspace_test.rb b/test/workspace_test.rb new file mode 100644 index 00000000..e69de29b From ff25ea4100024edd31c40ad00d03eed0776f58ee Mon Sep 17 00:00:00 2001 From: Stephanie Garcia Date: Tue, 10 Sep 2019 15:36:46 -0700 Subject: [PATCH 03/26] added new user method list --- lib/recipient.rb | 7 +++---- lib/user.rb | 21 +++++++++++++++++++++ test/recipient_test.rb | 5 ----- test/user_test.rb | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 9 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 7e4bc77d..5fe2fc83 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -6,10 +6,9 @@ def initialize(slack_id, name) @name = name end - - - - + def self.list + raise NotImplementedError, "Implement me in a child class!" + end diff --git a/lib/user.rb b/lib/user.rb index e69de29b..5caec516 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -0,0 +1,21 @@ +class User < Recipient + attr_reader :slack_id, :name, :real_name + + def initialize(slack_id, name, real_name) + super(slack_id, name) + @real_name = real_name + @users_list = [] + end + + def self.list + @users_list << self.User + return @users_list + end + + + + + + + +end \ No newline at end of file diff --git a/test/recipient_test.rb b/test/recipient_test.rb index c4343e35..8338d81f 100644 --- a/test/recipient_test.rb +++ b/test/recipient_test.rb @@ -14,9 +14,4 @@ xdescribe "send message method" do it "Should send a message to" end - - - - - end \ No newline at end of file diff --git a/test/user_test.rb b/test/user_test.rb index e69de29b..48a99f68 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -0,0 +1,39 @@ +require_relative 'test_helper' + +describe "user class" do + describe "constructor intialize " do + it "should return an instance of user" do + slack_id = 4 + name = "Dom" + real_name = "Dominic Tareto" + + slacker = User.new(slack_id, name, real_name) + expect(slacker.slack_id).must_equal slack_id + expect(slacker.name).must_equal name + expect(slacker.real_name).must_equal real_name + end + end + + describe "self.list method" do + it "should return an array of users" do + slack_id = 4 + name = "Dom" + real_name = "Dominic Tareto" + slacker = User.new(slack_id, name, real_name) + + expect(User.list).must_be_kind_of Array + #expect(list).must_be_kind_of Array + end + + it "should return instances of User" do + #expect(@user).must_be_kind_of User + end + end + + + + + + + +end \ No newline at end of file From 33ee02980f05e339b1b1a38b122364f542bf7d42 Mon Sep 17 00:00:00 2001 From: Farah Davoodi Date: Tue, 10 Sep 2019 15:43:09 -0700 Subject: [PATCH 04/26] created list method and passed test --- lib/user.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index 5caec516..b90ab6a2 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,15 +1,15 @@ class User < Recipient attr_reader :slack_id, :name, :real_name + @@users_list = [] def initialize(slack_id, name, real_name) super(slack_id, name) @real_name = real_name - @users_list = [] end def self.list - @users_list << self.User - return @users_list + @@users_list << self + return @@users_list end From b91c159dc64e3af38f2bc77e7c2bff6a38d42995 Mon Sep 17 00:00:00 2001 From: Farah Davoodi Date: Tue, 10 Sep 2019 15:57:35 -0700 Subject: [PATCH 05/26] added self.list method for User and passed nominal test --- lib/user.rb | 10 ++-------- test/user_test.rb | 24 +++++++++++++++++------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index b90ab6a2..e4334338 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -5,17 +5,11 @@ class User < Recipient def initialize(slack_id, name, real_name) super(slack_id, name) @real_name = real_name + @@users_list << self end def self.list - @@users_list << self - return @@users_list + return @@users_list end - - - - - - end \ No newline at end of file diff --git a/test/user_test.rb b/test/user_test.rb index 48a99f68..d2a2006e 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -1,4 +1,5 @@ require_relative 'test_helper' +require 'pry' describe "user class" do describe "constructor intialize " do @@ -16,17 +17,26 @@ describe "self.list method" do it "should return an array of users" do - slack_id = 4 - name = "Dom" - real_name = "Dominic Tareto" - slacker = User.new(slack_id, name, real_name) + slack_id = 4 + name = "Dom" + real_name = "Dominic Tareto" + slacker = User.new(slack_id, name, real_name) - expect(User.list).must_be_kind_of Array - #expect(list).must_be_kind_of Array + expect(User.list).must_be_kind_of Array + #expect(list).must_be_kind_of Array end it "should return instances of User" do - #expect(@user).must_be_kind_of User + slack_id = 4 + name = "Dom" + real_name = "Dominic Tareto" + slacker = User.new(slack_id, name, real_name) + + user_list = User.list + user_list.each do |user| + expect(user).must_be_instance_of User + end + end end From eb1d37501b2ad58983c0e90e95dc90bd2954b7e3 Mon Sep 17 00:00:00 2001 From: Stephanie Garcia Date: Tue, 10 Sep 2019 16:38:13 -0700 Subject: [PATCH 06/26] Added tests for Channel and List method --- lib/channel.rb | 20 ++++++++++++++++++++ lib/user.rb | 5 ----- test/channel_test.rb | 29 +++++++++++++++++++++++++++++ test/user_test.rb | 22 +++++++++++----------- 4 files changed, 60 insertions(+), 16 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index e69de29b..922f0518 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -0,0 +1,20 @@ +class Channel < Recipient + attr_reader :slack_id, :name, :topic, :member_count + @@channels_list = [] + + def initialize(slack_id, name, topic, member_count) + super(slack_id, name) + @topic = topic + @member_count = member_count + @@channels_list << self + end + + def self.list + return @@channels_list + end + + + + +end + diff --git a/lib/user.rb b/lib/user.rb index b90ab6a2..27047938 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -13,9 +13,4 @@ def self.list end - - - - - end \ No newline at end of file diff --git a/test/channel_test.rb b/test/channel_test.rb index e69de29b..d9dbefc4 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -0,0 +1,29 @@ +require_relative 'test_helper' + +describe "Channel Class"do + describe "constructor initialize" do + it "should return an instance of channel" do + slack_id = 4 + name = "Sick Rides" + topic = "Post here about your coolest cars" + member_count = 2 + + slack_channel = Channel.new(slack_id, name, topic, member_count) + expect(slack_channel.slack_id).must_equal slack_id + expect(slack_channel.name).must_equal name + expect(slack_channel.topic).must_equal topic + expect(slack_channel.member_count).must_equal member_count + end + end + + describe "self.list method" do + it "should return an array" do + slack_id = 4 + name = "Sick Rides" + topic = "Post here about your coolest cars" + member_count = 2 + slack_channel = Channel.new(slack_id, name, topic, member_count) + expect(Channel.list).must_be_kind_of Array + end + end +end \ No newline at end of file diff --git a/test/user_test.rb b/test/user_test.rb index 48a99f68..1aa41a50 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -6,34 +6,34 @@ slack_id = 4 name = "Dom" real_name = "Dominic Tareto" - + slacker = User.new(slack_id, name, real_name) expect(slacker.slack_id).must_equal slack_id expect(slacker.name).must_equal name expect(slacker.real_name).must_equal real_name end end - + describe "self.list method" do it "should return an array of users" do slack_id = 4 name = "Dom" real_name = "Dominic Tareto" slacker = User.new(slack_id, name, real_name) - + expect(User.list).must_be_kind_of Array #expect(list).must_be_kind_of Array end - + it "should return instances of User" do #expect(@user).must_be_kind_of User end end - - - - - - - + + + + + + + end \ No newline at end of file From 8fa86da6cd5243ce4939e7d015c1dfa57f1af095 Mon Sep 17 00:00:00 2001 From: Farah Davoodi Date: Tue, 10 Sep 2019 16:55:30 -0700 Subject: [PATCH 07/26] Formatted tabs --- lib/recipient.rb | 27 ++++++++++++--------------- lib/user.rb | 2 ++ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 5fe2fc83..c1d06ac0 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,17 +1,14 @@ class Recipient - attr_reader :slack_id, :name - - def initialize(slack_id, name) - @slack_id = slack_id - @name = name - end - - def self.list - raise NotImplementedError, "Implement me in a child class!" - end - - - - - + attr_reader :slack_id, :name + class SlackApiError < Exception + end + + def initialize(slack_id, name) + @slack_id = slack_id + @name = name + end + + def self.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 index e4334338..36356995 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,3 +1,5 @@ +require 'httparty' + class User < Recipient attr_reader :slack_id, :name, :real_name @@users_list = [] From 21f5bfa8f783fc4277674d913808ed21fd0805bb Mon Sep 17 00:00:00 2001 From: Stephanie Garcia Date: Tue, 10 Sep 2019 17:07:55 -0700 Subject: [PATCH 08/26] Attempted adding API component to user.list method --- lib/user.rb | 9 ++- test/cassettes/user_list.yml | 129 +++++++++++++++++++++++++++++++++++ test/user_test.rb | 15 ++-- 3 files changed, 146 insertions(+), 7 deletions(-) create mode 100644 test/cassettes/user_list.yml diff --git a/lib/user.rb b/lib/user.rb index 36356995..9a15e1e8 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,6 +1,9 @@ require 'httparty' class User < Recipient + URL = 'https://slack.com/api/users.list' + KEY = ENV['SLACK_API_TOKEN'] + attr_reader :slack_id, :name, :real_name @@users_list = [] @@ -11,7 +14,11 @@ def initialize(slack_id, name, real_name) end def self.list - return @@users_list + query = { + token: KEY + } + response = HTTParty.get(URL, query: query) + return response end end \ No newline at end of file diff --git a/test/cassettes/user_list.yml b/test/cassettes/user_list.yml new file mode 100644 index 00000000..abf26be4 --- /dev/null +++ b/test/cassettes/user_list.yml @@ -0,0 +1,129 @@ +--- +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: + - '53' + Connection: + - keep-alive + Date: + - Wed, 11 Sep 2019 00:04:38 GMT + Server: + - Apache + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + X-Accepted-Oauth-Scopes: + - users:read + Vary: + - Accept-Encoding + X-Slack-Req-Id: + - 78c40add-5723-429d-9b05-ae56306abfba + X-Xss-Protection: + - '0' + X-Content-Type-Options: + - nosniff + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-q8kd + X-Cache: + - Miss from cloudfront + Via: + - 1.1 8ae6af4d17aae7471e5fe2792eb6abcd.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C1 + X-Amz-Cf-Id: + - MWPaYv7LbrnJGj90mrCiQ039kcx2scz78bC1v3M093Pu82re7ZThaw== + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"not_authed"}' + http_version: + recorded_at: Wed, 11 Sep 2019 00:04:38 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: + - '53' + Connection: + - keep-alive + Date: + - Wed, 11 Sep 2019 00:06:40 GMT + Server: + - Apache + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + X-Accepted-Oauth-Scopes: + - users:read + Vary: + - Accept-Encoding + X-Slack-Req-Id: + - 74e47c40-d87a-48f8-b24f-1ba8ed79ea7e + X-Xss-Protection: + - '0' + X-Content-Type-Options: + - nosniff + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-45gn + X-Cache: + - Miss from cloudfront + Via: + - 1.1 deaaf0548506de20925615eb51a7ea7f.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C1 + X-Amz-Cf-Id: + - TMjshnKscjVKRtrGU51otPbuHd-zPYzdEf9cZmxHlsPlxb9eNBLEzQ== + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"not_authed"}' + http_version: + recorded_at: Wed, 11 Sep 2019 00:06:40 GMT +recorded_with: VCR 5.0.0 diff --git a/test/user_test.rb b/test/user_test.rb index 135319a1..42429b9b 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -17,13 +17,16 @@ describe "self.list method" do it "should return an array of users" do - slack_id = 4 - name = "Dom" - real_name = "Dominic Tareto" - slacker = User.new(slack_id, name, real_name) + VCR.use_cassette("user_list") do + slack_id = 4 + name = "Dom" + real_name = "Dominic Tareto" + slacker = User.new(slack_id, name, real_name) - expect(User.list).must_be_kind_of Array - #expect(list).must_be_kind_of Array + response = User.list + expect(response).must_be_kind_of Array + #expect(list).must_be_kind_of Array + end end it "should return instances of User" do From fc314b644f484bcafa1efd1eb1531638e94b2c51 Mon Sep 17 00:00:00 2001 From: Farah Davoodi Date: Tue, 10 Sep 2019 18:53:37 -0700 Subject: [PATCH 09/26] Fixed indentation/do&end issues --- lib/channel.rb | 4 --- lib/slack.rb | 17 +++++----- lib/user.rb | 20 +++++------ test/recipient_test.rb | 25 +++++++------- test/user_test.rb | 75 +++++++++++++++++++----------------------- 5 files changed, 64 insertions(+), 77 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 922f0518..ce6c81ad 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -12,9 +12,5 @@ def initialize(slack_id, name, topic, member_count) def self.list return @@channels_list end - - - - end diff --git a/lib/slack.rb b/lib/slack.rb index 088d1362..d91a1951 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -3,18 +3,17 @@ require "dotenv" Dotenv.load -BASE_URL = "https://slack.com/api/channels.list" -KEY = ENV["SLACK_API_TOKEN"] +# BASE_URL = "https://slack.com/api/channels.list" +# I think we need to move BASE_URL to channels since this URL is specific to list channels +# KEY = ENV["SLACK_API_TOKEN"] def main - query = { - token: KEY - } - response = HTTParty.get(BASE_URL, query: query) - #puts "Welcome to the Ada Slack CLI!" + # query = {token: KEY} + # response = HTTParty.get(BASE_URL, query: query) + puts "Welcome to the Ada Slack CLI!" # TODO project - return response - #puts "Thank you for using the Ada Slack CLI" + # return response + puts "Thank you for using the Ada Slack CLI" end puts main diff --git a/lib/user.rb b/lib/user.rb index 36356995..f7435383 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,17 +1,17 @@ require 'httparty' class User < Recipient - attr_reader :slack_id, :name, :real_name - @@users_list = [] + attr_reader :slack_id, :name, :real_name + @@users_list = [] - def initialize(slack_id, name, real_name) - super(slack_id, name) - @real_name = real_name - @@users_list << self - end + def initialize(slack_id, name, real_name) + super(slack_id, name) + @real_name = real_name + @@users_list << self + end - def self.list - return @@users_list - end + def self.list + return @@users_list + end end \ No newline at end of file diff --git a/test/recipient_test.rb b/test/recipient_test.rb index 8338d81f..0c106a87 100644 --- a/test/recipient_test.rb +++ b/test/recipient_test.rb @@ -1,17 +1,18 @@ require_relative 'test_helper' describe "Recipient Class" do - describe "Constructor" do - it "Should return a recipient class instance" do - #Expect recipient.new - slack_id = 1 - name = "Dom" - slacker = Recipient.new(slack_id, name) - expect(slacker.slack_id).must_equal slack_id - expect(slacker.name).must_equal "Dom" - end - end - xdescribe "send message method" do - it "Should send a message to" + describe "Constructor" do + it "Should return a recipient class instance" do + #Expect recipient.new + slack_id = 1 + name = "Dom" + slacker = Recipient.new(slack_id, name) + expect(slacker.slack_id).must_equal slack_id + expect(slacker.name).must_equal "Dom" end + end + + xdescribe "send message method" do + it "Should send a message to" + end end \ No newline at end of file diff --git a/test/user_test.rb b/test/user_test.rb index 135319a1..6ad1ee30 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -2,48 +2,39 @@ require 'pry' describe "user class" do - describe "constructor intialize " do - it "should return an instance of user" do - slack_id = 4 - name = "Dom" - real_name = "Dominic Tareto" - - slacker = User.new(slack_id, name, real_name) - expect(slacker.slack_id).must_equal slack_id - expect(slacker.name).must_equal name - expect(slacker.real_name).must_equal real_name - end + describe "constructor intialize " do + it "should return an instance of user" do + slack_id = 4 + name = "Dom" + real_name = "Dominic Tareto" + + slacker = User.new(slack_id, name, real_name) + expect(slacker.slack_id).must_equal slack_id + expect(slacker.name).must_equal name + expect(slacker.real_name).must_equal real_name end - - describe "self.list method" do - it "should return an array of users" do - slack_id = 4 - name = "Dom" - real_name = "Dominic Tareto" - slacker = User.new(slack_id, name, real_name) - - expect(User.list).must_be_kind_of Array - #expect(list).must_be_kind_of Array - end - - it "should return instances of User" do - slack_id = 4 - name = "Dom" - real_name = "Dominic Tareto" - slacker = User.new(slack_id, name, real_name) - - user_list = User.list - user_list.each do |user| - expect(user).must_be_instance_of User - end - - end + end + + describe "self.list method" do + it "should return an array of users" do + slack_id = 4 + name = "Dom" + real_name = "Dominic Tareto" + slacker = User.new(slack_id, name, real_name) + + expect(User.list).must_be_kind_of Array + #expect(list).must_be_kind_of Array end - - - - - - -end \ No newline at end of file + it "should return instances of User" do + slack_id = 4 + name = "Dom" + real_name = "Dominic Tareto" + slacker = User.new(slack_id, name, real_name) + user_list = User.list + user_list.each do |user| + expect(user).must_be_instance_of User + end + end + end +end From dccd54960a5b117f77fde99d55bde81df7dce588 Mon Sep 17 00:00:00 2001 From: Stephanie Garcia Date: Wed, 11 Sep 2019 09:32:52 -0700 Subject: [PATCH 10/26] Resolved more merge conflicts --- lib/user.rb | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index 32828356..a09d6bea 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,16 +1,8 @@ require 'httparty' class User < Recipient -<<<<<<< HEAD - URL = 'https://slack.com/api/users.list' - KEY = ENV['SLACK_API_TOKEN'] - - attr_reader :slack_id, :name, :real_name - @@users_list = [] -======= attr_reader :slack_id, :name, :real_name @@users_list = [] ->>>>>>> fc314b644f484bcafa1efd1eb1531638e94b2c51 def initialize(slack_id, name, real_name) super(slack_id, name) @@ -18,7 +10,6 @@ def initialize(slack_id, name, real_name) @@users_list << self end -<<<<<<< HEAD def self.list query = { token: KEY @@ -26,10 +17,5 @@ def self.list response = HTTParty.get(URL, query: query) return response end -======= - def self.list - return @@users_list - end ->>>>>>> fc314b644f484bcafa1efd1eb1531638e94b2c51 end \ No newline at end of file From dd51b5cdbb0f0617661d5e8029caecd9b9080e39 Mon Sep 17 00:00:00 2001 From: Farah Davoodi Date: Wed, 11 Sep 2019 15:15:50 -0700 Subject: [PATCH 11/26] deleted cassettes and added filter sensitive data for token --- lib/channel.rb | 14 +++- test/cassettes/user_list.yml | 129 ----------------------------------- test/channel_test.rb | 38 +++++------ test/test_helper.rb | 14 +++- 4 files changed, 42 insertions(+), 153 deletions(-) delete mode 100644 test/cassettes/user_list.yml diff --git a/lib/channel.rb b/lib/channel.rb index ce6c81ad..34b3f74a 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,6 +1,11 @@ +require 'httparty' +require 'pry' + class Channel < Recipient attr_reader :slack_id, :name, :topic, :member_count @@channels_list = [] + BASE_URL = "https://slack.com/api/channels.list" + API_KEY = ENV['SLACK_API_TOKEN'] def initialize(slack_id, name, topic, member_count) super(slack_id, name) @@ -10,7 +15,14 @@ def initialize(slack_id, name, topic, member_count) end def self.list - return @@channels_list + query = { + token: API_KEY + } + + response = HTTParty.get(BASE_URL, query: query) + binding.pry + + return response end end diff --git a/test/cassettes/user_list.yml b/test/cassettes/user_list.yml deleted file mode 100644 index abf26be4..00000000 --- a/test/cassettes/user_list.yml +++ /dev/null @@ -1,129 +0,0 @@ ---- -http_interactions: -- request: - method: get - uri: https://slack.com/api/users.list?token= - body: - encoding: US-ASCII - string: '' - headers: - Accept-Encoding: - - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 - Accept: - - "*/*" - User-Agent: - - Ruby - response: - status: - code: 200 - message: OK - headers: - Content-Type: - - application/json; charset=utf-8 - Content-Length: - - '53' - Connection: - - keep-alive - Date: - - Wed, 11 Sep 2019 00:04:38 GMT - Server: - - Apache - Access-Control-Expose-Headers: - - x-slack-req-id, retry-after - Access-Control-Allow-Headers: - - slack-route, x-slack-version-ts - Strict-Transport-Security: - - max-age=31536000; includeSubDomains; preload - Referrer-Policy: - - no-referrer - X-Accepted-Oauth-Scopes: - - users:read - Vary: - - Accept-Encoding - X-Slack-Req-Id: - - 78c40add-5723-429d-9b05-ae56306abfba - X-Xss-Protection: - - '0' - X-Content-Type-Options: - - nosniff - Access-Control-Allow-Origin: - - "*" - X-Via: - - haproxy-www-q8kd - X-Cache: - - Miss from cloudfront - Via: - - 1.1 8ae6af4d17aae7471e5fe2792eb6abcd.cloudfront.net (CloudFront) - X-Amz-Cf-Pop: - - SEA19-C1 - X-Amz-Cf-Id: - - MWPaYv7LbrnJGj90mrCiQ039kcx2scz78bC1v3M093Pu82re7ZThaw== - body: - encoding: ASCII-8BIT - string: '{"ok":false,"error":"not_authed"}' - http_version: - recorded_at: Wed, 11 Sep 2019 00:04:38 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: - - '53' - Connection: - - keep-alive - Date: - - Wed, 11 Sep 2019 00:06:40 GMT - Server: - - Apache - Access-Control-Expose-Headers: - - x-slack-req-id, retry-after - Access-Control-Allow-Headers: - - slack-route, x-slack-version-ts - Strict-Transport-Security: - - max-age=31536000; includeSubDomains; preload - Referrer-Policy: - - no-referrer - X-Accepted-Oauth-Scopes: - - users:read - Vary: - - Accept-Encoding - X-Slack-Req-Id: - - 74e47c40-d87a-48f8-b24f-1ba8ed79ea7e - X-Xss-Protection: - - '0' - X-Content-Type-Options: - - nosniff - Access-Control-Allow-Origin: - - "*" - X-Via: - - haproxy-www-45gn - X-Cache: - - Miss from cloudfront - Via: - - 1.1 deaaf0548506de20925615eb51a7ea7f.cloudfront.net (CloudFront) - X-Amz-Cf-Pop: - - SEA19-C1 - X-Amz-Cf-Id: - - TMjshnKscjVKRtrGU51otPbuHd-zPYzdEf9cZmxHlsPlxb9eNBLEzQ== - body: - encoding: ASCII-8BIT - string: '{"ok":false,"error":"not_authed"}' - http_version: - recorded_at: Wed, 11 Sep 2019 00:06:40 GMT -recorded_with: VCR 5.0.0 diff --git a/test/channel_test.rb b/test/channel_test.rb index d9dbefc4..a34353f7 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -1,29 +1,27 @@ require_relative 'test_helper' describe "Channel Class"do - describe "constructor initialize" do - it "should return an instance of channel" do - slack_id = 4 - name = "Sick Rides" - topic = "Post here about your coolest cars" - member_count = 2 + # describe "constructor initialize" do + # it "should return an instance of channel" do + # slack_id = 4 + # name = "Sick Rides" + # topic = "Post here about your coolest cars" + # member_count = 2 - slack_channel = Channel.new(slack_id, name, topic, member_count) - expect(slack_channel.slack_id).must_equal slack_id - expect(slack_channel.name).must_equal name - expect(slack_channel.topic).must_equal topic - expect(slack_channel.member_count).must_equal member_count - end - end + # slack_channel = Channel.new(slack_id, name, topic, member_count) + # expect(slack_channel.slack_id).must_equal slack_id + # expect(slack_channel.name).must_equal name + # expect(slack_channel.topic).must_equal topic + # expect(slack_channel.member_count).must_equal member_count + # end + # end describe "self.list method" do - it "should return an array" do - slack_id = 4 - name = "Sick Rides" - topic = "Post here about your coolest cars" - member_count = 2 - slack_channel = Channel.new(slack_id, name, topic, member_count) - expect(Channel.list).must_be_kind_of Array + it "should return true if the list was returned" do + VCR.use_cassette("channel-tests") do + response = Channel.list + expect(response).must_equal true + end end end end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 87d2ced6..1158bae0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -18,6 +18,14 @@ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new VCR.configure do |config| - config.cassette_library_dir = "test/cassettes" - config.hook_into :webmock -end + config.cassette_library_dir = "test/cassettes" # folder where casettes will be located + config.hook_into :webmock # tie into this other tool called webmock + config.default_cassette_options = { + :record => :new_episodes, # record new data when we don't have it yet + :match_requests_on => [:method, :uri, :body], # The http method, URI and body of a request all need to match + } + # Don't leave our token lying around in a cassette file. + config.filter_sensitive_data("") do + ENV["SLACK_API_TOKEN"] + end + \ No newline at end of file From 9bac8abf0605631855208fd0b66c3a77eceb9f66 Mon Sep 17 00:00:00 2001 From: Stephanie Garcia Date: Thu, 12 Sep 2019 08:26:58 -0700 Subject: [PATCH 12/26] Fixed list channel method and tests --- lib/channel.rb | 21 +++-- lib/user.rb | 12 ++- test/cassettes/channel-tests.yml | 144 +++++++++++++++++++++++++++++++ test/channel_test.rb | 30 +++---- test/test_helper.rb | 2 +- 5 files changed, 186 insertions(+), 23 deletions(-) create mode 100644 test/cassettes/channel-tests.yml diff --git a/lib/channel.rb b/lib/channel.rb index 34b3f74a..106d2f1a 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,4 +1,6 @@ require 'httparty' +require 'dotenv' +Dotenv.load require 'pry' class Channel < Recipient @@ -6,23 +8,30 @@ class Channel < Recipient @@channels_list = [] BASE_URL = "https://slack.com/api/channels.list" API_KEY = ENV['SLACK_API_TOKEN'] - + def initialize(slack_id, name, topic, member_count) super(slack_id, name) @topic = topic @member_count = member_count @@channels_list << self end - + def self.list query = { token: API_KEY } - response = HTTParty.get(BASE_URL, query: query) - binding.pry - + return response end -end + def printed_channels_list + channels_array = [] + + self.list["channels"].each do |channel| + channels_array << channel["name"] + end + + return channels_array + end +end \ No newline at end of file diff --git a/lib/user.rb b/lib/user.rb index a09d6bea..0e610fb4 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,8 +1,13 @@ require 'httparty' +require 'dotenv' +Dotenv.load +require 'pry' class User < Recipient attr_reader :slack_id, :name, :real_name @@users_list = [] + BASE_URL = "https://slack.com/api/users.list" + API_KEY = ENV['SLACK_API_TOKEN'] def initialize(slack_id, name, real_name) super(slack_id, name) @@ -15,7 +20,12 @@ def self.list token: KEY } response = HTTParty.get(URL, query: query) - return response + + users_names = [] + response["members"].each do |member| + users_names_array << member["name"] + end + return users_names end end \ No newline at end of file diff --git a/test/cassettes/channel-tests.yml b/test/cassettes/channel-tests.yml new file mode 100644 index 00000000..e38ff5a8 --- /dev/null +++ b/test/cassettes/channel-tests.yml @@ -0,0 +1,144 @@ +--- +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: + - '53' + Connection: + - keep-alive + Date: + - Wed, 11 Sep 2019 22:20:36 GMT + Server: + - Apache + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + X-Accepted-Oauth-Scopes: + - channels:read + Vary: + - Accept-Encoding + X-Slack-Req-Id: + - 5f291dbf-5181-4a7a-a0aa-5e1e46b8649c + X-Xss-Protection: + - '0' + X-Content-Type-Options: + - nosniff + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-vui8 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 a3bd0eb50c22e4d5fbda56a30b96002d.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C2 + X-Amz-Cf-Id: + - lPy3rnBE6GvRpY_UYYF33kS75WhLDo-i2fpeLrFMFMwkbZge_uoDHw== + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"not_authed"}' + http_version: + recorded_at: Wed, 11 Sep 2019 22:20:34 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: + - '599' + Connection: + - keep-alive + Date: + - Wed, 11 Sep 2019 22:31:00 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 2d902ccd-c9f8-4458-a2ad-ca964ef97a5a + X-Oauth-Scopes: + - identify,read,post,client,apps + 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,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-udcv + X-Cache: + - Miss from cloudfront + Via: + - 1.1 078ca3a7cfdee29c8e3514176205c50a.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19 + X-Amz-Cf-Id: + - 9SW3dIMAfd7u0JmyRxR7wha-tHMksRKPdjy4OqOdnclWj9jZzDwZAw== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CN70NEJ92","name":"ada-developers-academy","is_channel":true,"created":1568140876,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN7EHLGQ5","name_normalized":"ada-developers-academy","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UN7EHLGQ5","UN9ADP0KZ"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2},{"id":"CN12DA91P","name":"general","is_channel":true,"created":1568140875,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UN7EHLGQ5","name_normalized":"general","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UN7EHLGQ5","UN9ADP0KZ"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UN7EHLGQ5","last_set":1568140875},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UN7EHLGQ5","last_set":1568140875},"previous_names":[],"num_members":2},{"id":"CN9LMGB8E","name":"random","is_channel":true,"created":1568140875,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN7EHLGQ5","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UN7EHLGQ5","UN9ADP0KZ"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UN7EHLGQ5","last_set":1568140875},"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":"UN7EHLGQ5","last_set":1568140875},"previous_names":[],"num_members":2},{"id":"CMXCAQGP5","name":"sick-rides","is_channel":true,"created":1568223519,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UN7EHLGQ5","name_normalized":"sick-rides","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UN7EHLGQ5","UN9ADP0KZ"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"post + your cool cars here","creator":"UN7EHLGQ5","last_set":1568223520},"previous_names":[],"num_members":2}]}' + http_version: + recorded_at: Wed, 11 Sep 2019 22:30:58 GMT +recorded_with: VCR 5.0.0 diff --git a/test/channel_test.rb b/test/channel_test.rb index a34353f7..e4735d3b 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -1,26 +1,26 @@ require_relative 'test_helper' -describe "Channel Class"do - # describe "constructor initialize" do - # it "should return an instance of channel" do - # slack_id = 4 - # name = "Sick Rides" - # topic = "Post here about your coolest cars" - # member_count = 2 + describe "Channel Class"do +# # describe "constructor initialize" do +# # it "should return an instance of channel" do +# # slack_id = 4 +# # name = "Sick Rides" +# # topic = "Post here about your coolest cars" +# # member_count = 2 - # slack_channel = Channel.new(slack_id, name, topic, member_count) - # expect(slack_channel.slack_id).must_equal slack_id - # expect(slack_channel.name).must_equal name - # expect(slack_channel.topic).must_equal topic - # expect(slack_channel.member_count).must_equal member_count - # end - # end +# # slack_channel = Channel.new(slack_id, name, topic, member_count) +# # expect(slack_channel.slack_id).must_equal slack_id +# # expect(slack_channel.name).must_equal name +# # expect(slack_channel.topic).must_equal topic +# # expect(slack_channel.member_count).must_equal member_count +# # end +# # end describe "self.list method" do it "should return true if the list was returned" do VCR.use_cassette("channel-tests") do response = Channel.list - expect(response).must_equal true + expect(response["ok"]).must_equal true end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 1158bae0..7ab99062 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -28,4 +28,4 @@ config.filter_sensitive_data("") do ENV["SLACK_API_TOKEN"] end - \ No newline at end of file +end \ No newline at end of file From 149b664074255d1a0afb13d6032cca6a74f53084 Mon Sep 17 00:00:00 2001 From: Stephanie Garcia Date: Thu, 12 Sep 2019 12:52:20 -0700 Subject: [PATCH 13/26] Completed tests for users and channel class --- lib/user.rb | 29 +++++++----- test/cassettes/channel-tests.yml | 76 ++++++++++++++++++++++++++++++ test/cassettes/user-tests.yml | 79 ++++++++++++++++++++++++++++++++ test/channel_test.rb | 16 +------ test/user_test.rb | 35 ++------------ 5 files changed, 177 insertions(+), 58 deletions(-) create mode 100644 test/cassettes/user-tests.yml diff --git a/lib/user.rb b/lib/user.rb index 0e610fb4..58d31233 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -8,24 +8,29 @@ class User < Recipient @@users_list = [] BASE_URL = "https://slack.com/api/users.list" API_KEY = ENV['SLACK_API_TOKEN'] - + def initialize(slack_id, name, real_name) super(slack_id, name) @real_name = real_name @@users_list << self end + + def self.list + query = { + token: API_KEY + } + response = HTTParty.get(BASE_URL, query: query) + return response + end + + def printed_channels_list + users_array = [] - def self.list - query = { - token: KEY - } - response = HTTParty.get(URL, query: query) - - users_names = [] - response["members"].each do |member| - users_names_array << member["name"] - end - return users_names + self.list["members"].each do |member| + users_array << member["name"] end + return users_array + end + end \ No newline at end of file diff --git a/test/cassettes/channel-tests.yml b/test/cassettes/channel-tests.yml index e38ff5a8..fb8f7821 100644 --- a/test/cassettes/channel-tests.yml +++ b/test/cassettes/channel-tests.yml @@ -141,4 +141,80 @@ http_interactions: your cool cars here","creator":"UN7EHLGQ5","last_set":1568223520},"previous_names":[],"num_members":2}]}' http_version: recorded_at: Wed, 11 Sep 2019 22:30:58 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: + - '935' + Connection: + - keep-alive + Date: + - Thu, 12 Sep 2019 19:44:26 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 79d72217-8d8e-4597-854a-a827b8b9f638 + X-Oauth-Scopes: + - identify,read,post,client,apps + 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,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-1zz5 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 b2f9564ebf9c745cc2ceae96d434977e.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C2 + X-Amz-Cf-Id: + - D768CfxyOcScMjXpbgvlgscMpDKL4YZQ_Ls7ZuwkliDri4Qu610w2A== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"UN7EHLGQ5","team_id":"TN12D9LHF","name":"farahdavoodi","deleted":false,"color":"9f69e7","real_name":"farah","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"farah","real_name_normalized":"farah","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gd5897757f8e","email":"farahdavoodi@gmail.com","first_name":"farah","last_name":"","image_24":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-512.png","status_text_canonical":"","team":"TN12D9LHF"},"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":1568223956},{"id":"UN9ADP0KZ","team_id":"TN12D9LHF","name":"stephanie.garcia400","deleted":false,"color":"e7392d","real_name":"Stephanie + Garcia","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Stephanie + Garcia","real_name_normalized":"Stephanie Garcia","display_name":"Stephanie + Garcia","display_name_normalized":"Stephanie Garcia","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gbfa378df3b8","email":"stephanie.garcia400@myci.csuci.edu","image_24":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-512.png","status_text_canonical":"","team":"TN12D9LHF"},"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":1568141360,"has_2fa":false},{"id":"USLACKBOT","team_id":"TN12D9LHF","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":"TN12D9LHF"},"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}],"cache_ts":1568317466}' + http_version: + recorded_at: Thu, 12 Sep 2019 19:44:25 GMT recorded_with: VCR 5.0.0 diff --git a/test/cassettes/user-tests.yml b/test/cassettes/user-tests.yml new file mode 100644 index 00000000..df33224a --- /dev/null +++ b/test/cassettes/user-tests.yml @@ -0,0 +1,79 @@ +--- +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: + - '937' + Connection: + - keep-alive + Date: + - Thu, 12 Sep 2019 19:47:25 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - e076b3e4-c677-44e4-bc82-2af386ec3a28 + X-Oauth-Scopes: + - identify,read,post,client,apps + 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,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-qdiq + X-Cache: + - Miss from cloudfront + Via: + - 1.1 2dc84924ce70e874a873764fe1415858.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19 + X-Amz-Cf-Id: + - 2lX7FHRgQM9hBNN6rVMEAXCX6pHQs3m38zvP4CDELmXS_bXPFzxfIw== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"UN7EHLGQ5","team_id":"TN12D9LHF","name":"farahdavoodi","deleted":false,"color":"9f69e7","real_name":"farah","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"farah","real_name_normalized":"farah","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gd5897757f8e","email":"farahdavoodi@gmail.com","first_name":"farah","last_name":"","image_24":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-512.png","status_text_canonical":"","team":"TN12D9LHF"},"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":1568223956},{"id":"UN9ADP0KZ","team_id":"TN12D9LHF","name":"stephanie.garcia400","deleted":false,"color":"e7392d","real_name":"Stephanie + Garcia","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Stephanie + Garcia","real_name_normalized":"Stephanie Garcia","display_name":"Stephanie + Garcia","display_name_normalized":"Stephanie Garcia","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gbfa378df3b8","email":"stephanie.garcia400@myci.csuci.edu","image_24":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-512.png","status_text_canonical":"","team":"TN12D9LHF"},"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":1568141360,"has_2fa":false},{"id":"USLACKBOT","team_id":"TN12D9LHF","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":"TN12D9LHF"},"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}],"cache_ts":1568317645}' + http_version: + recorded_at: Thu, 12 Sep 2019 19:47:23 GMT +recorded_with: VCR 5.0.0 diff --git a/test/channel_test.rb b/test/channel_test.rb index e4735d3b..597bdb07 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -1,21 +1,7 @@ require_relative 'test_helper' describe "Channel Class"do -# # describe "constructor initialize" do -# # it "should return an instance of channel" do -# # slack_id = 4 -# # name = "Sick Rides" -# # topic = "Post here about your coolest cars" -# # member_count = 2 - -# # slack_channel = Channel.new(slack_id, name, topic, member_count) -# # expect(slack_channel.slack_id).must_equal slack_id -# # expect(slack_channel.name).must_equal name -# # expect(slack_channel.topic).must_equal topic -# # expect(slack_channel.member_count).must_equal member_count -# # end -# # end - + describe "self.list method" do it "should return true if the list was returned" do VCR.use_cassette("channel-tests") do diff --git a/test/user_test.rb b/test/user_test.rb index 6ad1ee30..87e6a0f2 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -2,38 +2,11 @@ require 'pry' describe "user class" do - describe "constructor intialize " do - it "should return an instance of user" do - slack_id = 4 - name = "Dom" - real_name = "Dominic Tareto" - - slacker = User.new(slack_id, name, real_name) - expect(slacker.slack_id).must_equal slack_id - expect(slacker.name).must_equal name - expect(slacker.real_name).must_equal real_name - end - end - describe "self.list method" do - it "should return an array of users" do - slack_id = 4 - name = "Dom" - real_name = "Dominic Tareto" - slacker = User.new(slack_id, name, real_name) - - expect(User.list).must_be_kind_of Array - #expect(list).must_be_kind_of Array - end - - it "should return instances of User" do - slack_id = 4 - name = "Dom" - real_name = "Dominic Tareto" - slacker = User.new(slack_id, name, real_name) - user_list = User.list - user_list.each do |user| - expect(user).must_be_instance_of User + it "should return true if the list was returned" do + VCR.use_cassette("user-tests") do + response = User.list + expect(response["ok"]).must_equal true end end end From 7b9089ac1a2186526cf701a2046a22514174b56a Mon Sep 17 00:00:00 2001 From: Farah Davoodi Date: Thu, 12 Sep 2019 13:44:16 -0700 Subject: [PATCH 14/26] Created while loop for slack.rb --- lib/channel.rb | 2 +- lib/slack.rb | 35 ++++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 106d2f1a..40bdf4ae 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -32,6 +32,6 @@ def printed_channels_list channels_array << channel["name"] end - return channels_array + puts channels_array end end \ No newline at end of file diff --git a/lib/slack.rb b/lib/slack.rb index d91a1951..45088f43 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -3,19 +3,32 @@ require "dotenv" Dotenv.load -# BASE_URL = "https://slack.com/api/channels.list" -# I think we need to move BASE_URL to channels since this URL is specific to list channels -# KEY = ENV["SLACK_API_TOKEN"] def main - # query = {token: KEY} - # response = HTTParty.get(BASE_URL, query: query) - puts "Welcome to the Ada Slack CLI!" - - # TODO project - # return response + puts"Welcome to the Ada Slack CLI!" + puts"Select an option by number:" + options_array=["List Channels","List Users","Quit"] + options_array.each_with_index{ |channel, index| + puts"#{index+1}.#{channel}" + } + + user_answer = gets.chomp.to_i + + while user_answer != 3 + if user_answer == 1 + # call list method + puts "this is answer 1" + elsif user_answer == 2 + # call user method + puts "this is answer 2" + end + + puts "Select an option by number:" + options_array.each_with_index { |channel,index| + puts "#{index+1}.#{channel}" + } + user_answer = gets.chomp.to_i + end puts "Thank you for using the Ada Slack CLI" end -puts main - main if __FILE__ == $PROGRAM_NAME \ No newline at end of file From 2cc91bf45390a152e8b5b3f5b51daf3f1113a6f7 Mon Sep 17 00:00:00 2001 From: Stephanie Garcia Date: Thu, 12 Sep 2019 15:03:23 -0700 Subject: [PATCH 15/26] Created Channels list and Users list --- lib/channel.rb | 4 +++- lib/slack.rb | 9 +++++---- lib/user.rb | 8 +++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 40bdf4ae..f2ba3231 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -2,6 +2,8 @@ require 'dotenv' Dotenv.load require 'pry' +require_relative 'recipient' +require 'table_print' class Channel < Recipient attr_reader :slack_id, :name, :topic, :member_count @@ -25,7 +27,7 @@ def self.list return response end - def printed_channels_list + def self.printed_channels_list channels_array = [] self.list["channels"].each do |channel| diff --git a/lib/slack.rb b/lib/slack.rb index 45088f43..92ffc8e9 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,7 +1,10 @@ #!/usr/bin/env ruby require "httparty" +require_relative "channel" +require_relative "user" require "dotenv" Dotenv.load +require 'table_print' def main puts"Welcome to the Ada Slack CLI!" @@ -15,11 +18,9 @@ def main while user_answer != 3 if user_answer == 1 - # call list method - puts "this is answer 1" + Channel.printed_channels_list elsif user_answer == 2 - # call user method - puts "this is answer 2" + User.printed_users_list end puts "Select an option by number:" diff --git a/lib/user.rb b/lib/user.rb index 58d31233..d51b9921 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -2,7 +2,7 @@ require 'dotenv' Dotenv.load require 'pry' - +require 'table_print' class User < Recipient attr_reader :slack_id, :name, :real_name @@users_list = [] @@ -23,14 +23,12 @@ def self.list return response end - def printed_channels_list + def self.printed_users_list users_array = [] - self.list["members"].each do |member| users_array << member["name"] end - - return users_array + puts users_array end end \ No newline at end of file From a32b69ac8e13984c6f004014280736d64ae88587 Mon Sep 17 00:00:00 2001 From: Stephanie Garcia Date: Thu, 12 Sep 2019 15:15:07 -0700 Subject: [PATCH 16/26] Finished Wave 1 --- lib/channel.rb | 8 ++++---- lib/user.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index f2ba3231..e8889cd2 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -26,14 +26,14 @@ def self.list return response end - + def self.printed_channels_list channels_array = [] - + self.list["channels"].each do |channel| - channels_array << channel["name"] + channels_array << {"name" => channel["name"],"topic" => channel["purpose"]["value"], "Member Count"=> channel["num_members"], "Slack ID"=> channel["id"]} end - + puts channels_array end end \ No newline at end of file diff --git a/lib/user.rb b/lib/user.rb index d51b9921..ca7aeb00 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -26,7 +26,7 @@ def self.list def self.printed_users_list users_array = [] self.list["members"].each do |member| - users_array << member["name"] + users_array << {"User Name" => member["name"],"Real Name" => member["real_name"],"Slack ID"=> member["id"]} end puts users_array end From 2a5d88b102f566362e316dd715f468738630cac3 Mon Sep 17 00:00:00 2001 From: Stephanie Garcia Date: Thu, 12 Sep 2019 15:23:24 -0700 Subject: [PATCH 17/26] pseudocode --- lib/user.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/user.rb b/lib/user.rb index ca7aeb00..4adc0407 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -31,4 +31,15 @@ def self.printed_users_list puts users_array end + def self.select_user(desired_person) + + #if they choose name go to hash and return namex + #self.printed_users_list.each do |user| + #user["User Name"] == desired_person + return desired_person + #elsif they id go to hash and return id + + + end + end \ No newline at end of file From 9069a3968edb8a46e88dbf808b412a9570ba6e46 Mon Sep 17 00:00:00 2001 From: Farah Davoodi Date: Thu, 12 Sep 2019 15:54:28 -0700 Subject: [PATCH 18/26] Added psuedocode for wave 2 --- lib/channel.rb | 13 +++++++++++++ lib/slack.rb | 22 ++++++++++++++++++++-- lib/user.rb | 16 +++++++++------- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index e8889cd2..3e17294d 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -36,4 +36,17 @@ def self.printed_channels_list puts channels_array end + + def self.select_channel(desired_channel) + + self.printed_channels_list.each do |channel| + if channel["name"] == desired_channel + return desired_channel + elsif channel["Slack ID"] == desired_channel + return desired_channel + else + return nil + end + end + end end \ No newline at end of file diff --git a/lib/slack.rb b/lib/slack.rb index 92ffc8e9..bbf42a61 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -9,18 +9,36 @@ def main puts"Welcome to the Ada Slack CLI!" puts"Select an option by number:" - options_array=["List Channels","List Users","Quit"] + options_array=["List Channels","List Users","Select User","Select Channel","Quit"] options_array.each_with_index{ |channel, index| puts"#{index+1}.#{channel}" } user_answer = gets.chomp.to_i - while user_answer != 3 + while user_answer != 5 if user_answer == 1 Channel.printed_channels_list elsif user_answer == 2 User.printed_users_list + elsif user_answer == 3 + # User.printed_users_list + # puts "Please enter a username or Slack ID" + # desired_name = gets.chomp + # if User.printed_users_list.include?(desired_name) + # return details on desired_name NEW METHOD + # else + # puts "That username or Slack ID is invalid" + # end + elsif user_answer == 4 + # Channel.printed_users_list + # puts "Please enter a channel name or Slack ID" + # desired_channel = gets.chomp + # if Channel.printed_channels_list.include?(desired_name) + # return details on desired channel NEW METHOD + # else + # puts "Not a valid selection." + # end end puts "Select an option by number:" diff --git a/lib/user.rb b/lib/user.rb index 4adc0407..26e821bd 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -33,13 +33,15 @@ def self.printed_users_list def self.select_user(desired_person) - #if they choose name go to hash and return namex - #self.printed_users_list.each do |user| - #user["User Name"] == desired_person - return desired_person - #elsif they id go to hash and return id - - + self.printed_users_list.each do |user| + if user["User Name"] == desired_person + return desired_person + elsif user["Slack ID"] == desired_person + return desired_person + else + return nil + end + end end end \ No newline at end of file From 4ff86ed8614ea03d5c22e82f29cd888c94a93b24 Mon Sep 17 00:00:00 2001 From: Farah Davoodi Date: Thu, 12 Sep 2019 16:03:55 -0700 Subject: [PATCH 19/26] started writing code for wave 2, token issues --- lib/slack.rb | 16 ++++++++-------- lib/user.rb | 10 ++++------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index bbf42a61..c9321943 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -22,14 +22,14 @@ def main elsif user_answer == 2 User.printed_users_list elsif user_answer == 3 - # User.printed_users_list - # puts "Please enter a username or Slack ID" - # desired_name = gets.chomp - # if User.printed_users_list.include?(desired_name) - # return details on desired_name NEW METHOD - # else - # puts "That username or Slack ID is invalid" - # end + User.printed_users_list + puts "Please enter a username or Slack ID:" + desired_person = gets.chomp + if User.printed_users_list.include?(desired_person) + return User.select_user_details(desired_person) + else + puts "That username or Slack ID is invalid" + end elsif user_answer == 4 # Channel.printed_users_list # puts "Please enter a channel name or Slack ID" diff --git a/lib/user.rb b/lib/user.rb index 26e821bd..07d47f79 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -25,21 +25,19 @@ def self.list def self.printed_users_list users_array = [] + binding.pry self.list["members"].each do |member| users_array << {"User Name" => member["name"],"Real Name" => member["real_name"],"Slack ID"=> member["id"]} end puts users_array end - def self.select_user(desired_person) - + def self.select_user_details(desired_person) self.printed_users_list.each do |user| if user["User Name"] == desired_person - return desired_person + puts user elsif user["Slack ID"] == desired_person - return desired_person - else - return nil + puts user end end end From 06908fe36038727d65c6daff2eaebb446137fe31 Mon Sep 17 00:00:00 2001 From: Stephanie Garcia Date: Thu, 12 Sep 2019 16:19:12 -0700 Subject: [PATCH 20/26] Completed user details method --- lib/slack.rb | 15 ++++++++------- lib/user.rb | 7 +++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index c9321943..8e1b0c5b 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -20,16 +20,17 @@ def main if user_answer == 1 Channel.printed_channels_list elsif user_answer == 2 - User.printed_users_list + puts User.printed_users_list elsif user_answer == 3 - User.printed_users_list + puts User.printed_users_list puts "Please enter a username or Slack ID:" desired_person = gets.chomp - if User.printed_users_list.include?(desired_person) - return User.select_user_details(desired_person) - else - puts "That username or Slack ID is invalid" - end + puts User.select_user_details(desired_person) + # if User.printed_users_list.include?(desired_person) + # return User.select_user_details(desired_person) + # else + # puts "That username or Slack ID is invalid" + # end elsif user_answer == 4 # Channel.printed_users_list # puts "Please enter a channel name or Slack ID" diff --git a/lib/user.rb b/lib/user.rb index 07d47f79..d4180949 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -25,19 +25,18 @@ def self.list def self.printed_users_list users_array = [] - binding.pry self.list["members"].each do |member| users_array << {"User Name" => member["name"],"Real Name" => member["real_name"],"Slack ID"=> member["id"]} end - puts users_array + return users_array end def self.select_user_details(desired_person) self.printed_users_list.each do |user| if user["User Name"] == desired_person - puts user + return user elsif user["Slack ID"] == desired_person - puts user + return user end end end From ed6d5032ebfc5860ecc0d15046a8025f447c7f05 Mon Sep 17 00:00:00 2001 From: Stephanie Garcia Date: Thu, 12 Sep 2019 16:59:44 -0700 Subject: [PATCH 21/26] Added select channel details method --- lib/channel.rb | 11 ++++------- lib/slack.rb | 18 +++++------------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 3e17294d..32dda3ed 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -34,18 +34,15 @@ def self.printed_channels_list channels_array << {"name" => channel["name"],"topic" => channel["purpose"]["value"], "Member Count"=> channel["num_members"], "Slack ID"=> channel["id"]} end - puts channels_array + return channels_array end - def self.select_channel(desired_channel) - + def self.select_channel_details(desired_channel) self.printed_channels_list.each do |channel| if channel["name"] == desired_channel - return desired_channel + return channel elsif channel["Slack ID"] == desired_channel - return desired_channel - else - return nil + return channel end end end diff --git a/lib/slack.rb b/lib/slack.rb index 8e1b0c5b..42a37fc7 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -5,6 +5,7 @@ require "dotenv" Dotenv.load require 'table_print' +require 'pry' def main puts"Welcome to the Ada Slack CLI!" @@ -26,20 +27,11 @@ def main puts "Please enter a username or Slack ID:" desired_person = gets.chomp puts User.select_user_details(desired_person) - # if User.printed_users_list.include?(desired_person) - # return User.select_user_details(desired_person) - # else - # puts "That username or Slack ID is invalid" - # end elsif user_answer == 4 - # Channel.printed_users_list - # puts "Please enter a channel name or Slack ID" - # desired_channel = gets.chomp - # if Channel.printed_channels_list.include?(desired_name) - # return details on desired channel NEW METHOD - # else - # puts "Not a valid selection." - # end + Channel.printed_channels_list + puts "Please enter a channel name or Slack ID" + desired_channel = gets.chomp + puts Channel.select_channel_details(desired_channel) end puts "Select an option by number:" From 5d45c48d1174ca8c88330e6a6909a1f32ec2110e Mon Sep 17 00:00:00 2001 From: Stephanie Garcia Date: Thu, 12 Sep 2019 17:20:49 -0700 Subject: [PATCH 22/26] Cleaned up --- lib/channel.rb | 5 ++++- lib/user.rb | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 32dda3ed..5e52c421 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -36,13 +36,16 @@ def self.printed_channels_list return channels_array end - + def self.select_channel_details(desired_channel) self.printed_channels_list.each do |channel| if channel["name"] == desired_channel return channel elsif channel["Slack ID"] == desired_channel return channel + else + statement = "Not a valid Channel name/Slack ID" + return statement end end end diff --git a/lib/user.rb b/lib/user.rb index d4180949..22a8bbd1 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -30,15 +30,18 @@ def self.printed_users_list end return users_array end - + def self.select_user_details(desired_person) self.printed_users_list.each do |user| if user["User Name"] == desired_person return user elsif user["Slack ID"] == desired_person return user + else + statement = "Not a valid Username/Slack ID" + return statement end end end - + end \ No newline at end of file From 08181a47de6431cf178cf804d30da07b1807a0cd Mon Sep 17 00:00:00 2001 From: Farah Davoodi Date: Fri, 13 Sep 2019 11:57:24 -0700 Subject: [PATCH 23/26] Started writing tests for user --- test/user_test.rb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/test/user_test.rb b/test/user_test.rb index 87e6a0f2..f4476cd3 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -3,11 +3,34 @@ describe "user class" do describe "self.list method" do - it "should return true if the list was returned" do + it "should return true if API was validated correctly" do VCR.use_cassette("user-tests") do response = User.list expect(response["ok"]).must_equal true end end end + + describe "self.printed_users_list" do + it "should contain a user named slackbot" do + VCR.use_cassette("user-tests") do + users_array = User.printed_users_list + users_array.each do |user| + if user["name"] == "slackbot" + assert (user), "Expected true" + end + end + end + end + + it "should return an array of users" do + VCR.use_cassette("user-tests") do + users_array = User.printed_users_list + users_array.each do |user| + expect + end + expect(users_array).must_be_kind_of Array + end + end + end end From 466523c4013becc61b3baf4ec4c63da5d02d43fb Mon Sep 17 00:00:00 2001 From: Farah Davoodi Date: Fri, 13 Sep 2019 12:44:07 -0700 Subject: [PATCH 24/26] Created more tests for User class --- .gitignore | 2 +- lib/slack.rb | 3 + test/cassettes/user-tests.yml | 228 ++++++++++++++++++++++++++++++++++ test/user_test.rb | 16 ++- 4 files changed, 245 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 58e18732..7bca64ac 100644 --- a/.gitignore +++ b/.gitignore @@ -54,4 +54,4 @@ build-iPhoneSimulator/ .env # Ignore cassette files -/specs/cassettes/ +/test/cassettes/ diff --git a/lib/slack.rb b/lib/slack.rb index 42a37fc7..66edfdb3 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -20,13 +20,16 @@ def main while user_answer != 5 if user_answer == 1 Channel.printed_channels_list + elsif user_answer == 2 puts User.printed_users_list + elsif user_answer == 3 puts User.printed_users_list puts "Please enter a username or Slack ID:" desired_person = gets.chomp puts User.select_user_details(desired_person) + elsif user_answer == 4 Channel.printed_channels_list puts "Please enter a channel name or Slack ID" diff --git a/test/cassettes/user-tests.yml b/test/cassettes/user-tests.yml index df33224a..74c07171 100644 --- a/test/cassettes/user-tests.yml +++ b/test/cassettes/user-tests.yml @@ -76,4 +76,232 @@ http_interactions: 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":"TN12D9LHF"},"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}],"cache_ts":1568317645}' http_version: recorded_at: Thu, 12 Sep 2019 19:47:23 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: + - '935' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 19:34:46 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 52391197-f357-4d97-bce1-098abe448de5 + 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-an04 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 39688168a2a3353be1f3c9378d12d89f.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C2 + X-Amz-Cf-Id: + - dPEgVH1mxwx6XlZkPjgxIf_e1c3KBX9RTzQ-J6I5HpJzDQ2MkB_ocA== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TN12D9LHF","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":"TN12D9LHF"},"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":"UN7EHLGQ5","team_id":"TN12D9LHF","name":"farahdavoodi","deleted":false,"color":"9f69e7","real_name":"farah","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"farah","real_name_normalized":"farah","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gd5897757f8e","first_name":"farah","last_name":"","image_24":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-512.png","status_text_canonical":"","team":"TN12D9LHF"},"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":1568223956,"has_2fa":false},{"id":"UN9ADP0KZ","team_id":"TN12D9LHF","name":"stephanie.garcia400","deleted":false,"color":"e7392d","real_name":"Stephanie + Garcia","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Stephanie + Garcia","real_name_normalized":"Stephanie Garcia","display_name":"Stephanie + Garcia","display_name_normalized":"Stephanie Garcia","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gbfa378df3b8","image_24":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-512.png","status_text_canonical":"","team":"TN12D9LHF"},"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":1568141360,"has_2fa":false}],"cache_ts":1568403286,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Fri, 13 Sep 2019 19:34:45 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: + - '935' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 19:35:12 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - c1324278-a757-4188-845d-46154e5b5d7e + 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-8emn + X-Cache: + - Miss from cloudfront + Via: + - 1.1 1b74ccf4cb51eacf97a0e6d60ae46a3f.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C2 + X-Amz-Cf-Id: + - FZ5cVjwsZ7a_Jqy7baHtcr-54xIdwDBptFCLFhJHDh32_0ZcPK9X0w== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TN12D9LHF","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":"TN12D9LHF"},"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":"UN7EHLGQ5","team_id":"TN12D9LHF","name":"farahdavoodi","deleted":false,"color":"9f69e7","real_name":"farah","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"farah","real_name_normalized":"farah","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gd5897757f8e","first_name":"farah","last_name":"","image_24":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-512.png","status_text_canonical":"","team":"TN12D9LHF"},"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":1568223956,"has_2fa":false},{"id":"UN9ADP0KZ","team_id":"TN12D9LHF","name":"stephanie.garcia400","deleted":false,"color":"e7392d","real_name":"Stephanie + Garcia","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Stephanie + Garcia","real_name_normalized":"Stephanie Garcia","display_name":"Stephanie + Garcia","display_name_normalized":"Stephanie Garcia","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gbfa378df3b8","image_24":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-512.png","status_text_canonical":"","team":"TN12D9LHF"},"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":1568141360,"has_2fa":false}],"cache_ts":1568403312,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Fri, 13 Sep 2019 19:35:11 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: + - '935' + Connection: + - keep-alive + Date: + - Fri, 13 Sep 2019 19:35:31 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 2b09e52d-0c50-42db-9f02-f41425bfa83e + 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-61a2 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 7e87179efaa9e3c316bd3d3a74cfded8.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - SEA19-C2 + X-Amz-Cf-Id: + - LdoQ714TEpaAr1FesQu66uzqbBS5ddnKmvnkGRfbgpaZR9TrKaH4vA== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TN12D9LHF","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":"TN12D9LHF"},"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":"UN7EHLGQ5","team_id":"TN12D9LHF","name":"farahdavoodi","deleted":false,"color":"9f69e7","real_name":"farah","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"farah","real_name_normalized":"farah","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gd5897757f8e","first_name":"farah","last_name":"","image_24":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/d5897757f8e8a7677a3786b9ca90ce9d.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0005-512.png","status_text_canonical":"","team":"TN12D9LHF"},"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":1568223956,"has_2fa":false},{"id":"UN9ADP0KZ","team_id":"TN12D9LHF","name":"stephanie.garcia400","deleted":false,"color":"e7392d","real_name":"Stephanie + Garcia","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Stephanie + Garcia","real_name_normalized":"Stephanie Garcia","display_name":"Stephanie + Garcia","display_name_normalized":"Stephanie Garcia","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gbfa378df3b8","image_24":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/bfa378df3b85d9cd3bc67a1438db57aa.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F80588%2Fimg%2Favatars%2Fuser_shapes%2Fava_0003-512.png","status_text_canonical":"","team":"TN12D9LHF"},"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":1568141360,"has_2fa":false}],"cache_ts":1568403331,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Fri, 13 Sep 2019 19:35:30 GMT recorded_with: VCR 5.0.0 diff --git a/test/user_test.rb b/test/user_test.rb index f4476cd3..c8eb2c3d 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -12,6 +12,7 @@ end describe "self.printed_users_list" do + it "should contain a user named slackbot" do VCR.use_cassette("user-tests") do users_array = User.printed_users_list @@ -26,11 +27,20 @@ it "should return an array of users" do VCR.use_cassette("user-tests") do users_array = User.printed_users_list - users_array.each do |user| - expect - end expect(users_array).must_be_kind_of Array end end end + + describe "self.select_user_details method" do + it "should return true four slackbot details" do + VCR.use_cassette("user-tests") do + desired_person = User.select_user_details("slackbot") + expect(desired_person["User Name"]).must_equal "slackbot" + expect(desired_person["Slack ID"]).must_equal "USLACKBOT" + expect(desired_person["User Name"]).must_be_kind_of String + expect(desired_person["Slack ID"]).must_be_kind_of String + end + end + end end From 74ef32fef9f3297291885c195b11ea5839016ead Mon Sep 17 00:00:00 2001 From: Stephanie Garcia Date: Fri, 13 Sep 2019 15:02:06 -0700 Subject: [PATCH 25/26] Fixed user class and created more tests --- lib/user.rb | 15 ++++++--------- test/user_test.rb | 7 +++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index 22a8bbd1..c82b8840 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -32,16 +32,13 @@ def self.printed_users_list end def self.select_user_details(desired_person) - self.printed_users_list.each do |user| - if user["User Name"] == desired_person - return user - elsif user["Slack ID"] == desired_person - return user - else - statement = "Not a valid Username/Slack ID" - return statement + self.printed_users_list.each do |user_hash| + if user_hash["User Name"] == desired_person || user_hash["Slack ID"] == desired_person + return user_hash end end + + statement = "Not a valid Username/Slack ID" + return statement end - end \ No newline at end of file diff --git a/test/user_test.rb b/test/user_test.rb index c8eb2c3d..19f08b62 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -42,5 +42,12 @@ expect(desired_person["Slack ID"]).must_be_kind_of String end end + + it "should return 'Not valid' statement if the user does not exist" do + VCR.use_cassette("user-tests") do + desired_person = User.select_user_details("alsdjflai") + expect(desired_person).must_equal "Not a valid Username/Slack ID" + end + end end end From 66f643d1d83948a0758e18f744575ae768ee3e58 Mon Sep 17 00:00:00 2001 From: Stephanie Garcia Date: Fri, 13 Sep 2019 15:17:30 -0700 Subject: [PATCH 26/26] Added tests for channel class --- lib/channel.rb | 11 ++++------- test/channel_test.rb | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 5e52c421..e5e69f47 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -38,15 +38,12 @@ def self.printed_channels_list end def self.select_channel_details(desired_channel) - self.printed_channels_list.each do |channel| - if channel["name"] == desired_channel + self.printed_channels_list.each do |channel| + if channel["name"] == desired_channel || channel["Slack ID"] == desired_channel return channel - elsif channel["Slack ID"] == desired_channel - return channel - else - statement = "Not a valid Channel name/Slack ID" - return statement end end + statement = "Not a valid Channel name/Slack ID" + return statement end end \ No newline at end of file diff --git a/test/channel_test.rb b/test/channel_test.rb index 597bdb07..33f612e5 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -10,4 +10,45 @@ end end end -end \ No newline at end of file + + describe "self.printed_channels_list" do + + it "should contain a channel named general" do + VCR.use_cassette("channel-tests") do + channels_array = Channel.printed_channels_list + channels_array.each do |channel| + if channel["name"] == "general" + assert (channel), "Expected true" + end + end + end + end + + it "should return an array of channels" do + VCR.use_cassette("channel-tests") do + channels_array = Channel.printed_channels_list + expect(channels_array).must_be_kind_of Array + end + end + end + + describe "self.select_channel_details method" do + it "should return true four 'general' details" do + VCR.use_cassette("channel-tests") do + desired_person = Channel.select_channel_details("general") + expect(desired_person["name"]).must_equal "general" + expect(desired_person["topic"]).must_equal "This channel is for workspace-wide communication and announcements. All members are in this channel." + expect(desired_person["name"]).must_be_kind_of String + expect(desired_person["topic"]).must_be_kind_of String + end + end + + it "should return 'Not valid' statement if the Channel does not exist" do + VCR.use_cassette("channel-tests") do + desired_channel = Channel.select_channel_details("alsdjflai") + expect(desired_channel).must_equal "Not a valid Channel name/Slack ID" + end + end + end +end +