Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
42cf5d3
initial setup done
MonaRahmani Oct 6, 2020
cb3067a
tested the token - request sent and got the data back
MonaRahmani Oct 6, 2020
a81cd6e
all files added
MonaRahmani Oct 6, 2020
caf8e12
Add coverage directory to .gitignore file
MonaRahmani Oct 7, 2020
d24fd7e
still working on wave 1
MonaRahmani Oct 7, 2020
54fa953
slack.rb edited
MonaRahmani Oct 7, 2020
1256221
commit before starting Floobits
MonaRahmani Oct 7, 2020
5d37f27
updated some of the methods
MonaRahmani Oct 7, 2020
25d5ba4
channel & user tests added - not done yet
MonaRahmani Oct 8, 2020
4ae2649
workspace methods added
MonaRahmani Oct 8, 2020
614ded9
ss
MonaRahmani Oct 8, 2020
10e2c11
some tests added
MonaRahmani Oct 8, 2020
a176b03
edited user test
MonaRahmani Oct 8, 2020
a3e6328
edited channel test
MonaRahmani Oct 8, 2020
5326903
def details added for user and channel
MonaRahmani Oct 8, 2020
ff0817a
def send_message added
MonaRahmani Oct 8, 2020
1f3f1c2
test passes
MonaRahmani Oct 8, 2020
b25fd29
last push
MonaRahmani Oct 8, 2020
056e7ac
commit so I can pull
StacyLundquist Oct 8, 2020
ad9f987
Merge branch 'master' of https://github.com/MonaRahmani/slack-cli int…
StacyLundquist Oct 8, 2020
f183941
test error for channel fixed
MonaRahmani Oct 8, 2020
405efc9
asedf
StacyLundquist Oct 8, 2020
57413c2
latest version
MonaRahmani Oct 8, 2020
75d4510
Revert "asedf"
StacyLundquist Oct 8, 2020
1130c34
revert asedf
StacyLundquist Oct 8, 2020
883a744
reset channel
StacyLundquist Oct 8, 2020
919b362
reset recipient
StacyLundquist Oct 8, 2020
f822985
reset slack
StacyLundquist Oct 8, 2020
b94443d
reset user
StacyLundquist Oct 8, 2020
7a12649
reset workspace
StacyLundquist Oct 8, 2020
f0293fa
workspace reset
StacyLundquist Oct 8, 2020
a290ed9
user_test reset
StacyLundquist Oct 8, 2020
1df996c
recipient_test reset
StacyLundquist Oct 8, 2020
c9eeb86
channel_test reset
StacyLundquist Oct 8, 2020
a15ccac
still working
MonaRahmani Oct 8, 2020
949a8cf
Merge branch 'master' of https://github.com/MonaRahmani/slack-cli int…
MonaRahmani Oct 8, 2020
ca8bbaf
workspace & recipient tets added - working on passing the test
MonaRahmani Oct 9, 2020
de5cc4e
all tests passed
MonaRahmani Oct 9, 2020
6456bad
Adding terminal table
StacyLundquist Oct 9, 2020
e38cf05
Adding use of table print
StacyLundquist Oct 9, 2020
a1f200f
added option to select with number
StacyLundquist Oct 9, 2020
548dfc8
7
StacyLundquist Oct 9, 2020
eae11aa
added token to lib
StacyLundquist Oct 9, 2020
cbbb447
upating
StacyLundquist Oct 9, 2020
93e8000
fixed slack-line-23. Removed bug.
StacyLundquist Oct 9, 2020
4b2dfc1
slack.rb line 41 bug fix
StacyLundquist Oct 9, 2020
387c217
recipient.rb formatting fix
StacyLundquist Oct 9, 2020
e94d74e
final typo changes. Final push.
StacyLundquist Oct 9, 2020
fad5ba7
final push
MonaRahmani Oct 9, 2020
e258fcb
activated API again
MonaRahmani Oct 10, 2020
1cdf44d
small correction
MonaRahmani Oct 10, 2020
a4a33a4
token changed
MonaRahmani Oct 10, 2020
774b4bb
.env added
MonaRahmani Oct 10, 2020
4971df7
.env added to .git ignore
MonaRahmani Oct 10, 2020
71c2d89
new api
MonaRahmani Oct 10, 2020
512c078
had to remove api, I couldnt hide it
MonaRahmani Oct 10, 2020
136ceed
header added to the post request
MonaRahmani Oct 10, 2020
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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SLACK_TOKEN=

Choose a reason for hiding this comment

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

uh oh!

Choose a reason for hiding this comment

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

When something like this happens, it's good to make sure it also gets deleted from the workspace. :)

9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@
.DS_Store

# Ignore environemnt variables
.env
lib/.env



coverage

.rvmrc
.env
34 changes: 34 additions & 0 deletions lib/channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require_relative 'recipient'

class Channel < Recipient

attr_reader :topic, :member_count

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

def details
#prints info for currently selected channel, if not, should let user know and return to main command prompt
detailed_info = "Slack_id: #{slack_id}, Name: #{@name}, Member Count: #{@member_count}"
return detailed_info
end

def self.list_all
response = get(CHANNEL_LIST, {token: ENV['SLACK_TOKEN']})
channels = []
response["channels"].each do |channel|
new_channel = new(
name: channel["name"],
slack_id: channel["id"],
topic: channel["topic"]["value"],
member_count: channel["num_members"]
)
channels << new_channel
end
return channels
end

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

class SlackAPIError < StandardError; end

class Recipient
CHANNEL_LIST = 'https://slack.com/api/conversations.list'
USER_LIST = 'https://slack.com/api/users.list'
MESSAGE_LIST = 'https://slack.com/api/chat.postMessage'

Choose a reason for hiding this comment

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

MESSAGE_LIST seems like a copy paste name for this. Perhaps MESSAGE_SEND or MESSAGE_URL instead?


attr_reader :slack_id, :name

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

def send_message(message)
response = HTTParty.post(
MESSAGE_LIST,
headers: { 'Content-Type' => 'application/x-www-form-urlencoded' },
body: {
token: ENV['SLACK_TOKEN'],
text: message,
channel: @slack_id
})
unless response['ok'] == true
raise SlackAPIError, "API call failed with reason #{response['error']}"
end
return true
end


def self.get(url, params)
response = HTTParty.get(url, query: params)

if !response["ok"]
raise SlackAPIError, "API call failed with reason #{response['error']}"
end
return response
end

def details
raise NotImplementedError, 'Implement me in a child class!'
end

def self.list_all
raise NotImplementedError, 'Implement me in a child class!'
end

end
55 changes: 53 additions & 2 deletions lib/slack.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,63 @@
#!/usr/bin/env ruby
require_relative 'workspace'
require 'dotenv'
require 'table_print'
require 'terminal-table'

def main

Dotenv.load
puts "Welcome to the Ada Slack CLI!"
workspace = Workspace.new

# TODO project
user_input = request_input
until user_input == "quit"

case user_input
when "list users", '1'
tp workspace.users, :name, :slack_id, :real_name
when "list channels", '2'
tp workspace.channels, :name, :topic, :member_count, :slack_id
when "select user", '3'
puts "What is the slack Id"
id = gets.chomp
unless workspace.select_user(id).nil?
puts "enter details to see information about #{id}"
puts "enter send message to send a message to #{id}"
end
when "select channel", '4'
puts "Please type the channel name: "
id = gets.chomp
if workspace.select_channel(id).nil?
puts "#{id} is not a channel, try again?"
else
puts "enter details to see information about #{id}"
puts "enter 'send message' to send a message to #{id}"
end
when "details", '5'
puts workspace.show_details
when "send message", '6'
puts "Please type your message: "
message = gets.chomp
unless workspace.send_message(message).nil?
puts "Your message was sent!"
end
when "quit", '7'
break
end
puts "======================================="
puts "Would you like to select another option?"
user_input = request_input
end
puts "Thank you for using the Ada Slack CLI"
end
def request_input
options_table = [[1, 'List Users'], [2, 'List Channels'], [3, 'Select User'],
[4, 'Select Channel'], [5, 'Details'], [6, 'Send Message'], [7, 'QUIT']]

options = Terminal::Table.new :title => 'What would you like to do?', :rows => options_table
puts options

main if __FILE__ == $PROGRAM_NAME
return gets.chomp.downcase
end
main if __FILE__ == $PROGRAM_NAME
37 changes: 37 additions & 0 deletions lib/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require_relative 'recipient'

class User < Recipient

attr_reader :real_name, :status_text, :status_emoji

def initialize(name:, slack_id:, real_name:, status_text:, status_emoji:)
super(name: name, slack_id: slack_id)
@real_name = real_name
@status_text = status_text
@status_emoji = status_emoji
end

def details
#prints info for currently selected user, if not, should let user know and return to main command prompt
detailed_info = "Slack_id: #{@slack_id}, Name: #{@name}"
return detailed_info
end

def self.list_all
users = []
# get method defined in recipient.rb
response = get(USER_LIST, {token: ENV['SLACK_TOKEN']})
response["members"].each do |user|
new_user = new(
name: user["name"],
slack_id: user["id"],
real_name: user["profile"]["real_name"],
status_text: user["profile"]["status_text"],
status_emoji: user["profile"]["status_emoji"]
)
users << new_user
end
return users
end
end

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


class Workspace

attr_reader :users, :channels
attr_accessor :selected

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

def select_channel(id)
requested_channel = @channels.find do |channel|
channel.slack_id == id || channel.name == id
end
@selected = requested_channel
return @selected
end


def select_user(id)
user = @users.find do |user|
user.slack_id == id || user.name == id
end
@selected = user
puts "#{id} not exist" if @selected.nil?
return @selected
end


def show_details
if @selected.nil?
puts "Nothing selected, pick a user or channel first."
else
return @selected.details
end
end

def send_message(message)
if @selected.nil?
puts "No recipient selected"
else
begin
return @selected.send_message(message)
rescue SlackAPIError => exception
puts "error: #{exception}"
end

end
end
end





Loading