Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f7204f2
Project setup, url and key
dora1405 Sep 10, 2019
05da021
Project setup, fixing secret file
dora1405 Sep 10, 2019
a800226
Project design, created classes
dora1405 Sep 10, 2019
4b4c5da
Project design, update classes
dora1405 Sep 10, 2019
845b0d0
Created workspace.rb
dora1405 Sep 10, 2019
9302604
Project setup, added super variables in subclasses
dora1405 Sep 10, 2019
1ef14ce
Wave 1, working channel.rb self.list method
dora1405 Sep 11, 2019
78010de
Wave 1, channel.rb self.list method complete
dora1405 Sep 11, 2019
58d9be5
Wave 1, channel.rb self.list method, updated variable names in the me…
dora1405 Sep 11, 2019
d9723f7
Wave 1, channel.rb self.list method, minor variable name changes
dora1405 Sep 11, 2019
60f56e0
Wave 1, started on slack.rb for user input
dora1405 Sep 11, 2019
6482413
Wave 1, channel_test.rb passed instaniate test
dora1405 Sep 11, 2019
418a91b
Wave 1, updated channel.rb url and add case-when-else to slack.rb
dora1405 Sep 12, 2019
6e24945
User list method written, .history/ added to .gitignore
Sep 12, 2019
5faccdc
Wave 1, recipient.rb self.get method and channel.rb update
dora1405 Sep 12, 2019
ae5d805
Wave 1, channel.rb, editing self.list method
dora1405 Sep 12, 2019
9d4971c
Wave 1, added comment channel.rb
dora1405 Sep 12, 2019
d8b0488
Merge branch 'master' of https://github.com/dora1405/slack-cli
Sep 12, 2019
7afda0c
Wave 1, using table print for workspace.rb
dora1405 Sep 12, 2019
2fbef17
Wave 1, update to workspace.rb
dora1405 Sep 12, 2019
83b27ff
Updated User self.list method: incomplete
Sep 12, 2019
e6377b0
git pushMerge branch 'master' of https://github.com/dora1405/slack-cli
Sep 12, 2019
a831192
Users list method call working from slack.rb
Sep 13, 2019
7c6b4e7
Wave 1, slack.rb for list channels complete
dora1405 Sep 13, 2019
820b1e5
Wave 1, user.rb self.list method and tests completed
dora1405 Sep 13, 2019
d9ce1ae
Wave 1, recipient.rb added implement error for details method
dora1405 Sep 13, 2019
b37ceb4
Wave 1 VCR cassettes for channel.rb and user.rb
dora1405 Sep 13, 2019
7c47ea2
Wave 1 VCR cassette tests
dora1405 Sep 13, 2019
c4686c5
Workspace_test for instantiate passing
Sep 14, 2019
d925feb
List loop created in slack.rb
Sep 14, 2019
48852c2
Wave 2, workspace.rb completed working select_user method, added slac…
dora1405 Sep 14, 2019
94b85f2
Workspace test for select_user method pass 100% coverage
Sep 14, 2019
2ce8ed2
VCR security update
dora1405 Sep 14, 2019
eb2304e
Wave 2, select_channel method for workspace.rb complete and passed te…
dora1405 Sep 14, 2019
3ce2510
Purpose added to self.list
Sep 14, 2019
06de147
Wave 2, completed workspace.rb show_details method for channel details
dora1405 Sep 14, 2019
0519a35
Wave 2, details completed for channel and user. Testing needed
dora1405 Sep 14, 2019
3af96bd
Wave 2 workspace.rb show_details method updated
dora1405 Sep 16, 2019
de1a4f7
Send_message method implemented
Sep 16, 2019
507deab
Wave 2 complete. workspace.rb shows_details method tested
dora1405 Sep 16, 2019
2be8793
Cleaned up commented-out codes/lines
dora1405 Sep 16, 2019
c0999ae
Workspace test 100%
Sep 16, 2019
4b15006
Workspace tests 100%
Sep 16, 2019
751c504
Test names were changed for better readability. Cassette names are up…
dora1405 Sep 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
/tmp/

# Used by dotenv library to load environment variables.
# .env
.env

## Specific to RubyMotion:
.dat*
.repl_history
.history/
build/
*.bridgesupport
build-iPhoneOS/
Expand Down
31 changes: 31 additions & 0 deletions lib/channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require_relative 'recipient'


class Channel < Recipient
attr_reader :topic, :member_count, :detail

def initialize(slack_id:, name:, topic:, member_count:, detail:)
super(slack_id: slack_id, name: name)
@topic = topic
@member_count = member_count
@detail = detail
end



# Source Citation: lines 20-23 & 27 with Paige and Angele
def self.list
channels = self.get("https://slack.com/api/conversations.list")["channels"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be error handling here, reading the response code and returning an instance of SlackApiError.


channels.map do |channel|
name = channel["name"]
topic = channel["topic"]["value"]
member_count = channel["num_members"]
slack_id = channel["id"]
detail = channel["purpose"]["value"]

Channel.new(slack_id: slack_id, name: name, topic: topic, member_count: member_count, detail: detail)
end
end
end

11 changes: 11 additions & 0 deletions lib/error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

class SlackApiError < Exception
# attr_reader

def initialize

end



end
29 changes: 29 additions & 0 deletions lib/recipient.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'httparty'
require 'dotenv'

Dotenv.load


class Recipient
attr_reader :slack_id, :name

KEY = ENV['SLACK_TOKEN']

def initialize(slack_id:, name:)
@slack_id = slack_id
@name = name
end



def self.get(url)
HTTParty.get(url, query: {token: KEY})
end



def self.list
raise NotImplementedError 'Children implement this'
end

end
75 changes: 71 additions & 4 deletions lib/slack.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,78 @@
#!/usr/bin/env ruby
require_relative 'workspace'

def main
workspace = Workspace.new

puts "Welcome to the Ada Slack CLI!"

# TODO project

puts "Select one of the following options: \'list users\', \'list channels\', \'select user\', \'select channel\', \'details\', \'send message'\ or \'quit\': "
user_input = gets.chomp.downcase
until user_input == "quit"
case user_input
when "list users", "list user", "user", "users"
workspace.users.each do |user|
puts """
Slack ID: #{user.slack_id}
Real name: #{user.real_name}
Username: #{user.user_name}
"""
end

when "list channels", "list channel", "channels", "channel"
workspace.channels.each do |channel|
puts """
Slack ID: #{channel.slack_id}
Name: #{channel.name}
Topic: #{channel.topic}
Member count: #{channel.member_count}
"""
end

when "select user", "user"
puts "Enter username or ID"
selection = gets.chomp.downcase
if workspace.select_user(selection) == nil
puts "Invalid input - username or ID does not exist"
end

when "select channel", "channel"
puts "Enter channel name or ID"
selection = gets.chomp.downcase
if workspace.select_channel(selection) == nil
puts "Invalid input. Channel name or ID does not exist"
end

when "send message", "message"
if workspace.selected == nil
puts "A recipient has not been selected."
else
puts "Enter the message you would like to send:"
message = gets.chomp
workspace.send_message(message, workspace.selected.slack_id)
puts "You sent the following message:"
puts message
end

when "details", "detail"
if workspace.show_details == nil
puts "No recipient (user/channel) has been selected"
end
puts """
#{workspace.show_details.slack_id}
#{workspace.show_details.detail}
"""

end

puts "Select one of the following options: \'list users\', \'list channels\', \'select user\', \'select channel\', \'send message'\ \'details\' or \'quit\': "
user_input = gets.chomp.downcase
end


puts "Thank you for using the Ada Slack CLI"

end




main if __FILE__ == $PROGRAM_NAME
33 changes: 33 additions & 0 deletions lib/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require_relative 'recipient'
require 'pry'


class User < Recipient

attr_reader :slack_id, :user_name, :real_name, :detail

def initialize(slack_id:, user_name:, real_name:, detail:)
@user_name = user_name
@real_name = real_name
@slack_id = slack_id
@detail = detail
end




def self.list

response = self.get("https://slack.com/api/users.list")["members"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be error handling here, reading the response code and returning an instance of SlackApiError.


users = []
response.each do |member|
user = self.new(slack_id: member["id"], real_name: member["real_name"], user_name: member["name"], detail: member["profile"]["status_text"])
users << user
end
return users
end

end


59 changes: 59 additions & 0 deletions lib/workspace.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require_relative 'channel'
require_relative 'user'
require 'dotenv'

Dotenv.load

class Workspace
attr_reader :users, :channels, :selected
KEY = ENV['SLACK_TOKEN']

def initialize
@users = User.list
@channels = Channel.list
@selected = nil
end


def select_channel(selection)
@selected = @channels.find do |channel|
channel.name == selection || channel.slack_id == selection.upcase
end

end


def select_user(selection)
@selected = @users.find do |user|
user.user_name == selection || user.slack_id == selection.upcase
end
end



def show_details

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to talk with y'all to understand why y'all chose to put this and send_message here rather than in the Recipient, User, and Channel like the design prescribes.

if @selected != nil
if @selected.class == Channel
return @selected
elsif @selected.class == User
return @selected
end
else
return nil
end

end


def send_message(message, channel)
response = HTTParty.post("https://slack.com/api/chat.postMessage",
body: {
token: ENV["SLACK_TOKEN"],
channel: channel,
text: message
},
headers: { 'Content-type' => 'application/x-www-form-urlencoded' }
)
end

end
Loading