Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions Untitled 3.rtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{\rtf1\ansi\ansicpg1252\cocoartf2511
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fnil\fcharset0 Menlo-Regular;}
{\colortbl;\red255\green255\blue255;\red242\green242\blue242;\red0\green0\blue0;}
{\*\expandedcolortbl;;\csgray\c95825;\csgray\c0\c85000;}
\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\partightenfactor0

\f0\fs22 \cf2 \cb3 \CocoaLigature0 1\
[#<UserRecipient:0x00007ff73e40c968 @slack_id="USLACKBOT", @name="slackbot", @real_name="Slackbot", @status_text="", @status_emoji="">, #<UserRecipient:0x00007ff73e40c940 @slack_id="UUVTJ2NPK", @name="quinruby0", @real_name="quin", @status_text="", @status_emoji="">, #<UserRecipient:0x00007ff73e40c918 @slack_id="UV5RDS2GL", @name="timequinapi_project", @real_name="timequinapi_project", @status_text="", @status_emoji="">]\
Choose from the following: \
1. list users\
2. list channels\
3. select user\
4. select channel\
5. details\
\
-1. quit\
\
2\
[#<ChannelRecipient:0x00007ff73d132360 @slack_id="CUUG9HF6X", @name="general", @topic=\{"value"=>"Company-wide announcements and work-based matters", "creator"=>"UUVTJ2NPK", "last_set"=>1583865667\}, @member_count=1>, #<ChannelRecipient:0x00007ff73d132338 @slack_id="CUVKG668J", @name="creating-another-channel", @topic=\{"value"=>"", "creator"=>"", "last_set"=>0\}, @member_count=1>, #<ChannelRecipient:0x00007ff73d132310 @slack_id="CUYATKU49", @name="one-more", @topic=\{"value"=>"", "creator"=>"", "last_set"=>0\}, @member_count=1>, #<ChannelRecipient:0x00007ff73d1322e8 @slack_id="CV60LSW0Y", @name="quin-api-test", @topic=\{"value"=>"", "creator"=>"", "last_set"=>0\}, @member_count=1>, #<ChannelRecipient:0x00007ff73d1322c0 @slack_id="CV86THB7G", @name="random", @topic=\{"value"=>"Non-work banter and water cooler conversation", "creator"=>"UUVTJ2NPK", "last_set"=>1583865667\}, @member_count=1>]\
Choose from the following: \
}
48 changes: 48 additions & 0 deletions lib/channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

require_relative 'recipient'
require 'httparty'
require 'dotenv'


class ChannelRecipient < Recipient
attr_reader :topic, :member_count

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

def details
pretty_string = "DETAILS:
Slack ID: #{@slack_id}
Name: #{@name}
Topic: #{@topic}
Member Count: #{@member_count}
"
return pretty_string
end

def self.list_all
query = {
token: ENV["SLACK_TOKEN"]
}
response = HTTParty.get(BASE_URL + "conversations.list", query: query)

channels = response["channels"]
channels_array = []
channels.each do |channel|
channels_array << ChannelRecipient.new(channel["id"], channel["name"], channel["topic"], channel["num_members"])
end
return channels_array
end

def self.find(id)
self.list_all.each do |channel|
if id == channel.slack_id
return channel
end
end
return "CHANNEL NOT FOUND"
end
end
36 changes: 36 additions & 0 deletions lib/recipient.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#both user and channel can inherit
require 'httparty'
require 'dotenv'

BASE_URL = "https://slack.com/api/"

Dotenv.load

class Recipient
attr_reader :slack_id, :name

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

end

def details
#override
end

def self.list_all
#override
end

def send_message(message)
query = {
token: ENV["SLACK_TOKEN"],
text: message,
channel: @slack_id
}
response = HTTParty.post(BASE_URL + "chat.postMessage", query: query)
return response
end
end

60 changes: 56 additions & 4 deletions lib/slack.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,64 @@
#!/usr/bin/env ruby
require_relative 'workspace'
require 'dotenv'
require 'httparty'
require 'table_print'


def ask_again
puts "Choose from the following:
1. list users
2. list channels
3. select user
4. select channel
5. details
6. send message

-1. quit
"
return gets.chomp.to_i
end


def main
workspace = Workspace.new()
puts "Welcome to the Ada Slack CLI!"
workspace = Workspace.new

# TODO project
input = ask_again
recipient = nil
while input != -1

if input == 1
tp workspace.list_users, :slack_id, :name, :real_name, :status_text, :status_emoji

input = ask_again
elsif input == 2
tp workspace.list_channels, :slack_id, :name, :topic, :member_count
input = ask_again
elsif input == 3
puts "What is the user's ID?"
recipient = workspace.select_user(gets.chomp)
puts "User: #{recipient}"
input = ask_again
elsif input == 4
puts "What is the channels's ID?"
recipient = workspace.select_channel(gets.chomp)
puts "Channel: #{recipient}"
input = ask_again
elsif input == 5
puts workspace.get_details
input = ask_again
elsif input == 6
puts "Input the message you would like to send:"
workspace.send_message(gets.chomp)
input = ask_again
else
puts "You did not enter a valid number"
input = ask_again
end
end
puts "Thank you for using the Ada Slack CLI"
end

main if __FILE__ == $PROGRAM_NAME
main if __FILE__ == $PROGRAM_NAME


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



class UserRecipient < Recipient
attr_reader :real_name, :status_text, :status_emoji

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

end

def details
pretty_string = "DETAILS:
Slack ID: #{@slack_id}
Name: #{@name}
Real Name: #{@real_name}
Status Text: #{@status_text}
Status Emoji: #{@status_emoji}
"
return pretty_string

end

def self.list_all
query = {
token: ENV["SLACK_TOKEN"]
}
response = HTTParty.get(BASE_URL + "users.list", query: query)
users = response["members"]
name_array = []
users.each do |user|
name_array << UserRecipient.new(user["id"], user["name"],user["profile"]["real_name"], user["profile"]["status_text"], user["profile"]["status_emoji"])
end
return name_array
end

def self.find(id)

self.list_all.each do |user|
if id == user.slack_id
return user
end
end
return "USER NOT FOUND"
end

end

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




class Workspace

attr_reader :users, :channels, :selected

def initialize
@users = UserRecipient.list_all
@channels = ChannelRecipient.list_all
@selected = selected

end
def list_users
return @users
end

def list_channels
return @channels
end

def select_user(id)
@selected = UserRecipient.find(id)
return @selected
end

def select_channel(id)
@selected = ChannelRecipient.find(id)
return @selected
end

def get_details
if @selected.instance_of?(UserRecipient) || @selected.instance_of?(ChannelRecipient)
return @selected.details
else
return "You have not chosen a user or channel, can't grab details for ya"
end
end

def send_message(message)
if selected.instance_of? UserRecipient
@selected.send_message(message)
elsif selected.instance_of? ChannelRecipient
@selected.send_message(message)
end
end

end

Loading