From 4b2d5027c05a884a9891dac7f552cc60ffcacb53 Mon Sep 17 00:00:00 2001 From: Bitaman Date: Tue, 19 Mar 2019 13:57:49 -0700 Subject: [PATCH 01/45] set up the files --- lib/channel.rb | 0 lib/recipient.rb | 0 lib/user.rb | 0 specs/channel_spec.rb | 0 specs/recipient_spec.rb | 0 specs/slack_spec.rb | 0 specs/test_helper.rb | 23 ++++++++++++++++------- specs/user_spec.rb | 0 8 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 lib/channel.rb create mode 100644 lib/recipient.rb create mode 100644 lib/user.rb create mode 100644 specs/channel_spec.rb create mode 100644 specs/recipient_spec.rb create mode 100644 specs/slack_spec.rb create mode 100644 specs/user_spec.rb 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..e69de29b diff --git a/lib/user.rb b/lib/user.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/slack_spec.rb b/specs/slack_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 81ccd06b..d0518749 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -1,15 +1,24 @@ -require 'simplecov' +require "simplecov" SimpleCov.start -require 'minitest' -require 'minitest/autorun' -require 'minitest/reporters' -require 'minitest/skip_dsl' -require 'vcr' +require "minitest" +require "minitest/autorun" +require "minitest/reporters" +require "webmock/minitest" +require "minitest/skip_dsl" +require "vcr" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new VCR.configure do |config| config.cassette_library_dir = "specs/cassettes" config.hook_into :webmock -end \ No newline at end of file + 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 + } + + config.filter_sensitive_data("") do + ENV["SLACK_TOKEN"] + end +end diff --git a/specs/user_spec.rb b/specs/user_spec.rb new file mode 100644 index 00000000..e69de29b From f502ab629eab6dfa7f6904837a249998e454b563 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 19 Mar 2019 14:17:37 -0700 Subject: [PATCH 02/45] created classes and shells for methods in each file --- .DS_Store | Bin 0 -> 8196 bytes .gitignore | 2 +- lib/channel.rb | 14 ++++++++++++++ lib/recipient.rb | 17 +++++++++++++++++ lib/slack.rb | 24 +++++++++++++++++++----- lib/user.rb | 15 +++++++++++++++ 6 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5614ccd539c33bcef527742a18374a9dae07e9e5 GIT binary patch literal 8196 zcmeHMTWl3Y829a%Es+(J-g== zs3es{@kZ2$_!Lgp%^pL76-PkgOrK zOjM?GfQ(5-G9AeYC1ohJsZI|Vg<^EXKow5*q;Myhj^u=rDjZOS14cb#bV5PdJH;iX zJ78MLIFAvC5x5xvadw{x4vc^W!#AGa#X747mrVKmSTLG*{XA)|=0{y82;17e#j5I> z88d4&-Kf*+=G5s2Ge`ZgOlXCrpvx-eSX0KadEP1xI(B$8%e`Kgm$|pAxWfv0aldfR z(k%fwsIrycrP^DQ8`qs|O^&D5ZcMc%H?*%gc~aLjbH&!(hf1eTzjEf>n{T~+>9ULh zj6N;Upz7E1D^!Z0sN8PcfQ}oKyA?WBFW(9sv+vREMvl!b)BEij4ISSL_V8jrGRNuz z!lAF=d;LW&?1Kg0Esc0Vjx`i4w@`8ktWMX>I45{86!K%CDD4aUV%RMmha8F(x*TJr zfbZrM;FNg}g#`@t^RwnJUV7iEwso5x?wOoDr=B&;HH>|PsTVp&99|q46O*&o3JTn_ z9dCHB>;z8U-yw^g^jb#gxORvO%2gli#AlsJCB!~@c1N~Q$O2iHt*Hh zMeTr1quA-&q99j+c@F49++u#7LluDq_zJ#d9sYo;@F)C@8tPbwv(Ut)*n-Qj4cl=Grm+*d za69(nZp>g74`Km19>HN8#bbB^$MFe#3Qyzn_yWF&ui|U?I=+Dy@Ljxwm+=aIh@a!v z_=6f?RfWGhRlSnqk5r2IOJt3fa@C<*ku}k~^^rS7*6(I1hTb!8{*soJtJiGU+<9## zr_9@p6q3wQ)R2^^P(n`Lzd1-;HWQ1C#nW+lfEdS*X@WMacG4tnG$#`YCWxcS>ayij zts-t~VqKWV0}1l9G*&IEiHD4oM)YJely$AKUMB*x8f9%aIyB-bo2jf@jI=J67z5d~ zzC2-Q`hVx%SvU{x!AI~Zaqb)V34Vd!;4eh1#Rgo6jkpM#a0#x!`*9Vv;%Z!v8*vkM z;AZT_t+);Qh<#Zcz(E|seZ)Rnvd_UH23W!}vG7SeMI3w@pNUxb60z_so}a?Gz6#rv z#CNW9uAC`)uI~+#Mlf^+1hjTI6t3SDSBR@(F@t<(`e#uVgzCY z?gRo@)064xqMoPw4vVvPlAgo#h$Q?bl$0Tq2^XQ4$8nO^ei%|Y8QId2oKTW1ly3V) PK)nCQ`@dw~-JSgd0E-Zi literal 0 HcmV?d00001 diff --git a/.gitignore b/.gitignore index 8d6a243f..dbe92e37 100644 --- a/.gitignore +++ b/.gitignore @@ -53,4 +53,4 @@ build-iPhoneSimulator/ .env # Ignore cassette files -/specs/cassettes/ +/specs/cassette \ No newline at end of file diff --git a/lib/channel.rb b/lib/channel.rb index e69de29b..6b923555 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -0,0 +1,14 @@ + +class Channel < Recipient + def initialize(slack_id, name, topic, member_count) + super + @topic = topic + @member_count = member_count + end + + def details + end + + def self.list + end +end diff --git a/lib/recipient.rb b/lib/recipient.rb index e69de29b..be48b81a 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -0,0 +1,17 @@ + +class Recipient + def initialize(slack_id, name) + @slack_id = slack_id + @name = name + end + + def send_message(message) + end + + def self.get(url, params) + end + + # def details - request details "package" from user or channel + # def list - request list "package" from user or channel + +end diff --git a/lib/slack.rb b/lib/slack.rb index 960cf2f7..9fdc8f96 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,11 +1,25 @@ #!/usr/bin/env ruby -def main - puts "Welcome to the Ada Slack CLI!" +class Slack + def initialize + end - # TODO project + def main + puts "Welcome to the Ada Slack CLI!" + + def select_channel + end + + def select_user + end + + def show_details + end + + def send_message + end puts "Thank you for using the Ada Slack CLI" -end + end -main if __FILE__ == $PROGRAM_NAME \ No newline at end of file + main if __FILE__ == $PROGRAM_NAME \ No newline at end of file diff --git a/lib/user.rb b/lib/user.rb index e69de29b..190782c3 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -0,0 +1,15 @@ + +class User < Recipient + def initialize(slack_id, name, real_name, status_text, status_emoji) + super + @real_name = real_name + @status_text = status_text + @status_emoji = status_emoji + end + + def details + end + + def self.list + end +end From 8c83fc0d07fc508399e9f57355722979e1ca908a Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 19 Mar 2019 14:43:47 -0700 Subject: [PATCH 03/45] added base_urls and tokens to recipient, user, and channel --- lib/channel.rb | 3 +++ lib/recipient.rb | 3 +++ lib/user.rb | 3 +++ 3 files changed, 9 insertions(+) diff --git a/lib/channel.rb b/lib/channel.rb index 6b923555..e1820935 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,5 +1,8 @@ class Channel < Recipient + BASE_URL = "https://slack.com/api/channels.list" + TOKEN = ENV["SLACK_TOKEN"] + def initialize(slack_id, name, topic, member_count) super @topic = topic diff --git a/lib/recipient.rb b/lib/recipient.rb index be48b81a..0d292b24 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,5 +1,8 @@ class Recipient + BASE_URL = "https://slack.com/api/chat.postMessage" + TOKEN = ENV["SLACK_TOKEN"] + def initialize(slack_id, name) @slack_id = slack_id @name = name diff --git a/lib/user.rb b/lib/user.rb index 190782c3..7946f83d 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,5 +1,8 @@ class User < Recipient + BASE_URL = "https://slack.com/api/users.list" + TOKEN = ENV["SLACK_TOKEN"] + def initialize(slack_id, name, real_name, status_text, status_emoji) super @real_name = real_name From 3f9786fbfc94f91de360b4551eea6a5e6c4adb12 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 19 Mar 2019 15:08:33 -0700 Subject: [PATCH 04/45] added httparty. refined planned tests for user_spec --- lib/slack.rb | 1 + lib/user.rb | 2 ++ specs/test_helper.rb | 6 ++++++ specs/user_spec.rb | 24 ++++++++++++++++++++++++ 4 files changed, 33 insertions(+) diff --git a/lib/slack.rb b/lib/slack.rb index 9fdc8f96..a9529d1c 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +require 'httparty' class Slack def initialize diff --git a/lib/user.rb b/lib/user.rb index 7946f83d..f22e6209 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,4 +1,6 @@ +require "httparty" + class User < Recipient BASE_URL = "https://slack.com/api/users.list" TOKEN = ENV["SLACK_TOKEN"] diff --git a/specs/test_helper.rb b/specs/test_helper.rb index d0518749..7fe59dcc 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -8,6 +8,12 @@ require "minitest/skip_dsl" require "vcr" +require "channel" +require "user" +require "recipient" +require "slack" +require "httparty" + Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new VCR.configure do |config| diff --git a/specs/user_spec.rb b/specs/user_spec.rb index e69de29b..4a509d35 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -0,0 +1,24 @@ +require "test_helper" + +describe "User" do + before do + @user = User.new(1010, "shrutifruity", "Shruti", "droppin' knowledge", ":books:" ) + end + + it "is an instance of user" do + VCR.use_casette "initialize" do + expect(@user).must_be_kind_of User + end + end + + it "returns details about a user" do + VCR.use_casette "details" do + expect(@user.details).must_be_kind_of Array + end + + it "returns a list of users" do + VCR.use_casette "self.list" do + expect(@user.self.list).must_be_kind_of Array + end + +end From ff7f7a256bb1d196eb05efbe6ba53af43194a149 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 19 Mar 2019 15:13:29 -0700 Subject: [PATCH 05/45] initial menu drafted for slack.rb --- lib/slack.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/slack.rb b/lib/slack.rb index a9529d1c..0bd77fb0 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -7,6 +7,25 @@ def initialize def main puts "Welcome to the Ada Slack CLI!" + + puts "Slack CLI Menu\n" + puts "1. List Users\n" + puts "2. List Channels\n" + puts "3. Quit\n" + + loop do + "Please enter your selection from the above options." + input = gets.chomp.to_s + case + when input == "1" + puts users.list + when input == "2" + puts channels.list + when input == "3" + exit + when input =~ /[[:alpha:]]/ + puts "\nYour request was invalid." + end def select_channel end From 145d312447fc35fe27b569e140032abf30533850 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 19 Mar 2019 15:44:21 -0700 Subject: [PATCH 06/45] added require relative to specs, channel params added to channel.rb --- lib/channel.rb | 20 ++++++++++++++++++++ lib/slack.rb | 37 +++++++++++++++++++------------------ specs/channel_spec.rb | 1 + specs/recipient_spec.rb | 1 + specs/slack_spec.rb | 1 + specs/test_helper.rb | 1 - specs/user_spec.rb | 13 +++++++------ 7 files changed, 49 insertions(+), 25 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index e1820935..c938234a 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,8 +1,11 @@ +require "httparty" class Channel < Recipient BASE_URL = "https://slack.com/api/channels.list" TOKEN = ENV["SLACK_TOKEN"] + class SlackAPIError < StandardError; end + def initialize(slack_id, name, topic, member_count) super @topic = topic @@ -12,6 +15,23 @@ def initialize(slack_id, name, topic, member_count) def details end + def get_channels(workspace) + query_params = { + workspace: workspace, + token: TOKEN, + format: json, + } + response = HTTParty.get(BASE_URL, query: query) + + if response.code != 200 || response == nil + raise SlackAPIError, "API call failed with code #{response.code} and reason '#{response["reason"]}" + end + + channel = response["response"].map do |channel| + self.new(channel["id"], channel["name"], channel["topic"], channel["members"]) + end + end + def self.list end end diff --git a/lib/slack.rb b/lib/slack.rb index 0bd77fb0..c8434fd6 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -8,24 +8,25 @@ def initialize def main puts "Welcome to the Ada Slack CLI!" - puts "Slack CLI Menu\n" - puts "1. List Users\n" - puts "2. List Channels\n" - puts "3. Quit\n" - - loop do - "Please enter your selection from the above options." - input = gets.chomp.to_s - case - when input == "1" - puts users.list - when input == "2" - puts channels.list - when input == "3" - exit - when input =~ /[[:alpha:]]/ - puts "\nYour request was invalid." - end + # puts "Slack CLI Menu\n" + # puts "1. List Users\n" + # puts "2. List Channels\n" + # puts "3. Quit\n" + + # loop do + # "Please enter your selection from the above options." + # input = gets.chomp.to_s + # case + # when input == "1" + # puts users.list + # when input == "2" + # puts channels.list + # when input == "3" + # exit + # when input =~ /[[:alpha:]]/ + # puts "\nYour request was invalid." + # end + # end def select_channel end diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index e69de29b..b5cae113 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -0,0 +1 @@ +require_relative "test_helper" diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index e69de29b..b5cae113 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -0,0 +1 @@ +require_relative "test_helper" diff --git a/specs/slack_spec.rb b/specs/slack_spec.rb index e69de29b..b5cae113 100644 --- a/specs/slack_spec.rb +++ b/specs/slack_spec.rb @@ -0,0 +1 @@ +require_relative "test_helper" diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 7fe59dcc..c51bb53a 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -12,7 +12,6 @@ require "user" require "recipient" require "slack" -require "httparty" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 4a509d35..83f47027 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -1,24 +1,25 @@ -require "test_helper" +require_relative "test_helper" describe "User" do before do - @user = User.new(1010, "shrutifruity", "Shruti", "droppin' knowledge", ":books:" ) + @user = User.new(1010, "shrutifruity", "Shruti", "droppin' knowledge", ":books:") end it "is an instance of user" do VCR.use_casette "initialize" do - expect(@user).must_be_kind_of User + expect(@user).must_be_kind_of User end end it "returns details about a user" do VCR.use_casette "details" do - expect(@user.details).must_be_kind_of Array + expect(@user.details).must_be_kind_of Array + end end it "returns a list of users" do VCR.use_casette "self.list" do - expect(@user.self.list).must_be_kind_of Array + expect(@user.self.list).must_be_kind_of Array + end end - end From e9f005c9657b39830641ae896146663171b6d1fd Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 19 Mar 2019 16:16:07 -0700 Subject: [PATCH 07/45] channel self.list somewhat working! returns not_authed --- lib/channel.rb | 32 ++++++++++++++++++-------------- lib/recipient.rb | 3 +++ lib/slack.rb | 9 +++++---- lib/user.rb | 3 ++- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index c938234a..2d61dff0 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,4 +1,7 @@ require "httparty" +require_relative "recipient" +require "dotenv" +Dotenv.load class Channel < Recipient BASE_URL = "https://slack.com/api/channels.list" @@ -6,7 +9,7 @@ class Channel < Recipient class SlackAPIError < StandardError; end - def initialize(slack_id, name, topic, member_count) + def initialize super @topic = topic @member_count = member_count @@ -15,23 +18,24 @@ def initialize(slack_id, name, topic, member_count) def details end - def get_channels(workspace) + def self.list query_params = { - workspace: workspace, token: TOKEN, - format: json, } - response = HTTParty.get(BASE_URL, query: query) - - if response.code != 200 || response == nil - raise SlackAPIError, "API call failed with code #{response.code} and reason '#{response["reason"]}" - end + response = HTTParty.get(BASE_URL, query: query_params) + # responses = response["response"] - channel = response["response"].map do |channel| - self.new(channel["id"], channel["name"], channel["topic"], channel["members"]) - end - end + # if response.code != 200 || response == nil + # raise SlackAPIError + # end - def self.list + # responses.each do |pass| + # puts "#{pass["topic"].to_s}" + # puts "#{pass["members"].to_a}" + # end end end + +puts Channel.list + +# , "API call failed with code #{response.code} and reason '#{response["reason"]}" diff --git a/lib/recipient.rb b/lib/recipient.rb index 0d292b24..9527dea3 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,3 +1,6 @@ +require "httparty" +require "dotenv" +Dotenv.load class Recipient BASE_URL = "https://slack.com/api/chat.postMessage" diff --git a/lib/slack.rb b/lib/slack.rb index c8434fd6..56fb5ee4 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -require 'httparty' +require "httparty" class Slack def initialize @@ -7,7 +7,7 @@ def initialize def main puts "Welcome to the Ada Slack CLI!" - + # puts "Slack CLI Menu\n" # puts "1. List Users\n" # puts "2. List Channels\n" @@ -40,7 +40,8 @@ def show_details def send_message end - puts "Thank you for using the Ada Slack CLI" + puts "Thank you for using the Ada Slack CLI" end - main if __FILE__ == $PROGRAM_NAME \ No newline at end of file + main if __FILE__ == $PROGRAM_NAME +end diff --git a/lib/user.rb b/lib/user.rb index f22e6209..9691783a 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,11 +1,12 @@ require "httparty" +require_relative "recipient" class User < Recipient BASE_URL = "https://slack.com/api/users.list" TOKEN = ENV["SLACK_TOKEN"] - def initialize(slack_id, name, real_name, status_text, status_emoji) + def initialize(slack_id, name) super @real_name = real_name @status_text = status_text From af7056c7ce25ebb6f6526621a8c54341bfa4441c Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Tue, 19 Mar 2019 16:31:50 -0700 Subject: [PATCH 08/45] auth issue overcome by moving .env from specs to lib --- lib/lib | 2 ++ specs/.DS_Store | Bin 0 -> 6148 bytes 2 files changed, 2 insertions(+) create mode 100644 lib/lib create mode 100644 specs/.DS_Store diff --git a/lib/lib b/lib/lib new file mode 100644 index 00000000..d4ab97ff --- /dev/null +++ b/lib/lib @@ -0,0 +1,2 @@ + +SLACK_TOKEN=xoxp-580897966018-580897966418-578499710768-76030bd068bc58190d258a72c4828317 \ No newline at end of file diff --git a/specs/.DS_Store b/specs/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Wed, 20 Mar 2019 09:12:55 -0700 Subject: [PATCH 09/45] use_casette tests missing parentheses, added --- lib/lib | 2 -- specs/user_spec.rb | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) delete mode 100644 lib/lib diff --git a/lib/lib b/lib/lib deleted file mode 100644 index d4ab97ff..00000000 --- a/lib/lib +++ /dev/null @@ -1,2 +0,0 @@ - -SLACK_TOKEN=xoxp-580897966018-580897966418-578499710768-76030bd068bc58190d258a72c4828317 \ No newline at end of file diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 83f47027..bcab8d0f 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -6,19 +6,19 @@ end it "is an instance of user" do - VCR.use_casette "initialize" do + VCR.use_casette("initialize") do expect(@user).must_be_kind_of User end end it "returns details about a user" do - VCR.use_casette "details" do + VCR.use_casette("details") do expect(@user.details).must_be_kind_of Array end end it "returns a list of users" do - VCR.use_casette "self.list" do + VCR.use_casette("self.list") do expect(@user.self.list).must_be_kind_of Array end end From 6569872b0140b11df0e170fae142deede4321abb Mon Sep 17 00:00:00 2001 From: Bitaman Date: Wed, 20 Mar 2019 13:39:47 -0700 Subject: [PATCH 10/45] get the list of users and wrote the VCR for that, it's passing --- .DS_Store | Bin 8196 -> 8196 bytes lib/channel.rb | 26 +++++----- lib/slack.rb | 81 +++++++++++++++--------------- lib/user.rb | 31 ++++++++++-- specs/cassettes/list_of_users.yml | 77 ++++++++++++++++++++++++++++ specs/test_helper.rb | 9 ++-- specs/user_spec.rb | 46 ++++++++++------- 7 files changed, 190 insertions(+), 80 deletions(-) create mode 100644 specs/cassettes/list_of_users.yml diff --git a/.DS_Store b/.DS_Store index 5614ccd539c33bcef527742a18374a9dae07e9e5..319b42d8180cb0f48d6c3e1a2f3d6375bfdbcd4a 100644 GIT binary patch delta 80 zcmZp1XmOa}&&aVcU^hP_$7UXZ4mNRChGK>ShE#@RhT^i|qP(2^ymSTz2F8trF^rqp LC3^8Fh-3r+X$2K3 delta 32 mcmZp1XmOa}&&a+pU^hP_`(_@24z`UY#f+QTC3=C30!9F + 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: + - '899' + Connection: + - keep-alive + Date: + - Wed, 20 Mar 2019 20:36:10 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 40a883c9-a8ea-4071-80a8-1d629e19b48f + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - users:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-nx2y + X-Cache: + - Miss from cloudfront + Via: + - 1.1 3e5a2f6c5b1171dae267d5a9344f95e8.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - 3cYtRde0aiCiTy7aH2DZrNWHJhslzthqkFrlXUQlENr8O6QzHY9jow== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH2SDUE0J","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":null,"tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Slackbot","real_name_normalized":"Slackbot","display_name":"Slackbot","display_name_normalized":"Slackbot","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"sv41d8cd98f0","always_active":true,"first_name":"slackbot","last_name":"","image_24":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH2SDUE0J"},"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":"UH2SDUECA","team_id":"TH2SDUE0J","name":"grace.m.shea","deleted":false,"color":"9f69e7","real_name":"grace.m.shea","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"grace.m.shea","real_name_normalized":"grace.m.shea","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g7af0be2aaaf","image_24":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-512.png","status_text_canonical":"","team":"TH2SDUE0J"},"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":1552952598},{"id":"UH4A0RV4N","team_id":"TH2SDUE0J","name":"b.amani.s","deleted":false,"color":"4bbe2e","real_name":"Bita + Amani Shahrak","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Bita + Amani Shahrak","real_name_normalized":"Bita Amani Shahrak","display_name":"Bita + Amani Shahrak","display_name_normalized":"Bita Amani Shahrak","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gb4955531fdb","image_24":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-512.png","status_text_canonical":"","team":"TH2SDUE0J"},"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":1552952825,"has_2fa":false}],"cache_ts":1553114170,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 20 Mar 2019 20:36:10 GMT +recorded_with: VCR 4.0.0 diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 7fe59dcc..24b337fa 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -8,11 +8,10 @@ require "minitest/skip_dsl" require "vcr" -require "channel" -require "user" -require "recipient" -require "slack" -require "httparty" +require_relative "../lib/channel" +require_relative "../lib/user" +require_relative "../lib/recipient" +require_relative "../lib/slack" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 4a509d35..377ece01 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -1,24 +1,36 @@ -require "test_helper" +require_relative "test_helper" + -describe "User" do - before do - @user = User.new(1010, "shrutifruity", "Shruti", "droppin' knowledge", ":books:" ) - end - it "is an instance of user" do - VCR.use_casette "initialize" do - expect(@user).must_be_kind_of User +describe "list" do + it "can get a list of users" do + VCR.use_cassette("list_of_users") do + response = User.list + expect(response).wont_be_nil + #expect(response["members"]["id"]).must_equal "USLACKBOT" end end +end - it "returns details about a user" do - VCR.use_casette "details" do - expect(@user.details).must_be_kind_of Array - end +# describe "User" do +# before do +# @user = User.new(1010, "shrutifruity", "Shruti", "droppin' knowledge", ":books:" ) +# end - it "returns a list of users" do - VCR.use_casette "self.list" do - expect(@user.self.list).must_be_kind_of Array - end +# it "is an instance of user" do +# VCR.use_casette "initialize" do +# expect(@user).must_be_kind_of User +# end +# end -end +# it "returns details about a user" do +# VCR.use_casette "details" do +# expect(@user.details).must_be_kind_of Array +# end + +# it "returns a list of users" do +# VCR.use_casette "self.list" do +# expect(@user.self.list).must_be_kind_of Array +# end + +# end From 604fd81f902eb73ef2ccf2250cde1ecdaf07e425 Mon Sep 17 00:00:00 2001 From: Bitaman Date: Wed, 20 Mar 2019 13:44:57 -0700 Subject: [PATCH 11/45] made changes to user --- specs/user_spec.rb | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 377ece01..e6cfdeff 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -12,25 +12,4 @@ end end -# describe "User" do -# before do -# @user = User.new(1010, "shrutifruity", "Shruti", "droppin' knowledge", ":books:" ) -# end -# it "is an instance of user" do -# VCR.use_casette "initialize" do -# expect(@user).must_be_kind_of User -# end -# end - -# it "returns details about a user" do -# VCR.use_casette "details" do -# expect(@user.details).must_be_kind_of Array -# end - -# it "returns a list of users" do -# VCR.use_casette "self.list" do -# expect(@user.self.list).must_be_kind_of Array -# end - -# end From b8d80513cd1953447b2bf82a8decca05185e6065 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Wed, 20 Mar 2019 13:58:39 -0700 Subject: [PATCH 12/45] channel list functioning --- lib/channel.rb | 26 ++++++-------------------- lib/slack.rb | 45 +-------------------------------------------- lib/user.rb | 14 +++----------- specs/user_spec.rb | 30 ------------------------------ 4 files changed, 10 insertions(+), 105 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 909aea6d..685f5aa8 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -3,17 +3,10 @@ require "dotenv" Dotenv.load -# class Channel < Recipient -# BASE_URL = "https://slack.com/api/channels.list" -# TOKEN = ENV["SLACK_TOKEN"] - -<<<<<<< HEAD -# def initialize(slack_id, name, topic, member_count) -# super -# @topic = topic -# @member_count = member_count -# end -======= +class Channel < Recipient + BASE_URL = "https://slack.com/api/channels.list" + TOKEN = ENV["SLACK_TOKEN"] + class SlackAPIError < StandardError; end def initialize @@ -21,16 +14,10 @@ def initialize @topic = topic @member_count = member_count end ->>>>>>> refs/remotes/origin/master -# def details -# end + # def details + # end -<<<<<<< HEAD -# def self.list -# end -# end -======= def self.list query_params = { token: TOKEN, @@ -52,4 +39,3 @@ def self.list puts Channel.list # , "API call failed with code #{response.code} and reason '#{response["reason"]}" ->>>>>>> refs/remotes/origin/master diff --git a/lib/slack.rb b/lib/slack.rb index 760f2127..05c488d1 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -5,10 +5,9 @@ # def initialize # end -<<<<<<< HEAD # def main # puts "Welcome to the Ada Slack CLI!" - + # puts "Slack CLI Menu\n" # puts "1. List Users\n" # puts "2. List Channels\n" @@ -45,45 +44,3 @@ # end # main if __FILE__ == $PROGRAM_NAME -======= - def main - puts "Welcome to the Ada Slack CLI!" - - # puts "Slack CLI Menu\n" - # puts "1. List Users\n" - # puts "2. List Channels\n" - # puts "3. Quit\n" - - # loop do - # "Please enter your selection from the above options." - # input = gets.chomp.to_s - # case - # when input == "1" - # puts users.list - # when input == "2" - # puts channels.list - # when input == "3" - # exit - # when input =~ /[[:alpha:]]/ - # puts "\nYour request was invalid." - # end - # end - - def select_channel - end - - def select_user - end - - def show_details - end - - def send_message - end - - puts "Thank you for using the Ada Slack CLI" - end - - main if __FILE__ == $PROGRAM_NAME -end ->>>>>>> refs/remotes/origin/master diff --git a/lib/user.rb b/lib/user.rb index bf95a596..f4d54916 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,23 +1,15 @@ require "httparty" -<<<<<<< HEAD require "pry" require_relative "recipient" require "dotenv" Dotenv.load -======= -require_relative "recipient" ->>>>>>> refs/remotes/origin/master class User < Recipient BASE_URL = "https://slack.com/api/users.list" TOKEN = ENV["SLACK_TOKEN"] -<<<<<<< HEAD def initialize -======= - def initialize(slack_id, name) ->>>>>>> refs/remotes/origin/master super @real_name = real_name @status_text = status_text @@ -34,16 +26,16 @@ def self.list unless response.code == 200 raise SearchError, "Cannot find #{search_term}" - end + end # response.each do |response| # puts "id: #{response.first["members"][0]}" # end return response - end + end end #puts User.list #binding.pry #puts User.list # puts User.list["members"][0]["id"] -# puts User.list["members"][0]["real_name"] \ No newline at end of file +# puts User.list["members"][0]["real_name"] diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 262425f4..b11e3a5d 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -1,41 +1,11 @@ require_relative "test_helper" -<<<<<<< HEAD - - describe "list" do it "can get a list of users" do VCR.use_cassette("list_of_users") do response = User.list expect(response).wont_be_nil #expect(response["members"]["id"]).must_equal "USLACKBOT" -======= -describe "User" do - before do - @user = User.new(1010, "shrutifruity", "Shruti", "droppin' knowledge", ":books:") - end - - it "is an instance of user" do - VCR.use_casette("initialize") do - expect(@user).must_be_kind_of User - end - end - - it "returns details about a user" do - VCR.use_casette("details") do - expect(@user.details).must_be_kind_of Array ->>>>>>> refs/remotes/origin/master - end - end -end - -<<<<<<< HEAD - -======= - it "returns a list of users" do - VCR.use_casette("self.list") do - expect(@user.self.list).must_be_kind_of Array end end end ->>>>>>> refs/remotes/origin/master From 9258eb5aa74a265ceef298a569fc87fa4b81a119 Mon Sep 17 00:00:00 2001 From: Bitaman Date: Wed, 20 Mar 2019 14:00:52 -0700 Subject: [PATCH 13/45] merging --- lib/channel.rb | 22 ++++------------------ lib/slack.rb | 43 ------------------------------------------- lib/user.rb | 12 ++---------- 3 files changed, 6 insertions(+), 71 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 909aea6d..09d95466 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -3,17 +3,10 @@ require "dotenv" Dotenv.load -# class Channel < Recipient -# BASE_URL = "https://slack.com/api/channels.list" -# TOKEN = ENV["SLACK_TOKEN"] - -<<<<<<< HEAD -# def initialize(slack_id, name, topic, member_count) -# super -# @topic = topic -# @member_count = member_count -# end -======= +class Channel < Recipient + BASE_URL = "https://slack.com/api/channels.list" + TOKEN = ENV["SLACK_TOKEN"] + class SlackAPIError < StandardError; end def initialize @@ -21,16 +14,10 @@ def initialize @topic = topic @member_count = member_count end ->>>>>>> refs/remotes/origin/master # def details # end -<<<<<<< HEAD -# def self.list -# end -# end -======= def self.list query_params = { token: TOKEN, @@ -52,4 +39,3 @@ def self.list puts Channel.list # , "API call failed with code #{response.code} and reason '#{response["reason"]}" ->>>>>>> refs/remotes/origin/master diff --git a/lib/slack.rb b/lib/slack.rb index 760f2127..b91cdebf 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -5,7 +5,6 @@ # def initialize # end -<<<<<<< HEAD # def main # puts "Welcome to the Ada Slack CLI!" @@ -45,45 +44,3 @@ # end # main if __FILE__ == $PROGRAM_NAME -======= - def main - puts "Welcome to the Ada Slack CLI!" - - # puts "Slack CLI Menu\n" - # puts "1. List Users\n" - # puts "2. List Channels\n" - # puts "3. Quit\n" - - # loop do - # "Please enter your selection from the above options." - # input = gets.chomp.to_s - # case - # when input == "1" - # puts users.list - # when input == "2" - # puts channels.list - # when input == "3" - # exit - # when input =~ /[[:alpha:]]/ - # puts "\nYour request was invalid." - # end - # end - - def select_channel - end - - def select_user - end - - def show_details - end - - def send_message - end - - puts "Thank you for using the Ada Slack CLI" - end - - main if __FILE__ == $PROGRAM_NAME -end ->>>>>>> refs/remotes/origin/master diff --git a/lib/user.rb b/lib/user.rb index bf95a596..8ca922f4 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,23 +1,15 @@ require "httparty" -<<<<<<< HEAD require "pry" require_relative "recipient" require "dotenv" Dotenv.load -======= -require_relative "recipient" ->>>>>>> refs/remotes/origin/master class User < Recipient BASE_URL = "https://slack.com/api/users.list" TOKEN = ENV["SLACK_TOKEN"] -<<<<<<< HEAD def initialize -======= - def initialize(slack_id, name) ->>>>>>> refs/remotes/origin/master super @real_name = real_name @status_text = status_text @@ -34,12 +26,12 @@ def self.list unless response.code == 200 raise SearchError, "Cannot find #{search_term}" - end + end # response.each do |response| # puts "id: #{response.first["members"][0]}" # end return response - end + end end #puts User.list From 2742dd975ebffa80e3da409a9614bf922f4928f4 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Wed, 20 Mar 2019 14:27:04 -0700 Subject: [PATCH 14/45] channel tests added, debugging --- lib/channel.rb | 6 +-- lib/recipient.rb | 2 +- lib/user.rb | 2 +- specs/cassettes/get_response.yml | 78 ++++++++++++++++++++++++++++++++ specs/channel_spec.rb | 41 +++++++++++++++++ 5 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 specs/cassettes/get_response.yml diff --git a/lib/channel.rb b/lib/channel.rb index 685f5aa8..3972e626 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -15,8 +15,8 @@ def initialize @member_count = member_count end - # def details - # end + def details + end def self.list query_params = { @@ -36,6 +36,6 @@ def self.list end end -puts Channel.list +# puts Channel.list # , "API call failed with code #{response.code} and reason '#{response["reason"]}" diff --git a/lib/recipient.rb b/lib/recipient.rb index 9527dea3..6546cda3 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -14,7 +14,7 @@ def initialize(slack_id, name) def send_message(message) end - def self.get(url, params) + def self.get end # def details - request details "package" from user or channel diff --git a/lib/user.rb b/lib/user.rb index f4d54916..302531b6 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -34,7 +34,7 @@ def self.list end end -#puts User.list +# puts User.list #binding.pry #puts User.list # puts User.list["members"][0]["id"] diff --git a/specs/cassettes/get_response.yml b/specs/cassettes/get_response.yml new file mode 100644 index 00000000..6ef6f423 --- /dev/null +++ b/specs/cassettes/get_response.yml @@ -0,0 +1,78 @@ +--- +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: + - '563' + Connection: + - keep-alive + Date: + - Wed, 20 Mar 2019 21:20:18 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - e5bef177-648f-4594-a4de-9971e8569520 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - channels:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-haq2 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 64a11a52a1b20918fec274138dd1ba05.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - bII6Pc7kTQ_W_MhEpFBExxS41BxFqUsktuPZNtPYX5MMoLXAvBVS0Q== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CH0EFGWQ0","name":"everyone","is_channel":true,"created":1552952597,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UH2SDUECA","name_normalized":"everyone","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2SDUECA","UH4A0RV4N"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UH2SDUECA","last_set":1552952597},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UH2SDUECA","last_set":1552952597},"previous_names":[],"num_members":2},{"id":"CH0EFH3CG","name":"slack-api-project","is_channel":true,"created":1552952598,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2SDUECA","name_normalized":"slack-api-project","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2SDUECA","UH4A0RV4N"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2},{"id":"CH36U0J9K","name":"random","is_channel":true,"created":1552952597,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2SDUECA","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2SDUECA","UH4A0RV4N"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UH2SDUECA","last_set":1552952597},"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":"UH2SDUECA","last_set":1552952597},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 20 Mar 2019 21:20:18 GMT +recorded_with: VCR 4.0.0 diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index b5cae113..3619909e 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -1 +1,42 @@ require_relative "test_helper" + +describe "self get method" do + it "successfully returns list of members of that channel" do + VCR.use_cassette("get_response") do + channels = Channel.get + + expect(channels["ok"]).must_equal true + end + end + + # it "raises SlackError for for bad request" do + # # VCR.use_cassette("get_response") do + # # end + # end +end + +describe "list" do + it "creates a list of all channels" do + VCR.use_cassette("get_response") do + channels = Channel.list + + expect(channels).must_be_kind_of Array + expect(channels.first).must_be_instance_of Channel + expect(channels.last).must_be_instance_of Channel + end + end +end + +describe "details" do + it "lists details for an instance of channel" do + VCR.use_cassette("get_response") do + channels = Channel.list + channel_details = channels[1].details + + expect(channel_details).must_equal channels[1].details + end + end + + # it "returns nil for a channel that doesn't exist" do + # end +end From 390fedb774bf23909b369453244a71f41e7197c7 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Wed, 20 Mar 2019 14:57:14 -0700 Subject: [PATCH 15/45] refining channel_list output, created workspace files --- lib/channel.rb | 37 +++++++++++++++++++------------------ lib/recipient.rb | 10 +++++----- lib/slack.rb | 2 +- lib/user.rb | 2 ++ lib/workspace.rb | 10 ++++++++++ specs/workspace_spec.rb | 1 + 6 files changed, 38 insertions(+), 24 deletions(-) create mode 100644 lib/workspace.rb create mode 100644 specs/workspace_spec.rb diff --git a/lib/channel.rb b/lib/channel.rb index 3972e626..f432f1c7 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -9,7 +9,7 @@ class Channel < Recipient class SlackAPIError < StandardError; end - def initialize + def initialize(slack_id, name, topic, member_count) super @topic = topic @member_count = member_count @@ -19,23 +19,24 @@ def details end def self.list - query_params = { - token: TOKEN, - } - response = HTTParty.get(BASE_URL, query: query_params) - # responses = response["response"] - - # if response.code != 200 || response == nil - # raise SlackAPIError - # end - - # responses.each do |pass| - # puts "#{pass["topic"].to_s}" - # puts "#{pass["members"].to_a}" - # end + raw_data = self.get("channel") + + unless raw_data.code == 200 + raise SlackApiError, "Improper request: #{raw_data.message}" + end + channel_list = [] + channels = raw_data["channels"] + channels.each do |channel| + slack_id = channel["id"] + name = channel["name"] + topic = channel["topic"]["value"] + member_count = channel["members"].count + + new_channel = Channel.new(slack_id, name, topic, member_count) + channel_list << new_channel + end + return channel_list end end -# puts Channel.list - -# , "API call failed with code #{response.code} and reason '#{response["reason"]}" +puts Channel.list diff --git a/lib/recipient.rb b/lib/recipient.rb index 6546cda3..3b9e32e6 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -6,16 +6,16 @@ class Recipient BASE_URL = "https://slack.com/api/chat.postMessage" TOKEN = ENV["SLACK_TOKEN"] - def initialize(slack_id, name) + def initialize @slack_id = slack_id @name = name end - def send_message(message) - end + # def send_message(message) + # end - def self.get - end + # def self.get + # end # def details - request details "package" from user or channel # def list - request list "package" from user or channel diff --git a/lib/slack.rb b/lib/slack.rb index 05c488d1..b8e3308f 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -28,7 +28,7 @@ # end # end -# def select_channel +# def select_channel. # end # def select_user diff --git a/lib/user.rb b/lib/user.rb index 302531b6..e8f02574 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -16,6 +16,7 @@ def initialize @status_emoji = status_emoji end + # This list should include the channel's name, topic, member count, and Slack ID. def self.list puts TOKEN query_params = { @@ -27,6 +28,7 @@ def self.list unless response.code == 200 raise SearchError, "Cannot find #{search_term}" end + # response.each do |response| # puts "id: #{response.first["members"][0]}" # end diff --git a/lib/workspace.rb b/lib/workspace.rb new file mode 100644 index 00000000..c1eaddf7 --- /dev/null +++ b/lib/workspace.rb @@ -0,0 +1,10 @@ +require "httparty" +require_relative "recipient" +require "dotenv" +Dotenv.load + +class Workspace + + # holds users and channels + +end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb new file mode 100644 index 00000000..b5cae113 --- /dev/null +++ b/specs/workspace_spec.rb @@ -0,0 +1 @@ +require_relative "test_helper" From 093b250819a6ba5f9738f48104484121de01f7a9 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Wed, 20 Mar 2019 15:20:12 -0700 Subject: [PATCH 16/45] workspace tests evolving --- lib/channel.rb | 13 +++-------- lib/slack.rb | 16 +++---------- lib/workspace.rb | 48 ++++++++++++++++++++++++++++++++++----- specs/channel_spec.rb | 47 +++++++++----------------------------- specs/workspace_spec.rb | 50 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 109 insertions(+), 65 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index f432f1c7..b0f16be2 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,21 +1,16 @@ -require "httparty" require_relative "recipient" -require "dotenv" -Dotenv.load class Channel < Recipient - BASE_URL = "https://slack.com/api/channels.list" - TOKEN = ENV["SLACK_TOKEN"] - - class SlackAPIError < StandardError; end + attr_reader :topic, :member_count def initialize(slack_id, name, topic, member_count) - super + super(slack_id, name) @topic = topic @member_count = member_count end def details + return "#{name} #{topic} member count: #{member_count} slack id: #{slack_id}" end def self.list @@ -38,5 +33,3 @@ def self.list return channel_list end end - -puts Channel.list diff --git a/lib/slack.rb b/lib/slack.rb index b8e3308f..13d93ac9 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,5 +1,7 @@ #!/usr/bin/env ruby -require "httparty" +# require "httparty" + +# PURPOSE OF THIS FILE IS TO HOLD CLI PROMPTS # class Slack # def initialize @@ -28,18 +30,6 @@ # end # end -# def select_channel. -# end - -# def select_user -# end - -# def show_details -# end - -# def send_message -# end - # puts "Thank you for using the Ada Slack CLI" # end diff --git a/lib/workspace.rb b/lib/workspace.rb index c1eaddf7..3494792b 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,10 +1,48 @@ -require "httparty" -require_relative "recipient" -require "dotenv" -Dotenv.load +require_relative "user" +require_relative "channel" class Workspace + attr_reader :users, :channels, :selected - # holds users and channels + def initialize + @users = User.list + @channels = Channel.list + @selected = nil + end + def select_channel(user_input) + selected = channels.select do |channel| + channel.name == user_input || channel.slack_id == user_input + end + @selected = selected.first + end + + def select_user(user_input) + selected = users.select do |user| + user.name == user_input || user.slack_id == user_input + end + @selected = selected.first + end + + def show_details + return @selected.details + end + + def print_details(recipients) + if recipients == "users" + return_array = [] + users.each do |user| + return_array << user.details + end + elsif recipients == "channels" + return_array = [] + channels.each do |channel| + return_array << channel.details + end + end + return return_array + end + + def send_message + end end diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 3619909e..b5c9c1b0 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -1,42 +1,15 @@ require_relative "test_helper" -describe "self get method" do - it "successfully returns list of members of that channel" do - VCR.use_cassette("get_response") do - channels = Channel.get - - expect(channels["ok"]).must_equal true - end - end - - # it "raises SlackError for for bad request" do - # # VCR.use_cassette("get_response") do - # # end - # end -end - -describe "list" do - it "creates a list of all channels" do - VCR.use_cassette("get_response") do - channels = Channel.list - - expect(channels).must_be_kind_of Array - expect(channels.first).must_be_instance_of Channel - expect(channels.last).must_be_instance_of Channel +describe "Channel class" do + describe "self.list" do + it "can return all channels" do + VCR.use_cassette("slack_channel") do + response = Channel.get("channel") + + expect(response["channels"]).wont_be_nil + expect(response["channels"].first["name"]).must_equal "random" + expect(response["channels"].first["members"].count).must_equal 2 + end end end end - -describe "details" do - it "lists details for an instance of channel" do - VCR.use_cassette("get_response") do - channels = Channel.list - channel_details = channels[1].details - - expect(channel_details).must_equal channels[1].details - end - end - - # it "returns nil for a channel that doesn't exist" do - # end -end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index b5cae113..5fce82e2 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -1 +1,51 @@ require_relative "test_helper" + +describe "Workspace class" do + before do + workspace = Workspace.new + end + + it "creates a list of channels and users" do + VCR.use_cassette("slack_workspace") do + expect(workspace.channels.first).must_be_kind_of Channel + expect(workspace.users.first).must_be_kind_of User + end + end + + it "returns text from print_details" do + VCR.use_cassette("slack_workspace") do + expect(workspace.print_details("users")).must_be_kind_of String + expect(workspace.print_details("channels")).must_be_kind_of String + end + + it "returns a user object from select_user" do + expect(workspace.select_user("slackbot")).must_be_kind_of User + expect(workspace.select_user("USLACKBOT")).must_be_kind_of User + end + end + + it "returns a channel object from select_channel" do + VCR.use_cassette("slack_workspace") do + expect(workspace.select_channel("random")).must_be_kind_of Channel + expect(workspace.select_channel("CH2RY8RQT")).must_be_kind_of Channel + end + end + + it "returns channel details from show_details" do + VCR.use_cassette("slack_workspace") do + workspace.select_channel("random") + expect(workspace.show_details).must_be_kind_of String + workspace.select_channel("CH2RY8RQT") + expect(workspace.show_details).must_be_kind_of String + end + end + + it "returns user details from show_details" do + VCR.use_cassette("slack_workspace") do + workspace.select_user("slackbot") + expect(workspace.show_details).must_be_kind_of String + workspace.select_user("USLACKBOT") + expect(workspace.show_details).must_be_kind_of String + end + end +end From fe50b30d254e6b78deae41906478887852e038a3 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Wed, 20 Mar 2019 15:45:06 -0700 Subject: [PATCH 17/45] resolved HTTPS error --- lib/recipient.rb | 41 ++++++-- specs/cassettes/slack_channel.yml | 78 ++++++++++++++ specs/cassettes/slack_workspace.yml | 152 ++++++++++++++++++++++++++++ specs/test_helper.rb | 1 + specs/workspace_spec.rb | 36 +++---- 5 files changed, 281 insertions(+), 27 deletions(-) create mode 100644 specs/cassettes/slack_channel.yml create mode 100644 specs/cassettes/slack_workspace.yml diff --git a/lib/recipient.rb b/lib/recipient.rb index 3b9e32e6..98deb82c 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,23 +1,44 @@ -require "httparty" require "dotenv" +require "httparty" Dotenv.load class Recipient - BASE_URL = "https://slack.com/api/chat.postMessage" - TOKEN = ENV["SLACK_TOKEN"] + class SlackApiError < StandardError; end + + attr_reader :slack_id, :name - def initialize + def initialize(slack_id, name) @slack_id = slack_id @name = name end - # def send_message(message) - # end + CHANNEL_URL = "https://slack.com/api/channels.list" + USER_URL = "https://slack.com/api/users.list" + + def self.get(type) + params = { + "token" => ENV["SLACK_TOKEN"], + } + if type == "user" + url = USER_URL + elsif type == "channel" + url = CHANNEL_URL + end + + response = HTTParty.get(url, query: params) + end + + def send_message(message) + response = HTTParty.post(url, message?) + end - # def self.get - # end + private - # def details - request details "package" from user or channel - # def list - request list "package" from user or channel + def details + raise NotImplementedError + end + def self.list + raise NotImplementedError + end end diff --git a/specs/cassettes/slack_channel.yml b/specs/cassettes/slack_channel.yml new file mode 100644 index 00000000..54784908 --- /dev/null +++ b/specs/cassettes/slack_channel.yml @@ -0,0 +1,78 @@ +--- +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: + - '563' + Connection: + - keep-alive + Date: + - Wed, 20 Mar 2019 22:31:30 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 05d255a4-8129-4677-843a-9f39a77e4730 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - channels:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-5zng + X-Cache: + - Miss from cloudfront + Via: + - 1.1 1850877f8309c8b6f987c10f734a7aef.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - likJm2U5S3-rw8y6f5dkbfxQgVAJslhH9LSDqVn6C7pBey23i26QFA== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CH0EFGWQ0","name":"everyone","is_channel":true,"created":1552952597,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UH2SDUECA","name_normalized":"everyone","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2SDUECA","UH4A0RV4N"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UH2SDUECA","last_set":1552952597},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UH2SDUECA","last_set":1552952597},"previous_names":[],"num_members":2},{"id":"CH0EFH3CG","name":"slack-api-project","is_channel":true,"created":1552952598,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2SDUECA","name_normalized":"slack-api-project","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2SDUECA","UH4A0RV4N"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2},{"id":"CH36U0J9K","name":"random","is_channel":true,"created":1552952597,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2SDUECA","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2SDUECA","UH4A0RV4N"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UH2SDUECA","last_set":1552952597},"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":"UH2SDUECA","last_set":1552952597},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 20 Mar 2019 22:31:30 GMT +recorded_with: VCR 4.0.0 diff --git a/specs/cassettes/slack_workspace.yml b/specs/cassettes/slack_workspace.yml new file mode 100644 index 00000000..5d088154 --- /dev/null +++ b/specs/cassettes/slack_workspace.yml @@ -0,0 +1,152 @@ +--- +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: + - '899' + Connection: + - keep-alive + Date: + - Wed, 20 Mar 2019 22:43:45 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - f158738e-5d42-4c38-bba9-1e4e319801b1 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - users:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-tiix + X-Cache: + - Miss from cloudfront + Via: + - 1.1 cb7132faa45d3b1ff4d65185f2d36d27.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - 10W-fWCS6gT3UHP0M2DMnI9jFji7-UOwX0Lul_ThT-jcJ2EL7-jmTA== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH2SDUE0J","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":null,"tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Slackbot","real_name_normalized":"Slackbot","display_name":"Slackbot","display_name_normalized":"Slackbot","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"sv41d8cd98f0","always_active":true,"first_name":"slackbot","last_name":"","image_24":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH2SDUE0J"},"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":"UH2SDUECA","team_id":"TH2SDUE0J","name":"grace.m.shea","deleted":false,"color":"9f69e7","real_name":"grace.m.shea","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"grace.m.shea","real_name_normalized":"grace.m.shea","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g7af0be2aaaf","image_24":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-512.png","status_text_canonical":"","team":"TH2SDUE0J"},"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":1552952598,"has_2fa":false},{"id":"UH4A0RV4N","team_id":"TH2SDUE0J","name":"b.amani.s","deleted":false,"color":"4bbe2e","real_name":"Bita + Amani Shahrak","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Bita + Amani Shahrak","real_name_normalized":"Bita Amani Shahrak","display_name":"Bita + Amani Shahrak","display_name_normalized":"Bita Amani Shahrak","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gb4955531fdb","image_24":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-512.png","status_text_canonical":"","team":"TH2SDUE0J"},"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":1552952825,"has_2fa":false}],"cache_ts":1553121825,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 20 Mar 2019 22:43:45 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: + - '563' + Connection: + - keep-alive + Date: + - Wed, 20 Mar 2019 22:43:45 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 91a852ad-065b-4624-94d6-0eaf05fc5edb + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - channels:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-5tv9 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 e9485f60105658dfd8d6d4dbc070260a.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - FPjrGd6TqlqaSrXphtR0H5lKh6u-Uyq9fs20_O_F5QwfgiglwUc7WQ== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CH0EFGWQ0","name":"everyone","is_channel":true,"created":1552952597,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UH2SDUECA","name_normalized":"everyone","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2SDUECA","UH4A0RV4N"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UH2SDUECA","last_set":1552952597},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UH2SDUECA","last_set":1552952597},"previous_names":[],"num_members":2},{"id":"CH0EFH3CG","name":"slack-api-project","is_channel":true,"created":1552952598,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2SDUECA","name_normalized":"slack-api-project","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2SDUECA","UH4A0RV4N"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2},{"id":"CH36U0J9K","name":"random","is_channel":true,"created":1552952597,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2SDUECA","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2SDUECA","UH4A0RV4N"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UH2SDUECA","last_set":1552952597},"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":"UH2SDUECA","last_set":1552952597},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 20 Mar 2019 22:43:45 GMT +recorded_with: VCR 4.0.0 diff --git a/specs/test_helper.rb b/specs/test_helper.rb index 24b337fa..6fe8e46c 100644 --- a/specs/test_helper.rb +++ b/specs/test_helper.rb @@ -12,6 +12,7 @@ require_relative "../lib/user" require_relative "../lib/recipient" require_relative "../lib/slack" +require_relative "../lib/workspace" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 5fce82e2..fe3b56f8 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -2,50 +2,52 @@ describe "Workspace class" do before do - workspace = Workspace.new + VCR.use_cassette("slack_workspace") do + @workspace = Workspace.new + end end it "creates a list of channels and users" do VCR.use_cassette("slack_workspace") do - expect(workspace.channels.first).must_be_kind_of Channel - expect(workspace.users.first).must_be_kind_of User + expect(@workspace.channels.first).must_be_kind_of Channel + expect(@workspace.users.first).must_be_kind_of User end end it "returns text from print_details" do VCR.use_cassette("slack_workspace") do - expect(workspace.print_details("users")).must_be_kind_of String - expect(workspace.print_details("channels")).must_be_kind_of String + expect(@workspace.print_details("users")).must_be_kind_of String + expect(@workspace.print_details("channels")).must_be_kind_of String end it "returns a user object from select_user" do - expect(workspace.select_user("slackbot")).must_be_kind_of User - expect(workspace.select_user("USLACKBOT")).must_be_kind_of User + expect(@workspace.select_user("slackbot")).must_be_kind_of User + expect(@workspace.select_user("USLACKBOT")).must_be_kind_of User end end it "returns a channel object from select_channel" do VCR.use_cassette("slack_workspace") do - expect(workspace.select_channel("random")).must_be_kind_of Channel - expect(workspace.select_channel("CH2RY8RQT")).must_be_kind_of Channel + expect(@workspace.select_channel("random")).must_be_kind_of Channel + expect(@workspace.select_channel("CH2RY8RQT")).must_be_kind_of Channel end end it "returns channel details from show_details" do VCR.use_cassette("slack_workspace") do - workspace.select_channel("random") - expect(workspace.show_details).must_be_kind_of String - workspace.select_channel("CH2RY8RQT") - expect(workspace.show_details).must_be_kind_of String + @workspace.select_channel("random") + expect(@workspace.show_details).must_be_kind_of String + @workspace.select_channel("CH2RY8RQT") + expect(@workspace.show_details).must_be_kind_of String end end it "returns user details from show_details" do VCR.use_cassette("slack_workspace") do - workspace.select_user("slackbot") - expect(workspace.show_details).must_be_kind_of String - workspace.select_user("USLACKBOT") - expect(workspace.show_details).must_be_kind_of String + @workspace.select_user("slackbot") + expect(@workspace.show_details).must_be_kind_of String + @workspace.select_user("USLACKBOT") + expect(@workspace.show_details).must_be_kind_of String end end end From 8f059c8f71fe014a17318c0ca080ae80445fd273 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Wed, 20 Mar 2019 18:32:25 -0700 Subject: [PATCH 18/45] list methods tests/methods refined. passing those tests. --- lib/channel.rb | 1 + specs/channel_spec.rb | 12 ++++++++---- specs/workspace_spec.rb | 34 +++++++++++++++++++--------------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index b0f16be2..0a009242 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -21,6 +21,7 @@ def self.list end channel_list = [] channels = raw_data["channels"] + channels.each do |channel| slack_id = channel["id"] name = channel["name"] diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index b5c9c1b0..1e15a59b 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -4,12 +4,16 @@ describe "self.list" do it "can return all channels" do VCR.use_cassette("slack_channel") do - response = Channel.get("channel") + response = Channel.list - expect(response["channels"]).wont_be_nil - expect(response["channels"].first["name"]).must_equal "random" - expect(response["channels"].first["members"].count).must_equal 2 + channel = response.first + + expect(response).wont_be_nil + expect(response.first.name).must_equal channel.name end end end end + +# members = response[0].members.count +# expect(response.first.member_count).must_equal members diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index fe3b56f8..c246b0ff 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -10,22 +10,24 @@ it "creates a list of channels and users" do VCR.use_cassette("slack_workspace") do expect(@workspace.channels.first).must_be_kind_of Channel - expect(@workspace.users.first).must_be_kind_of User + + # expect(@workspace.users.first).must_be_kind_of User end end it "returns text from print_details" do VCR.use_cassette("slack_workspace") do - expect(@workspace.print_details("users")).must_be_kind_of String + # expect(@workspace.print_details("users")).must_be_kind_of String expect(@workspace.print_details("channels")).must_be_kind_of String end - - it "returns a user object from select_user" do - expect(@workspace.select_user("slackbot")).must_be_kind_of User - expect(@workspace.select_user("USLACKBOT")).must_be_kind_of User - end end + # it "returns a user object from select_user" do + # expect(@workspace.select_user("slackbot")).must_be_kind_of User + # expect(@workspace.select_user("USLACKBOT")).must_be_kind_of User + # end + # end + it "returns a channel object from select_channel" do VCR.use_cassette("slack_workspace") do expect(@workspace.select_channel("random")).must_be_kind_of Channel @@ -37,17 +39,19 @@ VCR.use_cassette("slack_workspace") do @workspace.select_channel("random") expect(@workspace.show_details).must_be_kind_of String + @workspace.select_channel("CH2RY8RQT") expect(@workspace.show_details).must_be_kind_of String end end - it "returns user details from show_details" do - VCR.use_cassette("slack_workspace") do - @workspace.select_user("slackbot") - expect(@workspace.show_details).must_be_kind_of String - @workspace.select_user("USLACKBOT") - expect(@workspace.show_details).must_be_kind_of String - end - end + # it "returns user details from show_details" do + # VCR.use_cassette("slack_workspace") do + # @workspace.select_user("slackbot") + # expect(@workspace.show_details).must_be_kind_of String + + # @workspace.select_user("USLACKBOT") + # expect(@workspace.show_details).must_be_kind_of String + # end + # end end From 1a3732ada7818a16e0d8b5805ab25293255216d7 Mon Sep 17 00:00:00 2001 From: Bitaman Date: Thu, 21 Mar 2019 12:41:33 -0700 Subject: [PATCH 19/45] added the detail method to user --- lib/channel.rb | 68 +++++++++++++-------------- lib/recipient.rb | 15 +++--- lib/user.rb | 40 ++++++++++------ specs/cassettes/list_of_users.yml | 16 +++---- specs/cassettes/list_users.yml | 77 +++++++++++++++++++++++++++++++ specs/user_spec.rb | 14 +++++- 6 files changed, 163 insertions(+), 67 deletions(-) create mode 100644 specs/cassettes/list_users.yml diff --git a/lib/channel.rb b/lib/channel.rb index 685f5aa8..2b99d44e 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -3,39 +3,39 @@ require "dotenv" Dotenv.load -class Channel < Recipient - BASE_URL = "https://slack.com/api/channels.list" - TOKEN = ENV["SLACK_TOKEN"] - - class SlackAPIError < StandardError; end - - def initialize - super - @topic = topic - @member_count = member_count - end - - # def details - # end - - def self.list - query_params = { - token: TOKEN, - } - response = HTTParty.get(BASE_URL, query: query_params) - # responses = response["response"] - - # if response.code != 200 || response == nil - # raise SlackAPIError - # end - - # responses.each do |pass| - # puts "#{pass["topic"].to_s}" - # puts "#{pass["members"].to_a}" - # end - end -end - -puts Channel.list +# class Channel < Recipient +# BASE_URL = "https://slack.com/api/channels.list" +# TOKEN = ENV["SLACK_TOKEN"] + +# class SlackAPIError < StandardError; end + +# def initialize +# super +# @topic = topic +# @member_count = member_count +# end + +# # def details +# # end + +# def self.list +# query_params = { +# token: TOKEN, +# } +# response = HTTParty.get(BASE_URL, query: query_params) +# # responses = response["response"] + +# # if response.code != 200 || response == nil +# # raise SlackAPIError +# # end + +# # responses.each do |pass| +# # puts "#{pass["topic"].to_s}" +# # puts "#{pass["members"].to_a}" +# # end +# end +# end + +# puts Channel.list # , "API call failed with code #{response.code} and reason '#{response["reason"]}" diff --git a/lib/recipient.rb b/lib/recipient.rb index 9527dea3..38403416 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -3,21 +3,18 @@ Dotenv.load class Recipient - BASE_URL = "https://slack.com/api/chat.postMessage" TOKEN = ENV["SLACK_TOKEN"] - def initialize(slack_id, name) - @slack_id = slack_id + def initialize(id, name) + + @id = id @name = name end - def send_message(message) - end +# def self.list +# raise NotImplemented Error +# end - def self.get(url, params) - end - # def details - request details "package" from user or channel - # def list - request list "package" from user or channel end diff --git a/lib/user.rb b/lib/user.rb index f4d54916..c1d8f492 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -9,15 +9,15 @@ class User < Recipient BASE_URL = "https://slack.com/api/users.list" TOKEN = ENV["SLACK_TOKEN"] - def initialize - super + def initialize(id, name, real_name) + super(id, name) @real_name = real_name - @status_text = status_text - @status_emoji = status_emoji + @id = id + @name = name + end def self.list - puts TOKEN query_params = { token: TOKEN, } @@ -27,15 +27,27 @@ def self.list unless response.code == 200 raise SearchError, "Cannot find #{search_term}" end - # response.each do |response| - # puts "id: #{response.first["members"][0]}" - # end - return response + members_list = [] + members = response["members"] + members.each do |member| + id = member["id"] + name = member["name"] + real_name = member["real_name"] + new_member = User.new(id, name, real_name) + members_list << new_member + end + return members_list + end + def detail + puts "#{real_name}, slack user name: #{name}, id: #{id}" end + + end -#puts User.list -#binding.pry -#puts User.list -# puts User.list["members"][0]["id"] -# puts User.list["members"][0]["real_name"] +# puts User.list +# puts User.list[0] +# #puts User.list +# puts User.list["members"][0]["id"] +# puts User.list["members"][0]["real_name"] +# puts User.list["members"][0]["name"] \ No newline at end of file diff --git a/specs/cassettes/list_of_users.yml b/specs/cassettes/list_of_users.yml index 5a82d476..b4d9d618 100644 --- a/specs/cassettes/list_of_users.yml +++ b/specs/cassettes/list_of_users.yml @@ -21,17 +21,17 @@ http_interactions: Content-Type: - application/json; charset=utf-8 Content-Length: - - '899' + - '900' Connection: - keep-alive Date: - - Wed, 20 Mar 2019 20:36:10 GMT + - Wed, 20 Mar 2019 21:15:34 GMT Server: - Apache X-Content-Type-Options: - nosniff X-Slack-Req-Id: - - 40a883c9-a8ea-4071-80a8-1d629e19b48f + - d33cd83b-adf9-4c92-b064-a92ab98d5659 X-Oauth-Scopes: - identify,channels:read,users:read,chat:write:bot Expires: @@ -57,13 +57,13 @@ http_interactions: Access-Control-Allow-Origin: - "*" X-Via: - - haproxy-www-nx2y + - haproxy-www-6ur8 X-Cache: - Miss from cloudfront Via: - - 1.1 3e5a2f6c5b1171dae267d5a9344f95e8.cloudfront.net (CloudFront) + - 1.1 7430a54821bbaeddfc77b56ba1b84eae.cloudfront.net (CloudFront) X-Amz-Cf-Id: - - 3cYtRde0aiCiTy7aH2DZrNWHJhslzthqkFrlXUQlENr8O6QzHY9jow== + - g65DUs2andF3ojA1MuSSlQzu-QQsDmlPJLnuSupD9vxkXOH2I_Ls0w== body: encoding: ASCII-8BIT string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH2SDUE0J","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":null,"tz_label":"Pacific @@ -71,7 +71,7 @@ http_interactions: Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"grace.m.shea","real_name_normalized":"grace.m.shea","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g7af0be2aaaf","image_24":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-512.png","status_text_canonical":"","team":"TH2SDUE0J"},"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":1552952598},{"id":"UH4A0RV4N","team_id":"TH2SDUE0J","name":"b.amani.s","deleted":false,"color":"4bbe2e","real_name":"Bita Amani Shahrak","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Bita Amani Shahrak","real_name_normalized":"Bita Amani Shahrak","display_name":"Bita - Amani Shahrak","display_name_normalized":"Bita Amani Shahrak","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gb4955531fdb","image_24":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-512.png","status_text_canonical":"","team":"TH2SDUE0J"},"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":1552952825,"has_2fa":false}],"cache_ts":1553114170,"response_metadata":{"next_cursor":""}}' + Amani Shahrak","display_name_normalized":"Bita Amani Shahrak","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gb4955531fdb","image_24":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-512.png","status_text_canonical":"","team":"TH2SDUE0J"},"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":1552952825,"has_2fa":false}],"cache_ts":1553116534,"response_metadata":{"next_cursor":""}}' http_version: - recorded_at: Wed, 20 Mar 2019 20:36:10 GMT + recorded_at: Wed, 20 Mar 2019 21:15:34 GMT recorded_with: VCR 4.0.0 diff --git a/specs/cassettes/list_users.yml b/specs/cassettes/list_users.yml new file mode 100644 index 00000000..a3fa8c70 --- /dev/null +++ b/specs/cassettes/list_users.yml @@ -0,0 +1,77 @@ +--- +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: + - '900' + Connection: + - keep-alive + Date: + - Wed, 20 Mar 2019 22:55:30 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 7ae54ef8-e13d-4a99-aa84-893eae1aa66d + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write:bot + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - users:read + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-2ok9 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 44f18fa5317ccaef6a4a5e65d43dd8c8.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - K06KwyF8RMP5AEjV1XNS8D3ikE3HdGnKvH9XgYlSPP5fKBZ2WRXu_g== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"TH2SDUE0J","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":null,"tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Slackbot","real_name_normalized":"Slackbot","display_name":"Slackbot","display_name_normalized":"Slackbot","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"sv41d8cd98f0","always_active":true,"first_name":"slackbot","last_name":"","image_24":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH2SDUE0J"},"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":"UH2SDUECA","team_id":"TH2SDUE0J","name":"grace.m.shea","deleted":false,"color":"9f69e7","real_name":"grace.m.shea","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"grace.m.shea","real_name_normalized":"grace.m.shea","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g7af0be2aaaf","image_24":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-512.png","status_text_canonical":"","team":"TH2SDUE0J"},"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":1552952598},{"id":"UH4A0RV4N","team_id":"TH2SDUE0J","name":"b.amani.s","deleted":false,"color":"4bbe2e","real_name":"Bita + Amani Shahrak","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Bita + Amani Shahrak","real_name_normalized":"Bita Amani Shahrak","display_name":"Bita + Amani Shahrak","display_name_normalized":"Bita Amani Shahrak","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gb4955531fdb","image_24":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-512.png","status_text_canonical":"","team":"TH2SDUE0J"},"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":1552952825,"has_2fa":false}],"cache_ts":1553122530,"response_metadata":{"next_cursor":""}}' + http_version: + recorded_at: Wed, 20 Mar 2019 22:55:30 GMT +recorded_with: VCR 4.0.0 diff --git a/specs/user_spec.rb b/specs/user_spec.rb index b11e3a5d..b071e823 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -2,10 +2,20 @@ describe "list" do it "can get a list of users" do - VCR.use_cassette("list_of_users") do + VCR.use_cassette("list users") do response = User.list expect(response).wont_be_nil - #expect(response["members"]["id"]).must_equal "USLACKBOT" + expect(response["members"]).must_be_kind_of Array end end + # it "will raise an exception if the search fails" do + # VCR.use_cassette("list user") do + # location = "" + # expect { + # response = get_location(location) + # }.must_raise SearchError + # end + # end + + end From 32350f2acefd0832d04bbc7b766e5426b4d00458 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 06:47:25 -0700 Subject: [PATCH 20/45] user spec finished --- lib/channel.rb | 39 -------------------------------- lib/slack.rb | 56 +++++++++++++++++++++++----------------------- lib/user.rb | 6 ++--- lib/workspace.rb | 28 +++++++++++------------ specs/user_spec.rb | 26 +++++++++------------ 5 files changed, 54 insertions(+), 101 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 68dcd383..0a009242 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,43 +1,5 @@ require_relative "recipient" -<<<<<<< HEAD -# class Channel < Recipient -# BASE_URL = "https://slack.com/api/channels.list" -# TOKEN = ENV["SLACK_TOKEN"] - -# class SlackAPIError < StandardError; end - -# def initialize -# super -# @topic = topic -# @member_count = member_count -# end - -# # def details -# # end - -# def self.list -# query_params = { -# token: TOKEN, -# } -# response = HTTParty.get(BASE_URL, query: query_params) -# # responses = response["response"] - -# # if response.code != 200 || response == nil -# # raise SlackAPIError -# # end - -# # responses.each do |pass| -# # puts "#{pass["topic"].to_s}" -# # puts "#{pass["members"].to_a}" -# # end -# end -# end - -# puts Channel.list - -# , "API call failed with code #{response.code} and reason '#{response["reason"]}" -======= class Channel < Recipient attr_reader :topic, :member_count @@ -72,4 +34,3 @@ def self.list return channel_list end end ->>>>>>> 8f059c8f71fe014a17318c0ca080ae80445fd273 diff --git a/lib/slack.rb b/lib/slack.rb index 13d93ac9..a2fa3507 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,36 +1,36 @@ -#!/usr/bin/env ruby -# require "httparty" +!/usr/bin/env ruby +require "httparty" # PURPOSE OF THIS FILE IS TO HOLD CLI PROMPTS -# class Slack -# def initialize -# end +class Slack + def initialize + end -# def main -# puts "Welcome to the Ada Slack CLI!" + def main + puts "Welcome to the Ada Slack CLI!" -# puts "Slack CLI Menu\n" -# puts "1. List Users\n" -# puts "2. List Channels\n" -# puts "3. Quit\n" + puts "Slack CLI Menu\n" + puts "1. List Users\n" + puts "2. List Channels\n" + puts "3. Quit\n" -# loop do -# puts "Please enter your selection from the above options." -# input = gets.chomp.to_s -# case -# when input == "1" -# puts users.list -# when input == "2" -# puts channels.list -# when input == "3" -# exit -# when input =~ /[[:alpha:]]/ -# puts "\nYour request was invalid." -# end -# end + loop do + puts "Please enter your selection from the above options." + input = gets.chomp.to_s + case + when input == "1" + puts users.list + when input == "2" + puts channels.list + when input == "3" + exit + when input =~ /[[:alpha:]]/ + puts "\nYour request was invalid." + end + end -# puts "Thank you for using the Ada Slack CLI" -# end + puts "Thank you for using the Ada Slack CLI" + end -# main if __FILE__ == $PROGRAM_NAME + main if __FILE__ == $PROGRAM_NAME diff --git a/lib/user.rb b/lib/user.rb index 37d2b866..1665d7f5 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -13,7 +13,6 @@ def initialize(slack_id, name, real_name) @real_name = real_name @slack_id = slack_id @name = name - end def self.list @@ -33,14 +32,13 @@ def self.list end return members_list end + def detail return "#{real_name}, slack user name: #{name}, slack_id: #{slack_id}" end - - end - puts User.list +# puts User.list # puts User.list[0] # #puts User.list # puts User.list["members"][0]["id"] diff --git a/lib/workspace.rb b/lib/workspace.rb index 3494792b..bbe2fdf3 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -28,20 +28,20 @@ def show_details return @selected.details end - def print_details(recipients) - if recipients == "users" - return_array = [] - users.each do |user| - return_array << user.details - end - elsif recipients == "channels" - return_array = [] - channels.each do |channel| - return_array << channel.details - end - end - return return_array - end + # def print_details(recipients) + # if recipients == "users" + # return_array = [] + # users.each do |user| + # return_array << user.details + # end + # elsif recipients == "channels" + # return_array = [] + # channels.each do |channel| + # return_array << channel.details + # end + # end + # return return_array + # end def send_message end diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 53bc22fb..95313508 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -1,21 +1,15 @@ require_relative "test_helper" -describe "list" do - it "can get a list of users" do - VCR.use_cassette("list users") do - users = User.list - expect(users).wont_be_nil - expect(users).must_be_kind_of Array +describe "User class" do + describe "self.list" do + it "can return all users" do + VCR.use_cassette("slack_user") do + response = User.get("user") + + expect(response["members"]).wont_be_nil + expect(response["members"].first["name"]).must_equal "slackbot" + expect(response["members"].first["id"]).must_equal "USLACKBOT" + end end end - # it "will raise an exception if the search fails" do - # VCR.use_cassette("list user") do - - # expect { - - # }.must_raise SearchError - # end - # end - - end From d6de4551ce03b5735d1864ba7c9f8fda439c9375 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 06:59:04 -0700 Subject: [PATCH 21/45] slack menu completed --- lib/recipient.rb | 21 +++++++-- lib/slack.rb | 83 ++++++++++++++++++++++------------ lib/workspace.rb | 2 + specs/cassettes/slack_user.yml | 77 +++++++++++++++++++++++++++++++ 4 files changed, 152 insertions(+), 31 deletions(-) create mode 100644 specs/cassettes/slack_user.yml diff --git a/lib/recipient.rb b/lib/recipient.rb index a18a168b..12677b3a 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -8,13 +8,13 @@ class SlackApiError < StandardError; end attr_reader :slack_id, :name def initialize(slack_id, name) - @slack_id = slack_id @name = name end CHANNEL_URL = "https://slack.com/api/channels.list" USER_URL = "https://slack.com/api/users.list" + POST_URL = "https://slack.com/api/chat.postMessage" def self.get(type) params = { @@ -29,8 +29,23 @@ def self.get(type) response = HTTParty.get(url, query: params) end - def send_message(message) - response = HTTParty.post(url, message?) + def send_message(message, recipient) + params = { + "token" => ENV["SLACK_API_TOKEN"], + "channel" => recipient, + "text" => message, + "as_user" => true, + } + + response = HTTParty.post( + POST_URL, + body: params, + headers: { "Content-Type" => "application/x-www-form-urlencoded" }, + ) + unless response.code == 200 && response.parsed_response["ok"] + raise SlackApiError, "Error: #{response.parsed_response["error"]}" + end + return response end private diff --git a/lib/slack.rb b/lib/slack.rb index a2fa3507..83359496 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,36 +1,63 @@ -!/usr/bin/env ruby -require "httparty" +#!/usr/bin/env ruby +require_relative "workspace" -# PURPOSE OF THIS FILE IS TO HOLD CLI PROMPTS +def main + puts "Welcome to the Ada Slack CLI!" -class Slack - def initialize - end - - def main - puts "Welcome to the Ada Slack CLI!" + workspace = Workspace.new + input = "" - puts "Slack CLI Menu\n" - puts "1. List Users\n" - puts "2. List Channels\n" - puts "3. Quit\n" + while input != "quit" + puts "Choose an option: + \n 1. List users + \n 2. List channels + \n 3. Select user + \n 4. Select channel + \n 5. Get details + \n 6. Send message + \n 7. Quit" - loop do - puts "Please enter your selection from the above options." - input = gets.chomp.to_s - case - when input == "1" - puts users.list - when input == "2" - puts channels.list - when input == "3" - exit - when input =~ /[[:alpha:]]/ - puts "\nYour request was invalid." + input = gets.chomp + case input + when "list users" + puts workspace.show_details("users") + when "list channels" + puts workspace.show_details("channels") + when "select user" + print "Enter the user name or Slack ID: " + input_user = gets.chomp + workspace.select_user(input_user) + if workspace.selected == nil + puts "User not found" + end + when "select channel" + print "Enter the channel name or Slack ID: " + input_channel = gets.chomp + workspace.select_channel(input_channel) + if workspace.selected == nil + puts "Channel not found" + end + when "details" + if workspace.selected == nil + puts "Please select a user or channel." + else + puts workspace.show_details end + when "send message" + if workspace.selected == nil + puts "Please select a user or channel." + else + print "Enter your message: " + text = gets.chomp + workspace.send_message(text) + end + when "quit" + else + puts "Please select a option from the menu." end - - puts "Thank you for using the Ada Slack CLI" end - main if __FILE__ == $PROGRAM_NAME + puts "Thank you for using the Ada Slack CLI" +end + +main if __FILE__ == $PROGRAM_NAME diff --git a/lib/workspace.rb b/lib/workspace.rb index bbe2fdf3..3d049e12 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -28,6 +28,8 @@ def show_details return @selected.details end + # this method might be redundant + # def print_details(recipients) # if recipients == "users" # return_array = [] diff --git a/specs/cassettes/slack_user.yml b/specs/cassettes/slack_user.yml new file mode 100644 index 00000000..5d60fd38 --- /dev/null +++ b/specs/cassettes/slack_user.yml @@ -0,0 +1,77 @@ +--- +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: + - '890' + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 13:48:24 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 79ab7d69-fc95-4e7c-8fd4-32aec4cddd96 + X-Oauth-Scopes: + - identify,read,post,client,apps,admin + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - users:read,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-ewco + X-Cache: + - Miss from cloudfront + Via: + - 1.1 3a9dca02f1ba6ecd49fee9a3ca7fcb81.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - YHZdE8Jqb94Kp0vdGiwOs3bJU6d3T_n3MrTNzPb6LdXtQEkzOy7z2w== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"UH2SDUECA","team_id":"TH2SDUE0J","name":"grace.m.shea","deleted":false,"color":"9f69e7","real_name":"grace.m.shea","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"grace.m.shea","real_name_normalized":"grace.m.shea","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g7af0be2aaaf","email":"grace.m.shea@gmail.com","image_24":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-512.png","status_text_canonical":"","team":"TH2SDUE0J"},"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":1552952598,"has_2fa":false},{"id":"UH4A0RV4N","team_id":"TH2SDUE0J","name":"b.amani.s","deleted":false,"color":"4bbe2e","real_name":"Bita + Amani Shahrak","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Bita + Amani Shahrak","real_name_normalized":"Bita Amani Shahrak","display_name":"Bita + Amani Shahrak","display_name_normalized":"Bita Amani Shahrak","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gb4955531fdb","email":"b.amani.s@gmail.com","image_24":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-512.png","status_text_canonical":"","team":"TH2SDUE0J"},"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":1552952825,"has_2fa":false},{"id":"USLACKBOT","team_id":"TH2SDUE0J","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":null,"tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Slackbot","real_name_normalized":"Slackbot","display_name":"Slackbot","display_name_normalized":"Slackbot","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"sv41d8cd98f0","always_active":true,"first_name":"slackbot","last_name":"","image_24":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH2SDUE0J"},"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":1553262504}' + http_version: + recorded_at: Fri, 22 Mar 2019 13:48:24 GMT +recorded_with: VCR 4.0.0 From 21ee33bceb3abc032ffa35d1d0ee4023de649a22 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 07:07:51 -0700 Subject: [PATCH 22/45] adding tests to workspace spec, resolving errors --- specs/cassettes/slack-posts.yml | 152 ++++++++++++++++++++++++++++++++ specs/workspace_spec.rb | 63 +++++++++++-- 2 files changed, 207 insertions(+), 8 deletions(-) create mode 100644 specs/cassettes/slack-posts.yml diff --git a/specs/cassettes/slack-posts.yml b/specs/cassettes/slack-posts.yml new file mode 100644 index 00000000..d28a9b91 --- /dev/null +++ b/specs/cassettes/slack-posts.yml @@ -0,0 +1,152 @@ +--- +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: + - '890' + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 14:05:21 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - fca04afb-fc27-4a6f-971c-e1d72e6aa488 + X-Oauth-Scopes: + - identify,read,post,client,apps,admin + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - users:read,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-zl12 + X-Cache: + - Miss from cloudfront + Via: + - 1.1 08f323eee70ddda7af34d5feb414ce27.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - Mf_OgI4ZzZX3Hz5-77lKhKioSFbLQSF6O5B1NyNp1eRtGhNlXH0nAA== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"UH2SDUECA","team_id":"TH2SDUE0J","name":"grace.m.shea","deleted":false,"color":"9f69e7","real_name":"grace.m.shea","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"grace.m.shea","real_name_normalized":"grace.m.shea","display_name":"","display_name_normalized":"","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g7af0be2aaaf","email":"grace.m.shea@gmail.com","image_24":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/7af0be2aaaf3e67ca1c00d48d132101c.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0007-512.png","status_text_canonical":"","team":"TH2SDUE0J"},"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":1552952598,"has_2fa":false},{"id":"UH4A0RV4N","team_id":"TH2SDUE0J","name":"b.amani.s","deleted":false,"color":"4bbe2e","real_name":"Bita + Amani Shahrak","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Bita + Amani Shahrak","real_name_normalized":"Bita Amani Shahrak","display_name":"Bita + Amani Shahrak","display_name_normalized":"Bita Amani Shahrak","status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gb4955531fdb","email":"b.amani.s@gmail.com","image_24":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/b4955531fdb9a07733e053153cf1b429.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0011-512.png","status_text_canonical":"","team":"TH2SDUE0J"},"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":1552952825,"has_2fa":false},{"id":"USLACKBOT","team_id":"TH2SDUE0J","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":null,"tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Slackbot","real_name_normalized":"Slackbot","display_name":"Slackbot","display_name_normalized":"Slackbot","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"sv41d8cd98f0","always_active":true,"first_name":"slackbot","last_name":"","image_24":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_192.png","image_512":"https:\/\/a.slack-edge.com\/16510\/img\/slackbot_512.png","status_text_canonical":"","team":"TH2SDUE0J"},"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":1553263521}' + http_version: + recorded_at: Fri, 22 Mar 2019 14:05:21 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: + - '537' + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 14:05:22 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 2edd6f4a-a016-49dc-9eda-9eff9be15d73 + X-Oauth-Scopes: + - identify,read,post,client,apps,admin + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - channels:read,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-9niu + X-Cache: + - Miss from cloudfront + Via: + - 1.1 6ba12aeff47e3e7677e084594bfce5e1.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - 8jR7P2VEH-PHCScDdMPJdoi0ApPZPgxosNIaXt-tpBpZxiKwo0F96Q== + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"CH0EFGWQ0","name":"everyone","is_channel":true,"created":1552952597,"is_archived":false,"is_general":true,"unlinked":0,"creator":"UH2SDUECA","name_normalized":"everyone","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2SDUECA","UH4A0RV4N"],"topic":{"value":"Company-wide + announcements and work-based matters","creator":"UH2SDUECA","last_set":1552952597},"purpose":{"value":"This + channel is for workspace-wide communication and announcements. All members + are in this channel.","creator":"UH2SDUECA","last_set":1552952597},"previous_names":[],"num_members":2},{"id":"CH36U0J9K","name":"random","is_channel":true,"created":1552952597,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2SDUECA","name_normalized":"random","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2SDUECA","UH4A0RV4N"],"topic":{"value":"Non-work + banter and water cooler conversation","creator":"UH2SDUECA","last_set":1552952597},"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":"UH2SDUECA","last_set":1552952597},"previous_names":[],"num_members":2},{"id":"CH0EFH3CG","name":"slack-api-project","is_channel":true,"created":1552952598,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2SDUECA","name_normalized":"slack-api-project","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2SDUECA","UH4A0RV4N"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2}]}' + http_version: + recorded_at: Fri, 22 Mar 2019 14:05:22 GMT +recorded_with: VCR 4.0.0 diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index c246b0ff..06d5c5f3 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -10,24 +10,33 @@ it "creates a list of channels and users" do VCR.use_cassette("slack_workspace") do expect(@workspace.channels.first).must_be_kind_of Channel + expect(@workspace.users.first).must_be_kind_of User + end + end +end + +describe "instance methods" do + it "returns text from print_details" do + VCR.use_cassette("slack_workspace") do + workspace = Workspace.new + expect(workspace.print_details("users")).must_be_kind_of Array - # expect(@workspace.users.first).must_be_kind_of User + expect(workspace.print_details("channels")).must_be_kind_of Array end end + it "returns a user object from select_user" do + expect(@workspace.select_user("slackbot")).must_be_kind_of User + expect(@workspace.select_user("USLACKBOT")).must_be_kind_of User + end + it "returns text from print_details" do VCR.use_cassette("slack_workspace") do - # expect(@workspace.print_details("users")).must_be_kind_of String + expect(@workspace.print_details("users")).must_be_kind_of String expect(@workspace.print_details("channels")).must_be_kind_of String end end - # it "returns a user object from select_user" do - # expect(@workspace.select_user("slackbot")).must_be_kind_of User - # expect(@workspace.select_user("USLACKBOT")).must_be_kind_of User - # end - # end - it "returns a channel object from select_channel" do VCR.use_cassette("slack_workspace") do expect(@workspace.select_channel("random")).must_be_kind_of Channel @@ -55,3 +64,41 @@ # end # end end + +describe "post message to slack" do + it "creates sends a message to a recipient" do + VCR.use_cassette("slack-posts") do + workspace = Workspace.new + workspace.select_channel("random") + response = workspace.send_message("should work") + expect(response["ok"]).must_equal true + end + end + + it "raises an error for invalid channel" do + VCR.use_cassette("slack-posts") do + workspace = Workspace.new + workspace.select_channel("random") + workspace.selected.slack_id = "abc" + expect { workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError + end + end + + it "raises an error for invalid user" do + VCR.use_cassette("slack-posts") do + workspace = Workspace.new + workspace.select_user("slackbot") + workspace.selected.slack_id = "abc" + expect { workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError + end + end + + it "raises an error for invalid user" do + VCR.use_cassette("slack-posts") do + workspace = Workspace.new + workspace.select_user("slackbot") + workspace.selected.slack_id = "abc" + expect { workspace.send_message("") }.must_raise Recipient::SlackApiError + end + end +end From eef74a45ca3685d8499649cd3c6e4a30a38f32e2 Mon Sep 17 00:00:00 2001 From: Bitaman Date: Fri, 22 Mar 2019 10:21:04 -0700 Subject: [PATCH 23/45] trying to merge --- lib/channel.rb | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 68dcd383..0a009242 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,43 +1,5 @@ require_relative "recipient" -<<<<<<< HEAD -# class Channel < Recipient -# BASE_URL = "https://slack.com/api/channels.list" -# TOKEN = ENV["SLACK_TOKEN"] - -# class SlackAPIError < StandardError; end - -# def initialize -# super -# @topic = topic -# @member_count = member_count -# end - -# # def details -# # end - -# def self.list -# query_params = { -# token: TOKEN, -# } -# response = HTTParty.get(BASE_URL, query: query_params) -# # responses = response["response"] - -# # if response.code != 200 || response == nil -# # raise SlackAPIError -# # end - -# # responses.each do |pass| -# # puts "#{pass["topic"].to_s}" -# # puts "#{pass["members"].to_a}" -# # end -# end -# end - -# puts Channel.list - -# , "API call failed with code #{response.code} and reason '#{response["reason"]}" -======= class Channel < Recipient attr_reader :topic, :member_count @@ -72,4 +34,3 @@ def self.list return channel_list end end ->>>>>>> 8f059c8f71fe014a17318c0ca080ae80445fd273 From 5cc917ad8bdd1b6bc5f59c1d21ed10df4355ecc4 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 10:21:53 -0700 Subject: [PATCH 24/45] user_spec edited, passes test --- specs/channel_spec.rb | 1 - specs/user_spec.rb | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 1e15a59b..720aafc4 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -5,7 +5,6 @@ it "can return all channels" do VCR.use_cassette("slack_channel") do response = Channel.list - channel = response.first expect(response).wont_be_nil diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 95313508..7c30744f 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -2,13 +2,13 @@ describe "User class" do describe "self.list" do - it "can return all users" do + it "can return all channels" do VCR.use_cassette("slack_user") do - response = User.get("user") + response = User.list + user = response.first - expect(response["members"]).wont_be_nil - expect(response["members"].first["name"]).must_equal "slackbot" - expect(response["members"].first["id"]).must_equal "USLACKBOT" + expect(response).wont_be_nil + expect(response.first.name).must_equal user.name end end end From d54ba414dd8e4344224edf992bfdf8184c7d25fd Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 10:35:06 -0700 Subject: [PATCH 25/45] tests refined --- lib/workspace.rb | 28 ++++++++++++++-------------- specs/workspace_spec.rb | 34 +++++++++++++++------------------- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index 3d049e12..c0a193ba 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -30,20 +30,20 @@ def show_details # this method might be redundant - # def print_details(recipients) - # if recipients == "users" - # return_array = [] - # users.each do |user| - # return_array << user.details - # end - # elsif recipients == "channels" - # return_array = [] - # channels.each do |channel| - # return_array << channel.details - # end - # end - # return return_array - # end + def print_details(recipients) + if recipients == "users" + return_array = [] + users.each do |user| + return_array << user.details + end + elsif recipients == "channels" + return_array = [] + channels.each do |channel| + return_array << channel.details + end + end + return return_array + end def send_message end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 06d5c5f3..0bdbc5c6 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -18,16 +18,16 @@ describe "instance methods" do it "returns text from print_details" do VCR.use_cassette("slack_workspace") do - workspace = Workspace.new - expect(workspace.print_details("users")).must_be_kind_of Array - - expect(workspace.print_details("channels")).must_be_kind_of Array + expect(@workspace.print_details("users")).must_be_kind_of Array + expect(@workspace.print_details("channels")).must_be_kind_of Array end end it "returns a user object from select_user" do - expect(@workspace.select_user("slackbot")).must_be_kind_of User - expect(@workspace.select_user("USLACKBOT")).must_be_kind_of User + VCR.use_cassette("slack_workspace") do + expect(@workspace.select_user("slackbot")).must_be_kind_of User + expect(@workspace.select_user("USLACKBOT")).must_be_kind_of User + end end it "returns text from print_details" do @@ -68,26 +68,23 @@ describe "post message to slack" do it "creates sends a message to a recipient" do VCR.use_cassette("slack-posts") do - workspace = Workspace.new - workspace.select_channel("random") - response = workspace.send_message("should work") + @workspace.select_channel("random") + response = @workspace.send_message("should work") expect(response["ok"]).must_equal true end end it "raises an error for invalid channel" do VCR.use_cassette("slack-posts") do - workspace = Workspace.new - workspace.select_channel("random") - workspace.selected.slack_id = "abc" - expect { workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError + @workspace.select_channel("random") + @workspace.selected.slack_id = "abc" + expect { @workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError end end it "raises an error for invalid user" do VCR.use_cassette("slack-posts") do - workspace = Workspace.new - workspace.select_user("slackbot") + @workspace.select_user("slackbot") workspace.selected.slack_id = "abc" expect { workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError end @@ -95,10 +92,9 @@ it "raises an error for invalid user" do VCR.use_cassette("slack-posts") do - workspace = Workspace.new - workspace.select_user("slackbot") - workspace.selected.slack_id = "abc" - expect { workspace.send_message("") }.must_raise Recipient::SlackApiError + @workspace.select_user("slackbot") + @workspace.selected.slack_id = "abc" + expect { @workspace.send_message("") }.must_raise Recipient::SlackApiError end end end From 8b4e25b26c2366279b90f6b0cc7490b6496b736b Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 10:37:16 -0700 Subject: [PATCH 26/45] initialized workspace in each describe block --- specs/workspace_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 0bdbc5c6..144d2206 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -16,6 +16,12 @@ end describe "instance methods" do + before do + VCR.use_cassette("slack_workspace") do + @workspace = Workspace.new + end + end + it "returns text from print_details" do VCR.use_cassette("slack_workspace") do expect(@workspace.print_details("users")).must_be_kind_of Array @@ -66,6 +72,12 @@ end describe "post message to slack" do + before do + VCR.use_cassette("slack_workspace") do + @workspace = Workspace.new + end + end + it "creates sends a message to a recipient" do VCR.use_cassette("slack-posts") do @workspace.select_channel("random") From 0304ab5a3d4a9fa68943a74fec92f9aea331ce16 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 10:39:36 -0700 Subject: [PATCH 27/45] error corrected --- specs/workspace_spec.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 144d2206..f60c9ee2 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -89,7 +89,6 @@ it "raises an error for invalid channel" do VCR.use_cassette("slack-posts") do @workspace.select_channel("random") - @workspace.selected.slack_id = "abc" expect { @workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError end end @@ -97,7 +96,6 @@ it "raises an error for invalid user" do VCR.use_cassette("slack-posts") do @workspace.select_user("slackbot") - workspace.selected.slack_id = "abc" expect { workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError end end @@ -105,7 +103,6 @@ it "raises an error for invalid user" do VCR.use_cassette("slack-posts") do @workspace.select_user("slackbot") - @workspace.selected.slack_id = "abc" expect { @workspace.send_message("") }.must_raise Recipient::SlackApiError end end From 855498a81a38ccf1ecb6272a9f809e345b20232a Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 10:50:04 -0700 Subject: [PATCH 28/45] debugging update --- lib/workspace.rb | 2 -- specs/workspace_spec.rb | 76 +++++++++++++++++++---------------------- 2 files changed, 35 insertions(+), 43 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index c0a193ba..3494792b 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -28,8 +28,6 @@ def show_details return @selected.details end - # this method might be redundant - def print_details(recipients) if recipients == "users" return_array = [] diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index f60c9ee2..ca3e4653 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -60,50 +60,44 @@ end end - # it "returns user details from show_details" do - # VCR.use_cassette("slack_workspace") do - # @workspace.select_user("slackbot") - # expect(@workspace.show_details).must_be_kind_of String - - # @workspace.select_user("USLACKBOT") - # expect(@workspace.show_details).must_be_kind_of String - # end - # end -end - -describe "post message to slack" do - before do + it "returns user details from show_details" do VCR.use_cassette("slack_workspace") do - @workspace = Workspace.new - end - end - - it "creates sends a message to a recipient" do - VCR.use_cassette("slack-posts") do - @workspace.select_channel("random") - response = @workspace.send_message("should work") - expect(response["ok"]).must_equal true - end - end - - it "raises an error for invalid channel" do - VCR.use_cassette("slack-posts") do - @workspace.select_channel("random") - expect { @workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError - end - end - - it "raises an error for invalid user" do - VCR.use_cassette("slack-posts") do @workspace.select_user("slackbot") - expect { workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError - end - end + expect(@workspace.show_details).must_be_kind_of String - it "raises an error for invalid user" do - VCR.use_cassette("slack-posts") do - @workspace.select_user("slackbot") - expect { @workspace.send_message("") }.must_raise Recipient::SlackApiError + @workspace.select_user("USLACKBOT") + expect(@workspace.show_details).must_be_kind_of String end end end + +# describe "post message to slack" do +# before do +# VCR.use_cassette("slack_workspace") do +# @workspace = Workspace.new +# end +# end + +# it "creates sends a message to a recipient" do +# VCR.use_cassette("slack-posts") do +# @workspace.select_channel("random") +# response = @workspace.send_message("should work") +# expect(response["ok"]).must_equal true +# end +# end + +# it "raises an error for invalid channel" do +# VCR.use_cassette("slack-posts") do +# @workspace.select_channel("random") +# expect { @workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError +# end +# end + +# it "raises an error for invalid user" do +# VCR.use_cassette("slack-posts") do +# @workspace.select_user("slackbot") +# expect { workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError +# end +# end + +# end From 47933a25d0d9b9304adf12dca517b57d0723871e Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 11:25:31 -0700 Subject: [PATCH 29/45] debugging joy --- lib/channel.rb | 2 ++ lib/user.rb | 8 -------- lib/workspace.rb | 5 +++-- specs/workspace_spec.rb | 43 ++++++++++++++++++++--------------------- 4 files changed, 26 insertions(+), 32 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 0a009242..ee7831d0 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -34,3 +34,5 @@ def self.list return channel_list end end + +# puts Channel.list diff --git a/lib/user.rb b/lib/user.rb index 1665d7f5..e26a2c5e 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,4 +1,3 @@ - require "httparty" require "pry" require_relative "recipient" @@ -37,10 +36,3 @@ def detail return "#{real_name}, slack user name: #{name}, slack_id: #{slack_id}" end end - -# puts User.list -# puts User.list[0] -# #puts User.list -# puts User.list["members"][0]["id"] -# puts User.list["members"][0]["real_name"] -# puts User.list["members"][0]["name"] diff --git a/lib/workspace.rb b/lib/workspace.rb index 3494792b..83e26958 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -10,6 +10,7 @@ def initialize @selected = nil end + # modify this def select_channel(user_input) selected = channels.select do |channel| channel.name == user_input || channel.slack_id == user_input @@ -18,10 +19,10 @@ def select_channel(user_input) end def select_user(user_input) - selected = users.select do |user| + @selected = users.find do |user| user.name == user_input || user.slack_id == user_input end - @selected = selected.first + return @selected end def show_details diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index ca3e4653..a028e456 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -46,26 +46,26 @@ it "returns a channel object from select_channel" do VCR.use_cassette("slack_workspace") do expect(@workspace.select_channel("random")).must_be_kind_of Channel - expect(@workspace.select_channel("CH2RY8RQT")).must_be_kind_of Channel + expect(@workspace.select_channel.first.must_be_kind_of Channel end end it "returns channel details from show_details" do VCR.use_cassette("slack_workspace") do - @workspace.select_channel("random") + @workspace.select_channel.first expect(@workspace.show_details).must_be_kind_of String - @workspace.select_channel("CH2RY8RQT") + @workspace.select_channel.last expect(@workspace.show_details).must_be_kind_of String end end it "returns user details from show_details" do VCR.use_cassette("slack_workspace") do - @workspace.select_user("slackbot") + @workspace.select_user.first expect(@workspace.show_details).must_be_kind_of String - @workspace.select_user("USLACKBOT") + @workspace.select_user.last expect(@workspace.show_details).must_be_kind_of String end end @@ -78,26 +78,25 @@ # end # end -# it "creates sends a message to a recipient" do -# VCR.use_cassette("slack-posts") do -# @workspace.select_channel("random") -# response = @workspace.send_message("should work") -# expect(response["ok"]).must_equal true +# it "creates sends a message to a recipient" do +# VCR.use_cassette("slack-posts") do +# @workspace.select_channel.first +# response = @workspace.send_message("should work") +# expect(response["ok"]).must_equal true +# end # end -# end -# it "raises an error for invalid channel" do -# VCR.use_cassette("slack-posts") do -# @workspace.select_channel("random") -# expect { @workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError +# it "raises an error for invalid channel" do +# VCR.use_cassette("slack-posts") do +# @workspace.select_channel.first +# expect { @workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError +# end # end -# end -# it "raises an error for invalid user" do -# VCR.use_cassette("slack-posts") do -# @workspace.select_user("slackbot") -# expect { workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError +# it "raises an error for invalid user" do +# VCR.use_cassette("slack-posts") do +# @workspace.select_user.first +# expect { workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError +# end # end # end - -# end From 4dd4e61e1d0d8109ab95ee56dfc75b86d7174ba2 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 11:26:54 -0700 Subject: [PATCH 30/45] syntax error fixed --- specs/workspace_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index a028e456..b339e694 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -46,7 +46,7 @@ it "returns a channel object from select_channel" do VCR.use_cassette("slack_workspace") do expect(@workspace.select_channel("random")).must_be_kind_of Channel - expect(@workspace.select_channel.first.must_be_kind_of Channel + expect(@workspace.select_channel.first).must_be_kind_of Channel end end From 55e891ff970729fea04b6a3c3773027bce05690a Mon Sep 17 00:00:00 2001 From: Bitaman Date: Fri, 22 Mar 2019 11:54:07 -0700 Subject: [PATCH 31/45] checked the user and channel class --- lib/channel.rb | 2 +- lib/user.rb | 1 + lib/workspace.rb | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index ee7831d0..ae2c61c9 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -35,4 +35,4 @@ def self.list end end -# puts Channel.list + puts Channel.list diff --git a/lib/user.rb b/lib/user.rb index e26a2c5e..de547a94 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -36,3 +36,4 @@ def detail return "#{real_name}, slack user name: #{name}, slack_id: #{slack_id}" end end +puts User.list \ No newline at end of file diff --git a/lib/workspace.rb b/lib/workspace.rb index 83e26958..88b8510d 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -19,7 +19,7 @@ def select_channel(user_input) end def select_user(user_input) - @selected = users.find do |user| + @selected = users.select do |user| user.name == user_input || user.slack_id == user_input end return @selected From 2cc177f50b34f464afdc40ee89445cef0a686c24 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 11:56:19 -0700 Subject: [PATCH 32/45] working through workspace_spec issues --- lib/workspace.rb | 4 +-- specs/workspace_spec.rb | 68 ++++++++++++++++++++++------------------- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index 83e26958..4bc2cc19 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -19,10 +19,10 @@ def select_channel(user_input) end def select_user(user_input) - @selected = users.find do |user| + @selected = users.select do |user| user.name == user_input || user.slack_id == user_input end - return @selected + @selected = selected.first end def show_details diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index b339e694..1ca4a3a5 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -19,56 +19,60 @@ before do VCR.use_cassette("slack_workspace") do @workspace = Workspace.new + @user = User.new("123", "usertest", "mr.usertest") + # (slack_id, name, real_name) + @channel = User.new("456", "channeltest", "testing", "100") + # (slack_id, name, topic, member_count) end end - it "returns text from print_details" do - VCR.use_cassette("slack_workspace") do - expect(@workspace.print_details("users")).must_be_kind_of Array - expect(@workspace.print_details("channels")).must_be_kind_of Array - end - end + # it "returns text from print_details" do + # VCR.use_cassette("slack_workspace") do + # expect(@workspace.print_details("users")).must_be_kind_of Array + # expect(@workspace.print_details("channels")).must_be_kind_of Array + # end + # end it "returns a user object from select_user" do VCR.use_cassette("slack_workspace") do - expect(@workspace.select_user("slackbot")).must_be_kind_of User - expect(@workspace.select_user("USLACKBOT")).must_be_kind_of User + expect(@workspace.select_user("usertest")).must_be_kind_of User + expect(@workspace.select_user("123")).must_be_kind_of User end end - it "returns text from print_details" do - VCR.use_cassette("slack_workspace") do - expect(@workspace.print_details("users")).must_be_kind_of String - expect(@workspace.print_details("channels")).must_be_kind_of String - end - end + # it "returns text from print_details" do + # VCR.use_cassette("slack_workspace") do + # expect(@workspace.print_details("users")).must_be_kind_of String + # expect(@workspace.print_details("channels")).must_be_kind_of String + # end + # end it "returns a channel object from select_channel" do VCR.use_cassette("slack_workspace") do - expect(@workspace.select_channel("random")).must_be_kind_of Channel - expect(@workspace.select_channel.first).must_be_kind_of Channel + expect(@workspace.select_channel("channel_test")).must_be_kind_of Channel + expect(@workspace.select_channel("456")).must_be_kind_of Channel end end - it "returns channel details from show_details" do - VCR.use_cassette("slack_workspace") do - @workspace.select_channel.first - expect(@workspace.show_details).must_be_kind_of String + # it "returns channel details from show_details" do + # VCR.use_cassette("slack_workspace") do + # @workspace.select_channel("channel_test") + # expect(@workspace.show_details).must_be_kind_of String - @workspace.select_channel.last - expect(@workspace.show_details).must_be_kind_of String - end - end + # @workspace.select_channel("456") + # expect(@workspace.show_details).must_be_kind_of String + # end + # end - it "returns user details from show_details" do - VCR.use_cassette("slack_workspace") do - @workspace.select_user.first - expect(@workspace.show_details).must_be_kind_of String + # it "returns user details from show_details" do + # VCR.use_cassette("slack_workspace") do + # @workspace.select_user("test") + # expect(@workspace.show_details).must_be_kind_of String - @workspace.select_user.last - expect(@workspace.show_details).must_be_kind_of String - end - end + # @workspace.select_user("test") + # expect(@workspace.show_details).must_be_kind_of String + # end + # end end # describe "post message to slack" do From 18a0e8a549ed234675c41b038181c2bdb52fad00 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 12:03:16 -0700 Subject: [PATCH 33/45] push --- lib/channel.rb | 2 +- lib/user.rb | 3 ++- specs/user_spec.rb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index ae2c61c9..1ded9200 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -35,4 +35,4 @@ def self.list end end - puts Channel.list +# puts Channel.list diff --git a/lib/user.rb b/lib/user.rb index de547a94..972809d3 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -36,4 +36,5 @@ def detail return "#{real_name}, slack user name: #{name}, slack_id: #{slack_id}" end end -puts User.list \ No newline at end of file + +# puts User.list diff --git a/specs/user_spec.rb b/specs/user_spec.rb index 7c30744f..6e57ac2b 100644 --- a/specs/user_spec.rb +++ b/specs/user_spec.rb @@ -2,7 +2,7 @@ describe "User class" do describe "self.list" do - it "can return all channels" do + it "can return all users" do VCR.use_cassette("slack_user") do response = User.list user = response.first From a2c704db7e6e3e19944aaa488a5c0d6b6261a840 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 12:14:14 -0700 Subject: [PATCH 34/45] select_user and select_channel by name functional --- specs/workspace_spec.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 1ca4a3a5..77320dac 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -19,10 +19,6 @@ before do VCR.use_cassette("slack_workspace") do @workspace = Workspace.new - @user = User.new("123", "usertest", "mr.usertest") - # (slack_id, name, real_name) - @channel = User.new("456", "channeltest", "testing", "100") - # (slack_id, name, topic, member_count) end end @@ -35,8 +31,8 @@ it "returns a user object from select_user" do VCR.use_cassette("slack_workspace") do - expect(@workspace.select_user("usertest")).must_be_kind_of User - expect(@workspace.select_user("123")).must_be_kind_of User + expect(@workspace.select_user("grace.m.shea")).must_be_kind_of User + # expect(@workspace.select_user("123")).must_be_kind_of User end end @@ -49,14 +45,14 @@ it "returns a channel object from select_channel" do VCR.use_cassette("slack_workspace") do - expect(@workspace.select_channel("channel_test")).must_be_kind_of Channel - expect(@workspace.select_channel("456")).must_be_kind_of Channel + expect(@workspace.select_channel("random")).must_be_kind_of Channel + # expect(@workspace.select_channel("456")).must_be_kind_of Channel end end # it "returns channel details from show_details" do # VCR.use_cassette("slack_workspace") do - # @workspace.select_channel("channel_test") + # @workspace.select_channel("random") # expect(@workspace.show_details).must_be_kind_of String # @workspace.select_channel("456") From 9e05aaf94ac49e24eb320038950f0238156d0602 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 14:18:05 -0700 Subject: [PATCH 35/45] print_details passes test --- lib/channel.rb | 8 +++--- lib/user.rb | 2 +- lib/workspace.rb | 2 ++ specs/workspace_spec.rb | 56 ++++++++++++++++++++--------------------- 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 1ded9200..1a5b6af1 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -9,10 +9,6 @@ def initialize(slack_id, name, topic, member_count) @member_count = member_count end - def details - return "#{name} #{topic} member count: #{member_count} slack id: #{slack_id}" - end - def self.list raw_data = self.get("channel") @@ -33,6 +29,10 @@ def self.list end return channel_list end + + def details + return "#{name} #{topic} member count: #{member_count} slack id: #{slack_id}" + end end # puts Channel.list diff --git a/lib/user.rb b/lib/user.rb index 972809d3..6e7d48d5 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -32,7 +32,7 @@ def self.list return members_list end - def detail + def details return "#{real_name}, slack user name: #{name}, slack_id: #{slack_id}" end end diff --git a/lib/workspace.rb b/lib/workspace.rb index 4bc2cc19..a5df5a29 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -25,10 +25,12 @@ def select_user(user_input) @selected = selected.first end + # used to show details for one user or channel def show_details return @selected.details end + # used to show details for all users or all channels def print_details(recipients) if recipients == "users" return_array = [] diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 77320dac..4e568e6b 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -22,12 +22,12 @@ end end - # it "returns text from print_details" do - # VCR.use_cassette("slack_workspace") do - # expect(@workspace.print_details("users")).must_be_kind_of Array - # expect(@workspace.print_details("channels")).must_be_kind_of Array - # end - # end + it "returns text from print_details" do + VCR.use_cassette("slack_workspace") do + expect(@workspace.print_details("users")).must_be_kind_of Array + expect(@workspace.print_details("channels")).must_be_kind_of Array + end + end it "returns a user object from select_user" do VCR.use_cassette("slack_workspace") do @@ -36,12 +36,12 @@ end end - # it "returns text from print_details" do - # VCR.use_cassette("slack_workspace") do - # expect(@workspace.print_details("users")).must_be_kind_of String - # expect(@workspace.print_details("channels")).must_be_kind_of String - # end - # end + it "returns text from print_details" do + VCR.use_cassette("slack_workspace") do + expect(@workspace.print_details("users")).must_be_kind_of Array + expect(@workspace.print_details("channels")).must_be_kind_of Array + end + end it "returns a channel object from select_channel" do VCR.use_cassette("slack_workspace") do @@ -50,25 +50,25 @@ end end - # it "returns channel details from show_details" do - # VCR.use_cassette("slack_workspace") do - # @workspace.select_channel("random") - # expect(@workspace.show_details).must_be_kind_of String + it "returns channel details from show_details" do + VCR.use_cassette("slack_workspace") do + @workspace.select_channel("random") + expect(@workspace.show_details).must_be_kind_of String - # @workspace.select_channel("456") - # expect(@workspace.show_details).must_be_kind_of String - # end - # end + @workspace.select_channel("random") + expect(@workspace.show_details).must_be_kind_of String + end + end - # it "returns user details from show_details" do - # VCR.use_cassette("slack_workspace") do - # @workspace.select_user("test") - # expect(@workspace.show_details).must_be_kind_of String + it "returns user details from show_details" do + VCR.use_cassette("slack_workspace") do + @workspace.select_user("test") + expect(@workspace.show_details).must_be_kind_of String - # @workspace.select_user("test") - # expect(@workspace.show_details).must_be_kind_of String - # end - # end + @workspace.select_user("test") + expect(@workspace.show_details).must_be_kind_of String + end + end end # describe "post message to slack" do From 9cb2224367da67d575d8d86e34f81c81cbf62aa1 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 14:21:38 -0700 Subject: [PATCH 36/45] show_details method passing tests --- lib/workspace.rb | 2 +- specs/workspace_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index a5df5a29..0c866015 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -25,7 +25,7 @@ def select_user(user_input) @selected = selected.first end - # used to show details for one user or channel + # used to show details for selected user or channel def show_details return @selected.details end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 4e568e6b..a9098ee8 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -62,10 +62,10 @@ it "returns user details from show_details" do VCR.use_cassette("slack_workspace") do - @workspace.select_user("test") + @workspace.select_user("grace.m.shea") expect(@workspace.show_details).must_be_kind_of String - @workspace.select_user("test") + @workspace.select_channel("random") expect(@workspace.show_details).must_be_kind_of String end end From 282dd5c4b0683e9a2e62c1735ec9e79c27cf6433 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 14:55:43 -0700 Subject: [PATCH 37/45] slack menu debugged --- lib/recipient.rb | 4 +- lib/slack.rb | 20 +++--- lib/workspace.rb | 6 +- specs/cassettes/slack-posts.yml | 114 ++++++++++++++++++++++++++++++++ specs/channel_spec.rb | 3 - specs/workspace_spec.rb | 30 ++++----- 6 files changed, 145 insertions(+), 32 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 12677b3a..a357ce44 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -29,10 +29,10 @@ def self.get(type) response = HTTParty.get(url, query: params) end - def send_message(message, recipient) + def send_msg(message, deliver_to) params = { "token" => ENV["SLACK_API_TOKEN"], - "channel" => recipient, + "channel" => deliver_to, "text" => message, "as_user" => true, } diff --git a/lib/slack.rb b/lib/slack.rb index 83359496..7783178e 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -9,20 +9,20 @@ def main while input != "quit" puts "Choose an option: - \n 1. List users - \n 2. List channels - \n 3. Select user - \n 4. Select channel - \n 5. Get details - \n 6. Send message - \n 7. Quit" + \n List users + \n List channels + \n Select user + \n Select channel + \n Get details + \n Send message + \n Quit" - input = gets.chomp + input = gets.chomp.downcase case input when "list users" - puts workspace.show_details("users") + puts workspace.print_details("users") when "list channels" - puts workspace.show_details("channels") + puts workspace.print_details("channels") when "select user" print "Enter the user name or Slack ID: " input_user = gets.chomp diff --git a/lib/workspace.rb b/lib/workspace.rb index 0c866015..716240c2 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -46,6 +46,8 @@ def print_details(recipients) return return_array end - def send_message - end + # def send_message(text,) + # selected.send_msg(text, selected) + # end + end diff --git a/specs/cassettes/slack-posts.yml b/specs/cassettes/slack-posts.yml index d28a9b91..37446e94 100644 --- a/specs/cassettes/slack-posts.yml +++ b/specs/cassettes/slack-posts.yml @@ -149,4 +149,118 @@ http_interactions: you''d prefer to keep out of more focused work-related channels.","creator":"UH2SDUECA","last_set":1552952597},"previous_names":[],"num_members":2},{"id":"CH0EFH3CG","name":"slack-api-project","is_channel":true,"created":1552952598,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2SDUECA","name_normalized":"slack-api-project","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2SDUECA","UH4A0RV4N"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2}]}' http_version: recorded_at: Fri, 22 Mar 2019 14:05:22 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=%23%3CChannel%3A0x00007f964e9b6c70%3E&text=should%20work&as_user=true + headers: + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 21:28:46 GMT + Server: + - Apache + Access-Control-Expose-Headers: + - x-slack-req-id + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + X-Accepted-Oauth-Scopes: + - chat:write:user + Vary: + - Accept-Encoding + X-Slack-Req-Id: + - 0bd37bdf-0ebf-4b91-889e-a135d2f1d171 + X-Xss-Protection: + - '0' + X-Content-Type-Options: + - nosniff + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-kq9w + X-Cache: + - Miss from cloudfront + Via: + - 1.1 d714b057e8bc1fb7da10bf9e59df1987.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - e1HOjxJYoKTene3lzjjkGZuyPxkf61PkYze9kvuAr2r8-BXsbJ2Zrw== + body: + encoding: UTF-8 + string: '{"ok":false,"error":"not_authed"}' + http_version: + recorded_at: Fri, 22 Mar 2019 21:28:46 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=%23%3CChannel%3A0x00007f89e7af5a28%3E&text=should%20work&as_user=true + headers: + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 21:31:20 GMT + Server: + - Apache + Access-Control-Expose-Headers: + - x-slack-req-id + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + X-Accepted-Oauth-Scopes: + - chat:write:user + Vary: + - Accept-Encoding + X-Slack-Req-Id: + - 824608ad-1790-454a-a216-4c3cbd1edbf6 + X-Xss-Protection: + - '0' + X-Content-Type-Options: + - nosniff + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-cge + X-Cache: + - Miss from cloudfront + Via: + - 1.1 4f81f573d1d8e804c79450e430cd47be.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - Z2-Qvy4I3B2JaLg1H2jEIRO8dgoP5TXYwSvbX4p0Y_jAfyHGwiEZmA== + body: + encoding: UTF-8 + string: '{"ok":false,"error":"not_authed"}' + http_version: + recorded_at: Fri, 22 Mar 2019 21:31:20 GMT recorded_with: VCR 4.0.0 diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 720aafc4..159d4133 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -13,6 +13,3 @@ end end end - -# members = response[0].members.count -# expect(response.first.member_count).must_equal members diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index a9098ee8..ce6852b4 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -80,23 +80,23 @@ # it "creates sends a message to a recipient" do # VCR.use_cassette("slack-posts") do -# @workspace.select_channel.first -# response = @workspace.send_message("should work") +# @workspace.select_channel("everyone") +# response = @workspace.send_message("this should post") # expect(response["ok"]).must_equal true # end # end -# it "raises an error for invalid channel" do -# VCR.use_cassette("slack-posts") do -# @workspace.select_channel.first -# expect { @workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError -# end -# end + # it "raises an error for invalid channel" do + # VCR.use_cassette("slack-posts") do + # @workspace.select_channel.first + # expect { @workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError + # end + # end -# it "raises an error for invalid user" do -# VCR.use_cassette("slack-posts") do -# @workspace.select_user.first -# expect { workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError -# end -# end -# end + # it "raises an error for invalid user" do + # VCR.use_cassette("slack-posts") do + # @workspace.select_user.first + # expect { workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError + # end + # end +end From d35ea1498d55837bc9e8954aa9faa826d62ce1e3 Mon Sep 17 00:00:00 2001 From: Bitaman Date: Fri, 22 Mar 2019 14:59:55 -0700 Subject: [PATCH 38/45] fixing the slack --- lib/slack.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/slack.rb b/lib/slack.rb index 83359496..a09a3e40 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -17,7 +17,7 @@ def main \n 6. Send message \n 7. Quit" - input = gets.chomp + input = gets.chomp.downcase case input when "list users" puts workspace.show_details("users") From 2281f75695a383acf7fb893d91ff40ce78cf17cf Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 15:32:56 -0700 Subject: [PATCH 39/45] send message test passing --- lib/recipient.rb | 7 +- lib/workspace.rb | 12 +- specs/cassettes/slack-posts.yml | 237 ++++++++++++++++++++++++++++++++ specs/workspace_spec.rb | 26 ++-- 4 files changed, 261 insertions(+), 21 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index a357ce44..21c9e42f 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -27,12 +27,13 @@ def self.get(type) end response = HTTParty.get(url, query: params) + return response end - def send_msg(message, deliver_to) + def send_msg(message) params = { - "token" => ENV["SLACK_API_TOKEN"], - "channel" => deliver_to, + "token" => ENV["SLACK_TOKEN"], + "channel" => @slack_id, "text" => message, "as_user" => true, } diff --git a/lib/workspace.rb b/lib/workspace.rb index 716240c2..ab94bd7a 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,5 +1,7 @@ require_relative "user" require_relative "channel" +require_relative "recipient" +require "pry" class Workspace attr_reader :users, :channels, :selected @@ -10,7 +12,6 @@ def initialize @selected = nil end - # modify this def select_channel(user_input) selected = channels.select do |channel| channel.name == user_input || channel.slack_id == user_input @@ -46,8 +47,9 @@ def print_details(recipients) return return_array end - # def send_message(text,) - # selected.send_msg(text, selected) - # end - + def send_message(text) + # binding.pry + @selected.send_msg(text) + # binding.pry + end end diff --git a/specs/cassettes/slack-posts.yml b/specs/cassettes/slack-posts.yml index 37446e94..27c9269a 100644 --- a/specs/cassettes/slack-posts.yml +++ b/specs/cassettes/slack-posts.yml @@ -263,4 +263,241 @@ http_interactions: string: '{"ok":false,"error":"not_authed"}' http_version: recorded_at: Fri, 22 Mar 2019 21:31:20 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=%23%3CChannel%3A0x00007f8958479aa8%3E&text=this%20should%20post&as_user=true + headers: + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 21:58:35 GMT + Server: + - Apache + Access-Control-Expose-Headers: + - x-slack-req-id + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + X-Accepted-Oauth-Scopes: + - chat:write:user + Vary: + - Accept-Encoding + X-Slack-Req-Id: + - 862fb0c7-6981-4cef-9eaf-305839a8a0be + X-Xss-Protection: + - '0' + X-Content-Type-Options: + - nosniff + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-f4rs + X-Cache: + - Miss from cloudfront + Via: + - 1.1 a9587eaa1ec3f78d147d395dced29552.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - 3DhI7K-Tz7feFMZ-m6y8_sDkAGE16CPtUJDjIAnx5zO14WavhQ_hGw== + body: + encoding: UTF-8 + string: '{"ok":false,"error":"not_authed"}' + http_version: + recorded_at: Fri, 22 Mar 2019 21:58:35 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=%23%3CChannel%3A0x00007fa87561b730%3E&text=this%20should%20post&as_user=true + headers: + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 22:03:59 GMT + Server: + - Apache + Access-Control-Expose-Headers: + - x-slack-req-id + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + X-Accepted-Oauth-Scopes: + - chat:write:user + Vary: + - Accept-Encoding + X-Slack-Req-Id: + - 07faf59f-4c86-4ad8-a6d5-b02aaa349fe0 + X-Xss-Protection: + - '0' + X-Content-Type-Options: + - nosniff + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-wzdz + X-Cache: + - Miss from cloudfront + Via: + - 1.1 53332bd6d55cfd374862eac4265e274a.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - HRZ9iK1an_CDmipz6vK5qUBdqlGG_yrsdVBzi9nA7yAU5zN8arJW1w== + body: + encoding: UTF-8 + string: '{"ok":false,"error":"not_authed"}' + http_version: + recorded_at: Fri, 22 Mar 2019 22:03:59 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=CH0EFGWQ0&text=this%20should%20post&as_user=true + headers: + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 22:30:10 GMT + Server: + - Apache + Access-Control-Expose-Headers: + - x-slack-req-id + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + X-Accepted-Oauth-Scopes: + - chat:write:user + Vary: + - Accept-Encoding + X-Slack-Req-Id: + - ddb2f83a-f0d8-4895-bd63-940a878eb7ca + X-Xss-Protection: + - '0' + X-Content-Type-Options: + - nosniff + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-qdfp + X-Cache: + - Miss from cloudfront + Via: + - 1.1 7fe3163daf2d65b2899c9b0772889524.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - xJtvRD-izQHnFMUT8nXYZdJMRfvwfXudj0BLTNGQg2OdBDVP6P4gDA== + body: + encoding: UTF-8 + string: '{"ok":false,"error":"not_authed"}' + http_version: + recorded_at: Fri, 22 Mar 2019 22:30:10 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=CH0EFGWQ0&text=this%20should%20post&as_user=true + headers: + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 22:32:13 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - bb321a31-b60a-4121-aab3-688329d9cf86 + X-Oauth-Scopes: + - identify,read,post,client,apps,admin + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:user,client + Vary: + - Accept-Encoding + Pragma: + - no-cache + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Access-Control-Allow-Origin: + - "*" + X-Via: + - haproxy-www-shy + X-Cache: + - Miss from cloudfront + Via: + - 1.1 d714b057e8bc1fb7da10bf9e59df1987.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - DTSwfTckOXWlPONatysPNFHZrj6DV6imVt6dcmeTt8Y8nuiMqdbd0g== + body: + encoding: UTF-8 + string: '{"ok":true,"channel":"CH0EFGWQ0","ts":"1553293933.000100","message":{"bot_id":"BH78ZSEUB","type":"message","text":"this + should post","user":"UH2SDUECA","ts":"1553293933.000100"}}' + http_version: + recorded_at: Fri, 22 Mar 2019 22:32:13 GMT recorded_with: VCR 4.0.0 diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index ce6852b4..1a2e88d4 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -71,20 +71,20 @@ end end -# describe "post message to slack" do -# before do -# VCR.use_cassette("slack_workspace") do -# @workspace = Workspace.new -# end -# end +describe "post message to slack" do + before do + VCR.use_cassette("slack_workspace") do + @workspace = Workspace.new + end + end -# it "creates sends a message to a recipient" do -# VCR.use_cassette("slack-posts") do -# @workspace.select_channel("everyone") -# response = @workspace.send_message("this should post") -# expect(response["ok"]).must_equal true -# end -# end + it "creates sends a message to a recipient" do + VCR.use_cassette("slack-posts") do + @workspace.select_channel("everyone") + response = @workspace.send_message("this should post") + expect(response["ok"]).must_equal true + end + end # it "raises an error for invalid channel" do # VCR.use_cassette("slack-posts") do From 501080d2bff7ec24ef4ee9c39c0e2c2bc403f592 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 15:39:12 -0700 Subject: [PATCH 40/45] for sharing --- lib/workspace.rb | 2 -- specs/workspace_spec.rb | 12 ++++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index ab94bd7a..553ee9e5 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -48,8 +48,6 @@ def print_details(recipients) end def send_message(text) - # binding.pry @selected.send_msg(text) - # binding.pry end end diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 1a2e88d4..7cc8eebb 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -86,12 +86,12 @@ end end - # it "raises an error for invalid channel" do - # VCR.use_cassette("slack-posts") do - # @workspace.select_channel.first - # expect { @workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError - # end - # end + it "raises an error for invalid channel" do + VCR.use_cassette("slack-posts") do + @workspace.select_channel("imaginary") + expect { @workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError + end + end # it "raises an error for invalid user" do # VCR.use_cassette("slack-posts") do From f2bd699d64aa88120a2f72dcb186689d10fc2aa2 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 15:46:00 -0700 Subject: [PATCH 41/45] reversed a merge error --- lib/recipient.rb | 6 +-- specs/cassettes/slack-posts.yml | 66 +++++++++++++++++++++++++++++++++ specs/workspace_spec.rb | 50 ++++++++++++------------- 3 files changed, 94 insertions(+), 28 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 12677b3a..25585f89 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -29,10 +29,10 @@ def self.get(type) response = HTTParty.get(url, query: params) end - def send_message(message, recipient) + def send_msg(message) params = { - "token" => ENV["SLACK_API_TOKEN"], - "channel" => recipient, + "token" => ENV["SLACK_TOKEN"], + "channel" => @slack_id, "text" => message, "as_user" => true, } diff --git a/specs/cassettes/slack-posts.yml b/specs/cassettes/slack-posts.yml index d28a9b91..3e6bf7b7 100644 --- a/specs/cassettes/slack-posts.yml +++ b/specs/cassettes/slack-posts.yml @@ -149,4 +149,70 @@ http_interactions: you''d prefer to keep out of more focused work-related channels.","creator":"UH2SDUECA","last_set":1552952597},"previous_names":[],"num_members":2},{"id":"CH0EFH3CG","name":"slack-api-project","is_channel":true,"created":1552952598,"is_archived":false,"is_general":false,"unlinked":0,"creator":"UH2SDUECA","name_normalized":"slack-api-project","is_shared":false,"is_org_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"members":["UH2SDUECA","UH4A0RV4N"],"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2}]}' http_version: recorded_at: Fri, 22 Mar 2019 14:05:22 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=CH0EFGWQ0&text=should%20work&as_user=true + headers: + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 22:45:32 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 8020e455-0052-42dd-b4c9-dfa8474db6bf + X-Oauth-Scopes: + - identify,read,post,client,apps,admin + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:user,client + 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-31hm + X-Cache: + - Miss from cloudfront + Via: + - 1.1 8ce0f76d2391b7bf264596884970edb3.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - ofiWgMAioI-P-ZvOu3giQG5eSlNveemG0huAtqug8jy2puvsJwgOLQ== + body: + encoding: UTF-8 + string: '{"ok":true,"channel":"CH0EFGWQ0","ts":"1553294732.000200","message":{"bot_id":"BH78ZSEUB","type":"message","text":"should + work","user":"UH2SDUECA","ts":"1553294732.000200"}}' + http_version: + recorded_at: Fri, 22 Mar 2019 22:45:32 GMT recorded_with: VCR 4.0.0 diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index 0d49ebcd..f68c23b5 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -71,32 +71,32 @@ end end -# describe "post message to slack" do -# before do -# VCR.use_cassette("slack_workspace") do -# @workspace = Workspace.new -# end -# end +describe "post message to slack" do + before do + VCR.use_cassette("slack_workspace") do + @workspace = Workspace.new + end + end -# it "creates sends a message to a recipient" do -# VCR.use_cassette("slack-posts") do -# @workspace.select_channel.first -# response = @workspace.send_message("should work") -# expect(response["ok"]).must_equal true -# end -# end + it "creates sends a message to a recipient" do + VCR.use_cassette("slack-posts") do + @workspace.select_channel("everyone") + response = @workspace.send_message("should work") + expect(response["ok"]).must_equal true + end + end -it "raises an error for invalid channel" do - VCR.use_cassette("slack-posts") do - @workspace.select_channel("imaginary") - expect { @workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError + it "raises an error for invalid channel" do + VCR.use_cassette("slack-posts") do + @workspace.select_channel("imaginary") + expect { @workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError + end end -end -# it "raises an error for invalid user" do -# VCR.use_cassette("slack-posts") do -# @workspace.select_user.first -# expect { workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError -# end -# end -# end + # it "raises an error for invalid user" do + # VCR.use_cassette("slack-posts") do + # @workspace.select_user.first + # expect { workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError + # end + # end +end From 0db833f8d9beac70a6f5af187ffa90e5f5dca487 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 15:57:10 -0700 Subject: [PATCH 42/45] raises errors for invalid channel and user --- lib/recipient.rb | 2 +- specs/cassettes/slack-posts.yml | 65 +++++++++++++++++++++++++++++++++ specs/workspace_spec.rb | 16 ++++---- 3 files changed, 75 insertions(+), 8 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index 25585f89..f36704c9 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -5,7 +5,7 @@ class Recipient class SlackApiError < StandardError; end - attr_reader :slack_id, :name + attr_accessor :slack_id, :name def initialize(slack_id, name) @slack_id = slack_id diff --git a/specs/cassettes/slack-posts.yml b/specs/cassettes/slack-posts.yml index 3e6bf7b7..ab8a5ee9 100644 --- a/specs/cassettes/slack-posts.yml +++ b/specs/cassettes/slack-posts.yml @@ -215,4 +215,69 @@ http_interactions: work","user":"UH2SDUECA","ts":"1553294732.000200"}}' http_version: recorded_at: Fri, 22 Mar 2019 22:45:32 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=whatever&text=shouldn%27t%20work&as_user=true + headers: + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Date: + - Fri, 22 Mar 2019 22:54:29 GMT + Server: + - Apache + X-Content-Type-Options: + - nosniff + X-Slack-Req-Id: + - 8e41640a-afc9-4bb8-9b2a-1e7a64c77035 + X-Oauth-Scopes: + - identify,read,post,client,apps,admin + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + Access-Control-Expose-Headers: + - x-slack-req-id + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write:user,client + 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-852m + X-Cache: + - Miss from cloudfront + Via: + - 1.1 e9dbb62af8eec6cb13379a137374c506.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - TJgLKvzvBn7sgT3ghRYpPbQntywNr0Gfj5nyM9wzTrvqrshFRJHoQA== + body: + encoding: UTF-8 + string: '{"ok":false,"error":"channel_not_found"}' + http_version: + recorded_at: Fri, 22 Mar 2019 22:54:29 GMT recorded_with: VCR 4.0.0 diff --git a/specs/workspace_spec.rb b/specs/workspace_spec.rb index f68c23b5..7d1e5a51 100644 --- a/specs/workspace_spec.rb +++ b/specs/workspace_spec.rb @@ -88,15 +88,17 @@ it "raises an error for invalid channel" do VCR.use_cassette("slack-posts") do - @workspace.select_channel("imaginary") + @workspace.select_channel("everyone") + @workspace.selected.slack_id = "whatever" expect { @workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError end end - # it "raises an error for invalid user" do - # VCR.use_cassette("slack-posts") do - # @workspace.select_user.first - # expect { workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError - # end - # end + it "raises an error for invalid user" do + VCR.use_cassette("slack-posts") do + @workspace.select_user("grace.m.shea") + @workspace.selected.slack_id = "whatever" + expect { @workspace.send_message("shouldn't work") }.must_raise Recipient::SlackApiError + end + end end From cfce3baefe9c2a32ea95074e9b12a61634fcf761 Mon Sep 17 00:00:00 2001 From: Grace Shea Date: Fri, 22 Mar 2019 16:00:02 -0700 Subject: [PATCH 43/45] passing to bita --- specs/channel_spec.rb | 3 --- specs/recipient_spec.rb | 12 +++++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/specs/channel_spec.rb b/specs/channel_spec.rb index 720aafc4..159d4133 100644 --- a/specs/channel_spec.rb +++ b/specs/channel_spec.rb @@ -13,6 +13,3 @@ end end end - -# members = response[0].members.count -# expect(response.first.member_count).must_equal members diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb index b5cae113..395c5578 100644 --- a/specs/recipient_spec.rb +++ b/specs/recipient_spec.rb @@ -1 +1,11 @@ -require_relative "test_helper" +describe "Recipient class" do + describe "" do + it "can get raw data for user and channel" do + VCR.use_cassette("slack_channel") do + type = "user" + expect(response).wont_be_nil + expect(response.first.name).must_equal channel.name + end + end + end +end From 0151a137a1aa22eec1026ef95796393906841078 Mon Sep 17 00:00:00 2001 From: Bitaman Date: Fri, 22 Mar 2019 16:10:42 -0700 Subject: [PATCH 44/45] removing slac spec and recipient spec --- lib/recipient.rb | 1 + specs/recipient_spec.rb | 11 ----------- specs/slack_spec.rb | 1 - 3 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 specs/recipient_spec.rb delete mode 100644 specs/slack_spec.rb diff --git a/lib/recipient.rb b/lib/recipient.rb index f36704c9..36d51cf6 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -27,6 +27,7 @@ def self.get(type) end response = HTTParty.get(url, query: params) + return response end def send_msg(message) diff --git a/specs/recipient_spec.rb b/specs/recipient_spec.rb deleted file mode 100644 index 395c5578..00000000 --- a/specs/recipient_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -describe "Recipient class" do - describe "" do - it "can get raw data for user and channel" do - VCR.use_cassette("slack_channel") do - type = "user" - expect(response).wont_be_nil - expect(response.first.name).must_equal channel.name - end - end - end -end diff --git a/specs/slack_spec.rb b/specs/slack_spec.rb deleted file mode 100644 index b5cae113..00000000 --- a/specs/slack_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative "test_helper" From 791d92a8421a3dfc685cff026610b7ccc53c9d77 Mon Sep 17 00:00:00 2001 From: Bitaman Date: Fri, 29 Mar 2019 11:20:18 -0700 Subject: [PATCH 45/45] added status text and imoji to user --- lib/user.rb | 6 ++++-- lib/workspace.rb | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/user.rb b/lib/user.rb index 6e7d48d5..183d21c4 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -5,13 +5,15 @@ Dotenv.load class User < Recipient - attr_reader :real_name, :name, :slack_id + attr_reader :real_name, :name, :slack_id, :status_text, :status_imoji - def initialize(slack_id, name, real_name) + def initialize(slack_id, name, real_name, status_text, status_imoji) super(slack_id, name) @real_name = real_name @slack_id = slack_id @name = name + @status_text = status_text + @status_imoji = status_imoji end def self.list diff --git a/lib/workspace.rb b/lib/workspace.rb index 4aebaf28..bc01004a 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -26,7 +26,7 @@ def select_user(user_input) end # used to show details for selected user or channel - def show_details + def show_details(selected) return @selected.details end